作者 yangfu

重构-我审核的机会

@@ -140,14 +140,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab @@ -140,14 +140,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab
140 140
141 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 141 func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
142 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 142 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
143 -select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status from ( 143 +select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status from (
144 select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time 144 select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
145 from audit_flow_process where uid=? and review_status in (%v) 145 from audit_flow_process where uid=? and review_status in (%v)
146 )a left outer join chance b on a.chance_id = b.id 146 )a left outer join chance b on a.chance_id = b.id
147 )a left outer join chance_data b on a.chance_id =b.chance_id 147 )a left outer join chance_data b on a.chance_id =b.chance_id
148 where (?=0 or unix_timestamp(a.update_at)<?) 148 where (?=0 or unix_timestamp(a.update_at)<?)
149 order by a.update_at desc 149 order by a.update_at desc
150 -LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除 150 +LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //备注:and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
151 151
152 sqlCount := fmt.Sprintf(`select count(0) 152 sqlCount := fmt.Sprintf(`select count(0)
153 from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 153 from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1
@@ -162,9 +162,10 @@ from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8 @@ -162,9 +162,10 @@ from audit_flow_process where uid=? and review_status in (%v) `, utils.JoinInt8
162 return 162 return
163 } 163 }
164 164
  165 +//获取有效的机会
165 func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) { 166 func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
166 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 167 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
167 -select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status,b.update_at process_create_time,b.self_checks from ( 168 +select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time,b.status,b.update_at process_create_time,b.self_checks from (
168 select id,approve_time,approve_data,uid,chance_id,approve_message 169 select id,approve_time,approve_data,uid,chance_id,approve_message
169 from audit_flow_process where uid=? and review_status in (%v) and enable_status =1 170 from audit_flow_process where uid=? and review_status in (%v) and enable_status =1
170 )a left outer join chance b on a.chance_id = b.id 171 )a left outer join chance b on a.chance_id = b.id
@@ -219,17 +219,18 @@ type MyApproveChanceResponse struct { @@ -219,17 +219,18 @@ type MyApproveChanceResponse struct {
219 219
220 //我的审核机会列表 220 //我的审核机会列表
221 type ChanceApproveItemOrm struct { 221 type ChanceApproveItemOrm struct {
222 - ChanceUserId int64 `orm:"column(user_id)"`  
223 - CreateTime time.Time `orm:"column(create_at)"`  
224 - UpdateTime time.Time `orm:"column(update_at)"`  
225 - ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`  
226 - SourceContent string `orm:"column(source_content)"`  
227 - ChanceEnableStatus int `orm:"column(enable_status)"`  
228 - Images string `orm:"column(images)"`  
229 - Voices string `orm:"column(speechs)"`  
230 - Videos string `orm:"column(videos)"`  
231 - ReviewStatus int `orm:"column(review_status)"`  
232 - Status int `orm:"column(status)"` 222 + //ChanceUserId int64 `orm:"column(user_id)"`
  223 + //CreateTime time.Time `orm:"column(create_at)"`
  224 + //UpdateTime time.Time `orm:"column(update_at)"`
  225 + //ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
  226 + //SourceContent string `orm:"column(source_content)"`
  227 + //ChanceEnableStatus int `orm:"column(enable_status)"`
  228 + //Images string `orm:"column(images)"`
  229 + //Voices string `orm:"column(speechs)"`
  230 + //Videos string `orm:"column(videos)"`
  231 + //ReviewStatus int `orm:"column(review_status)"`
  232 + //Status int `orm:"column(status)"`
  233 + CommChanceItemOrm
233 234
234 Id int64 `orm:"column(id)"` //审核id 235 Id int64 `orm:"column(id)"` //审核id
235 ApproveTime time.Time `orm:"column(approve_time)"` 236 ApproveTime time.Time `orm:"column(approve_time)"`
@@ -363,7 +364,7 @@ type CommChanceItemOrm struct { @@ -363,7 +364,7 @@ type CommChanceItemOrm struct {
363 ChanceUserId int64 `orm:"column(chance_user_id)"` 364 ChanceUserId int64 `orm:"column(chance_user_id)"`
364 CreateTime time.Time `orm:"column(create_at)"` 365 CreateTime time.Time `orm:"column(create_at)"`
365 UpdateTime time.Time `orm:"column(update_at)"` 366 UpdateTime time.Time `orm:"column(update_at)"`
366 - ApproveTime time.Time `orm:"column(chance_approve_time)"` 367 + ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
367 SourceContent string `orm:"column(source_content)"` 368 SourceContent string `orm:"column(source_content)"`
368 ChanceEnableStatus int `orm:"column(enable_status)"` 369 ChanceEnableStatus int `orm:"column(enable_status)"`
369 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过 370 ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
@@ -1607,11 +1607,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1607,11 +1607,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1607 //我审核的机会 1607 //我审核的机会
1608 func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) { 1608 func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) {
1609 var ( 1609 var (
1610 - myChances []protocol.ChanceApproveItemOrm  
1611 - total int  
1612 - provider *protocol.BaseUserInfo 1610 + ormItems []protocol.ChanceApproveItemOrm
1613 chance *models.Chance 1611 chance *models.Chance
1614 ) 1612 )
  1613 + rsp = &protocol.MyApproveChanceResponse{List: make([]protocol.CommonListItem, 0)}
1615 if request.LastId > 0 { 1614 if request.LastId > 0 {
1616 if chance, err = models.GetChanceById(request.LastId); err != nil { 1615 if chance, err = models.GetChanceById(request.LastId); err != nil {
1617 log.Error("审批不存在", request.LastId, err) 1616 log.Error("审批不存在", request.LastId, err)
@@ -1620,7 +1619,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1620,7 +1619,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1620 request.LastId = chance.UpdateAt.Unix() 1619 request.LastId = chance.UpdateAt.Unix()
1621 } 1620 }
1622 if request.ReviewStatus == protocol.ReviewStatusAuditging { 1621 if request.ReviewStatus == protocol.ReviewStatusAuditging {
1623 - if total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1622 + if rsp.Total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1624 if err == orm.ErrNoRows { 1623 if err == orm.ErrNoRows {
1625 err = nil 1624 err = nil
1626 return 1625 return
@@ -1629,7 +1628,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1629,7 +1628,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1629 return 1628 return
1630 } 1629 }
1631 } else { 1630 } else {
1632 - if total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil { 1631 + if rsp.Total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
1633 if err == orm.ErrNoRows { 1632 if err == orm.ErrNoRows {
1634 err = nil 1633 err = nil
1635 return 1634 return
@@ -1638,65 +1637,39 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove @@ -1638,65 +1637,39 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
1638 return 1637 return
1639 } 1638 }
1640 } 1639 }
1641 - rsp = &protocol.MyApproveChanceResponse{Total: total}  
1642 - for i := 0; i < len(myChances); i++ {  
1643 - chance := myChances[i] 1640 + for i := 0; i < len(ormItems); i++ {
  1641 + ormItem := ormItems[i]
1644 commItem := protocol.CommonListItem{} 1642 commItem := protocol.CommonListItem{}
1645 - commItem.ReviewStatus = chance.ReviewStatus  
1646 - if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除  
1647 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1648 - }  
1649 - if chance.Status == models.ChanceStatusClose {  
1650 - commItem.ChanceStatus = protocol.ChanceStatusClose  
1651 - }  
1652 - if chance.ChanceUserId > 0 {  
1653 - if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {  
1654 - commItem.ChanceStatus = protocol.ChanceStatusDelete  
1655 - log.Error(chance.ChanceUserId, header.CompanyId, err)  
1656 - err = nil  
1657 - } else {  
1658 - item := protocol.ChanceItem{  
1659 - Id: chance.ChanceId,  
1660 - Provider: provider,  
1661 - CreateTime: chance.CreateTime.Unix() * 1000,  
1662 - UpdateTime: chance.UpdateTime.Unix() * 1000,  
1663 - ApproveTime: chance.ChanceApproveTime.Unix() * 1000,  
1664 - }  
1665 - if item.ApproveTime < 0 {  
1666 - item.ApproveTime = chance.UpdateTime.Unix() * 1000  
1667 - }  
1668 - jsonUnmarshal(chance.SourceContent, &item.FormList)  
1669 - item.FormList = clearEmptyForm(item.FormList)  
1670 - jsonUnmarshal(chance.Images, &item.Pictures)  
1671 - jsonUnmarshal(chance.Voices, &item.Speechs)  
1672 - jsonUnmarshal(chance.Videos, &item.Videos)  
1673 - commItem.Chance = item  
1674 - }  
1675 - } 1643 + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
  1644 + commItem.ReviewStatus = ormItem.ReviewStatus
  1645 +
  1646 + //审核流数据
1676 approve := protocol.Approve{ 1647 approve := protocol.Approve{
1677 - ProcessId: chance.Id,  
1678 - CreateTime: chance.ProcessCreateTime.Unix() * 1000, 1648 + ProcessId: ormItem.Id,
  1649 + CreateTime: ormItem.ProcessCreateTime.Unix() * 1000,
1679 } 1650 }
1680 - //审核过的有审核时间 1651 + //审核过的机会 有审核时间
1681 if request.ReviewStatus != protocol.ReviewStatusAuditging { 1652 if request.ReviewStatus != protocol.ReviewStatusAuditging {
1682 - approve.ApproveTime = chance.ApproveTime.Unix() * 1000 1653 + approve.ApproveTime = ormItem.ApproveTime.Unix() * 1000
1683 if approve.ApproveTime < 0 { 1654 if approve.ApproveTime < 0 {
1684 - approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000 1655 + approve.ApproveTime = ormItem.ChanceApproveTime.Unix() * 1000
1685 } 1656 }
1686 } 1657 }
1687 commItem.Approve = approve 1658 commItem.Approve = approve
1688 - //审核完有审核数据 1659 +
  1660 + //审核中 有审核消息
1689 if request.ReviewStatus == protocol.ReviewStatusAuditging { 1661 if request.ReviewStatus == protocol.ReviewStatusAuditging {
1690 - commItem.Message = chance.ApproveMessage 1662 + commItem.Message = ormItem.ApproveMessage
1691 } 1663 }
  1664 + //审核通过有审核评分数据
1692 if request.ReviewStatus == protocol.ReviewStatusPass { 1665 if request.ReviewStatus == protocol.ReviewStatusPass {
1693 var approveData *protocol.ApproveData 1666 var approveData *protocol.ApproveData
1694 - jsonUnmarshal(chance.ApproveData, &approveData) 1667 + jsonUnmarshal(ormItem.ApproveData, &approveData)
1695 if approveData != nil { 1668 if approveData != nil {
1696 commItem.Score = approveData.Score 1669 commItem.Score = approveData.Score
1697 } 1670 }
1698 } 1671 }
1699 - commItem.SelfCheckResult = protocol.NewSelfChecks(chance.SelfChecks).Static() 1672 + commItem.SelfCheckResult = protocol.NewSelfChecks(ormItem.SelfChecks).Static() //自查统计数据
1700 rsp.List = append(rsp.List, commItem) 1673 rsp.List = append(rsp.List, commItem)
1701 } 1674 }
1702 return 1675 return