正在显示
8 个修改的文件
包含
425 行增加
和
70 行删除
@@ -718,3 +718,24 @@ func (this *ChanceController) SiftingResults() { | @@ -718,3 +718,24 @@ func (this *ChanceController) SiftingResults() { | ||
718 | header := controllers.GetRequestHeader(this.Ctx) | 718 | header := controllers.GetRequestHeader(this.Ctx) |
719 | msg = protocol.NewReturnResponse(chance.SiftingResults(header, request)) | 719 | msg = protocol.NewReturnResponse(chance.SiftingResults(header, request)) |
720 | } | 720 | } |
721 | + | ||
722 | +//SubmitChecks 提交自查 | ||
723 | +//@router /submitSiftingResult [post] | ||
724 | +func (this *ChanceController) SubmitChecks() { | ||
725 | + var msg *protocol.ResponseMessage | ||
726 | + defer func() { | ||
727 | + this.Resp(msg) | ||
728 | + }() | ||
729 | + var request *protocol.SubmitChecksRequest | ||
730 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
731 | + log.Error(err) | ||
732 | + msg = protocol.BadRequestParam(1) | ||
733 | + return | ||
734 | + } | ||
735 | + if b, m := this.Valid(request); !b { | ||
736 | + msg = m | ||
737 | + return | ||
738 | + } | ||
739 | + header := controllers.GetRequestHeader(this.Ctx) | ||
740 | + msg = protocol.NewReturnResponse(chance.SubmitChecks(header, request)) | ||
741 | +} |
@@ -33,8 +33,8 @@ type AuditFlowProcess struct { | @@ -33,8 +33,8 @@ type AuditFlowProcess struct { | ||
33 | ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"` | 33 | ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"` |
34 | TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"` | 34 | TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"` |
35 | SelfChecks string `orm:"column(self_checks);null" description:"自查内容"` | 35 | SelfChecks string `orm:"column(self_checks);null" description:"自查内容"` |
36 | - CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"机会筛选审核时间"` | ||
37 | - CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"` | 36 | + SubmitCheckTime time.Time `orm:"column(submit_check_time);type(timestamp)" description:"提交筛选时间"` |
37 | + SubmitCheckStatus int `orm:"column(submit_check_status)" description:"提交筛选状态 0:未提交 1:已提交"` | ||
38 | } | 38 | } |
39 | 39 | ||
40 | func (t *AuditFlowProcess) TableName() string { | 40 | func (t *AuditFlowProcess) TableName() string { |
@@ -182,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev | @@ -182,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev | ||
182 | } | 182 | } |
183 | return | 183 | return |
184 | } | 184 | } |
185 | + | ||
186 | +//获取审核人最新的审核节点 | ||
187 | +func GetAuditorLatestAuditFlowProcess(chanceId int64, userId int64) (v *AuditFlowProcess, err error) { | ||
188 | + o := orm.NewOrm() | ||
189 | + sql := "select * from audit_flow_process where chance_id=? and level>0 and uid=? order by id desc limit 1" | ||
190 | + if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, userId); err != nil { | ||
191 | + return | ||
192 | + } | ||
193 | + return | ||
194 | +} | ||
195 | + | ||
196 | +//获取机会所有审核人 | ||
197 | +func GetChanceAllAuditors(chanceId int64) (v []*AuditFlowProcess, err error) { | ||
198 | + o := orm.NewOrm() | ||
199 | + sql := "select MAX(id) AS id,uid from audit_flow_process where chance_id=? and `level`>0 group by chance_id,uid" | ||
200 | + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil { | ||
201 | + return | ||
202 | + } | ||
203 | + return | ||
204 | +} |
models/chance_check_result.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "opp/internal/utils" | ||
6 | + "time" | ||
7 | + | ||
8 | + "github.com/astaxie/beego/orm" | ||
9 | +) | ||
10 | + | ||
11 | +type ChanceCheckResult struct { | ||
12 | + Id int64 `orm:"column(id);pk"` | ||
13 | + ChanceId int64 `orm:"column(chance_id)"` | ||
14 | + GroupId int64 `orm:"column(group_id);null"` | ||
15 | + CheckPid int64 `orm:"column(check_pid)"` | ||
16 | + CheckId int `orm:"column(check_id);null"` | ||
17 | + CheckItem string `orm:"column(check_item);size(20);null" description:"检查项"` | ||
18 | + Answer string `orm:"column(answer);size(50);null" description:"回答"` | ||
19 | + Reason string `orm:"column(reason);size(200);null" description:"理由"` | ||
20 | + UserCompanyId int64 `orm:"column(user_company_id);null"` | ||
21 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null"` | ||
22 | +} | ||
23 | + | ||
24 | +func (t *ChanceCheckResult) TableName() string { | ||
25 | + return "chance_check_result" | ||
26 | +} | ||
27 | + | ||
28 | +func init() { | ||
29 | + orm.RegisterModel(new(ChanceCheckResult)) | ||
30 | +} | ||
31 | + | ||
32 | +var ( | ||
33 | + SqlGetUserCheckResults = `select * from chance_check_result where chance_id =? and user_company_id=? order by group_id,check_id` //机会自查数据 | ||
34 | +) | ||
35 | + | ||
36 | +// AddChanceCheckResult insert a new ChanceCheckResult into database and returns | ||
37 | +// last inserted Id on success. | ||
38 | +func AddChanceCheckResult(m *ChanceCheckResult) (id int64, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + id, err = o.Insert(m) | ||
41 | + return | ||
42 | +} | ||
43 | + | ||
44 | +// GetChanceCheckResultById retrieves ChanceCheckResult by Id. Returns error if | ||
45 | +// Id doesn't exist | ||
46 | +func GetChanceCheckResultById(id int64) (v *ChanceCheckResult, err error) { | ||
47 | + o := orm.NewOrm() | ||
48 | + v = &ChanceCheckResult{Id: id} | ||
49 | + if err = o.Read(v); err == nil { | ||
50 | + return v, nil | ||
51 | + } | ||
52 | + return nil, err | ||
53 | +} | ||
54 | + | ||
55 | +// UpdateChanceCheckResult updates ChanceCheckResult by Id and returns error if | ||
56 | +// the record to be updated doesn't exist | ||
57 | +func UpdateChanceCheckResultById(m *ChanceCheckResult) (err error) { | ||
58 | + o := orm.NewOrm() | ||
59 | + v := ChanceCheckResult{Id: m.Id} | ||
60 | + // ascertain id exists in the database | ||
61 | + if err = o.Read(&v); err == nil { | ||
62 | + var num int64 | ||
63 | + if num, err = o.Update(m); err == nil { | ||
64 | + fmt.Println("Number of records updated in database:", num) | ||
65 | + } | ||
66 | + } | ||
67 | + return | ||
68 | +} | ||
69 | + | ||
70 | +// DeleteChanceCheckResult deletes ChanceCheckResult by Id and returns error if | ||
71 | +// the record to be deleted doesn't exist | ||
72 | +func DeleteChanceCheckResult(id int64) (err error) { | ||
73 | + o := orm.NewOrm() | ||
74 | + v := ChanceCheckResult{Id: id} | ||
75 | + // ascertain id exists in the database | ||
76 | + if err = o.Read(&v); err == nil { | ||
77 | + var num int64 | ||
78 | + if num, err = o.Delete(&ChanceCheckResult{Id: id}); err == nil { | ||
79 | + fmt.Println("Number of records deleted in database:", num) | ||
80 | + } | ||
81 | + } | ||
82 | + return | ||
83 | +} | ||
84 | + | ||
85 | +//获取机会所有审核人 | ||
86 | +func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) { | ||
87 | + o := orm.NewOrm() | ||
88 | + sql := "select DISTINCT user_company_id from chance_check_result where chance_id=?" | ||
89 | + if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil { | ||
90 | + return | ||
91 | + } | ||
92 | + return | ||
93 | +} |
@@ -59,7 +59,7 @@ type SelfCheck struct { | @@ -59,7 +59,7 @@ type SelfCheck struct { | ||
59 | Answer string `json:"answer,omitempty"` | 59 | Answer string `json:"answer,omitempty"` |
60 | Reason string `json:"reason,omitempty"` | 60 | Reason string `json:"reason,omitempty"` |
61 | 61 | ||
62 | - Id int64 `json:"Id"` | 62 | + Id int64 `json:"id"` |
63 | ParentId int64 `json:"parentId"` | 63 | ParentId int64 `json:"parentId"` |
64 | } | 64 | } |
65 | 65 | ||
@@ -168,14 +168,17 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) | @@ -168,14 +168,17 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption) | ||
168 | } | 168 | } |
169 | 169 | ||
170 | type CheckQuestion struct { | 170 | type CheckQuestion struct { |
171 | - Id int64 `json:"-"` | ||
172 | - ParentId int64 `json:"-"` | 171 | + Id int64 `json:"id"` |
172 | + ParentId int64 `json:"parentId"` | ||
173 | 173 | ||
174 | CheckItem string `json:"checkItem"` | 174 | CheckItem string `json:"checkItem"` |
175 | Title string `json:"title"` | 175 | Title string `json:"title"` |
176 | GroupId int64 `json:"groupId"` | 176 | GroupId int64 `json:"groupId"` |
177 | Answer string `json:"answer,omitempty"` | 177 | Answer string `json:"answer,omitempty"` |
178 | + Reason string `json:"reason,omitempty"` | ||
178 | CheckOptions []CheckOption `json:"options"` | 179 | CheckOptions []CheckOption `json:"options"` |
180 | + | ||
181 | + Required bool `json:"required"` //是否必填 | ||
179 | } | 182 | } |
180 | type CheckOption struct { | 183 | type CheckOption struct { |
181 | Item string `json:"item"` | 184 | Item string `json:"item"` |
@@ -184,6 +187,7 @@ type CheckOption struct { | @@ -184,6 +187,7 @@ type CheckOption struct { | ||
184 | 187 | ||
185 | /*CheckQuestions 自查问题列表*/ | 188 | /*CheckQuestions 自查问题列表*/ |
186 | type CheckQuestionsRequest struct { | 189 | type CheckQuestionsRequest struct { |
190 | + Type int `json:"type"` //0.自查 1.筛选结果 | ||
187 | ChanceId int64 `json:"chanceId" valid:"Required"` | 191 | ChanceId int64 `json:"chanceId" valid:"Required"` |
188 | } | 192 | } |
189 | type CheckQuestionsResponse struct { | 193 | type CheckQuestionsResponse struct { |
@@ -205,9 +209,18 @@ type SiftingPoolResponse struct { | @@ -205,9 +209,18 @@ type SiftingPoolResponse struct { | ||
205 | type SiftingResultsRequest struct { | 209 | type SiftingResultsRequest struct { |
206 | PageInfo | 210 | PageInfo |
207 | Uid int64 `json:"uid"` //注入用户 测试使用 | 211 | Uid int64 `json:"uid"` //注入用户 测试使用 |
208 | - //SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交 | ||
209 | - SiftedStatus int `json:"siftedStatus"` //筛选状态 1:待处理 2:通过 3:不通过 | 212 | + SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过 |
210 | } | 213 | } |
211 | type SiftingResultsResponse struct { | 214 | type SiftingResultsResponse struct { |
212 | ChancePoolResponse | 215 | ChancePoolResponse |
213 | } | 216 | } |
217 | + | ||
218 | +/*SubmitChecks 提交自查*/ | ||
219 | +type SubmitChecksRequest struct { | ||
220 | + //Type int `json:"type"` //1.审核人 | ||
221 | + Uid int64 `json:"uid"` | ||
222 | + ChanceId int64 `json:"chanceId" valid:"Required"` | ||
223 | + SelfChecks SelfChecks `json:"selfChecks"` | ||
224 | +} | ||
225 | +type SubmitChecksResponse struct { | ||
226 | +} |
@@ -289,6 +289,14 @@ func init() { | @@ -289,6 +289,14 @@ func init() { | ||
289 | 289 | ||
290 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | 290 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], |
291 | beego.ControllerComments{ | 291 | beego.ControllerComments{ |
292 | + Method: "SubmitChecks", | ||
293 | + Router: `/submitSiftingResult`, | ||
294 | + AllowHTTPMethods: []string{"post"}, | ||
295 | + MethodParams: param.Make(), | ||
296 | + Params: nil}) | ||
297 | + | ||
298 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
299 | + beego.ControllerComments{ | ||
292 | Method: "SympathyAction", | 300 | Method: "SympathyAction", |
293 | Router: `/sympathyAction`, | 301 | Router: `/sympathyAction`, |
294 | AllowHTTPMethods: []string{"post"}, | 302 | AllowHTTPMethods: []string{"post"}, |
@@ -281,6 +281,7 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err | @@ -281,6 +281,7 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err | ||
281 | rsp = append(rsp, item) | 281 | rsp = append(rsp, item) |
282 | idx++ | 282 | idx++ |
283 | } | 283 | } |
284 | + setQuestionRequire(rsp) | ||
284 | return | 285 | return |
285 | } | 286 | } |
286 | 287 | ||
@@ -302,17 +303,13 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp | @@ -302,17 +303,13 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp | ||
302 | if len(chance.SelfChecks) == 0 { | 303 | if len(chance.SelfChecks) == 0 { |
303 | return | 304 | return |
304 | } | 305 | } |
305 | - if chance.ReviewStatus == protocol.ReviewStatusPass { | ||
306 | - log.Warn("机会已审核通过不可编辑自查数据:", chance.Id) | ||
307 | - return | ||
308 | - } | ||
309 | if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil { | 306 | if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil { |
310 | log.Error(e) | 307 | log.Error(e) |
311 | return | 308 | return |
312 | } | 309 | } |
313 | var tmpGroupId int64 | 310 | var tmpGroupId int64 |
314 | - var idx int = 0 | ||
315 | - var groupIdx = 0 | 311 | + var idx int = 0 //组内排序 |
312 | + var groupIdx = 0 //分组序号 | ||
316 | for i := range selfChecks { | 313 | for i := range selfChecks { |
317 | c := selfChecks[i] | 314 | c := selfChecks[i] |
318 | if tmpGroupId != c.GroupId { | 315 | if tmpGroupId != c.GroupId { |
@@ -328,26 +325,91 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp | @@ -328,26 +325,91 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp | ||
328 | } | 325 | } |
329 | } | 326 | } |
330 | if item.Id == 0 { | 327 | if item.Id == 0 { |
331 | - item.Id, item.ParentId = genCustomizeQuestionId(idx, groupIdx) | 328 | + item.Id, item.ParentId = genCustomizeQuestionId(i, idx, tmpGroupId) |
332 | } | 329 | } |
333 | rsp = append(rsp, item) | 330 | rsp = append(rsp, item) |
334 | idx++ | 331 | idx++ |
335 | } | 332 | } |
333 | + setQuestionRequire(rsp) | ||
336 | return | 334 | return |
337 | } | 335 | } |
336 | + | ||
337 | +//从问题筛选结果获取已回答的问题 | ||
338 | +func GetCheckQuestionsByChanceCheckResult(header *protocol.RequestHeader, id int64) (rsp []*protocol.CheckQuestion, err error) { | ||
339 | + var ( | ||
340 | + checks []*models.ChanceCheckResult | ||
341 | + groupIdx int = 1 //分组序号 | ||
342 | + ) | ||
343 | + if err = utils.ExecuteQueryAll(&checks, models.SqlGetUserCheckResults, id, header.UserId); err != nil { | ||
344 | + if err == orm.ErrNoRows { | ||
345 | + return | ||
346 | + } | ||
347 | + log.Error(err) | ||
348 | + return | ||
349 | + } | ||
350 | + for i := range checks { | ||
351 | + c := checks[i] | ||
352 | + item := &protocol.CheckQuestion{ | ||
353 | + Id: int64(c.CheckId), | ||
354 | + ParentId: int64(c.CheckPid), | ||
355 | + GroupId: int64(c.GroupId), | ||
356 | + CheckItem: c.CheckItem, | ||
357 | + Answer: c.Answer, | ||
358 | + Reason: c.Reason, | ||
359 | + CheckOptions: protocol.CheckOptionsApprove, | ||
360 | + } | ||
361 | + if c.CheckPid == 0 { | ||
362 | + item.Title = fmt.Sprintf("%v、%v", groupIdx, c.CheckItem) | ||
363 | + } | ||
364 | + rsp = append(rsp, item) | ||
365 | + } | ||
366 | + setQuestionRequire(rsp) | ||
367 | + return | ||
368 | +} | ||
369 | + | ||
370 | +//设置问题需要填写 | ||
371 | +func setQuestionRequire(list []*protocol.CheckQuestion) { | ||
372 | + if len(list) == 0 { | ||
373 | + return | ||
374 | + } | ||
375 | + var gIdx = -1 | ||
376 | + for i := 0; i < len(list); i++ { | ||
377 | + if gIdx < 0 || list[gIdx].GroupId != list[i].GroupId { | ||
378 | + gIdx = i | ||
379 | + } else { | ||
380 | + continue | ||
381 | + } | ||
382 | + hasSub := false | ||
383 | + for j := i + 1; j < len(list); j++ { | ||
384 | + if list[i].GroupId == list[j].GroupId { | ||
385 | + if !hasSub { | ||
386 | + hasSub = true | ||
387 | + } | ||
388 | + } else { | ||
389 | + break | ||
390 | + } | ||
391 | + } | ||
392 | + //只有一级维度的必须填写 | ||
393 | + if !hasSub { | ||
394 | + list[gIdx].Required = true | ||
395 | + } | ||
396 | + } | ||
397 | +} | ||
398 | + | ||
338 | func getQuestionTitle(groupIdx int, idx int, title string) string { | 399 | func getQuestionTitle(groupIdx int, idx int, title string) string { |
339 | if idx == 0 { | 400 | if idx == 0 { |
340 | - return fmt.Sprintf("%v、%v?", groupIdx, title) | 401 | + return fmt.Sprintf("%v、%v", groupIdx, title) |
341 | } | 402 | } |
342 | - return fmt.Sprintf("%v.%v、%v?", groupIdx, idx, title) | 403 | + return fmt.Sprintf("%v.%v、%v", groupIdx, idx, title) |
343 | } | 404 | } |
344 | 405 | ||
345 | //自定义id | 406 | //自定义id |
346 | //@return id:问题序号 parentId:父级id | 407 | //@return id:问题序号 parentId:父级id |
347 | -func genCustomizeQuestionId(idx, groupId int) (id int64, parentId int64) { | ||
348 | - id = int64(idx) + 1 | 408 | +func genCustomizeQuestionId(seq int, idx int, groupId int64) (id int64, parentId int64) { |
409 | + id = int64(seq) + 1 | ||
349 | //同一分组的第一个 是一级 | 410 | //同一分组的第一个 是一级 |
350 | if idx == 0 { | 411 | if idx == 0 { |
412 | + //id = groupId | ||
351 | parentId = 0 | 413 | parentId = 0 |
352 | return | 414 | return |
353 | } | 415 | } |
@@ -2216,69 +2216,26 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance | @@ -2216,69 +2216,26 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance | ||
2216 | func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) { | 2216 | func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) { |
2217 | var () | 2217 | var () |
2218 | rsp = &protocol.CheckQuestionsResponse{} | 2218 | rsp = &protocol.CheckQuestionsResponse{} |
2219 | + switch request.Type { | ||
2220 | + case 0: //自查问题列表 | ||
2219 | rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId) | 2221 | rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId) |
2220 | if err != nil { | 2222 | if err != nil { |
2221 | log.Error(err) | 2223 | log.Error(err) |
2222 | - } | ||
2223 | - return | ||
2224 | -} | ||
2225 | - | ||
2226 | -//SiftingPool 筛选池 | ||
2227 | -func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) { | ||
2228 | - var ( | ||
2229 | - ormItems []protocol.ChanceSiftItemOrm | ||
2230 | - ) | ||
2231 | - rsp = &protocol.SiftingPoolResponse{} | ||
2232 | - rsp.List = make([]protocol.CommonListItem, 0) | ||
2233 | - //测试使用 | ||
2234 | - if request.Uid != 0 { | ||
2235 | - header.UserId = request.Uid | ||
2236 | - } | ||
2237 | - if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil { | ||
2238 | - if err == orm.ErrNoRows { | ||
2239 | - err = nil | ||
2240 | return | 2224 | return |
2241 | } | 2225 | } |
2226 | + case 1: //筛选结果问题列表 | ||
2227 | + rsp.Questions, err = agg.GetCheckQuestionsByChanceCheckResult(header, request.ChanceId) | ||
2228 | + if err == orm.ErrNoRows || len(rsp.Questions) == 0 { | ||
2229 | + rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId) | ||
2230 | + if err != nil { | ||
2242 | log.Error(err) | 2231 | log.Error(err) |
2243 | return | 2232 | return |
2244 | } | 2233 | } |
2245 | - for i := 0; i < len(ormItems); i++ { | ||
2246 | - ormItem := ormItems[i] | ||
2247 | - commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm) | ||
2248 | - commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000 | ||
2249 | - if request.SubmitStatus == protocol.Submited { | ||
2250 | - commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000 | ||
2251 | - } | ||
2252 | - rsp.List = append(rsp.List, commItem) | ||
2253 | - } | ||
2254 | - | ||
2255 | - return | ||
2256 | -} | ||
2257 | - | ||
2258 | -//筛选结果 | ||
2259 | -func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) { | ||
2260 | - var ( | ||
2261 | - ormItems []protocol.ChanceSiftResultOrm | ||
2262 | - ) | ||
2263 | - rsp = &protocol.SiftingResultsResponse{} | ||
2264 | - rsp.List = make([]protocol.CommonListItem, 0) | ||
2265 | - //测试使用 | ||
2266 | - if request.Uid != 0 { | ||
2267 | - header.UserId = request.Uid | ||
2268 | - } | ||
2269 | - if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil { | ||
2270 | - if err == orm.ErrNoRows { | ||
2271 | err = nil | 2234 | err = nil |
2272 | - return | ||
2273 | } | 2235 | } |
2274 | - log.Error(err) | ||
2275 | - return | 2236 | + for i := range rsp.Questions { |
2237 | + rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove | ||
2276 | } | 2238 | } |
2277 | - for i := 0; i < len(ormItems); i++ { | ||
2278 | - ormItem := ormItems[i] | ||
2279 | - commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm) | ||
2280 | - commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000 | ||
2281 | - rsp.List = append(rsp.List, commItem) | ||
2282 | } | 2239 | } |
2283 | return | 2240 | return |
2284 | } | 2241 | } |
services/chance/check.go
0 → 100644
1 | +package chance | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego/orm" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
7 | + "opp/internal/utils" | ||
8 | + "opp/models" | ||
9 | + "opp/protocol" | ||
10 | + "opp/services/agg" | ||
11 | + "time" | ||
12 | +) | ||
13 | + | ||
14 | +//SiftingPool 筛选池 | ||
15 | +func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) { | ||
16 | + var ( | ||
17 | + ormItems []protocol.ChanceSiftItemOrm | ||
18 | + ) | ||
19 | + rsp = &protocol.SiftingPoolResponse{} | ||
20 | + rsp.List = make([]protocol.CommonListItem, 0) | ||
21 | + //测试使用 | ||
22 | + if request.Uid != 0 { | ||
23 | + header.UserId = request.Uid | ||
24 | + } | ||
25 | + if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil { | ||
26 | + if err == orm.ErrNoRows { | ||
27 | + err = nil | ||
28 | + return | ||
29 | + } | ||
30 | + log.Error(err) | ||
31 | + return | ||
32 | + } | ||
33 | + for i := 0; i < len(ormItems); i++ { | ||
34 | + ormItem := ormItems[i] | ||
35 | + commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm) | ||
36 | + commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000 | ||
37 | + if request.SubmitStatus == protocol.Submited { | ||
38 | + commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000 | ||
39 | + } | ||
40 | + rsp.List = append(rsp.List, commItem) | ||
41 | + } | ||
42 | + | ||
43 | + return | ||
44 | +} | ||
45 | + | ||
46 | +//筛选结果 | ||
47 | +func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) { | ||
48 | + var ( | ||
49 | + ormItems []protocol.ChanceSiftResultOrm | ||
50 | + ) | ||
51 | + rsp = &protocol.SiftingResultsResponse{} | ||
52 | + rsp.List = make([]protocol.CommonListItem, 0) | ||
53 | + //测试使用 | ||
54 | + if request.Uid != 0 { | ||
55 | + header.UserId = request.Uid | ||
56 | + } | ||
57 | + if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil { | ||
58 | + if err == orm.ErrNoRows { | ||
59 | + err = nil | ||
60 | + return | ||
61 | + } | ||
62 | + log.Error(err) | ||
63 | + return | ||
64 | + } | ||
65 | + for i := 0; i < len(ormItems); i++ { | ||
66 | + ormItem := ormItems[i] | ||
67 | + commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm) | ||
68 | + commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000 | ||
69 | + rsp.List = append(rsp.List, commItem) | ||
70 | + } | ||
71 | + return | ||
72 | +} | ||
73 | + | ||
74 | +//提交自查 | ||
75 | +func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecksRequest) (rsp *protocol.SubmitChecksResponse, err error) { | ||
76 | + var ( | ||
77 | + p *models.AuditFlowProcess | ||
78 | + ) | ||
79 | + //测试 | ||
80 | + if request.Uid != 0 { | ||
81 | + header.UserId = request.Uid | ||
82 | + } | ||
83 | + if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil { | ||
84 | + log.Error(request.ChanceId, header.UserId, err) | ||
85 | + if err == orm.ErrNoRows { | ||
86 | + err = nil | ||
87 | + } | ||
88 | + return | ||
89 | + } | ||
90 | + rsp = &protocol.SubmitChecksResponse{} | ||
91 | + o := orm.NewOrm() | ||
92 | + o.Begin() | ||
93 | + var ( | ||
94 | + DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? ` | ||
95 | + UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?` | ||
96 | + UpdateChanceCheckResultStatus = `update chance set check_result_status=? where id=? and (check_result_status=? or check_result_status is null)` | ||
97 | + ) | ||
98 | + if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil { | ||
99 | + log.Error(err) | ||
100 | + o.Rollback() | ||
101 | + return | ||
102 | + } | ||
103 | + var groupIdx = -1 | ||
104 | + for i := range request.SelfChecks { | ||
105 | + c := request.SelfChecks[i] | ||
106 | + m := NewChanceCheckResult(c, request.ChanceId, header.UserId) | ||
107 | + if groupIdx == -1 || request.SelfChecks[groupIdx].GroupId != request.SelfChecks[i].GroupId { | ||
108 | + groupIdx = i | ||
109 | + } | ||
110 | + if c.Id == 0 { | ||
111 | + m.CheckId = i + 1 | ||
112 | + m.CheckPid = int64(groupIdx + 1) | ||
113 | + if groupIdx == i { | ||
114 | + m.CheckPid = 0 | ||
115 | + } | ||
116 | + } else { | ||
117 | + m.CheckId = int(c.Id) | ||
118 | + m.CheckPid = int64(c.ParentId) | ||
119 | + } | ||
120 | + if _, err = o.Insert(m); err != nil { | ||
121 | + log.Error(err) | ||
122 | + o.Rollback() | ||
123 | + return | ||
124 | + } | ||
125 | + } | ||
126 | + //更新审核人提交状态 | ||
127 | + if p.SubmitCheckStatus == protocol.Submiting { | ||
128 | + //更新 | ||
129 | + if err = utils.ExecuteSQLWithOrmer(o, UpdateCommitStatus, protocol.Submited, request.ChanceId, p.Id); err != nil { | ||
130 | + log.Error(err) | ||
131 | + o.Rollback() | ||
132 | + return | ||
133 | + } | ||
134 | + //插入一条数据 | ||
135 | + } | ||
136 | + //更新机会筛选状态 | ||
137 | + if _, result := CheckIsCommitAllCheck(request.ChanceId); result { | ||
138 | + if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, request.ChanceId, protocol.None); err != nil { | ||
139 | + log.Error(err) | ||
140 | + o.Rollback() | ||
141 | + return | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + o.Commit() | ||
146 | + return | ||
147 | +} | ||
148 | + | ||
149 | +func NewChanceCheckResult(c protocol.SelfCheck, chanceId int64, uid int64) *models.ChanceCheckResult { | ||
150 | + return &models.ChanceCheckResult{ | ||
151 | + Id: idgen.Next(), | ||
152 | + ChanceId: chanceId, | ||
153 | + GroupId: c.GroupId, | ||
154 | + CheckItem: c.CheckItem, | ||
155 | + Answer: c.Answer, | ||
156 | + Reason: c.Reason, | ||
157 | + UserCompanyId: uid, | ||
158 | + CreateAt: time.Now(), | ||
159 | + } | ||
160 | +} | ||
161 | + | ||
162 | +//判断审核人筛选结果是否都已提交 | ||
163 | +func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) { | ||
164 | + var ( | ||
165 | + audits []*models.AuditFlowProcess | ||
166 | + submiters []int64 | ||
167 | + ) | ||
168 | + result = false | ||
169 | + if audits, err = models.GetChanceAllAuditors(chanceId); err != nil { | ||
170 | + log.Error(err) | ||
171 | + return | ||
172 | + } | ||
173 | + if submiters, err = models.GetCheckResultAllSubmitters(chanceId); err != nil { | ||
174 | + log.Error(err) | ||
175 | + return | ||
176 | + } | ||
177 | + if len(audits) == len(submiters) { | ||
178 | + result = true | ||
179 | + } | ||
180 | + return | ||
181 | +} |
-
请 注册 或 登录 后发表评论