|
@@ -99,8 +99,9 @@ var ChanceStatusMap = map[int8]string{ |
|
@@ -99,8 +99,9 @@ var ChanceStatusMap = map[int8]string{ |
99
|
ChanceStatusForbid: "已关闭",
|
99
|
ChanceStatusForbid: "已关闭",
|
100
|
}
|
100
|
}
|
101
|
|
101
|
|
102
|
-//机会自查内容筛选状态 【1:待处理未设置】【2:通过】【3:不通过】
|
102
|
+//机会自查内容筛选状态 【0:未提交】【1:待处理未设置】【2:通过】【3:不通过】
|
103
|
const (
|
103
|
const (
|
|
|
104
|
+ CheckResultStatusNone int8 = 0
|
104
|
CheckResultStatusWait int8 = 1
|
105
|
CheckResultStatusWait int8 = 1
|
105
|
CheckResultStatusPass int8 = 2
|
106
|
CheckResultStatusPass int8 = 2
|
106
|
CheckResultStatusNOPass int8 = 3
|
107
|
CheckResultStatusNOPass int8 = 3
|
|
@@ -124,27 +125,96 @@ type ChanceSelfCheckData struct { |
|
@@ -124,27 +125,96 @@ type ChanceSelfCheckData struct { |
124
|
|
125
|
|
125
|
func (m *Chance) GetSelfCheckData() []ChanceSelfCheckData {
|
126
|
func (m *Chance) GetSelfCheckData() []ChanceSelfCheckData {
|
126
|
var data []ChanceSelfCheckData
|
127
|
var data []ChanceSelfCheckData
|
127
|
- if m.CheckResultStatus > CheckResultStatusWait {
|
|
|
128
|
- var temp []ChanceSelfCheckData
|
|
|
129
|
- json.Unmarshal([]byte(m.CheckResult), &temp)
|
|
|
130
|
- //只要一级的数据
|
|
|
131
|
- for i := range temp {
|
|
|
132
|
- if temp[i].ParentId > 0 {
|
128
|
+ json.Unmarshal([]byte(m.CheckResult), &data)
|
|
|
129
|
+ return data
|
|
|
130
|
+}
|
|
|
131
|
+
|
|
|
132
|
+func (m *Chance) GetCheckResultData() []ChanceSelfCheckData {
|
|
|
133
|
+ var data []ChanceSelfCheckData
|
|
|
134
|
+ json.Unmarshal([]byte(m.CheckResult), &data)
|
|
|
135
|
+ return data
|
|
|
136
|
+}
|
|
|
137
|
+
|
|
|
138
|
+type ChanceSelfCheckList []ChanceSelfCheckData
|
|
|
139
|
+
|
|
|
140
|
+func (s ChanceSelfCheckList) Format() ChanceSelfCheckList {
|
|
|
141
|
+ if len(s) == 0 {
|
|
|
142
|
+ return s
|
|
|
143
|
+ }
|
|
|
144
|
+ for i := range s {
|
|
|
145
|
+ if strings.TrimSpace(s[i].Answer) == "否" {
|
|
|
146
|
+ s[i].Reason = strings.TrimSpace(s[i].Reason)
|
|
|
147
|
+ }
|
|
|
148
|
+ }
|
|
|
149
|
+ return s
|
|
|
150
|
+}
|
|
|
151
|
+
|
|
|
152
|
+func (s ChanceSelfCheckList) SetSelfChecksLevel1ByRule() (err error) {
|
|
|
153
|
+ if len(s) == 0 {
|
|
|
154
|
+ return
|
|
|
155
|
+ }
|
|
|
156
|
+ s.Format()
|
|
|
157
|
+ var gIdx = -1
|
|
|
158
|
+ for i := 0; i < len(s); i++ {
|
|
|
159
|
+ if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
|
|
|
160
|
+ gIdx = i
|
|
|
161
|
+ } else {
|
133
|
continue
|
162
|
continue
|
134
|
}
|
163
|
}
|
135
|
- data = append(data, temp[i])
|
164
|
+ hasSub := false
|
|
|
165
|
+ var (
|
|
|
166
|
+ cntYes = 0 //是
|
|
|
167
|
+ cntNo = 0 //否
|
|
|
168
|
+ cntUncertain = 0 //不确定
|
|
|
169
|
+ )
|
|
|
170
|
+ for j := i + 1; j < len(s); j++ {
|
|
|
171
|
+ if s[i].GroupId == s[j].GroupId {
|
|
|
172
|
+ if !hasSub {
|
|
|
173
|
+ hasSub = true
|
136
|
}
|
174
|
}
|
137
|
} else {
|
175
|
} else {
|
138
|
- json.Unmarshal([]byte(m.SelfChecks), &data)
|
|
|
139
|
- for i := range data {
|
|
|
140
|
- reason := strings.TrimSpace(data[i].Reason)
|
|
|
141
|
- if data[i].Answer == "否" && len(reason) > 0 {
|
|
|
142
|
- data[i].Answer = fmt.Sprintf("否,理由:%s", data[i].Reason)
|
176
|
+ break
|
|
|
177
|
+ }
|
|
|
178
|
+ answer := s[j].Answer
|
|
|
179
|
+ if strings.EqualFold(strings.TrimSpace(answer), "是") {
|
|
|
180
|
+ cntYes++
|
|
|
181
|
+ } else if strings.EqualFold(strings.TrimSpace(answer), "否") {
|
|
|
182
|
+ cntNo++
|
|
|
183
|
+ } else if strings.EqualFold(strings.TrimSpace(answer), "不清楚") {
|
|
|
184
|
+ cntUncertain++
|
|
|
185
|
+ }
|
|
|
186
|
+ }
|
|
|
187
|
+ //只有一级维度的必须填写
|
|
|
188
|
+ if hasSub {
|
|
|
189
|
+ if cntYes > 0 {
|
|
|
190
|
+ s[gIdx].Answer = "是"
|
|
|
191
|
+ } else if cntNo > 0 {
|
|
|
192
|
+ s[gIdx].Answer = "否"
|
|
|
193
|
+ } else if cntUncertain > 0 {
|
|
|
194
|
+ s[gIdx].Answer = "不清楚"
|
143
|
}
|
195
|
}
|
144
|
}
|
196
|
}
|
|
|
197
|
+ if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
|
|
|
198
|
+ err = fmt.Errorf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem)
|
145
|
}
|
199
|
}
|
|
|
200
|
+ if !hasSub && len(s[gIdx].Answer) == 0 {
|
|
|
201
|
+ err = fmt.Errorf("未填写自查项:%v", s[gIdx].CheckItem)
|
|
|
202
|
+ }
|
|
|
203
|
+ }
|
|
|
204
|
+ return
|
|
|
205
|
+}
|
146
|
|
206
|
|
147
|
- return data
|
207
|
+//格式化数据结构
|
|
|
208
|
+func (s ChanceSelfCheckList) ClearEmpty() (rsp ChanceSelfCheckList) {
|
|
|
209
|
+ if len(s) == 0 {
|
|
|
210
|
+ return
|
|
|
211
|
+ }
|
|
|
212
|
+ for i := range s {
|
|
|
213
|
+ if len(s[i].Answer) > 0 {
|
|
|
214
|
+ rsp = append(rsp, s[i])
|
|
|
215
|
+ }
|
|
|
216
|
+ }
|
|
|
217
|
+ return
|
148
|
}
|
218
|
}
|
149
|
|
219
|
|
150
|
// AddChance insert a new Chance into database and returns
|
220
|
// AddChance insert a new Chance into database and returns
|