feat: 添加部门处理人。

This commit is contained in:
Mr. Lan 2020-11-15 20:13:17 +08:00
parent 6addad26cb
commit ba74c8c748
6 changed files with 102 additions and 50 deletions

View File

@ -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"))

View File

@ -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 {

View File

@ -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
}
}

View File

@ -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(&currentUserInfo).
Where("user_id = ?", tools.GetUserId(c)).
Find(&currentUserInfo).
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)) {

View File

@ -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还需要找最优解决方案

View File

@ -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)