作者 yangfu

重构-我审核的机会

... ... @@ -140,14 +140,14 @@ where user_id=? and company_id=? and review_status in (%v) and status=1 and enab
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,approve_time,approve_data,uid,chance_id,approve_message,update_at process_create_time
from audit_flow_process where uid=? and review_status in (%v)
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.chance_id =b.chance_id
where (?=0 or unix_timestamp(a.update_at)<?)
order by a.update_at desc
LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
LIMIT ?`, utils.JoinInt8s(reviewStatus, ",")) //备注:and enable_status =1 //就算已经删除了,列表上面还是要体现已经删除
sqlCount := fmt.Sprintf(`select count(0)
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
return
}
//获取有效的机会
func GetChanceMyApproveChanceEnable(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
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 (
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 (
select id,approve_time,approve_data,uid,chance_id,approve_message
from audit_flow_process where uid=? and review_status in (%v) and enable_status =1
)a left outer join chance b on a.chance_id = b.id
... ...
... ... @@ -219,17 +219,18 @@ type MyApproveChanceResponse struct {
//我的审核机会列表
type ChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"`
Status int `orm:"column(status)"`
//ChanceUserId int64 `orm:"column(user_id)"`
//CreateTime time.Time `orm:"column(create_at)"`
//UpdateTime time.Time `orm:"column(update_at)"`
//ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
//SourceContent string `orm:"column(source_content)"`
//ChanceEnableStatus int `orm:"column(enable_status)"`
//Images string `orm:"column(images)"`
//Voices string `orm:"column(speechs)"`
//Videos string `orm:"column(videos)"`
//ReviewStatus int `orm:"column(review_status)"`
//Status int `orm:"column(status)"`
CommChanceItemOrm
Id int64 `orm:"column(id)"` //审核id
ApproveTime time.Time `orm:"column(approve_time)"`
... ... @@ -363,7 +364,7 @@ type CommChanceItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ApproveTime time.Time `orm:"column(chance_approve_time)"`
ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
ReviewStatus int `orm:"column(review_status)"` //审核状态 1:待审核 2:被退回 3:已通过
... ...
... ... @@ -1607,11 +1607,10 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
//我审核的机会
func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) {
var (
myChances []protocol.ChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
chance *models.Chance
ormItems []protocol.ChanceApproveItemOrm
chance *models.Chance
)
rsp = &protocol.MyApproveChanceResponse{List: make([]protocol.CommonListItem, 0)}
if request.LastId > 0 {
if chance, err = models.GetChanceById(request.LastId); err != nil {
log.Error("审批不存在", request.LastId, err)
... ... @@ -1620,7 +1619,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
request.LastId = chance.UpdateAt.Unix()
}
if request.ReviewStatus == protocol.ReviewStatusAuditging {
if total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyApproveChanceEnable(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1629,7 +1628,7 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
return
}
} else {
if total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
if rsp.Total, err = models.GetChanceMyApproveChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1638,65 +1637,39 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
return
}
}
rsp = &protocol.MyApproveChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(chance.ChanceUserId, header.CompanyId, err)
err = nil
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ChanceApproveTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = chance.UpdateTime.Unix() * 1000
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
//审核流数据
approve := protocol.Approve{
ProcessId: chance.Id,
CreateTime: chance.ProcessCreateTime.Unix() * 1000,
ProcessId: ormItem.Id,
CreateTime: ormItem.ProcessCreateTime.Unix() * 1000,
}
//审核过的有审核时间
//审核过的机会 有审核时间
if request.ReviewStatus != protocol.ReviewStatusAuditging {
approve.ApproveTime = chance.ApproveTime.Unix() * 1000
approve.ApproveTime = ormItem.ApproveTime.Unix() * 1000
if approve.ApproveTime < 0 {
approve.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
approve.ApproveTime = ormItem.ChanceApproveTime.Unix() * 1000
}
}
commItem.Approve = approve
//审核完有审核数据
//审核中 有审核消息
if request.ReviewStatus == protocol.ReviewStatusAuditging {
commItem.Message = chance.ApproveMessage
commItem.Message = ormItem.ApproveMessage
}
//审核通过有审核评分数据
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData *protocol.ApproveData
jsonUnmarshal(chance.ApproveData, &approveData)
jsonUnmarshal(ormItem.ApproveData, &approveData)
if approveData != nil {
commItem.Score = approveData.Score
}
}
commItem.SelfCheckResult = protocol.NewSelfChecks(chance.SelfChecks).Static()
commItem.SelfCheckResult = protocol.NewSelfChecks(ormItem.SelfChecks).Static() //自查统计数据
rsp.List = append(rsp.List, commItem)
}
return
... ...