Merge pull request #102 from lanyulei/dev

feat: 添加部门处理人。
This commit is contained in:
lanyulei 2020-11-15 20:14:57 +08:00 committed by GitHub
commit df08b89bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 50 deletions

View File

@ -1,6 +1,7 @@
package system package system
import ( import (
"ferry/global/orm"
"ferry/models/system" "ferry/models/system"
"ferry/tools" "ferry/tools"
"ferry/tools/app" "ferry/tools/app"
@ -46,6 +47,21 @@ func GetDeptList(c *gin.Context) {
app.OK(c, result, "") 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) { func GetDeptTree(c *gin.Context) {
var ( var (
Dept system.Dept Dept system.Dept
@ -158,7 +174,7 @@ func DeleteDept(c *gin.Context) {
app.OK(c, "", msg.DeletedSuccess) app.OK(c, "", msg.DeletedSuccess)
} }
func GetDeptTreeRoleselect(c *gin.Context) { func GetDeptTreeRoleSelect(c *gin.Context) {
var Dept system.Dept var Dept system.Dept
var SysRole system.SysRole var SysRole system.SysRole
id, _ := tools.StringToInt(c.Param("roleId")) id, _ := tools.StringToInt(c.Param("roleId"))

View File

@ -36,11 +36,13 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
if err != nil { if err != nil {
return return
} }
//case "department": case "department":
// err = orm.Eloquent.Model(&user.Dept{}).Where("id in (?)", processor).Pluck("nickname", &principalList).Error err = orm.Eloquent.Model(&system.Dept{}).
// if err != nil { Where("dept_id in (?)", processor).
// return Pluck("dept_name", &principalList).Error
// } if err != nil {
return
}
case "variable": case "variable":
for _, p := range processor { for _, p := range processor {
switch p { switch p {

View File

@ -69,7 +69,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
stateIdMap map[string]interface{} stateIdMap map[string]interface{}
currentState map[string]interface{} currentState map[string]interface{}
cirHistoryCount int cirHistoryCount int
roleUserInfo []system.SysUser userInfoList []system.SysUser
circulationStatus bool circulationStatus bool
) )
@ -85,7 +85,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
currentState = v currentState = v
} }
} }
roleStatusCount := 0 userStatusCount := 0
circulationStatus = false circulationStatus = false
for _, cirHistoryValue := range h.cirHistoryList { for _, cirHistoryValue := range h.cirHistoryList {
if len(currentState["processor"].([]interface{})) > 1 { if len(currentState["processor"].([]interface{})) > 1 {
@ -107,18 +107,22 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
circulationStatus = true circulationStatus = true
break break
} }
} else if currentState["process_method"].(string) == "role" { } else if currentState["process_method"].(string) == "role" || currentState["process_method"].(string) == "department" {
// 全员处理 // 全员处理
var tmpUserList []system.SysUser var tmpUserList []system.SysUser
if h.stateValue["fullHandle"].(bool) { if h.stateValue["fullHandle"].(bool) {
err = orm.Eloquent.Model(&system.SysUser{}). db := orm.Eloquent.Model(&system.SysUser{})
Where("role_id in (?)", currentState["processor"].([]interface{})). if currentState["process_method"].(string) == "role" {
Find(&roleUserInfo).Error 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 { if err != nil {
return return
} }
temp := map[string]struct{}{} temp := map[string]struct{}{}
for _, user := range roleUserInfo { for _, user := range userInfoList {
if _, ok := temp[user.Username]; !ok { if _, ok := temp[user.Username]; !ok {
temp[user.Username] = struct{}{} temp[user.Username] = struct{}{}
tmpUserList = append(tmpUserList, user) tmpUserList = append(tmpUserList, user)
@ -128,33 +132,39 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
if cirHistoryValue.Source == currentState["id"].(string) && if cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId != tools.GetUserId(c) && cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.ProcessorId == user.UserId { cirHistoryValue.ProcessorId == user.UserId {
roleStatusCount += 1 userStatusCount += 1
break break
} }
} }
} else { } else {
// 普通会签 // 普通会签
for _, processor := range currentState["processor"].([]interface{}) { 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 { if err != nil {
return return
} }
for _, user := range roleUserInfo { for _, user := range userInfoList {
if user.UserId != tools.GetUserId(c) && if user.UserId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) && cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == user.UserId { cirHistoryValue.ProcessorId == user.UserId {
roleStatusCount += 1 userStatusCount += 1
break break
} }
} }
} }
} }
if h.stateValue["fullHandle"].(bool) { if h.stateValue["fullHandle"].(bool) {
if roleStatusCount == len(tmpUserList)-1 { if userStatusCount == len(tmpUserList)-1 {
circulationStatus = true circulationStatus = true
} }
} else { } else {
if roleStatusCount == len(currentState["processor"].([]interface{}))-1 { if userStatusCount == len(currentState["processor"].([]interface{}))-1 {
circulationStatus = true circulationStatus = true
} }
} }

View File

@ -32,6 +32,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
processState ProcessState processState ProcessState
currentStateList []map[string]interface{} currentStateList []map[string]interface{}
currentStateValue map[string]interface{} currentStateValue map[string]interface{}
currentUserInfo system.SysUser
) )
// 获取工单信息 // 获取工单信息
err = orm.Eloquent.Model(&workOrderInfo). err = orm.Eloquent.Model(&workOrderInfo).
@ -68,6 +69,15 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
} }
} }
// 获取当前用户信息
err = orm.Eloquent.Model(&currentUserInfo).
Where("user_id = ?", tools.GetUserId(c)).
Find(&currentUserInfo).
Error
if err != nil {
return
}
// 会签 // 会签
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, ok := stateValue["isCounterSign"]; ok {
@ -107,6 +117,28 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
return 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 status = true
} }
} }
//case "persongroup": case "department":
// var persongroupCount int for _, processorValue := range currentStateValue["processor"].([]interface{}) {
// err = orm.Eloquent.Model(&user.UserGroup{}). if int(processorValue.(float64)) == currentUserInfo.DeptId {
// Where("group in (?) and user = ?", currentStateValue["processor"].([]interface{}), tools.GetUserId(c)). status = true
// 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 "variable": case "variable":
for _, p := range currentStateValue["processor"].([]interface{}) { for _, p := range currentStateValue["processor"].([]interface{}) {
switch int(p.(float64)) { switch int(p.(float64)) {

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"ferry/global/orm" "ferry/global/orm"
"ferry/models/process" "ferry/models/process"
"ferry/models/system"
"ferry/pkg/pagination" "ferry/pkg/pagination"
"ferry/tools" "ferry/tools"
"fmt" "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)) roleSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'role')))", tools.GetRoleId(w.GinObj))
// 3. 部门 // 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. 变量会转成个人数据 // 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 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: case 2:
// 我创建的 // 我创建的
db = db.Where("creator = ?", tools.GetUserId(w.GinObj)) 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) { 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 ( var (
stateName string stateName string
structResult map[string]interface{} structResult map[string]interface{}
authStatus bool authStatus bool
) )
err = json.Unmarshal(v.State, &StateList)
if err != nil {
err = fmt.Errorf("json反序列化失败%v", err.Error())
return
}
if len(StateList) != 0 { if len(StateList) != 0 {
// 仅待办工单需要验证 // 仅待办工单需要验证
// todo还需要找最优解决方案 // todo还需要找最优解决方案

View File

@ -35,8 +35,7 @@ func RegisterBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
v1auth.GET("/getinfo", system.GetInfo) v1auth.GET("/getinfo", system.GetInfo)
v1auth.GET("/menurole", system.GetMenuRole) v1auth.GET("/menurole", system.GetMenuRole)
v1auth.GET("/roleMenuTreeselect/:roleId", system.GetMenuTreeRoleselect) v1auth.GET("/roleMenuTreeselect/:roleId", system.GetMenuTreeRoleselect)
v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleselect) v1auth.GET("/roleDeptTreeselect/:roleId", system.GetDeptTreeRoleSelect)
v1auth.POST("/logout", handler.LogOut) v1auth.POST("/logout", handler.LogOut)
v1auth.GET("/menuids", system.GetMenuIDS) 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 := v1.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{ {
v1auth.GET("/deptList", system.GetDeptList) v1auth.GET("/deptList", system.GetDeptList)
v1auth.GET("/ordinaryDeptList", system.GetOrdinaryDeptList)
v1auth.GET("/deptTree", system.GetDeptTree) v1auth.GET("/deptTree", system.GetDeptTree)
v1auth.GET("/sysUserList", system.GetSysUserList) v1auth.GET("/sysUserList", system.GetSysUserList)
v1auth.GET("/rolelist", system.GetRoleList) v1auth.GET("/rolelist", system.GetRoleList)