2020-07-15 01:40:56 +08:00
|
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-07-17 01:20:25 +08:00
|
|
|
|
"ferry/global/orm"
|
|
|
|
|
"ferry/models/process"
|
2020-11-15 20:13:17 +08:00
|
|
|
|
"ferry/models/system"
|
2020-07-15 01:40:56 +08:00
|
|
|
|
"ferry/pkg/pagination"
|
2020-07-17 01:20:25 +08:00
|
|
|
|
"ferry/tools"
|
2020-07-15 01:40:56 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@Author : lanyulei
|
2020-07-25 14:20:15 +08:00
|
|
|
|
@todo: 添加新的处理人时候,需要修改(先完善功能,后续有时间的时候优化一下这部分。)
|
2020-07-15 01:40:56 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2020-07-23 00:42:46 +08:00
|
|
|
|
type WorkOrder struct {
|
|
|
|
|
Classify int
|
|
|
|
|
GinObj *gin.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type workOrderInfo struct {
|
|
|
|
|
process.WorkOrderInfo
|
|
|
|
|
Principals string `json:"principals"`
|
2020-10-09 00:23:59 +08:00
|
|
|
|
StateName string `json:"state_name"`
|
2020-07-23 00:42:46 +08:00
|
|
|
|
DataClassify int `json:"data_classify"`
|
2021-05-12 16:40:28 +08:00
|
|
|
|
ProcessName string `json:"process_name"`
|
2020-07-23 00:42:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 23:14:28 +08:00
|
|
|
|
func NewWorkOrder(classify int, c *gin.Context) *WorkOrder {
|
|
|
|
|
return &WorkOrder{
|
|
|
|
|
Classify: classify,
|
|
|
|
|
GinObj: c,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:42:46 +08:00
|
|
|
|
func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
|
2020-07-15 01:40:56 +08:00
|
|
|
|
var (
|
|
|
|
|
workOrderInfoList []workOrderInfo
|
2020-11-22 16:46:16 +08:00
|
|
|
|
processorInfo system.SysUser
|
2020-07-15 01:40:56 +08:00
|
|
|
|
)
|
|
|
|
|
|
2021-05-18 14:45:13 +08:00
|
|
|
|
personSelectValue := "(JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('process_method', 'person')))"
|
|
|
|
|
roleSelectValue := "(JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('process_method', 'role')))"
|
|
|
|
|
departmentSelectValue := "(JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(p_work_order_info.state, JSON_OBJECT('process_method', 'department')))"
|
2020-11-22 16:46:16 +08:00
|
|
|
|
|
2020-07-23 00:42:46 +08:00
|
|
|
|
title := w.GinObj.DefaultQuery("title", "")
|
2020-11-22 16:46:16 +08:00
|
|
|
|
startTime := w.GinObj.DefaultQuery("startTime", "")
|
|
|
|
|
endTime := w.GinObj.DefaultQuery("endTime", "")
|
|
|
|
|
isEnd := w.GinObj.DefaultQuery("isEnd", "")
|
|
|
|
|
processor := w.GinObj.DefaultQuery("processor", "")
|
|
|
|
|
priority := w.GinObj.DefaultQuery("priority", "")
|
2021-09-16 22:35:13 +08:00
|
|
|
|
creator := w.GinObj.DefaultQuery("creator", "")
|
2021-11-16 22:23:09 +08:00
|
|
|
|
processParam := w.GinObj.DefaultQuery("process", "")
|
2020-11-22 16:46:16 +08:00
|
|
|
|
db := orm.Eloquent.Model(&process.WorkOrderInfo{}).
|
2021-05-12 16:40:28 +08:00
|
|
|
|
Where("p_work_order_info.title like ?", fmt.Sprintf("%%%v%%", title))
|
2020-11-22 16:46:16 +08:00
|
|
|
|
if startTime != "" {
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where("p_work_order_info.create_time >= ?", startTime)
|
2020-11-22 16:46:16 +08:00
|
|
|
|
}
|
|
|
|
|
if endTime != "" {
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where("p_work_order_info.create_time <= ?", endTime)
|
2020-11-22 16:46:16 +08:00
|
|
|
|
}
|
|
|
|
|
if isEnd != "" {
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where("p_work_order_info.is_end = ?", isEnd)
|
2020-11-22 16:46:16 +08:00
|
|
|
|
}
|
2021-09-16 22:35:13 +08:00
|
|
|
|
if creator != "" {
|
|
|
|
|
db = db.Where("p_work_order_info.creator = ?", creator)
|
|
|
|
|
}
|
2021-11-16 22:23:09 +08:00
|
|
|
|
if processParam != "" {
|
|
|
|
|
db = db.Where("p_work_order_info.process = ?", processParam)
|
|
|
|
|
}
|
2020-11-22 16:46:16 +08:00
|
|
|
|
if processor != "" && w.Classify != 1 {
|
|
|
|
|
err = orm.Eloquent.Model(&processorInfo).
|
|
|
|
|
Where("user_id = ?", processor).
|
|
|
|
|
Find(&processorInfo).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where(fmt.Sprintf("(%v or %v or %v) and p_work_order_info.is_end = 0",
|
2020-11-22 16:46:16 +08:00
|
|
|
|
fmt.Sprintf(personSelectValue, processorInfo.UserId),
|
|
|
|
|
fmt.Sprintf(roleSelectValue, processorInfo.RoleId),
|
|
|
|
|
fmt.Sprintf(departmentSelectValue, processorInfo.DeptId),
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
if priority != "" {
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where("p_work_order_info.priority = ?", priority)
|
2020-11-22 16:46:16 +08:00
|
|
|
|
}
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
// 获取当前用户信息
|
2020-07-23 00:42:46 +08:00
|
|
|
|
switch w.Classify {
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 1:
|
|
|
|
|
// 待办工单
|
|
|
|
|
// 1. 个人
|
2020-11-22 16:46:16 +08:00
|
|
|
|
personSelect := fmt.Sprintf(personSelectValue, tools.GetUserId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
2020-11-15 14:52:09 +08:00
|
|
|
|
// 2. 角色
|
2020-11-22 16:46:16 +08:00
|
|
|
|
roleSelect := fmt.Sprintf(roleSelectValue, tools.GetRoleId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
// 3. 部门
|
2020-11-15 20:13:17 +08:00
|
|
|
|
var userInfo system.SysUser
|
|
|
|
|
err = orm.Eloquent.Model(&system.SysUser{}).
|
|
|
|
|
Where("user_id = ?", tools.GetUserId(w.GinObj)).
|
|
|
|
|
Find(&userInfo).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-11-22 16:46:16 +08:00
|
|
|
|
departmentSelect := fmt.Sprintf(departmentSelectValue, userInfo.DeptId)
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
2020-07-20 23:57:42 +08:00
|
|
|
|
// 4. 变量会转成个人数据
|
2020-07-17 01:20:25 +08:00
|
|
|
|
//db = db.Where(fmt.Sprintf("(%v or %v or %v or %v) and is_end = 0", personSelect, personGroupSelect, departmentSelect, variableSelect))
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where(fmt.Sprintf("(%v or %v or %v) and p_work_order_info.is_end = 0", personSelect, roleSelect, departmentSelect))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 2:
|
|
|
|
|
// 我创建的
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where("p_work_order_info.creator = ?", tools.GetUserId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 3:
|
|
|
|
|
// 我相关的
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Where(fmt.Sprintf("JSON_CONTAINS(p_work_order_info.related_person, '%v')", tools.GetUserId(w.GinObj)))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 4:
|
|
|
|
|
// 所有工单
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("请确认查询的数据类型是否正确")
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-12 16:40:28 +08:00
|
|
|
|
db = db.Joins("left join p_process_info on p_work_order_info.process = p_process_info.id").
|
|
|
|
|
Select("p_work_order_info.*, p_process_info.name as process_name")
|
|
|
|
|
|
2020-07-15 01:40:56 +08:00
|
|
|
|
result, err = pagination.Paging(&pagination.Param{
|
2020-07-23 00:42:46 +08:00
|
|
|
|
C: w.GinObj,
|
2020-07-15 01:40:56 +08:00
|
|
|
|
DB: db,
|
2021-05-12 16:40:28 +08:00
|
|
|
|
}, &workOrderInfoList, map[string]map[string]interface{}{}, "p_process_info")
|
2020-07-15 01:40:56 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("查询工单列表失败,%v", err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-07-23 00:42:46 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *WorkOrder) WorkOrderList() (result interface{}, err error) {
|
|
|
|
|
|
|
|
|
|
var (
|
2020-10-09 00:40:04 +08:00
|
|
|
|
principals string
|
|
|
|
|
StateList []map[string]interface{}
|
|
|
|
|
workOrderInfoList []workOrderInfo
|
|
|
|
|
minusTotal int
|
2020-07-23 00:42:46 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result, err = w.PureWorkOrderList()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
2020-10-09 00:23:59 +08:00
|
|
|
|
for i, v := range *result.(*pagination.Paginator).Data.(*[]workOrderInfo) {
|
|
|
|
|
var (
|
2020-10-09 00:40:04 +08:00
|
|
|
|
stateName string
|
|
|
|
|
structResult map[string]interface{}
|
|
|
|
|
authStatus bool
|
2020-10-09 00:23:59 +08:00
|
|
|
|
)
|
2020-11-15 20:13:17 +08:00
|
|
|
|
err = json.Unmarshal(v.State, &StateList)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("json反序列化失败,%v", err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-07-15 01:40:56 +08:00
|
|
|
|
if len(StateList) != 0 {
|
2020-10-09 00:58:14 +08:00
|
|
|
|
// 仅待办工单需要验证
|
|
|
|
|
// todo:还需要找最优解决方案
|
|
|
|
|
if w.Classify == 1 {
|
|
|
|
|
structResult, err = ProcessStructure(w.GinObj, v.Process, v.Id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
authStatus, err = JudgeUserAuthority(w.GinObj, v.Id, structResult["workOrder"].(WorkOrderData).CurrentState)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if !authStatus {
|
|
|
|
|
minusTotal += 1
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
authStatus = true
|
2020-10-09 00:40:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 01:40:56 +08:00
|
|
|
|
processorList := make([]int, 0)
|
2020-10-09 00:23:59 +08:00
|
|
|
|
if len(StateList) > 1 {
|
|
|
|
|
for _, s := range StateList {
|
|
|
|
|
for _, p := range s["processor"].([]interface{}) {
|
|
|
|
|
if int(p.(float64)) == tools.GetUserId(w.GinObj) {
|
|
|
|
|
processorList = append(processorList, int(p.(float64)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(processorList) > 0 {
|
|
|
|
|
stateName = s["label"].(string)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(processorList) == 0 {
|
|
|
|
|
for _, v := range StateList[0]["processor"].([]interface{}) {
|
|
|
|
|
processorList = append(processorList, int(v.(float64)))
|
|
|
|
|
}
|
|
|
|
|
stateName = StateList[0]["label"].(string)
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
principals, err = GetPrincipal(processorList, StateList[0]["process_method"].(string))
|
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("查询处理人名称失败,%v", err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
workOrderDetails := *result.(*pagination.Paginator).Data.(*[]workOrderInfo)
|
|
|
|
|
workOrderDetails[i].Principals = principals
|
2020-10-09 00:23:59 +08:00
|
|
|
|
workOrderDetails[i].StateName = stateName
|
|
|
|
|
workOrderDetails[i].DataClassify = v.Classify
|
2020-10-09 00:40:04 +08:00
|
|
|
|
if authStatus {
|
|
|
|
|
workOrderInfoList = append(workOrderInfoList, workOrderDetails[i])
|
|
|
|
|
}
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-09 00:40:04 +08:00
|
|
|
|
result.(*pagination.Paginator).Data = &workOrderInfoList
|
|
|
|
|
result.(*pagination.Paginator).TotalCount -= minusTotal
|
|
|
|
|
|
2020-07-15 01:40:56 +08:00
|
|
|
|
return result, nil
|
|
|
|
|
}
|