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-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"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
|
2020-07-15 01:40:56 +08:00
|
|
|
|
var (
|
|
|
|
|
workOrderInfoList []workOrderInfo
|
|
|
|
|
)
|
|
|
|
|
|
2020-07-23 00:42:46 +08:00
|
|
|
|
title := w.GinObj.DefaultQuery("title", "")
|
2020-07-17 01:20:25 +08:00
|
|
|
|
db := orm.Eloquent.Model(&process.WorkOrderInfo{}).Where("title like ?", fmt.Sprintf("%%%v%%", title))
|
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-07-23 00:42:46 +08:00
|
|
|
|
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", tools.GetUserId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
2020-11-15 14:52:09 +08:00
|
|
|
|
// 2. 角色
|
|
|
|
|
roleSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'role')))", tools.GetRoleId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
// 3. 部门
|
2020-07-17 01:20:25 +08:00
|
|
|
|
//departmentSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'department')))", userInfo.Dept)
|
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))
|
2020-11-15 14:52:09 +08:00
|
|
|
|
db = db.Where(fmt.Sprintf("(%v or %v) and is_end = 0", personSelect, roleSelect))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 2:
|
|
|
|
|
// 我创建的
|
2020-07-23 00:42:46 +08:00
|
|
|
|
db = db.Where("creator = ?", tools.GetUserId(w.GinObj))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 3:
|
|
|
|
|
// 我相关的
|
2020-07-23 00:42:46 +08:00
|
|
|
|
db = db.Where(fmt.Sprintf("JSON_CONTAINS(related_person, '%v')", tools.GetUserId(w.GinObj)))
|
2020-07-15 01:40:56 +08:00
|
|
|
|
case 4:
|
|
|
|
|
// 所有工单
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("请确认查询的数据类型是否正确")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}, &workOrderInfoList)
|
|
|
|
|
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) {
|
|
|
|
|
err = json.Unmarshal(v.State, &StateList)
|
2020-07-15 01:40:56 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
err = fmt.Errorf("json反序列化失败,%v", err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-10-09 00:23:59 +08:00
|
|
|
|
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-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
|
|
|
|
|
}
|