作者 yangfu

审批退回

@@ -103,8 +103,7 @@ func GetAuditFlowProcessBy(processId, uid int64) (v *AuditFlowProcess, err error @@ -103,8 +103,7 @@ func GetAuditFlowProcessBy(processId, uid int64) (v *AuditFlowProcess, err error
103 } 103 }
104 104
105 //当前审批批次已经结束 唤醒下一批次审批人 105 //当前审批批次已经结束 唤醒下一批次审批人
106 -func UpdatetAuditFlowProcessToNext(chanceId int64, level int, uids []int64) (err error) {  
107 - o := orm.NewOrm() 106 +func UpdatetAuditFlowProcessToNext(o orm.Ormer, chanceId int64, level int, uids []int64) (err error) {
108 sql := "update audit_flow_process set enable_status =1,is_active=1,update_at=now() where chance_id=? and level=? and uid in (?)" 107 sql := "update audit_flow_process set enable_status =1,is_active=1,update_at=now() where chance_id=? and level=? and uid in (?)"
109 if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, utils.JoinInt64s(uids, ",")); err != nil { 108 if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, utils.JoinInt64s(uids, ",")); err != nil {
110 return 109 return
@@ -113,8 +112,7 @@ func UpdatetAuditFlowProcessToNext(chanceId int64, level int, uids []int64) (err @@ -113,8 +112,7 @@ func UpdatetAuditFlowProcessToNext(chanceId int64, level int, uids []int64) (err
113 } 112 }
114 113
115 //或签 有一人已经通过 同批次在审核状态置为无效 114 //或签 有一人已经通过 同批次在审核状态置为无效
116 -func UpdatetAuditFlowProcessNoApprove(chanceId int64, level int, reviewStatus int) (err error) {  
117 - o := orm.NewOrm() 115 +func UpdatetAuditFlowProcessNoApprove(o orm.Ormer, chanceId int64, level int, reviewStatus int) (err error) {
118 sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=? and level=? and review_status=?" 116 sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=? and level=? and review_status=?"
119 if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, reviewStatus); err != nil { 117 if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId, level, reviewStatus); err != nil {
120 return 118 return
@@ -52,7 +52,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces @@ -52,7 +52,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
52 Approver: userCompany.NickName, 52 Approver: userCompany.NickName,
53 Uid: userCompany.Id, 53 Uid: userCompany.Id,
54 Sign: ApproveSign, 54 Sign: ApproveSign,
55 - Type: 1, 55 + Type: 2,
56 } 56 }
57 for i := range process { 57 for i := range process {
58 var ( 58 var (
@@ -343,29 +343,42 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -343,29 +343,42 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
343 return 343 return
344 } 344 }
345 log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus)) 345 log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
  346 + orm := orm.NewOrm()
  347 + orm.Begin()
  348 + if request.ReviewStatus == protocol.ReviewStatusReturn {
  349 + mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
  350 + //增加一条待处理记录到审核列表
  351 + //生成提交记录
  352 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
  353 + log.Error(err)
  354 + orm.Rollback()
  355 + return
  356 + }
  357 + }
346 { 358 {
347 //更新下一批次的审核人 359 //更新下一批次的审核人
348 var nextApprovers []int64 360 var nextApprovers []int64
  361 + if err = agg.SendApprovedMsg(chance.UserId, "",
  362 + header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {
  363 + log.Error(err)
  364 + orm.Rollback()
  365 + return
  366 + }
349 if approveItemResponse.IsOver == 1 { 367 if approveItemResponse.IsOver == 1 {
350 //结束审批 368 //结束审批
351 { 369 {
352 mapChance["ReviewStatus"] = int8(request.ReviewStatus) 370 mapChance["ReviewStatus"] = int8(request.ReviewStatus)
353 } 371 }
354 //发送审核结果消息给提交人 372 //发送审核结果消息给提交人
355 - for i := range approveItemResponse.MessageData.ApplyUserMessage {  
356 - message := approveItemResponse.MessageData.ApplyUserMessage[i]  
357 - nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)  
358 - if err = agg.SendApprovedMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,  
359 - header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {  
360 - log.Error(err)  
361 - return  
362 - }  
363 - }  
364 - //更新同批次的为审核的状态置为无效  
365 - if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {  
366 - log.Error(err)  
367 - return  
368 - } 373 + //for i := range approveItemResponse.MessageData.ApplyUserMessage {
  374 + // message := approveItemResponse.MessageData.ApplyUserMessage[i]
  375 + // nextApprovers = append(nextApprovers, message.ReceiverInfo.ReceiverUid)
  376 + // if err = agg.SendApprovedMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
  377 + // header.CompanyId, chance.Id, chance.ChanceTypeId, request.ReviewStatus, protocol.MsgTypeAuditBy); err != nil {
  378 + // log.Error(err)
  379 + // return
  380 + // }
  381 + //}
369 } else { 382 } else {
370 //发送下一个消息给下一流程的审核人 383 //发送下一个消息给下一流程的审核人
371 for i := range approveItemResponse.MessageData.ApproveMessage { 384 for i := range approveItemResponse.MessageData.ApproveMessage {
@@ -374,26 +387,27 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -374,26 +387,27 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
374 if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName, 387 if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
375 header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil { 388 header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
376 log.Error(err) 389 log.Error(err)
  390 + orm.Rollback()
377 return 391 return
378 } 392 }
379 } 393 }
380 //更新下一批次的审核人 同批次的为审核的状态置为无效 394 //更新下一批次的审核人 同批次的为审核的状态置为无效
381 if len(nextApprovers) != 0 { 395 if len(nextApprovers) != 0 {
382 - if err = models.UpdatetAuditFlowProcessToNext(chance.Id, chance.AuditLevel+1, nextApprovers); err != nil { 396 + if err = models.UpdatetAuditFlowProcessToNext(orm, chance.Id, chance.AuditLevel+1, nextApprovers); err != nil {
383 log.Error(err) 397 log.Error(err)
  398 + orm.Rollback()
384 log.Info(fmt.Sprintf("更新机会失败 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers)) 399 log.Info(fmt.Sprintf("更新机会失败 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers))
385 return 400 return
386 } 401 }
387 log.Info(fmt.Sprintf("更新机会 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers)) 402 log.Info(fmt.Sprintf("更新机会 chance_id:%v 下一批次审批人员:%v", chance.Id, nextApprovers))
388 - if err = models.UpdatetAuditFlowProcessNoApprove(chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil { 403 + if err = models.UpdatetAuditFlowProcessNoApprove(orm, chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
389 log.Error(err) 404 log.Error(err)
  405 + orm.Rollback()
390 return 406 return
391 } 407 }
392 } 408 }
393 } 409 }
394 } 410 }
395 - orm := orm.NewOrm()  
396 - orm.Begin()  
397 if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil { 411 if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
398 log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err) 412 log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
399 orm.Rollback() 413 orm.Rollback()
@@ -404,6 +418,14 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -404,6 +418,14 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
404 log.Error("更新机会审核状态失败 chance_id:", chance.Id, err) 418 log.Error("更新机会审核状态失败 chance_id:", chance.Id, err)
405 return 419 return
406 } 420 }
  421 + if request.ReviewStatus == protocol.ReviewStatusReturn || approveItemResponse.IsOver == 1 {
  422 + //更新同批次的为审核的状态置为无效
  423 + if err = models.UpdatetAuditFlowProcessNoApprove(orm, chance.Id, chance.AuditLevel, protocol.ReviewStatusAuditging); err != nil {
  424 + log.Error(err)
  425 + orm.Rollback()
  426 + return
  427 + }
  428 + }
407 if request.ApproveData.PublicData.PublishStatus == protocol.PublicToDepartment { 429 if request.ApproveData.PublicData.PublishStatus == protocol.PublicToDepartment {
408 if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteChanceDepartment, chance.Id); err != nil { 430 if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteChanceDepartment, chance.Id); err != nil {
409 log.Error(err) 431 log.Error(err)
@@ -283,7 +283,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -283,7 +283,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
283 } 283 }
284 284
285 //生成提交记录 285 //生成提交记录
286 - if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id)); err != nil { 286 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
287 log.Error(err) 287 log.Error(err)
288 orm.Rollback() 288 orm.Rollback()
289 return 289 return
@@ -607,7 +607,7 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe @@ -607,7 +607,7 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe
607 } 607 }
608 608
609 //生成审批流-提交记录 609 //生成审批流-提交记录
610 -func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64) (v *models.AuditFlowProcess) { 610 +func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
611 v = &models.AuditFlowProcess{ 611 v = &models.AuditFlowProcess{
612 Id: idgen.Next(), 612 Id: idgen.Next(),
613 ChanceId: chanceId, 613 ChanceId: chanceId,
@@ -616,7 +616,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, @@ -616,7 +616,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64,
616 UpdateAt: time.Now(), 616 UpdateAt: time.Now(),
617 ApproveTime: time.Now(), 617 ApproveTime: time.Now(),
618 EnableStatus: 1, 618 EnableStatus: 1,
619 - ReviewStatus: protocol.ReviewStatusSubmit, 619 + ReviewStatus: int8(reviewStatus),
620 } 620 }
621 if approver, err := models.GetUsersById(header.Uid); err != nil { 621 if approver, err := models.GetUsersById(header.Uid); err != nil {
622 log.Error(err) 622 log.Error(err)