作者 yangfu

修改 提交筛选结果 / 机会详情(自查内容)

... ... @@ -36,8 +36,9 @@ type Chance struct {
Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "`
SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"`
SubmitCheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
SubmitCheckStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
CheckResult string `orm:"column(check_result);null" description:"筛选结果"`
}
const (
... ...
... ... @@ -538,3 +538,26 @@ func GetChanceType(chanceTypeId int) protocol.NameItem {
}
return protocol.NameItem{}
}
//获取自查内容 筛选前使用SelfChecks(提交人的筛查结果)
func GetChanceSelfChecks(chanceInfo *models.Chance) []protocol.SelfCheck {
var selfChecks []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
switch chanceInfo.CheckResultStatus {
case protocol.None: //未提交筛查结果
utils.JsonUnmarshal(chanceInfo.SelfChecks, &selfChecks)
break
case protocol.Waiting: //未通过审核的返回所有筛查结果(一级/二级)
utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
break
default: //审核通过/不通过只显示一级
utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
var lv1List []protocol.SelfCheck
for i := 0; i < len(selfChecks); i++ {
if selfChecks[i].ParentId == 0 {
lv1List = append(lv1List, selfChecks[i])
}
}
return lv1List
}
return selfChecks
}
... ...
... ... @@ -1970,7 +1970,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
UpdateTime: chance.UpdateAt.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
//jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
item.SelfChecks = agg.GetChanceSelfChecks(chance)
item.FormList = clearEmptyForm(item.FormList)
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
... ...
... ... @@ -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 (
... ...