From 5d7ca470a155d9966366590c59c73886e6cf6efe Mon Sep 17 00:00:00 2001 From: "Mr. Lan" Date: Sun, 15 Nov 2020 14:52:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/pagination/pagination.go | 1 - pkg/service/getPrincipal.go | 7 +++ pkg/service/handle.go | 91 ++++++++++++++++++++++++++++++------ pkg/service/userAuthority.go | 37 +++++++++++++-- pkg/service/workOrderList.go | 27 ++--------- 5 files changed, 121 insertions(+), 42 deletions(-) diff --git a/pkg/pagination/pagination.go b/pkg/pagination/pagination.go index 865c9fc..02a3070 100644 --- a/pkg/pagination/pagination.go +++ b/pkg/pagination/pagination.go @@ -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) diff --git a/pkg/service/getPrincipal.go b/pkg/service/getPrincipal.go index a478552..cb050ba 100644 --- a/pkg/service/getPrincipal.go +++ b/pkg/service/getPrincipal.go @@ -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 { diff --git a/pkg/service/handle.go b/pkg/service/handle.go index 139d4ab..ddece2a 100644 --- a/pkg/service/handle.go +++ b/pkg/service/handle.go @@ -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 diff --git a/pkg/service/userAuthority.go b/pkg/service/userAuthority.go index d336f2b..68e8a09 100644 --- a/pkg/service/userAuthority.go +++ b/pkg/service/userAuthority.go @@ -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{}). diff --git a/pkg/service/workOrderList.go b/pkg/service/workOrderList.go index bfda1da..a62b2ba 100644 --- a/pkg/service/workOrderList.go +++ b/pkg/service/workOrderList.go @@ -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))