|
@@ -314,50 +314,38 @@ func getQuestionTitle(groupIdx int, idx int, title string) string { |
|
@@ -314,50 +314,38 @@ func getQuestionTitle(groupIdx int, idx int, title string) string { |
314
|
|
314
|
|
315
|
//自查问题回答批量入库
|
315
|
//自查问题回答批量入库
|
316
|
//@isDelete
|
316
|
//@isDelete
|
317
|
-func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool) {
|
317
|
+func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool, checkerType int) {
|
318
|
defer func() {
|
318
|
defer func() {
|
319
|
if p := recover(); p != nil {
|
319
|
if p := recover(); p != nil {
|
320
|
log.Warn(p)
|
320
|
log.Warn(p)
|
321
|
}
|
321
|
}
|
322
|
}()
|
322
|
}()
|
323
|
var (
|
323
|
var (
|
324
|
- count int
|
|
|
325
|
- err error
|
|
|
326
|
- Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
|
|
327
|
- DeleteExistedRow = `update chance_self_check set enable=0,update_at=Now() where relateId=? and enable=1`
|
324
|
+ count int
|
|
|
325
|
+ err error
|
|
|
326
|
+ Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
|
|
327
|
+ DeleteExistedSubmitRow = `delete from chance_self_check where relateId=? and type=? and user_company_id=?` //删除提交人自查数据
|
328
|
)
|
328
|
)
|
329
|
if len(selfChecks) == 0 {
|
329
|
if len(selfChecks) == 0 {
|
330
|
return
|
330
|
return
|
331
|
}
|
331
|
}
|
332
|
o := orm.NewOrm()
|
332
|
o := orm.NewOrm()
|
333
|
o.Begin()
|
333
|
o.Begin()
|
334
|
- if err = utils.ExecuteQueryOneWithOrmer(o, &count, Exists, relateId, chanceId); err != nil {
|
|
|
335
|
- log.Error(err)
|
|
|
336
|
- o.Rollback()
|
|
|
337
|
- return
|
|
|
338
|
- }
|
|
|
339
|
if isDeleteExisted {
|
334
|
if isDeleteExisted {
|
340
|
- if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, chanceId); err != nil {
|
335
|
+ if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedSubmitRow, chanceId, checkerType, header.UserId); err != nil {
|
341
|
log.Error(err)
|
336
|
log.Error(err)
|
342
|
o.Rollback()
|
337
|
o.Rollback()
|
343
|
return
|
338
|
return
|
344
|
}
|
339
|
}
|
345
|
}
|
340
|
}
|
|
|
341
|
+ if err = utils.ExecuteQueryOneWithOrmer(o, &count, Exists, relateId, chanceId); err != nil {
|
|
|
342
|
+ log.Error(err)
|
|
|
343
|
+ o.Rollback()
|
|
|
344
|
+ return
|
|
|
345
|
+ }
|
346
|
if count == 0 {
|
346
|
if count == 0 {
|
347
|
insertFunc := func(check protocol.SelfCheck, r int64) (err error) {
|
347
|
insertFunc := func(check protocol.SelfCheck, r int64) (err error) {
|
348
|
- m := &models.ChanceSelfCheck{
|
|
|
349
|
- Id: idgen.Next(),
|
|
|
350
|
- UserCompanyId: header.UserId,
|
|
|
351
|
- ChanceId: chanceId,
|
|
|
352
|
- RelateId: r,
|
|
|
353
|
- CheckItem: check.CheckItem,
|
|
|
354
|
- GroupId: check.GroupId,
|
|
|
355
|
- Answer: check.Answer,
|
|
|
356
|
- Reason: check.Reason,
|
|
|
357
|
- CreateAt: time.Now(),
|
|
|
358
|
- UpdateAt: time.Now(),
|
|
|
359
|
- Enable: protocol.Valid,
|
|
|
360
|
- }
|
348
|
+ m := NewChanceSelfCheck(header, check, chanceId, r, checkerType)
|
361
|
//插入审核的自查内容
|
349
|
//插入审核的自查内容
|
362
|
if _, err = o.Insert(m); err != nil {
|
350
|
if _, err = o.Insert(m); err != nil {
|
363
|
log.Error(err)
|
351
|
log.Error(err)
|
|
@@ -372,7 +360,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
@@ -372,7 +360,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
372
|
return
|
360
|
return
|
373
|
}
|
361
|
}
|
374
|
//审核通过更新之前机会的自查内容(重新插入一条机会的自查内容)
|
362
|
//审核通过更新之前机会的自查内容(重新插入一条机会的自查内容)
|
375
|
- if isDeleteExisted {
|
363
|
+ if checkerType == protocol.TypeApprove && isDeleteExisted {
|
376
|
if err = insertFunc(check, chanceId); err != nil {
|
364
|
if err = insertFunc(check, chanceId); err != nil {
|
377
|
return
|
365
|
return
|
378
|
}
|
366
|
}
|
|
@@ -381,3 +369,20 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
@@ -381,3 +369,20 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
381
|
}
|
369
|
}
|
382
|
o.Commit()
|
370
|
o.Commit()
|
383
|
}
|
371
|
}
|
|
|
372
|
+
|
|
|
373
|
+func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck, chanceId, r int64, checkerType int) *models.ChanceSelfCheck {
|
|
|
374
|
+ return &models.ChanceSelfCheck{
|
|
|
375
|
+ Id: idgen.Next(),
|
|
|
376
|
+ UserCompanyId: header.UserId,
|
|
|
377
|
+ ChanceId: chanceId,
|
|
|
378
|
+ RelateId: r,
|
|
|
379
|
+ CheckItem: check.CheckItem,
|
|
|
380
|
+ GroupId: check.GroupId,
|
|
|
381
|
+ Answer: check.Answer,
|
|
|
382
|
+ Reason: check.Reason,
|
|
|
383
|
+ CreateAt: time.Now(),
|
|
|
384
|
+ //UpdateAt: time.Now(),
|
|
|
385
|
+ CompanyId: header.CompanyId,
|
|
|
386
|
+ Type: checkerType,
|
|
|
387
|
+ }
|
|
|
388
|
+} |