...
|
...
|
@@ -3,6 +3,7 @@ package chance |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"opp/internal/utils"
|
...
|
...
|
@@ -99,7 +100,7 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks |
|
|
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)`
|
|
|
UpdateChanceCheckResultStatus = `update chance set check_result_status=?,check_result=? where id=?`
|
|
|
)
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -139,16 +140,21 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks |
|
|
}
|
|
|
//插入一条数据
|
|
|
}
|
|
|
o.Commit()
|
|
|
|
|
|
//更新机会筛选状态
|
|
|
if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, request.ChanceId, protocol.None); err != nil {
|
|
|
var results []*models.ChanceCheckResult
|
|
|
if results, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
var checkResult = collectChanceCheckResultData(results)
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, common.AssertJson(checkResult), request.ChanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
o.Commit()
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -186,6 +192,100 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) { |
|
|
return
|
|
|
}
|
|
|
|
|
|
type chanceCheckResultTotal struct {
|
|
|
GroupId int64
|
|
|
CheckItem string
|
|
|
CheckId int64
|
|
|
CheckPid int64
|
|
|
AnswerYes int
|
|
|
AnswerNo int
|
|
|
AnswerAny int
|
|
|
Child []*chanceCheckResultTotal
|
|
|
}
|
|
|
|
|
|
//collectChanceCheckResultData 汇总机会自查内容筛选结果
|
|
|
func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) protocol.SelfChecks {
|
|
|
checkResultMap := map[int]*chanceCheckResultTotal{}
|
|
|
checkResultSlice := []*chanceCheckResultTotal{}
|
|
|
for _, resultData := range checkResultData {
|
|
|
answerYes := 0
|
|
|
answerNo := 0
|
|
|
answerAny := 0
|
|
|
switch resultData.Answer {
|
|
|
case "是":
|
|
|
answerYes++
|
|
|
case "否":
|
|
|
answerNo++
|
|
|
case "不清楚":
|
|
|
answerAny++
|
|
|
}
|
|
|
if _, ok := checkResultMap[resultData.CheckId]; !ok {
|
|
|
r := &chanceCheckResultTotal{
|
|
|
CheckId: int64(resultData.CheckId),
|
|
|
CheckPid: resultData.CheckPid,
|
|
|
CheckItem: resultData.CheckItem,
|
|
|
GroupId: resultData.GroupId,
|
|
|
AnswerYes: answerYes,
|
|
|
AnswerNo: answerNo,
|
|
|
AnswerAny: answerAny,
|
|
|
}
|
|
|
checkResultMap[resultData.CheckId] = r
|
|
|
checkResultSlice = append(checkResultSlice, r)
|
|
|
} else {
|
|
|
checkResultMap[resultData.CheckId].AnswerYes += answerYes
|
|
|
checkResultMap[resultData.CheckId].AnswerNo += answerNo
|
|
|
checkResultMap[resultData.CheckId].AnswerAny += answerAny
|
|
|
}
|
|
|
}
|
|
|
//构建层级关系
|
|
|
for i := range checkResultSlice {
|
|
|
if checkResultSlice[i].CheckPid == 0 {
|
|
|
continue
|
|
|
}
|
|
|
pid := int(checkResultSlice[i].CheckPid)
|
|
|
if _, ok := checkResultMap[pid]; ok {
|
|
|
checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkResultSlice[i])
|
|
|
}
|
|
|
}
|
|
|
var selfCheckData []protocol.SelfCheck
|
|
|
for i := range checkResultSlice {
|
|
|
if checkResultSlice[i].CheckPid > 0 {
|
|
|
continue
|
|
|
}
|
|
|
dd := protocol.SelfCheck{
|
|
|
CheckItem: checkResultSlice[i].CheckItem,
|
|
|
GroupId: checkResultSlice[i].GroupId,
|
|
|
ParentId: checkResultSlice[i].CheckPid,
|
|
|
Id: checkResultSlice[i].CheckId,
|
|
|
}
|
|
|
if checkResultSlice[i].AnswerYes > 0 {
|
|
|
dd.Answer = protocol.OptionNo
|
|
|
} else if checkResultSlice[i].AnswerNo > 0 {
|
|
|
dd.Answer = protocol.OptionYes
|
|
|
} else if checkResultSlice[i].AnswerAny > 0 {
|
|
|
dd.Answer = protocol.OptionNoCertain
|
|
|
}
|
|
|
selfCheckData = append(selfCheckData, dd)
|
|
|
for _, child := range checkResultSlice[i].Child {
|
|
|
dd := protocol.SelfCheck{
|
|
|
CheckItem: child.CheckItem,
|
|
|
GroupId: child.GroupId,
|
|
|
ParentId: checkResultSlice[i].CheckPid,
|
|
|
Id: checkResultSlice[i].CheckId,
|
|
|
}
|
|
|
if child.AnswerYes > 0 {
|
|
|
dd.Answer = protocol.OptionYes
|
|
|
} else if child.AnswerNo > 0 {
|
|
|
dd.Answer = protocol.OptionNo
|
|
|
} else if child.AnswerAny > 0 {
|
|
|
dd.Answer = protocol.OptionNoCertain
|
|
|
}
|
|
|
selfCheckData = append(selfCheckData, dd)
|
|
|
}
|
|
|
}
|
|
|
return selfCheckData
|
|
|
}
|
|
|
|
|
|
//筛选历史
|
|
|
func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) {
|
|
|
var (
|
...
|
...
|
|