|
@@ -313,7 +313,8 @@ func getQuestionTitle(groupIdx int, idx int, title string) string { |
|
@@ -313,7 +313,8 @@ func getQuestionTitle(groupIdx int, idx int, title string) string { |
313
|
}
|
313
|
}
|
314
|
|
314
|
|
315
|
//自查问题回答批量入库
|
315
|
//自查问题回答批量入库
|
316
|
-func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks) {
|
316
|
+//@isDelete
|
|
|
317
|
+func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool) {
|
317
|
defer func() {
|
318
|
defer func() {
|
318
|
if p := recover(); p != nil {
|
319
|
if p := recover(); p != nil {
|
319
|
log.Warn(p)
|
320
|
log.Warn(p)
|
|
@@ -323,7 +324,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
@@ -323,7 +324,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
323
|
count int
|
324
|
count int
|
324
|
err error
|
325
|
err error
|
325
|
Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
326
|
Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
326
|
- DeleteExistedRow = `update chance_self_check set enable=0 where chanceId=? and relateId=?`
|
327
|
+ DeleteExistedRow = `update chance_self_check set enable=0,update_at=Now() where relateId=? and enable=1`
|
327
|
)
|
328
|
)
|
328
|
if len(selfChecks) == 0 {
|
329
|
if len(selfChecks) == 0 {
|
329
|
return
|
330
|
return
|
|
@@ -335,32 +336,48 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
@@ -335,32 +336,48 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
335
|
o.Rollback()
|
336
|
o.Rollback()
|
336
|
return
|
337
|
return
|
337
|
}
|
338
|
}
|
338
|
- if count > 0 {
|
|
|
339
|
- if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, relateId, chanceId); err != nil {
|
339
|
+ if isDeleteExisted {
|
|
|
340
|
+ if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, chanceId); err != nil {
|
340
|
log.Error(err)
|
341
|
log.Error(err)
|
341
|
o.Rollback()
|
342
|
o.Rollback()
|
342
|
return
|
343
|
return
|
343
|
}
|
344
|
}
|
344
|
}
|
345
|
}
|
345
|
- for i := range selfChecks {
|
|
|
346
|
- check := selfChecks[i]
|
|
|
347
|
- m := models.ChanceSelfCheck{
|
346
|
+ if count == 0 {
|
|
|
347
|
+ insertFunc := func(check protocol.SelfCheck, r int64) (err error) {
|
|
|
348
|
+ m := &models.ChanceSelfCheck{
|
348
|
Id: idgen.Next(),
|
349
|
Id: idgen.Next(),
|
349
|
UserCompanyId: header.UserId,
|
350
|
UserCompanyId: header.UserId,
|
350
|
ChanceId: chanceId,
|
351
|
ChanceId: chanceId,
|
351
|
- RelateId: relateId,
|
352
|
+ RelateId: r,
|
352
|
CheckItem: check.CheckItem,
|
353
|
CheckItem: check.CheckItem,
|
353
|
GroupId: check.GroupId,
|
354
|
GroupId: check.GroupId,
|
354
|
Answer: check.Answer,
|
355
|
Answer: check.Answer,
|
355
|
Reason: check.Reason,
|
356
|
Reason: check.Reason,
|
356
|
CreateAt: time.Now(),
|
357
|
CreateAt: time.Now(),
|
|
|
358
|
+ UpdateAt: time.Now(),
|
|
|
359
|
+ Enable: protocol.Valid,
|
357
|
}
|
360
|
}
|
|
|
361
|
+ //插入审核的自查内容
|
358
|
if _, err = o.Insert(m); err != nil {
|
362
|
if _, err = o.Insert(m); err != nil {
|
359
|
log.Error(err)
|
363
|
log.Error(err)
|
360
|
o.Rollback()
|
364
|
o.Rollback()
|
361
|
return
|
365
|
return
|
362
|
}
|
366
|
}
|
|
|
367
|
+ return
|
|
|
368
|
+ }
|
|
|
369
|
+ for i := range selfChecks {
|
|
|
370
|
+ check := selfChecks[i]
|
|
|
371
|
+ if err = insertFunc(check, relateId); err != nil {
|
|
|
372
|
+ return
|
|
|
373
|
+ }
|
|
|
374
|
+ //审核通过更新之前机会的自查内容(重新插入一条机会的自查内容)
|
|
|
375
|
+ if isDeleteExisted {
|
|
|
376
|
+ if err = insertFunc(check, chanceId); err != nil {
|
|
|
377
|
+ return
|
|
|
378
|
+ }
|
|
|
379
|
+ }
|
|
|
380
|
+ }
|
363
|
}
|
381
|
}
|
364
|
-
|
|
|
365
|
o.Commit()
|
382
|
o.Commit()
|
366
|
} |
383
|
} |