feat: 添加角色处理人。

This commit is contained in:
Mr. Lan 2020-11-15 14:52:09 +08:00
parent 2e8eb41434
commit 5d7ca470a1
5 changed files with 121 additions and 42 deletions

View File

@ -93,7 +93,6 @@ func Paging(p *Param, result interface{}, args ...interface{}) (*Paginator, erro
} else {
offset = (param.Page - 1) * param.PerPage
}
err := db.Limit(param.PerPage).Offset(offset).Scan(result).Error
if err != nil {
logger.Errorf("数据查询失败,错误:%v", err)

View File

@ -29,6 +29,13 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
if err != nil {
return
}
case "role":
err = orm.Eloquent.Model(&system.SysRole{}).
Where("role_id in (?)", processor).
Pluck("role_name", &principalList).Error
if err != nil {
return
}
//case "department":
// err = orm.Eloquent.Model(&user.Dept{}).Where("id in (?)", processor).Pluck("nickname", &principalList).Error
// if err != nil {

View File

@ -65,10 +65,12 @@ func fmtDuration(d time.Duration) string {
// 会签
func (h *Handle) Countersign(c *gin.Context) (err error) {
var (
stateList []map[string]interface{}
stateIdMap map[string]interface{}
currentState map[string]interface{}
cirHistoryCount int
stateList []map[string]interface{}
stateIdMap map[string]interface{}
currentState map[string]interface{}
cirHistoryCount int
roleUserInfo []system.SysUser
circulationStatus bool
)
err = json.Unmarshal(h.workOrderDetails.State, &stateList)
@ -83,19 +85,82 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
currentState = v
}
}
roleStatusCount := 0
circulationStatus = false
for _, cirHistoryValue := range h.cirHistoryList {
if _, ok := stateIdMap[cirHistoryValue.Source]; !ok {
break
if len(currentState["processor"].([]interface{})) > 1 {
if _, ok := stateIdMap[cirHistoryValue.Source]; !ok {
break
}
}
for _, processor := range currentState["processor"].([]interface{}) {
if cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == int(processor.(float64)) {
cirHistoryCount += 1
if currentState["process_method"].(string) == "person" {
// 用户会签
for _, processor := range currentState["processor"].([]interface{}) {
if cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == int(processor.(float64)) {
cirHistoryCount += 1
}
}
if cirHistoryCount == len(currentState["processor"].([]interface{}))-1 {
circulationStatus = true
break
}
} else if currentState["process_method"].(string) == "role" {
// 全员处理
var tmpUserList []system.SysUser
if h.stateValue["fullHandle"].(bool) {
err = orm.Eloquent.Model(&system.SysUser{}).
Where("role_id in (?)", currentState["processor"].([]interface{})).
Find(&roleUserInfo).Error
if err != nil {
return
}
temp := map[string]struct{}{}
for _, user := range roleUserInfo {
if _, ok := temp[user.Username]; !ok {
temp[user.Username] = struct{}{}
tmpUserList = append(tmpUserList, user)
}
}
for _, user := range tmpUserList {
if cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.ProcessorId == user.UserId {
roleStatusCount += 1
break
}
}
} else {
// 普通会签
for _, processor := range currentState["processor"].([]interface{}) {
err = orm.Eloquent.Model(&system.SysUser{}).Where("role_id = ?", processor).Find(&roleUserInfo).Error
if err != nil {
return
}
for _, user := range roleUserInfo {
if user.UserId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == user.UserId {
roleStatusCount += 1
break
}
}
}
}
if h.stateValue["fullHandle"].(bool) {
if roleStatusCount == len(tmpUserList)-1 {
circulationStatus = true
}
} else {
if roleStatusCount == len(currentState["processor"].([]interface{}))-1 {
circulationStatus = true
}
}
}
}
if cirHistoryCount == len(currentState["processor"].([]interface{}))-1 {
if circulationStatus {
h.endHistory = true
err = h.circulation()
if err != nil {
@ -298,7 +363,7 @@ func (h *Handle) commonProcessing(c *gin.Context) (err error) {
}
// 会签
if h.stateValue["assignValue"] != nil && len(h.stateValue["assignValue"].([]interface{})) > 1 {
if h.stateValue["assignValue"] != nil && len(h.stateValue["assignValue"].([]interface{})) > 0 {
if isCounterSign, ok := h.stateValue["isCounterSign"]; ok {
if isCounterSign.(bool) {
h.endHistory = false

View File

@ -69,7 +69,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
}
// 会签
if currentStateValue["processor"] != nil && len(currentStateValue["processor"].([]interface{})) > 1 {
if currentStateValue["processor"] != nil && len(currentStateValue["processor"].([]interface{})) >= 1 {
if isCounterSign, ok := stateValue["isCounterSign"]; ok {
if isCounterSign.(bool) {
err = orm.Eloquent.Model(&process.CirculationHistory{}).
@ -82,9 +82,32 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
for _, cirHistoryValue := range cirHistoryList {
if cirHistoryValue.Source != stateValue["id"] {
break
}
if cirHistoryValue.Source == stateValue["id"] && cirHistoryValue.ProcessorId == tools.GetUserId(c) {
return
} else if cirHistoryValue.Source == stateValue["id"] {
if currentStateValue["process_method"].(string) == "person" {
// 验证个人会签
if cirHistoryValue.ProcessorId == tools.GetUserId(c) {
return
}
} else if currentStateValue["process_method"].(string) == "role" {
// 验证角色会签
if stateValue["fullHandle"].(bool) {
if cirHistoryValue.ProcessorId == tools.GetUserId(c) {
return
}
} else {
var roleUserInfo system.SysUser
err = orm.Eloquent.Model(&roleUserInfo).
Where("user_id = ?", cirHistoryValue.ProcessorId).
Find(&roleUserInfo).
Error
if err != nil {
return
}
if roleUserInfo.RoleId == tools.GetRoleId(c) {
return
}
}
}
}
}
}
@ -98,6 +121,12 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
status = true
}
}
case "role":
for _, processorValue := range currentStateValue["processor"].([]interface{}) {
if int(processorValue.(float64)) == tools.GetRoleId(c) {
status = true
}
}
//case "persongroup":
// var persongroupCount int
// err = orm.Eloquent.Model(&user.UserGroup{}).

View File

@ -43,36 +43,15 @@ func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
// 1. 个人
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", tools.GetUserId(w.GinObj))
// 2. 小组
//groupList := make([]int, 0)
//err = orm.Eloquent.Model(&user.UserGroup{}).
// Where("user = ?", tools.GetUserId(c)).
// Pluck("`group`", &groupList).Error
//if err != nil {
// return
//}
//groupSqlList := make([]string, 0)
//if len(groupList) > 0 {
// for _, group := range groupList {
// groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', %v))", group))
// }
//} else {
// groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 0))"))
//}
//
//personGroupSelect := fmt.Sprintf(
// "((%v) and %v)",
// strings.Join(groupSqlList, " or "),
// "JSON_CONTAINS(state, JSON_OBJECT('process_method', 'persongroup'))",
//)
// 2. 角色
roleSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'role')))", tools.GetRoleId(w.GinObj))
// 3. 部门
//departmentSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'department')))", userInfo.Dept)
// 4. 变量会转成个人数据
//db = db.Where(fmt.Sprintf("(%v or %v or %v or %v) and is_end = 0", personSelect, personGroupSelect, departmentSelect, variableSelect))
db = db.Where(fmt.Sprintf("(%v) and is_end = 0", personSelect))
db = db.Where(fmt.Sprintf("(%v or %v) and is_end = 0", personSelect, roleSelect))
case 2:
// 我创建的
db = db.Where("creator = ?", tools.GetUserId(w.GinObj))