Skip to content

Commit

Permalink
添加变量"创建者负责人"
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyulei committed Jul 20, 2020
1 parent f8c177a commit bd2b8c6
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 35 deletions.
18 changes: 18 additions & 0 deletions apis/process/workOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions config/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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', '', '[email protected]', 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, '', '[email protected]', 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;
Expand Down
2 changes: 1 addition & 1 deletion models/system/dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -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);"` //状态
Expand Down
4 changes: 2 additions & 2 deletions pkg/service/getPrincipal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "创建者负责人")
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/service/getVariableValue.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions pkg/service/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 17 additions & 18 deletions pkg/service/userAuthority.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/system"
"ferry/tools"

"github.com/gin-gonic/gin"
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/service/workOrderList.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit bd2b8c6

Please sign in to comment.