From ba74c8c748c565cd1c8cf924327a4bc3c7744836 Mon Sep 17 00:00:00 2001 From: "Mr. Lan" Date: Sun, 15 Nov 2020 20:13:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=83=A8=E9=97=A8?= =?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 --- apis/system/dept.go | 18 ++++++++++- pkg/service/getPrincipal.go | 12 +++++--- pkg/service/handle.go | 36 ++++++++++++++-------- pkg/service/userAuthority.go | 60 +++++++++++++++++++++++------------- pkg/service/workOrderList.go | 22 ++++++++----- router/system/sys_router.go | 4 +-- 6 files changed, 102 insertions(+), 50 deletions(-) diff --git a/apis/system/dept.go b/apis/system/dept.go index 0c950f9..b3a90e3 100644 --- a/apis/system/dept.go +++ b/apis/system/dept.go @@ -1,6 +1,7 @@ package system import ( + "ferry/global/orm" "ferry/models/system" "ferry/tools" "ferry/tools/app" @@ -46,6 +47,21 @@ func GetDeptList(c *gin.Context) { app.OK(c, result, "") } +func GetOrdinaryDeptList(c *gin.Context) { + var ( + err error + deptList []system.Dept + ) + + err = orm.Eloquent.Model(&system.Dept{}).Find(&deptList).Error + if err != nil { + app.Error(c, -1, err, "") + return + } + + app.OK(c, deptList, "") +} + func GetDeptTree(c *gin.Context) { var ( Dept system.Dept @@ -158,7 +174,7 @@ func DeleteDept(c *gin.Context) { app.OK(c, "", msg.DeletedSuccess) } -func GetDeptTreeRoleselect(c *gin.Context) { +func GetDeptTreeRoleSelect(c *gin.Context) { var Dept system.Dept var SysRole system.SysRole id, _ := tools.StringToInt(c.Param("roleId")) diff --git a/pkg/service/getPrincipal.go b/pkg/service/getPrincipal.go index cb050ba..0c73416 100644 --- a/pkg/service/getPrincipal.go +++ b/pkg/service/getPrincipal.go @@ -36,11 +36,13 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err if err != nil { return } - //case "department": - // err = orm.Eloquent.Model(&user.Dept{}).Where("id in (?)", processor).Pluck("nickname", &principalList).Error - // if err != nil { - // return - // } + case "department": + err = orm.Eloquent.Model(&system.Dept{}). + Where("dept_id in (?)", processor). + Pluck("dept_name", &principalList).Error + if err != nil { + return + } case "variable": for _, p := range processor { switch p { diff --git a/pkg/service/handle.go b/pkg/service/handle.go index ddece2a..c4b6205 100644 --- a/pkg/service/handle.go +++ b/pkg/service/handle.go @@ -69,7 +69,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) { stateIdMap map[string]interface{} currentState map[string]interface{} cirHistoryCount int - roleUserInfo []system.SysUser + userInfoList []system.SysUser circulationStatus bool ) @@ -85,7 +85,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) { currentState = v } } - roleStatusCount := 0 + userStatusCount := 0 circulationStatus = false for _, cirHistoryValue := range h.cirHistoryList { if len(currentState["processor"].([]interface{})) > 1 { @@ -107,18 +107,22 @@ func (h *Handle) Countersign(c *gin.Context) (err error) { circulationStatus = true break } - } else if currentState["process_method"].(string) == "role" { + } else if currentState["process_method"].(string) == "role" || currentState["process_method"].(string) == "department" { // 全员处理 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 + db := orm.Eloquent.Model(&system.SysUser{}) + if currentState["process_method"].(string) == "role" { + db = db.Where("role_id in (?)", currentState["processor"].([]interface{})) + } else if currentState["process_method"].(string) == "department" { + db = db.Where("dept_id in (?)", currentState["processor"].([]interface{})) + } + err = db.Find(&userInfoList).Error if err != nil { return } temp := map[string]struct{}{} - for _, user := range roleUserInfo { + for _, user := range userInfoList { if _, ok := temp[user.Username]; !ok { temp[user.Username] = struct{}{} tmpUserList = append(tmpUserList, user) @@ -128,33 +132,39 @@ func (h *Handle) Countersign(c *gin.Context) (err error) { if cirHistoryValue.Source == currentState["id"].(string) && cirHistoryValue.ProcessorId != tools.GetUserId(c) && cirHistoryValue.ProcessorId == user.UserId { - roleStatusCount += 1 + userStatusCount += 1 break } } } else { // 普通会签 for _, processor := range currentState["processor"].([]interface{}) { - err = orm.Eloquent.Model(&system.SysUser{}).Where("role_id = ?", processor).Find(&roleUserInfo).Error + db := orm.Eloquent.Model(&system.SysUser{}) + if currentState["process_method"].(string) == "role" { + db = db.Where("role_id = ?", processor) + } else if currentState["process_method"].(string) == "department" { + db = db.Where("dept_id = ?", processor) + } + err = db.Find(&userInfoList).Error if err != nil { return } - for _, user := range roleUserInfo { + for _, user := range userInfoList { if user.UserId != tools.GetUserId(c) && cirHistoryValue.Source == currentState["id"].(string) && cirHistoryValue.ProcessorId == user.UserId { - roleStatusCount += 1 + userStatusCount += 1 break } } } } if h.stateValue["fullHandle"].(bool) { - if roleStatusCount == len(tmpUserList)-1 { + if userStatusCount == len(tmpUserList)-1 { circulationStatus = true } } else { - if roleStatusCount == len(currentState["processor"].([]interface{}))-1 { + if userStatusCount == len(currentState["processor"].([]interface{}))-1 { circulationStatus = true } } diff --git a/pkg/service/userAuthority.go b/pkg/service/userAuthority.go index 68e8a09..26c7334 100644 --- a/pkg/service/userAuthority.go +++ b/pkg/service/userAuthority.go @@ -32,6 +32,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s processState ProcessState currentStateList []map[string]interface{} currentStateValue map[string]interface{} + currentUserInfo system.SysUser ) // 获取工单信息 err = orm.Eloquent.Model(&workOrderInfo). @@ -68,6 +69,15 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s } } + // 获取当前用户信息 + err = orm.Eloquent.Model(¤tUserInfo). + Where("user_id = ?", tools.GetUserId(c)). + Find(¤tUserInfo). + Error + if err != nil { + return + } + // 会签 if currentStateValue["processor"] != nil && len(currentStateValue["processor"].([]interface{})) >= 1 { if isCounterSign, ok := stateValue["isCounterSign"]; ok { @@ -107,6 +117,28 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s return } } + } else if currentStateValue["process_method"].(string) == "department" { + // 部门会签 + if stateValue["fullHandle"].(bool) { + if cirHistoryValue.ProcessorId == tools.GetUserId(c) { + return + } + } else { + var ( + deptUserInfo system.SysUser + ) + err = orm.Eloquent.Model(&deptUserInfo). + Where("user_id = ?", cirHistoryValue.ProcessorId). + Find(&deptUserInfo). + Error + if err != nil { + return + } + + if deptUserInfo.DeptId == currentUserInfo.DeptId { + return + } + } } } } @@ -127,28 +159,12 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s status = true } } - //case "persongroup": - // var persongroupCount int - // err = orm.Eloquent.Model(&user.UserGroup{}). - // Where("group in (?) and user = ?", currentStateValue["processor"].([]interface{}), tools.GetUserId(c)). - // Count(&persongroupCount).Error - // if err != nil { - // return - // } - // if persongroupCount > 0 { - // status = true - // } - //case "department": - // var departmentCount int - // err = orm.Eloquent.Model(&system.SysUser{}). - // Where("dept in (?) and id = ?", currentStateValue["processor"].([]interface{}), tools.GetUserId(c)). - // Count(&departmentCount).Error - // if err != nil { - // return - // } - // if departmentCount > 0 { - // status = true - // } + case "department": + for _, processorValue := range currentStateValue["processor"].([]interface{}) { + if int(processorValue.(float64)) == currentUserInfo.DeptId { + status = true + } + } case "variable": for _, p := range currentStateValue["processor"].([]interface{}) { switch int(p.(float64)) { diff --git a/pkg/service/workOrderList.go b/pkg/service/workOrderList.go index a62b2ba..71f6ca2 100644 --- a/pkg/service/workOrderList.go +++ b/pkg/service/workOrderList.go @@ -4,6 +4,7 @@ import ( "encoding/json" "ferry/global/orm" "ferry/models/process" + "ferry/models/system" "ferry/pkg/pagination" "ferry/tools" "fmt" @@ -47,11 +48,18 @@ func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) { 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) + var userInfo system.SysUser + err = orm.Eloquent.Model(&system.SysUser{}). + Where("user_id = ?", tools.GetUserId(w.GinObj)). + Find(&userInfo).Error + if err != nil { + return + } + departmentSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'department')))", userInfo.DeptId) // 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 or %v) and is_end = 0", personSelect, roleSelect)) + db = db.Where(fmt.Sprintf("(%v or %v or %v) and is_end = 0", personSelect, roleSelect, departmentSelect)) case 2: // 我创建的 db = db.Where("creator = ?", tools.GetUserId(w.GinObj)) @@ -90,16 +98,16 @@ func (w *WorkOrder) WorkOrderList() (result interface{}, err error) { } for i, v := range *result.(*pagination.Paginator).Data.(*[]workOrderInfo) { - err = json.Unmarshal(v.State, &StateList) - if err != nil { - err = fmt.Errorf("json反序列化失败,%v", err.Error()) - return - } var ( stateName string structResult map[string]interface{} authStatus bool ) + err = json.Unmarshal(v.State, &StateList) + if err != nil { + err = fmt.Errorf("json反序列化失败,%v", err.Error()) + return + } if len(StateList) != 0 { // 仅待办工单需要验证 // todo:还需要找最优解决方案 diff --git a/router/system/sys_router.go b/router/system/sys_router.go index 23bf18c..eb5d1a3 100644 --- a/router/system/sys_router.go +++ b/router/system/sys_router.go @@ -35,8 +35,7 @@ func RegisterBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar v1auth.GET("/getinfo", system.GetInfo) v1auth.GET("/menurole", system.GetMenuRole) v1auth.GET("/roleMenuTreeselect/:roleId", system.GetMenuTreeRoleselect) - v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleselect) - + v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleSelect) v1auth.POST("/logout", handler.LogOut) v1auth.GET("/menuids", system.GetMenuIDS) } @@ -46,6 +45,7 @@ func RegisterPageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar v1auth := v1.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { v1auth.GET("/deptList", system.GetDeptList) + v1auth.GET("/ordinaryDeptList", system.GetOrdinaryDeptList) v1auth.GET("/deptTree", system.GetDeptTree) v1auth.GET("/sysUserList", system.GetSysUserList) v1auth.GET("/rolelist", system.GetRoleList)