作者 yangfu

审核修改

@@ -141,10 +141,10 @@ func CloseAuditFlowProcess(chanceId int64) (err error) { @@ -141,10 +141,10 @@ func CloseAuditFlowProcess(chanceId int64) (err error) {
141 } 141 }
142 142
143 //获取当前审批节点 是否已经有人审核通过的 143 //获取当前审批节点 是否已经有人审核通过的
144 -func GetAuditFlowProcessApproved(chanceId int64, level int) (v *AuditFlowProcess, err error) { 144 +func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProcess, err error) {
145 o := orm.NewOrm() 145 o := orm.NewOrm()
146 sql := "select id from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status<>1 and enable_status=1" 146 sql := "select id from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status<>1 and enable_status=1"
147 - if err = o.Raw(sql, chanceId, level).QueryRow(&v); err != nil { 147 + if _, err = o.Raw(sql, chanceId, level).QueryRows(&v); err != nil {
148 return 148 return
149 } 149 }
150 return 150 return
@@ -162,7 +162,7 @@ func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v @@ -162,7 +162,7 @@ func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v
162 162
163 //更新提交 163 //更新提交
164 func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, reviewStatus int, userId int64) (err error) { 164 func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, reviewStatus int, userId int64) (err error) {
165 - sql := "update audit_flow_process set enable_status =1,is_active=1,update_at=now(),review_status=? where chance_id=? and uid=? and level=? and and review_status=0 and enable_status=1" 165 + sql := "update audit_flow_process set enable_status =1,is_active=0,update_at=now(),review_status=? where chance_id=? and uid=? and level=? and review_status=0 and enable_status=1"
166 if err = utils.ExecuteSQLWithOrmer(o, sql, reviewStatus, chanceId, userId, level); err != nil { 166 if err = utils.ExecuteSQLWithOrmer(o, sql, reviewStatus, chanceId, userId, level); err != nil {
167 return 167 return
168 } 168 }
@@ -15,8 +15,8 @@ const ( @@ -15,8 +15,8 @@ const (
15 ) 15 )
16 16
17 const ( 17 const (
18 - ActionTypeOr = 1  
19 - ActionTypeAnd = 2 18 + ActionTypeAnd = 1 //会签
  19 + ActionTypeOr = 2 //或签
20 ) 20 )
21 21
22 //审核类型 22 //审核类型
@@ -349,7 +349,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro @@ -349,7 +349,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
349 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态 349 mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
350 //增加一条待处理记录到审核列表 350 //增加一条待处理记录到审核列表
351 //生成提交记录 351 //生成提交记录
352 - if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil { 352 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(chance.UserId, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
353 log.Error(err) 353 log.Error(err)
354 orm.Rollback() 354 orm.Rollback()
355 return 355 return
@@ -344,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -344,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
344 } 344 }
345 345
346 //生成提交记录 346 //生成提交记录
347 - if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil { 347 + if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
348 log.Error(err) 348 log.Error(err)
349 orm.Rollback() 349 orm.Rollback()
350 return 350 return
@@ -429,16 +429,26 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -429,16 +429,26 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
429 err = protocol.NewErrWithMessage(5101) 429 err = protocol.NewErrWithMessage(5101)
430 return 430 return
431 } 431 }
  432 + //1.模板是否存在
  433 + if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
  434 + log.Error("模板不存在:", chance.AuditTemplateId, err)
  435 + return
  436 + }
  437 + if chanceType, err = models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
  438 + log.Error("一级分类不存在:", chance.ChanceTypeId, err)
  439 + return
  440 + }
432 //编辑重新发布 是否可以重新发布 441 //编辑重新发布 是否可以重新发布
433 if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId { 442 if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
434 request.IsPublish = false 443 request.IsPublish = false
435 //当前没有被人审核过 444 //当前没有被人审核过
436 - if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {  
437 - //当前状态是退回-待处理 445 + //if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
  446 + // //当前状态是退回-待处理
  447 + //
  448 + //}
438 if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil { 449 if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
439 request.IsPublish = true 450 request.IsPublish = true
440 } 451 }
441 - }  
442 } else { 452 } else {
443 request.IsPublish = false 453 request.IsPublish = false
444 } 454 }
@@ -507,6 +517,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate @@ -507,6 +517,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
507 517
508 { 518 {
509 if request.IsPublish { 519 if request.IsPublish {
  520 +
510 //更新待处理->提交 521 //更新待处理->提交
511 if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil { 522 if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
512 log.Error(err) 523 log.Error(err)
@@ -737,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe @@ -737,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe
737 } 748 }
738 749
739 //生成审批流-提交记录 750 //生成审批流-提交记录
740 -func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) { 751 +func GenAuditFlowProcess_Submit(userId, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
741 v = &models.AuditFlowProcess{ 752 v = &models.AuditFlowProcess{
742 Id: idgen.Next(), 753 Id: idgen.Next(),
743 ChanceId: chanceId, 754 ChanceId: chanceId,
744 - Uid: header.UserId, 755 + Uid: userId,
745 CreateAt: time.Now(), 756 CreateAt: time.Now(),
746 UpdateAt: time.Now(), 757 UpdateAt: time.Now(),
747 ApproveTime: time.Now(), 758 ApproveTime: time.Now(),
748 EnableStatus: 1, 759 EnableStatus: 1,
  760 + IsActive: 1,
749 ReviewStatus: int8(reviewStatus), 761 ReviewStatus: int8(reviewStatus),
750 } 762 }
751 - if approver, err := models.GetUsersById(header.Uid); err != nil { 763 + if approver, err := models.GetUsersById(userId); err != nil {
752 log.Error(err) 764 log.Error(err)
753 return 765 return
754 } else { 766 } else {
@@ -767,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -767,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
767 company *models.Company 779 company *models.Company
768 roleName string 780 roleName string
769 approver *models.User 781 approver *models.User
770 - roleId []int 782 + roleIds []int
  783 + roleId int
771 ) 784 )
772 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil { 785 if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
773 if err == orm.ErrNoRows { 786 if err == orm.ErrNoRows {
@@ -849,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -849,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
849 } 862 }
850 break 863 break
851 case protocol.AuditByRole: 864 case protocol.AuditByRole:
852 - if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {  
853 - if userIds, err = getRoleUsers(header, roleId[0]); err != nil { 865 + if e := json.Unmarshal([]byte(config.ToRole), &roleIds); e == nil {
  866 + if userIds, err = getRoleUsers(header, roleIds[0]); err != nil {
854 log.Error(err) 867 log.Error(err)
855 return 868 return
856 } 869 }
  870 + if role, e := models.GetRoleById(roleIds[0]); e == nil {
  871 + roleName = role.Name
  872 + roleId = role.Id
  873 + }
857 } else { 874 } else {
858 log.Error(config.ToRole, e) 875 log.Error(config.ToRole, e)
859 } 876 }
@@ -890,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -890,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
890 ActionType: int(config.ActionType), 907 ActionType: int(config.ActionType),
891 RoleName: roleName, 908 RoleName: roleName,
892 UserName: approver.NickName, 909 UserName: approver.NickName,
  910 + RoleId: roleId,
893 ReviewStatus: protocol.ReviewStatusAuditging, 911 ReviewStatus: protocol.ReviewStatusAuditging,
894 TemplateId: int(templateId), 912 TemplateId: int(templateId),
895 } 913 }
@@ -897,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -897,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
897 item.IsActive = 1 915 item.IsActive = 1
898 item.EnableStatus = 1 916 item.EnableStatus = 1
899 } 917 }
900 - log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType))) 918 + log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v is_active:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType), item.IsActive))
901 v = append(v, item) 919 v = append(v, item)
902 } 920 }
903 } 921 }
@@ -905,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related @@ -905,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
905 } 923 }
906 func resolveActionType(t uint) string { 924 func resolveActionType(t uint) string {
907 if t == 1 { 925 if t == 1 {
908 - return "or" 926 + return "and"
909 } 927 }
910 if t == 2 { 928 if t == 2 {
911 - return "and" 929 + return "or"
912 } 930 }
913 return fmt.Sprintf("%v", t) 931 return fmt.Sprintf("%v", t)
914 } 932 }