作者 yangfu

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

@@ -36,8 +36,9 @@ type Chance struct { @@ -36,8 +36,9 @@ type Chance struct {
36 Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"` 36 Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
37 Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "` 37 Status int8 `orm:"column(status)" description:"状态 1:开启 2:关闭 "`
38 SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"` 38 SelfChecks string `orm:"column(self_checks);size(1000);null" description:"自查内容"`
39 - SubmitCheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`  
40 - SubmitCheckStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"` 39 + CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
  40 + CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
  41 + CheckResult string `orm:"column(check_result);null" description:"筛选结果"`
41 } 42 }
42 43
43 const ( 44 const (
@@ -538,3 +538,26 @@ func GetChanceType(chanceTypeId int) protocol.NameItem { @@ -538,3 +538,26 @@ func GetChanceType(chanceTypeId int) protocol.NameItem {
538 } 538 }
539 return protocol.NameItem{} 539 return protocol.NameItem{}
540 } 540 }
  541 +
  542 +//获取自查内容 筛选前使用SelfChecks(提交人的筛查结果)
  543 +func GetChanceSelfChecks(chanceInfo *models.Chance) []protocol.SelfCheck {
  544 + var selfChecks []protocol.SelfCheck = make([]protocol.SelfCheck, 0)
  545 + switch chanceInfo.CheckResultStatus {
  546 + case protocol.None: //未提交筛查结果
  547 + utils.JsonUnmarshal(chanceInfo.SelfChecks, &selfChecks)
  548 + break
  549 + case protocol.Waiting: //未通过审核的返回所有筛查结果(一级/二级)
  550 + utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
  551 + break
  552 + default: //审核通过/不通过只显示一级
  553 + utils.JsonUnmarshal(chanceInfo.CheckResult, &selfChecks)
  554 + var lv1List []protocol.SelfCheck
  555 + for i := 0; i < len(selfChecks); i++ {
  556 + if selfChecks[i].ParentId == 0 {
  557 + lv1List = append(lv1List, selfChecks[i])
  558 + }
  559 + }
  560 + return lv1List
  561 + }
  562 + return selfChecks
  563 +}
@@ -1970,7 +1970,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail @@ -1970,7 +1970,8 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail
1970 UpdateTime: chance.UpdateAt.Unix() * 1000, 1970 UpdateTime: chance.UpdateAt.Unix() * 1000,
1971 } 1971 }
1972 jsonUnmarshal(chance.SourceContent, &item.FormList) 1972 jsonUnmarshal(chance.SourceContent, &item.FormList)
1973 - jsonUnmarshal(chance.SelfChecks, &item.SelfChecks) 1973 + //jsonUnmarshal(chance.SelfChecks, &item.SelfChecks)
  1974 + item.SelfChecks = agg.GetChanceSelfChecks(chance)
1974 item.FormList = clearEmptyForm(item.FormList) 1975 item.FormList = clearEmptyForm(item.FormList)
1975 1976
1976 if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil { 1977 if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
@@ -3,6 +3,7 @@ package chance @@ -3,6 +3,7 @@ package chance
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/astaxie/beego/orm" 5 "github.com/astaxie/beego/orm"
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" 7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
8 "opp/internal/utils" 9 "opp/internal/utils"
@@ -99,7 +100,7 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks @@ -99,7 +100,7 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks
99 var ( 100 var (
100 DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? ` 101 DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? `
101 UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?` 102 UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?`
102 - UpdateChanceCheckResultStatus = `update chance set check_result_status=? where id=? and (check_result_status=? or check_result_status is null)` 103 + UpdateChanceCheckResultStatus = `update chance set check_result_status=?,check_result=? where id=?`
103 ) 104 )
104 if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil { 105 if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
105 log.Error(err) 106 log.Error(err)
@@ -139,16 +140,21 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks @@ -139,16 +140,21 @@ func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecks
139 } 140 }
140 //插入一条数据 141 //插入一条数据
141 } 142 }
  143 + o.Commit()
  144 +
142 //更新机会筛选状态 145 //更新机会筛选状态
143 if _, result := CheckIsCommitAllCheck(request.ChanceId); result { 146 if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
144 - if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, request.ChanceId, protocol.None); err != nil { 147 + var results []*models.ChanceCheckResult
  148 + if results, err = models.GetCheckResultsByChanceId(request.ChanceId); err != nil {
  149 + log.Error(err)
  150 + return
  151 + }
  152 + var checkResult = collectChanceCheckResultData(results)
  153 + if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, common.AssertJson(checkResult), request.ChanceId); err != nil {
145 log.Error(err) 154 log.Error(err)
146 - o.Rollback()  
147 return 155 return
148 } 156 }
149 } 157 }
150 -  
151 - o.Commit()  
152 return 158 return
153 } 159 }
154 160
@@ -186,6 +192,100 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) { @@ -186,6 +192,100 @@ func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
186 return 192 return
187 } 193 }
188 194
  195 +type chanceCheckResultTotal struct {
  196 + GroupId int64
  197 + CheckItem string
  198 + CheckId int64
  199 + CheckPid int64
  200 + AnswerYes int
  201 + AnswerNo int
  202 + AnswerAny int
  203 + Child []*chanceCheckResultTotal
  204 +}
  205 +
  206 +//collectChanceCheckResultData 汇总机会自查内容筛选结果
  207 +func collectChanceCheckResultData(checkResultData []*models.ChanceCheckResult) protocol.SelfChecks {
  208 + checkResultMap := map[int]*chanceCheckResultTotal{}
  209 + checkResultSlice := []*chanceCheckResultTotal{}
  210 + for _, resultData := range checkResultData {
  211 + answerYes := 0
  212 + answerNo := 0
  213 + answerAny := 0
  214 + switch resultData.Answer {
  215 + case "是":
  216 + answerYes++
  217 + case "否":
  218 + answerNo++
  219 + case "不清楚":
  220 + answerAny++
  221 + }
  222 + if _, ok := checkResultMap[resultData.CheckId]; !ok {
  223 + r := &chanceCheckResultTotal{
  224 + CheckId: int64(resultData.CheckId),
  225 + CheckPid: resultData.CheckPid,
  226 + CheckItem: resultData.CheckItem,
  227 + GroupId: resultData.GroupId,
  228 + AnswerYes: answerYes,
  229 + AnswerNo: answerNo,
  230 + AnswerAny: answerAny,
  231 + }
  232 + checkResultMap[resultData.CheckId] = r
  233 + checkResultSlice = append(checkResultSlice, r)
  234 + } else {
  235 + checkResultMap[resultData.CheckId].AnswerYes += answerYes
  236 + checkResultMap[resultData.CheckId].AnswerNo += answerNo
  237 + checkResultMap[resultData.CheckId].AnswerAny += answerAny
  238 + }
  239 + }
  240 + //构建层级关系
  241 + for i := range checkResultSlice {
  242 + if checkResultSlice[i].CheckPid == 0 {
  243 + continue
  244 + }
  245 + pid := int(checkResultSlice[i].CheckPid)
  246 + if _, ok := checkResultMap[pid]; ok {
  247 + checkResultMap[pid].Child = append(checkResultMap[pid].Child, checkResultSlice[i])
  248 + }
  249 + }
  250 + var selfCheckData []protocol.SelfCheck
  251 + for i := range checkResultSlice {
  252 + if checkResultSlice[i].CheckPid > 0 {
  253 + continue
  254 + }
  255 + dd := protocol.SelfCheck{
  256 + CheckItem: checkResultSlice[i].CheckItem,
  257 + GroupId: checkResultSlice[i].GroupId,
  258 + ParentId: checkResultSlice[i].CheckPid,
  259 + Id: checkResultSlice[i].CheckId,
  260 + }
  261 + if checkResultSlice[i].AnswerYes > 0 {
  262 + dd.Answer = protocol.OptionNo
  263 + } else if checkResultSlice[i].AnswerNo > 0 {
  264 + dd.Answer = protocol.OptionYes
  265 + } else if checkResultSlice[i].AnswerAny > 0 {
  266 + dd.Answer = protocol.OptionNoCertain
  267 + }
  268 + selfCheckData = append(selfCheckData, dd)
  269 + for _, child := range checkResultSlice[i].Child {
  270 + dd := protocol.SelfCheck{
  271 + CheckItem: child.CheckItem,
  272 + GroupId: child.GroupId,
  273 + ParentId: checkResultSlice[i].CheckPid,
  274 + Id: checkResultSlice[i].CheckId,
  275 + }
  276 + if child.AnswerYes > 0 {
  277 + dd.Answer = protocol.OptionYes
  278 + } else if child.AnswerNo > 0 {
  279 + dd.Answer = protocol.OptionNo
  280 + } else if child.AnswerAny > 0 {
  281 + dd.Answer = protocol.OptionNoCertain
  282 + }
  283 + selfCheckData = append(selfCheckData, dd)
  284 + }
  285 + }
  286 + return selfCheckData
  287 +}
  288 +
189 //筛选历史 289 //筛选历史
190 func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) { 290 func SiftingResultsItemHistory(header *protocol.RequestHeader, request *protocol.SiftingResultsItemHistoryRequest) (rsp *protocol.SiftingResultsItemHistoryResponse, err error) {
191 var ( 291 var (