添加变量"创建者负责人"
This commit is contained in:
parent
f8c177a138
commit
bd2b8c63bc
@ -56,6 +56,7 @@ func ProcessStructure(c *gin.Context) {
|
||||
func CreateWorkOrder(c *gin.Context) {
|
||||
var (
|
||||
userInfo system.SysUser
|
||||
variableValue []interface{}
|
||||
workOrderValue struct {
|
||||
process.WorkOrderInfo
|
||||
Tpls map[string][]interface{} `json:"tpls"`
|
||||
@ -77,6 +78,23 @@ func CreateWorkOrder(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取变量值
|
||||
err = json.Unmarshal(workOrderValue.State, &variableValue)
|
||||
if err != nil {
|
||||
app.Error(c, -1, err, "")
|
||||
return
|
||||
}
|
||||
err = service.GetVariableValue(variableValue, tools.GetUserId(c))
|
||||
if err != nil {
|
||||
app.Error(c, -1, err, fmt.Sprintf("获取处理人变量值失败,%v", err.Error()))
|
||||
return
|
||||
}
|
||||
workOrderValue.State, err = json.Marshal(variableValue)
|
||||
if err != nil {
|
||||
app.Error(c, -1, err, "")
|
||||
return
|
||||
}
|
||||
|
||||
// 创建工单数据
|
||||
tx := orm.Eloquent.Begin()
|
||||
var workOrderInfo = process.WorkOrderInfo{
|
||||
|
@ -79,11 +79,11 @@ INSERT INTO `casbin_rule`(`p_type`, `v0`, `v1`, `v2`, `v3`, `v4`, `v5`, `id`) VA
|
||||
COMMIT;
|
||||
|
||||
BEGIN;
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (1, 0, '/0/1', '磊哥科技', 0, 'leige', '', 'lanyulei@fdevops.com', 0, '1', '1');
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (7, 1, '/0/1/7', '研发部', 1, '', '', '', 0, '1', '1');
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (8, 1, '/0/1/8', '运维部', 0, '', '', '', 0, '1', NULL);
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (9, 1, '/0/1/9', '客服部', 0, '', '', '', 0, '1', NULL);
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (10, 1, '/0/1/10', '人力资源', 3, '张三', '', '', 1, '1', '1');
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (1, 0, '/0/1', '磊哥科技', 0, null, '', 'lanyulei@fdevops.com', 0, '1', '1');
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (7, 1, '/0/1/7', '研发部', 1, null, '', '', 0, '1', '1');
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (8, 1, '/0/1/8', '运维部', 0, null, '', '', 0, '1', NULL);
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (9, 1, '/0/1/9', '客服部', 0, null, '', '', 0, '1', NULL);
|
||||
INSERT INTO `sys_dept`(`dept_id`, `parent_id`, `dept_path`, `dept_name`, `sort`, `leader`, `phone`, `email`, `status`, `create_by`, `update_by`) VALUES (10, 1, '/0/1/10', '人力资源', 3, null, '', '', 1, '1', '1');
|
||||
COMMIT;
|
||||
|
||||
BEGIN;
|
||||
|
@ -17,7 +17,7 @@ type Dept struct {
|
||||
DeptPath string `json:"deptPath" gorm:"type:varchar(255);"` //
|
||||
DeptName string `json:"deptName" gorm:"type:varchar(128);"` //部门名称
|
||||
Sort int `json:"sort" gorm:"type:int(4);"` //排序
|
||||
Leader string `json:"leader" gorm:"type:varchar(128);"` //负责人
|
||||
Leader int `json:"leader" gorm:"type:int(11);"` //负责人
|
||||
Phone string `json:"phone" gorm:"type:varchar(11);"` //手机
|
||||
Email string `json:"email" gorm:"type:varchar(64);"` //邮箱
|
||||
Status string `json:"status" gorm:"type:int(1);"` //状态
|
||||
|
@ -35,9 +35,9 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
|
||||
for _, p := range processor {
|
||||
switch p {
|
||||
case 1:
|
||||
principalList = append(principalList, "创建人")
|
||||
principalList = append(principalList, "创建者")
|
||||
case 2:
|
||||
principalList = append(principalList, "创建人领导")
|
||||
principalList = append(principalList, "创建者负责人")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
46
pkg/service/getVariableValue.go
Normal file
46
pkg/service/getVariableValue.go
Normal file
@ -0,0 +1,46 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"ferry/global/orm"
|
||||
"ferry/models/system"
|
||||
)
|
||||
|
||||
/*
|
||||
@Author : lanyulei
|
||||
*/
|
||||
|
||||
func GetVariableValue(stateList []interface{}, creator int) (err error) {
|
||||
var (
|
||||
userInfo system.SysUser
|
||||
deptInfo system.Dept
|
||||
)
|
||||
|
||||
// 变量转为实际的数据
|
||||
for _, stateItem := range stateList {
|
||||
if stateItem.(map[string]interface{})["process_method"] == "variable" {
|
||||
for processorIndex, processor := range stateItem.(map[string]interface{})["processor"].([]interface{}) {
|
||||
if int(processor.(float64)) == 1 {
|
||||
// 创建者
|
||||
stateItem.(map[string]interface{})["processor"].([]interface{})[processorIndex] = creator
|
||||
} else if int(processor.(float64)) == 2 {
|
||||
// 1. 查询用户信息
|
||||
err = orm.Eloquent.Model(&userInfo).Where("user_id = ?", creator).Find(&userInfo).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// 2. 查询部门信息
|
||||
err = orm.Eloquent.Model(&deptInfo).Where("dept_id = ?", userInfo.DeptId).Find(&deptInfo).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 替换处理人信息
|
||||
stateItem.(map[string]interface{})["processor"].([]interface{})[processorIndex] = deptInfo.Leader
|
||||
}
|
||||
}
|
||||
stateItem.(map[string]interface{})["process_method"] = "person"
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -111,6 +111,11 @@ func (h *Handle) circulation() (err error) {
|
||||
stateValue []byte
|
||||
)
|
||||
|
||||
err = GetVariableValue(h.updateValue["state"].([]interface{}), h.workOrderDetails.Creator)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stateValue, err = json.Marshal(h.updateValue["state"])
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"ferry/global/orm"
|
||||
"ferry/models/process"
|
||||
"ferry/models/system"
|
||||
"ferry/tools"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -21,9 +22,9 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
|
||||
variable 变量
|
||||
*/
|
||||
var (
|
||||
workOrderInfo process.WorkOrderInfo
|
||||
//userInfo system.SysUser
|
||||
//userDept system.Dept
|
||||
userDept system.Dept
|
||||
workOrderInfo process.WorkOrderInfo
|
||||
userInfo system.SysUser
|
||||
cirHistoryList []process.CirculationHistory
|
||||
stateValue map[string]interface{}
|
||||
processInfo process.Info
|
||||
@ -125,21 +126,19 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
|
||||
if workOrderInfo.Creator == tools.GetUserId(c) {
|
||||
status = true
|
||||
}
|
||||
//case 2:
|
||||
// err = orm.Eloquent.Model(&userInfo).Where("id = ?", workOrderInfo.Creator).Find(&userInfo).Error
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
// err = orm.Eloquent.Model(&userDept).Where("id = ?", userInfo.Dept).Find(&userDept).Error
|
||||
// if err != nil {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if userDept.Approver == tools.GetUserId(c) {
|
||||
// status = true
|
||||
// } else if userDept.Leader == tools.GetUserId(c) {
|
||||
// status = true
|
||||
// }
|
||||
case 2:
|
||||
err = orm.Eloquent.Model(&userInfo).Where("user_id = ?", workOrderInfo.Creator).Find(&userInfo).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = orm.Eloquent.Model(&userDept).Where("dept_id = ?", userInfo.DeptId).Find(&userDept).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if userDept.Leader == tools.GetUserId(c) {
|
||||
status = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,17 +70,10 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
|
||||
// 3. 部门
|
||||
//departmentSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'department')))", userInfo.Dept)
|
||||
|
||||
// 4. 变量
|
||||
variableSelect := fmt.Sprintf("(%v)",
|
||||
fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 1)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'variable')) and creator = %v", tools.GetUserId(c)),
|
||||
)
|
||||
//variableSelect := fmt.Sprintf("((%v) or (%v))",
|
||||
// fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 1)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'variable')) and creator = %v", tools.GetUserId(c)),
|
||||
// fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 2)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'variable')) and creator = %v", 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 or %v) and is_end = 0", personSelect, variableSelect))
|
||||
db = db.Where(fmt.Sprintf("(%v) and is_end = 0", personSelect))
|
||||
case 2:
|
||||
// 我创建的
|
||||
db = db.Where("creator = ?", tools.GetUserId(c))
|
||||
|
Loading…
x
Reference in New Issue
Block a user