作者 yangfu

审核流修改

... ... @@ -16,7 +16,6 @@ type Department struct {
Relation string `orm:"column(relation);size(400)" description:"父子级关系树"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Member int `orm:"column(member)" description:"成员数量"`
Managers string `orm:"column(managers);null" description:"部门负责人id列表 json 数组 [ ]"`
}
... ...
... ... @@ -69,3 +69,13 @@ func DeleteUserRole(id int) (err error) {
}
return
}
func GetUserRolesById(roleId int) (v []*UserRole, err error) {
o := orm.NewOrm()
sql := `
select * from user_role where role_id =? and enable_status =1`
if _, err = o.Raw(sql, roleId).QueryRows(&v); err == nil {
return
}
return
}
... ...
... ... @@ -656,6 +656,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
company *models.Company
roleName string
approver *models.User
roleId []int
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
... ... @@ -678,16 +679,18 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
groupId = config.AuditGroupId
continue
}
if len(config.FromSpecialUser) > 0 {
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
log.Error(err)
return
}
for j := range ids {
if ids[j] == header.Uid {
groupId = config.AuditGroupId
IsSpecailAuditFlow = true
break
if config.FlowType == protocol.FlowTypeSpecail {
if len(config.FromSpecialUser) > 0 {
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
log.Error(err)
return
}
for j := range ids {
if ids[j] == header.Uid {
groupId = config.AuditGroupId
IsSpecailAuditFlow = true
break
}
}
}
}
... ... @@ -727,14 +730,24 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
log.Error(err)
return
}
break
case protocol.AuditByUser:
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
log.Error(err)
return
}
break
case protocol.AuditByRole:
//roleName="" //TODO:角色
return
if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
log.Error(err)
return
}
} else {
log.Error(config.ToRole, e)
}
break
}
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
userIds = append(userIds, 0)
... ... @@ -744,7 +757,10 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
uid = company.AdminId
}
if uid == header.Uid { //审核人自己 转交给管理员
if uid == 0 {
uid = company.AdminId
}
if uid == header.UserId { //审核人自己 转交给管理员
log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
uid = company.AdminId
}
... ... @@ -802,14 +818,38 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
}
if len(departments.Managers) > 0 {
var tmpIds []int64
if err = json.Unmarshal([]byte(departments.Managers), &tmpIds); err == nil && len(ids) > 0 {
ids = append(ids, tmpIds...)
if err = json.Unmarshal([]byte(departments.Managers), &tmpIds); err == nil {
if len(tmpIds) > 0 {
ids = append(ids, tmpIds...)
}
}
}
//部门长不存在
if len(ids) == 0 {
ids = append(ids, 0)
}
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids))
return
}
//获取角色ids
func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err error) {
var (
userRole []*models.UserRole
)
if userRole, err = models.GetUserRolesById(roleId); err != nil {
log.Error(roleId, err)
if err == orm.ErrNoRows {
err = nil
}
}
for i := range userRole {
ids = append(ids, userRole[i].UserCompanyId)
}
if len(ids) == 0 {
ids = append(ids, 0)
}
log.Info(fmt.Sprintf("生成机会审批流-角色:role_id:%v ids:%v", roleId, ids))
return
}
... ...