|
@@ -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 (
|