作者 yangfu

自查修改

@@ -110,7 +110,7 @@ func GetAuditTemplateExample(id int64) (v string, videos string, err error) { @@ -110,7 +110,7 @@ func GetAuditTemplateExample(id int64) (v string, videos string, err error) {
110 //获取审核模板列表 110 //获取审核模板列表
111 func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) { 111 func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) {
112 o := orm.NewOrm() 112 o := orm.NewOrm()
113 - sql := "select * from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1" 113 + sql := "select id,company_id,chance_type_id,`name`,doc,icon,code,sort_num,visible_type,visible_object,LEFT(example,5) example,videos from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
114 if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil { 114 if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil {
115 return 115 return
116 } 116 }
@@ -18,6 +18,7 @@ type ChanceSelfCheck struct { @@ -18,6 +18,7 @@ type ChanceSelfCheck struct {
18 Reason string `orm:"column(reason);size(200);null" description:"理由"` 18 Reason string `orm:"column(reason);size(200);null" description:"理由"`
19 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` 19 CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
20 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` 20 UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
  21 + Enable int8 `orm:"column(enable);size(200);null" description:"是否有效【0:无效】【1:有效】"`
21 } 22 }
22 23
23 func (t *ChanceSelfCheck) TableName() string { 24 func (t *ChanceSelfCheck) TableName() string {
@@ -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 }
@@ -456,6 +456,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -456,6 +456,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
456 } 456 }
457 } 457 }
458 } 458 }
  459 +
  460 + go agg.BulkInsertSelfChecks(header, process.Id, chance.Id, request.SelfChecks, request.ReviewStatus == protocol.ReviewStatusPass)
459 orm.Commit() 461 orm.Commit()
460 return 462 return
461 } 463 }
@@ -486,6 +486,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -486,6 +486,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
486 return 486 return
487 } 487 }
488 } 488 }
  489 + go agg.BulkInsertSelfChecks(header, chance.Id, chance.Id, request.SelfChecks, false)
489 orm.Commit() 490 orm.Commit()
490 491
491 rsp = &protocol.ChanceSubmitResponse{} 492 rsp = &protocol.ChanceSubmitResponse{}