作者 yangfu

审核修改

... ... @@ -141,10 +141,10 @@ func CloseAuditFlowProcess(chanceId int64) (err error) {
}
//获取当前审批节点 是否已经有人审核通过的
func GetAuditFlowProcessApproved(chanceId int64, level int) (v *AuditFlowProcess, err error) {
func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select id from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status<>1 and enable_status=1"
if err = o.Raw(sql, chanceId, level).QueryRow(&v); err != nil {
if _, err = o.Raw(sql, chanceId, level).QueryRows(&v); err != nil {
return
}
return
... ... @@ -162,7 +162,7 @@ func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v
//更新提交
func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, reviewStatus int, userId int64) (err error) {
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"
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"
if err = utils.ExecuteSQLWithOrmer(o, sql, reviewStatus, chanceId, userId, level); err != nil {
return
}
... ...
... ... @@ -15,8 +15,8 @@ const (
)
const (
ActionTypeOr = 1
ActionTypeAnd = 2
ActionTypeAnd = 1 //会签
ActionTypeOr = 2 //或签
)
//审核类型
... ...
... ... @@ -349,7 +349,7 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
mapChance["ReviewStatus"] = int8(request.ReviewStatus) //退回也要更新审核状态
//增加一条待处理记录到审核列表
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
if _, err = orm.Insert(GenAuditFlowProcess_Submit(chance.UserId, chance.Id, chance.AuditTemplateId, protocol.ReviewStatusWait)); err != nil {
log.Error(err)
orm.Rollback()
return
... ...
... ... @@ -344,7 +344,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
//生成提交记录
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header.UserId, chance.Id, template.Id, protocol.ReviewStatusSubmit)); err != nil {
log.Error(err)
orm.Rollback()
return
... ... @@ -429,16 +429,26 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
err = protocol.NewErrWithMessage(5101)
return
}
//1.模板是否存在
if template, err = models.GetAuditTemplateById(int64(chance.AuditTemplateId)); err != nil {
log.Error("模板不存在:", chance.AuditTemplateId, err)
return
}
if chanceType, err = models.GetChanceTypeById(chance.ChanceTypeId); err != nil {
log.Error("一级分类不存在:", chance.ChanceTypeId, err)
return
}
//编辑重新发布 是否可以重新发布
if request.IsPublish && chance.ReviewStatus == protocol.ReviewStatusReturn && chance.UserId == header.UserId {
request.IsPublish = false
//当前没有被人审核过
if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
//当前状态是退回-待处理
//if _, e := models.GetAuditFlowProcessApproved(request.Id, 1); e == orm.ErrNoRows && chance.AuditLevel == 1 {
// //当前状态是退回-待处理
//
//}
if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
request.IsPublish = true
}
}
} else {
request.IsPublish = false
}
... ... @@ -507,6 +517,7 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
{
if request.IsPublish {
//更新待处理->提交
if err = models.UpdatetAuditFlowProcessToSubmit(orm, request.Id, 0, protocol.ReviewStatusSubmit, header.UserId); err != nil {
log.Error(err)
... ... @@ -737,18 +748,19 @@ func ChancePermission(header *protocol.RequestHeader, request *protocol.ChancePe
}
//生成审批流-提交记录
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
func GenAuditFlowProcess_Submit(userId, chanceId int64, templateId int64, reviewStatus int) (v *models.AuditFlowProcess) {
v = &models.AuditFlowProcess{
Id: idgen.Next(),
ChanceId: chanceId,
Uid: header.UserId,
Uid: userId,
CreateAt: time.Now(),
UpdateAt: time.Now(),
ApproveTime: time.Now(),
EnableStatus: 1,
IsActive: 1,
ReviewStatus: int8(reviewStatus),
}
if approver, err := models.GetUsersById(header.Uid); err != nil {
if approver, err := models.GetUsersById(userId); err != nil {
log.Error(err)
return
} else {
... ... @@ -767,7 +779,8 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
company *models.Company
roleName string
approver *models.User
roleId []int
roleIds []int
roleId int
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
... ... @@ -849,11 +862,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
}
break
case protocol.AuditByRole:
if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
if e := json.Unmarshal([]byte(config.ToRole), &roleIds); e == nil {
if userIds, err = getRoleUsers(header, roleIds[0]); err != nil {
log.Error(err)
return
}
if role, e := models.GetRoleById(roleIds[0]); e == nil {
roleName = role.Name
roleId = role.Id
}
} else {
log.Error(config.ToRole, e)
}
... ... @@ -890,6 +907,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
ActionType: int(config.ActionType),
RoleName: roleName,
UserName: approver.NickName,
RoleId: roleId,
ReviewStatus: protocol.ReviewStatusAuditging,
TemplateId: int(templateId),
}
... ... @@ -897,7 +915,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
item.IsActive = 1
item.EnableStatus = 1
}
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)))
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))
v = append(v, item)
}
}
... ... @@ -905,10 +923,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
}
func resolveActionType(t uint) string {
if t == 1 {
return "or"
return "and"
}
if t == 2 {
return "and"
return "or"
}
return fmt.Sprintf("%v", t)
}
... ...