|
|
package chance
|
|
|
|
|
|
import (
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"opp/services/agg"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
//SiftingPool 筛选池
|
|
|
func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) {
|
|
|
var (
|
|
|
ormItems []protocol.ChanceSiftItemOrm
|
|
|
)
|
|
|
rsp = &protocol.SiftingPoolResponse{}
|
|
|
rsp.List = make([]protocol.CommonListItem, 0)
|
|
|
//测试使用
|
|
|
if request.Uid != 0 {
|
|
|
header.UserId = request.Uid
|
|
|
}
|
|
|
if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(ormItems); i++ {
|
|
|
ormItem := ormItems[i]
|
|
|
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
|
|
|
commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000
|
|
|
if request.SubmitStatus == protocol.Submited {
|
|
|
commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//筛选结果
|
|
|
func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) {
|
|
|
var (
|
|
|
ormItems []protocol.ChanceSiftResultOrm
|
|
|
)
|
|
|
rsp = &protocol.SiftingResultsResponse{}
|
|
|
rsp.List = make([]protocol.CommonListItem, 0)
|
|
|
//测试使用
|
|
|
if request.Uid != 0 {
|
|
|
header.UserId = request.Uid
|
|
|
}
|
|
|
if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(ormItems); i++ {
|
|
|
ormItem := ormItems[i]
|
|
|
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
|
|
|
commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//提交自查
|
|
|
func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecksRequest) (rsp *protocol.SubmitChecksResponse, err error) {
|
|
|
var (
|
|
|
p *models.AuditFlowProcess
|
|
|
)
|
|
|
//测试
|
|
|
if request.Uid != 0 {
|
|
|
header.UserId = request.Uid
|
|
|
}
|
|
|
if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
|
|
|
log.Error(request.ChanceId, header.UserId, err)
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.SubmitChecksResponse{}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
var (
|
|
|
DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? `
|
|
|
UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?`
|
|
|
UpdateChanceCheckResultStatus = `update chance set check_result_status=? where id=? and (check_result_status=? or check_result_status is null)`
|
|
|
)
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
var groupIdx = -1
|
|
|
for i := range request.SelfChecks {
|
|
|
c := request.SelfChecks[i]
|
|
|
m := NewChanceCheckResult(c, request.ChanceId, header.UserId)
|
|
|
if groupIdx == -1 || request.SelfChecks[groupIdx].GroupId != request.SelfChecks[i].GroupId {
|
|
|
groupIdx = i
|
|
|
}
|
|
|
if c.Id == 0 {
|
|
|
m.CheckId = i + 1
|
|
|
m.CheckPid = int64(groupIdx + 1)
|
|
|
if groupIdx == i {
|
|
|
m.CheckPid = 0
|
|
|
}
|
|
|
} else {
|
|
|
m.CheckId = int(c.Id)
|
|
|
m.CheckPid = int64(c.ParentId)
|
|
|
}
|
|
|
if _, err = o.Insert(m); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//更新审核人提交状态
|
|
|
if p.SubmitCheckStatus == protocol.Submiting {
|
|
|
//更新
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, UpdateCommitStatus, protocol.Submited, request.ChanceId, p.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//插入一条数据
|
|
|
}
|
|
|
//更新机会筛选状态
|
|
|
if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, request.ChanceId, protocol.None); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
o.Commit()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func NewChanceCheckResult(c protocol.SelfCheck, chanceId int64, uid int64) *models.ChanceCheckResult {
|
|
|
return &models.ChanceCheckResult{
|
|
|
Id: idgen.Next(),
|
|
|
ChanceId: chanceId,
|
|
|
GroupId: c.GroupId,
|
|
|
CheckItem: c.CheckItem,
|
|
|
Answer: c.Answer,
|
|
|
Reason: c.Reason,
|
|
|
UserCompanyId: uid,
|
|
|
CreateAt: time.Now(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//判断审核人筛选结果是否都已提交
|
|
|
func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
|
|
|
var (
|
|
|
audits []*models.AuditFlowProcess
|
|
|
submiters []int64
|
|
|
)
|
|
|
result = false
|
|
|
if audits, err = models.GetChanceAllAuditors(chanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if submiters, err = models.GetCheckResultAllSubmitters(chanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if len(audits) == len(submiters) {
|
|
|
result = true
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|