check.go
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
package protocol
import (
"bytes"
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"strings"
)
const (
TypeSubmit = iota + 1 //提交者类型
TypeApprove //审核人类型
)
//提交状态
const (
Submiting = iota //待我提交
Submited //我已提交
)
//通过状态
const (
None = iota //未提交
Waiting //已提交待处理
Reject //退回
Pass //通过
)
const (
OptionYes = "是"
OptionNo = "否"
OptionUncertain = "不清楚"
)
/*机会-自查内容*/
var CheckOptionsCommit = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: false}, {Item: "不清楚", NeedOther: false}}
var CheckOptionsApprove = []CheckOption{{Item: "是", NeedOther: false}, {Item: "否", NeedOther: true}, {Item: "不清楚", NeedOther: false}}
/*自查结果列表*/
type SelfCheckResults []selfCheckResult
type selfCheckResult struct {
Item string `json:"item"`
Total int `json:"total"`
}
/*自查项*/
type SelfCheck struct {
CheckItem string `json:"checkItem"`
GroupId int64 `json:"groupId"` //分组
Answer string `json:"answer"`
Reason string `json:"reason"`
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
}
//自查项 键值
func (c SelfCheck) Key() string {
return fmt.Sprintf("%v-%v", c.GroupId, c.CheckItem)
}
//新建自查项列表
//@data json格式的数据体
func NewSelfChecks(data string) (rsp SelfChecks) {
if len(data) == 0 {
return
}
e := json.Unmarshal([]byte(data), &rsp)
if e != nil {
log.Error(e)
}
return
}
/*自查项列表*/
type SelfChecks []SelfCheck
//统计自查结果
func (s SelfChecks) Static() SelfCheckResults {
if len(s) == 0 {
return []selfCheckResult{}
}
results := []selfCheckResult{{Item: "是"}, {Item: "否"}, {Item: "不清楚"}}
var gIdx int64
for i := range s {
check := (s)[i]
if gIdx == check.GroupId {
continue
}
gIdx = check.GroupId
for k := range results {
if strings.EqualFold(results[k].Item, strings.TrimSpace(check.Answer)) {
results[k].Total = results[k].Total + 1
break
}
}
}
return SelfCheckResults(results)
}
//自查校验
func (s SelfChecks) Valid() (err error) {
if len(s) == 0 {
return
}
for i := range s {
c := s[i]
if c.GroupId == 0 {
err = NewErrWithMessage(2)
return
}
if len(c.CheckItem) == 0 {
err = NewErrWithMessage(2)
return
}
if len(c.Answer) == 0 {
err = NewCustomMessage(2, "自查项未填写")
return
}
}
return
}
//自查内容
func (s SelfChecks) String() string {
var buf bytes.Buffer
for i := range s {
c := s[i]
if len(c.Answer) == 0 {
continue
}
if len(c.Reason) == 0 {
buf.WriteString(fmt.Sprintf("\n%v:%v;", c.CheckItem, c.Answer))
} else {
buf.WriteString(fmt.Sprintf("\n%v:%v,理由:%v;", c.CheckItem, c.Answer, c.Reason))
}
}
return buf.String()
}
//比较自查内容 ,返回差级
func (s SelfChecks) Compare(dst string) (rspChecks SelfChecks, err error) {
var (
dstChecks SelfChecks
mapChecks = make(map[string]SelfCheck)
)
rspChecks = make([]SelfCheck, 0)
if len(s) == 0 {
return
}
utils.JsonUnmarshal(dst, &dstChecks)
if len(s) != len(dstChecks) {
err = NewCustomMessage(1, "自查项有误")
log.Error(err, s, dstChecks)
return
}
for i := range dstChecks {
c := dstChecks[i]
mapChecks[c.Key()] = c
}
for i := range s {
c := s[i]
if v, ok := mapChecks[c.Key()]; ok {
if len(c.Answer) == 0 {
continue
}
//回答不一致
if !strings.EqualFold(c.Answer, v.Answer) {
rspChecks = append(rspChecks, c)
continue
}
if len(strings.TrimSpace(c.Reason)) > 0 {
rspChecks = append(rspChecks, c)
continue
}
}
}
return
}
//按规则设置自查 一级自查
func (s SelfChecks) SetSelfChecksLevel1ByRule() (err error) {
if len(s) == 0 {
return
}
s.Format()
var gIdx = -1
for i := 0; i < len(s); i++ {
if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
gIdx = i
} else {
continue
}
hasSub := false
var (
cntYes = 0 //是
cntNo = 0 //否
cntUncertain = 0 //不确定
)
for j := i + 1; j < len(s); j++ {
if s[i].GroupId == s[j].GroupId {
if !hasSub {
hasSub = true
}
} else {
break
}
answer := s[j].Answer
if strings.EqualFold(strings.TrimSpace(answer), OptionYes) {
cntYes++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionNo) {
cntNo++
} else if strings.EqualFold(strings.TrimSpace(answer), OptionUncertain) {
cntUncertain++
}
}
//只有一级维度的必须填写
if hasSub {
if cntYes > 0 {
s[gIdx].Answer = OptionYes
} else if cntNo > 0 {
s[gIdx].Answer = OptionNo
} else if cntUncertain > 0 {
s[gIdx].Answer = OptionUncertain
}
}
if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem))
}
if !hasSub && len(s[gIdx].Answer) == 0 {
err = NewCustomMessage(2, fmt.Sprintf("未填写自查项:%v", s[gIdx].CheckItem))
}
}
return
}
//格式化数据结构
func (s SelfChecks) Format() SelfChecks {
if len(s) == 0 {
return s
}
for i := range s {
if strings.TrimSpace(s[i].Answer) == OptionNo {
s[i].Reason = strings.TrimSpace(s[i].Reason)
}
}
return s
}
//格式化数据结构
func (s SelfChecks) ClearEmpty() (rsp SelfChecks) {
if len(s) == 0 {
return
}
for i := range s {
if len(s[i].Answer) > 0 {
rsp = append(rsp, s[i])
}
}
return
}
//新建自查问题
func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) *CheckQuestion {
return &CheckQuestion{
CheckItem: checkItem,
Title: title,
GroupId: groupId,
CheckOptions: ops,
}
}
/*问题*/
type CheckQuestion struct {
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
CheckItem string `json:"checkItem"`
Title string `json:"title"`
GroupId int64 `json:"groupId"`
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
CheckOptions []CheckOption `json:"options"`
Required bool `json:"required"` //是否必填
}
/*问题选项*/
type CheckOption struct {
Item string `json:"item"`
NeedOther bool `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】
}
//筛选结果
type SiftingResult struct {
CheckId int `json:"checkId"` //检查项id
CheckParentId int64 `json:"parentId"` //项父id
//GroupId int `json:"json:groupId"`//项分组id
Title string `json:"title"` //标题
CheckItem string `json:"checkItem"` //自查项
TotalYes int `json:"totalYes"` //选择是的人数
TotalNo int `json:"totalNo"` //选择否的人数
TotalUncertain int `json:"totalUncertain"` //选择不清楚的人数
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
SubSiftingResults SiftingResults `json:"subSiftingResults"`
}
//筛选结果列表
type SiftingResults []SiftingResult
//清空统计结果
func (s SiftingResults) ClearStatic() {
for i := range s {
s[i].TotalYes = 0
s[i].TotalNo = 0
s[i].TotalUncertain = 0
s[i].TotalSubmitters = 0
s[i].SubSiftingResults.ClearStatic()
}
}
/*
设置一级筛选结果
单个维度显示“是”、“否”、“不清楚”的规则:
1、所有人均选择“是”,则该维度的结果为“是”
2、只要有一个“否”,则该维度的结果为“否” ,不需要显示理由
3、其他情况则显示为“不清楚”
*/
func (s SiftingResults) SetSelfChecksLevel1ByRule() {
for i := range s {
tmpAnswer := ""
if s[i].TotalNo > 0 {
tmpAnswer = OptionNo
}
if s[i].TotalYes > 0 && s[i].TotalNo == 0 && s[i].TotalUncertain == 0 {
tmpAnswer = OptionYes
}
if s[i].TotalNo == 0 && s[i].TotalUncertain > 0 {
tmpAnswer = OptionUncertain
}
s[i].TotalNo = 0
s[i].TotalYes = 0
s[i].TotalUncertain = 0
if tmpAnswer == OptionNo {
s[i].TotalNo = s[i].TotalSubmitters
} else if tmpAnswer == OptionYes {
s[i].TotalYes = s[i].TotalSubmitters
} else if tmpAnswer == OptionUncertain {
s[i].TotalUncertain = s[i].TotalSubmitters
}
}
}
//添加统计
func (s SiftingResults) AddStatic(checkId int, answer string) {
s.addStatic(checkId, answer)
}
func (s SiftingResults) addStatic(checkId int, answer string) {
for i := range s {
if s[i].CheckId == checkId {
var isAnswer = true
switch answer {
case OptionYes:
s[i].TotalYes++
break
case OptionNo:
s[i].TotalNo++
break
case OptionUncertain:
s[i].TotalUncertain++
break
default:
isAnswer = false
break
}
if isAnswer {
s[i].TotalSubmitters++
}
}
s[i].SubSiftingResults.AddStatic(checkId, answer)
}
}
//筛选结果详情
type SiftingResultDetail struct {
Option string `json:"option"` //选项:是 否 不清楚
Items SiftingCommitItems `json:"items"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}
//筛选结果提交人项
type SiftingCommitItems []SiftingCommitItem
type SiftingCommitItem struct {
Provider *BaseUserInfo `json:"provider"`
Reason string `json:"reason"` //理由
}
/******************REQUEST/RESPONSE (请求应答实体)*******************/
/*CheckQuestions 自查问题列表*/
type CheckQuestionsRequest struct {
Type int `json:"type"` //0.自查 1.筛选结果
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type CheckQuestionsResponse struct {
Questions []*CheckQuestion `json:"questions"`
}
//SiftingPool 筛选池
type SiftingPoolRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
SiftedStatus int `-` //筛选状态 1:提交中 2:通过 3:不通过
}
type SiftingPoolResponse struct{ ChancePoolResponse }
/*筛选结果 SiftingResults */
type SiftingResultsRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
}
type SiftingResultsResponse struct{ ChancePoolResponse }
/*SubmitChecks 提交自查*/
type SubmitChecksRequest struct {
//Type int `json:"type"` //1.审核人
Uid int64 `json:"uid"`
ChanceId int64 `json:"chanceId" valid:"Required"`
SelfChecks SelfChecks `json:"selfChecks"`
}
type SubmitChecksResponse struct{}
/*SiftingResultsItemHistory 筛选历史*/
type SiftingResultsItemHistoryRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type SiftingResultsItemHistoryResponse struct {
SiftingResults SiftingResults `json:"siftingResults"`
TotalSubmitters int `json:"totalSubmitters"`
}
/*SiftingResultsItemDetail 筛选历史详情*/
type SiftingResultsItemDetailRequest struct {
ChanceId int64 `json:"chanceId" valid:"Required"`
CheckId int `json:"checkId" valid:"Required"` //检查项id
}
type SiftingResultsItemDetailResponse struct {
SiftingResultDetails []SiftingResultDetail `json:"siftingResultDetails"`
TotalSubmitters int `json:"totalSubmitters"` //总提交人数
}