添加流程申请。

This commit is contained in:
Mr. Lan 2020-07-17 01:20:25 +08:00
parent 93c7f1f470
commit 38cac4050c
14 changed files with 840 additions and 829 deletions

View File

@ -154,53 +154,51 @@ func ProcessDetails(c *gin.Context) {
}
// 分类流程列表
//func ClassifyProcessList(c *gin.Context) {
// type classifyProcess struct {
// process2.Classify
// ProcessList []*process2.Info `json:"process_list"`
// }
//
// var (
// err error
// classifyList []*classifyProcess
// )
//
// processName := c.DefaultQuery("name", "")
// if processName == "" {
// err = connection.DB.Self.Model(&process2.Classify{}).Find(&classifyList).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("获取分类列表失败,%v", err.Error()))
// return
// }
// } else {
// var classifyIdList []int
// err = connection.DB.Self.Model(&process2.Info{}).
// Where("name LIKE ?", fmt.Sprintf("%%%v%%", processName)).
// Pluck("distinct classify", &classifyIdList).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("获取分类失败,%v", err.Error()))
// return
// }
//
// err = connection.DB.Self.Model(&process2.Classify{}).
// Where("id in (?)", classifyIdList).
// Find(&classifyList).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("获取分类失败,%v", err.Error()))
// return
// }
// }
//
// for _, item := range classifyList {
// err = connection.DB.Self.Model(&process2.Info{}).
// Where("classify = ?", item.Id).
// Select("id, create_time, update_time, name").
// Find(&item.ProcessList).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("获取流程失败,%v", err.Error()))
// return
// }
// }
//
// Response(c, nil, classifyList, "")
//}
func ClassifyProcessList(c *gin.Context) {
var (
err error
classifyIdList []int
classifyList []*struct {
process2.Classify
ProcessList []*process2.Info `json:"process_list"`
}
)
processName := c.DefaultQuery("name", "")
if processName == "" {
err = orm.Eloquent.Model(&process2.Classify{}).Find(&classifyList).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("获取分类列表失败,%v", err.Error()))
return
}
} else {
err = orm.Eloquent.Model(&process2.Info{}).
Where("name LIKE ?", fmt.Sprintf("%%%v%%", processName)).
Pluck("distinct classify", &classifyIdList).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("获取分类失败,%v", err.Error()))
return
}
err = orm.Eloquent.Model(&process2.Classify{}).
Where("id in (?)", classifyIdList).
Find(&classifyList).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("获取分类失败,%v", err.Error()))
return
}
}
for _, item := range classifyList {
err = orm.Eloquent.Model(&process2.Info{}).
Where("classify = ? and name LIKE ?", item.Id, fmt.Sprintf("%%%v%%", processName)).
Select("id, create_time, update_time, name").
Find(&item.ProcessList).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("获取流程失败,%v", err.Error()))
return
}
}
app.OK(c, classifyList, "成功获取数据")
}

View File

@ -1,230 +1,235 @@
package process
//import (
// "ferry/pkg/pagination"
// "ferry/pkg/response/code"
// . "ferry/pkg/response/response"
// "fmt"
// "io/ioutil"
// "os"
// "strings"
//
// "github.com/gin-gonic/gin"
// uuid "github.com/satori/go.uuid"
// "github.com/spf13/viper"
//)
//
///*
// @Author : lanyulei
//*/
//
//// 任务列表
//func TaskList(c *gin.Context) {
// var (
// err error
// pageValue pagination.ListRequest
// taskName string
// taskData []map[string]interface{}
// total_count int
// )
// taskName = c.DefaultQuery("name", "")
//
// err = c.ShouldBind(&pageValue)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// getFileDetails := func(fn string) map[string]interface{} {
// file := make(map[string]interface{})
// fileClassify := strings.Split(fn, ".")
// fileDetails := strings.Split(fileClassify[0], "-")
// switch fileClassify[1] {
// case "py":
// file["classify"] = "Python"
// case "sh":
// file["classify"] = "Shell"
// default:
// file["classify"] = "Other"
// }
// if len(fileDetails) == 3 {
// file["name"] = fileDetails[0]
// file["uuid"] = fileDetails[1]
// file["creator"] = fileDetails[2]
// }
// file["full_name"] = fn
// return file
// }
// files, _ := ioutil.ReadDir(viper.GetString("script.path"))
// var endIndex int
// if taskName != "" {
// for _, f := range files {
// if strings.Contains(strings.Split(f.Name(), "-")[0], taskName) {
// taskData = append(taskData, getFileDetails(f.Name()))
// }
// }
// total_count = len(taskData)
// if pageValue.Page*pageValue.PerPage > len(taskData) {
// endIndex = len(taskData)
// } else {
// endIndex = pageValue.Page * pageValue.PerPage
// }
// taskData = taskData[(pageValue.Page-1)*pageValue.PerPage : endIndex]
// } else {
// if pageValue.Page*pageValue.PerPage > len(files) {
// endIndex = len(files)
// } else {
// endIndex = pageValue.Page * pageValue.PerPage
// }
// for _, f := range files[(pageValue.Page-1)*pageValue.PerPage : endIndex] {
// taskData = append(taskData, getFileDetails(f.Name()))
// }
// total_count = len(files)
// }
//
// Response(c, nil, map[string]interface{}{
// "data": taskData,
// "page": pageValue.Page,
// "per_page": pageValue.PerPage,
// "total_count": total_count,
// }, "")
//}
//
//// 创建任务
//func CreateTask(c *gin.Context) {
// type Task struct {
// Name string `json:"name"`
// Classify string `json:"classify"`
// Content string `json:"content"`
// }
//
// var (
// err error
// taskValue Task
// )
//
// err = c.ShouldBind(&taskValue)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// uuidValue := uuid.Must(uuid.NewV4(), err)
// fileName := fmt.Sprintf("%v/%v-%v-%v",
// viper.GetString("script.path"),
// taskValue.Name,
// strings.Split(uuidValue.String(), "-")[4],
// c.GetString("username"),
// )
// if taskValue.Classify == "python" {
// fileName = fileName + ".py"
// } else if taskValue.Classify == "shell" {
// fileName = fileName + ".sh"
// }
//
// err = ioutil.WriteFile(fileName, []byte(taskValue.Content), 0666)
// if err != nil {
// Response(c, code.BindError, nil, fmt.Sprintf("创建任务脚本失败: %v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
//
//// 更新任务
//func UpdateTask(c *gin.Context) {
// type fileDetails struct {
// Name string `json:"name"`
// FullName string `json:"full_name"`
// Classify string `json:"classify"`
// Content string `json:"content"`
// }
//
// var (
// err error
// file fileDetails
// )
//
// err = c.ShouldBind(&file)
// if err != nil {
// Response(c, code.BindError, nil, "")
// return
// }
//
// fullNameList := strings.Split(file.FullName, "-")
// if fullNameList[0] != file.Name {
// fullNameList[0] = file.Name
// }
// var suffixName string
// if strings.ToLower(file.Classify) == "python" {
// suffixName = ".py"
// } else if strings.ToLower(file.Classify) == "shell" {
// suffixName = ".sh"
// }
//
// if fullNameList[len(fullNameList)-1][len(fullNameList[len(fullNameList)-1])-3:len(fullNameList[len(fullNameList)-1])] != suffixName {
// tList := strings.Split(fullNameList[len(fullNameList)-1], ".")
// tList[len(tList)-1] = suffixName[1:len(suffixName)]
// fullNameList[len(fullNameList)-1] = strings.Join(tList, ".")
// }
//
// fileFullName := strings.Join(fullNameList, "-")
//
// // 修改文件内容
// err = ioutil.WriteFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName), []byte(file.Content), 0666)
// if err != nil {
// Response(c, code.BindError, nil, fmt.Sprintf("更新脚本文件失败,%v", err.Error()))
// return
// }
//
// // 修改文件名称
// err = os.Rename(
// fmt.Sprintf("%v/%v", viper.GetString("script.path"), file.FullName),
// fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName),
// )
// if err != nil {
// Response(c, code.BindError, nil, fmt.Sprintf("更改脚本文件名称失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
//
//// 删除任务
//func DeleteTask(c *gin.Context) {
// fullName := c.DefaultQuery("full_name", "")
// if fullName == "" {
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数full_name是否传递")
// return
// }
//
// err := os.Remove(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fullName))
// if err != nil {
// Response(c, code.DeleteError, nil, fmt.Sprintf("删除文件失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
//
//// 任务详情
//func TaskDetails(c *gin.Context) {
// var (
// err error
// fileName string
// content []byte
// )
//
// fileName = c.DefaultQuery("file_name", "")
// if fileName == "" {
// Response(c, code.ParamError, nil, "参数不正确请确认file_name参数是否存在")
// return
// }
//
// content, err = ioutil.ReadFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileName))
// if err != nil {
// return
// }
//
// Response(c, nil, string(content), "")
//}
import (
"errors"
"ferry/pkg/pagination"
"ferry/tools"
"ferry/tools/app"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/gin-gonic/gin"
uuid "github.com/satori/go.uuid"
"github.com/spf13/viper"
)
/*
@Author : lanyulei
*/
// 任务列表
func TaskList(c *gin.Context) {
var (
err error
pageValue pagination.ListRequest
taskName string
taskData []map[string]interface{}
totalCount int
)
taskName = c.DefaultQuery("name", "")
err = c.ShouldBind(&pageValue)
if err != nil {
app.Error(c, -1, err, "")
return
}
if pageValue.Page == 0 {
pageValue.Page = 1
}
if pageValue.PerPage == 0 {
pageValue.PerPage = 10
}
getFileDetails := func(fn string) map[string]interface{} {
file := make(map[string]interface{})
fileClassify := strings.Split(fn, ".")
fileDetails := strings.Split(fileClassify[0], "-")
switch fileClassify[1] {
case "py":
file["classify"] = "Python"
case "sh":
file["classify"] = "Shell"
default:
file["classify"] = "Other"
}
if len(fileDetails) == 3 {
file["name"] = fileDetails[0]
file["uuid"] = fileDetails[1]
file["creator"] = fileDetails[2]
}
file["full_name"] = fn
return file
}
files, _ := ioutil.ReadDir(viper.GetString("script.path"))
var endIndex int
if taskName != "" {
for _, f := range files {
if strings.Contains(strings.Split(f.Name(), "-")[0], taskName) {
taskData = append(taskData, getFileDetails(f.Name()))
}
}
totalCount = len(taskData)
if pageValue.Page*pageValue.PerPage > len(taskData) {
endIndex = len(taskData)
} else {
endIndex = pageValue.Page * pageValue.PerPage
}
taskData = taskData[(pageValue.Page-1)*pageValue.PerPage : endIndex]
} else {
if pageValue.Page*pageValue.PerPage > len(files) {
endIndex = len(files)
} else {
endIndex = pageValue.Page * pageValue.PerPage
}
for _, f := range files[(pageValue.Page-1)*pageValue.PerPage : endIndex] {
taskData = append(taskData, getFileDetails(f.Name()))
}
totalCount = len(files)
}
app.OK(c, map[string]interface{}{
"data": taskData,
"page": pageValue.Page,
"per_page": pageValue.PerPage,
"total_count": totalCount,
}, "")
}
// 创建任务
func CreateTask(c *gin.Context) {
var (
err error
taskValue struct {
Name string `json:"name"`
Classify string `json:"classify"`
Content string `json:"content"`
}
)
err = c.ShouldBind(&taskValue)
if err != nil {
app.Error(c, -1, err, "")
return
}
uuidValue := uuid.Must(uuid.NewV4(), err)
fileName := fmt.Sprintf("%v/%v-%v-%v",
viper.GetString("script.path"),
taskValue.Name,
strings.Split(uuidValue.String(), "-")[4],
tools.GetUserName(c),
)
if taskValue.Classify == "python" {
fileName = fileName + ".py"
} else if taskValue.Classify == "shell" {
fileName = fileName + ".sh"
}
err = ioutil.WriteFile(fileName, []byte(taskValue.Content), 0666)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("创建任务脚本失败: %v", err.Error()))
return
}
app.OK(c, "", "任务创建成功")
}
// 更新任务
func UpdateTask(c *gin.Context) {
var (
err error
file struct {
Name string `json:"name"`
FullName string `json:"full_name"`
Classify string `json:"classify"`
Content string `json:"content"`
}
)
err = c.ShouldBind(&file)
if err != nil {
app.Error(c, -1, err, "")
return
}
fullNameList := strings.Split(file.FullName, "-")
if fullNameList[0] != file.Name {
fullNameList[0] = file.Name
}
var suffixName string
if strings.ToLower(file.Classify) == "python" {
suffixName = ".py"
} else if strings.ToLower(file.Classify) == "shell" {
suffixName = ".sh"
}
if fullNameList[len(fullNameList)-1][len(fullNameList[len(fullNameList)-1])-3:len(fullNameList[len(fullNameList)-1])] != suffixName {
tList := strings.Split(fullNameList[len(fullNameList)-1], ".")
tList[len(tList)-1] = suffixName[1:len(suffixName)]
fullNameList[len(fullNameList)-1] = strings.Join(tList, ".")
}
fileFullName := strings.Join(fullNameList, "-")
// 修改文件内容
err = ioutil.WriteFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName), []byte(file.Content), 0666)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("更新脚本文件失败,%v", err.Error()))
return
}
// 修改文件名称
err = os.Rename(
fmt.Sprintf("%v/%v", viper.GetString("script.path"), file.FullName),
fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName),
)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("更改脚本文件名称失败,%v", err.Error()))
return
}
app.OK(c, "", "更新成功")
}
// 删除任务
func DeleteTask(c *gin.Context) {
fullName := c.DefaultQuery("full_name", "")
if fullName == "" {
app.Error(c, -1, errors.New("参数不正确请确定参数full_name是否传递"), "")
return
}
err := os.Remove(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fullName))
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("删除文件失败,%v", err.Error()))
return
}
app.OK(c, nil, "任务删除成功")
}
// 任务详情
func TaskDetails(c *gin.Context) {
var (
err error
fileName string
content []byte
)
fileName = c.DefaultQuery("file_name", "")
if fileName == "" {
app.Error(c, -1, errors.New("参数不正确请确认file_name参数是否存在"), "")
return
}
content, err = ioutil.ReadFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileName))
if err != nil {
return
}
app.OK(c, string(content), "")
}

View File

@ -1,400 +1,403 @@
package process
//import (
// "encoding/json"
// "errors"
// "ferry/models/user"
// "ferry/models/workOrder"
// "ferry/pkg/connection"
// "ferry/pkg/response/code"
// . "ferry/pkg/response/response"
// "ferry/pkg/service"
// "fmt"
// "strconv"
//
// "github.com/gin-gonic/gin"
//)
//
///*
// @Author : lanyulei
//*/
//
//// 流程结构包括节点,流转和模版
//func ProcessStructure(c *gin.Context) {
// processId := c.DefaultQuery("processId", "")
// if processId == "" {
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数processId是否传递")
// return
// }
// workOrderId := c.DefaultQuery("workOrderId", "0")
// if processId == "" {
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数processId是否传递")
// return
// }
// workOrderIdInt, _ := strconv.Atoi(workOrderId)
// processIdInt, _ := strconv.Atoi(processId)
// result, err := service.ProcessStructure(c, processIdInt, workOrderIdInt)
// if err != nil {
// Response(c, code.SelectError, nil, err.Error())
// return
// }
//
// if workOrderIdInt != 0 {
// currentState := result["workOrder"].(service.WorkOrderData).CurrentState
// userAuthority, err := service.JudgeUserAuthority(c, workOrderIdInt, currentState)
// if err != nil {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
// return
// }
// result["userAuthority"] = userAuthority
// }
//
// Response(c, nil, result, "")
//}
//
//// 新建工单
//func CreateWorkOrder(c *gin.Context) {
// var workOrderValue struct {
// workOrder.Info
// Tpls map[string][]interface{} `json:"tpls"`
// SourceState string `json:"source_state"`
// Tasks json.RawMessage `json:"tasks"`
// Source string `json:"source"`
// }
//
// err := c.ShouldBind(&workOrderValue)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// relatedPerson, err := json.Marshal([]int{c.GetInt("userId")})
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// // 创建工单数据
// tx := connection.DB.Self.Begin()
// var workOrderInfo = workOrder.Info{
// Title: workOrderValue.Title,
// Process: workOrderValue.Process,
// Classify: workOrderValue.Classify,
// State: workOrderValue.State,
// RelatedPerson: relatedPerson,
// Creator: c.GetInt("userId"),
// }
// err = tx.Create(&workOrderInfo).Error
// if err != nil {
// tx.Rollback()
// Response(c, code.CreateError, nil, fmt.Sprintf("创建工单失败,%v", err.Error()))
// return
// }
//
// // 创建工单模版关联数据
// for i := 0; i < len(workOrderValue.Tpls["form_structure"]); i++ {
// formDataJson, err := json.Marshal(workOrderValue.Tpls["form_data"][i])
// if err != nil {
// tx.Rollback()
// Response(c, code.InternalServerError, nil, fmt.Sprintf("生成json字符串错误%v", err.Error()))
// return
// }
// formStructureJson, err := json.Marshal(workOrderValue.Tpls["form_structure"][i])
// if err != nil {
// tx.Rollback()
// Response(c, code.InternalServerError, nil, fmt.Sprintf("生成json字符串错误%v", err.Error()))
// return
// }
//
// formData := workOrder.TplData{
// WorkOrder: workOrderInfo.Id,
// FormStructure: formStructureJson,
// FormData: formDataJson,
// }
//
// err = tx.Create(&formData).Error
// if err != nil {
// tx.Rollback()
// Response(c, code.CreateError, nil, fmt.Sprintf("创建工单模版关联数据失败,%v", err.Error()))
// return
// }
// }
//
// // 获取当前用户信息
// var userInfo user.Info
// err = tx.Model(&user.Info{}).Where("id = ?", c.GetInt("userId")).Find(&userInfo).Error
// if err != nil {
// tx.Rollback()
// Response(c, code.SelectError, nil, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
// return
// }
//
// nameValue := userInfo.Nickname
// if nameValue == "" {
// nameValue = userInfo.Username
// }
//
// // 创建历史记录
// var stateList []map[string]interface{}
// err = json.Unmarshal(workOrderInfo.State, &stateList)
// if err != nil {
// tx.Rollback()
// Response(c, code.InternalServerError, nil, fmt.Sprintf("Json序列化失败%v", err.Error()))
// return
// }
// err = tx.Create(&workOrder.CirculationHistory{
// Title: workOrderValue.Title,
// WorkOrder: workOrderInfo.Id,
// State: workOrderValue.SourceState,
// Source: workOrderValue.Source,
// Target: stateList[0]["id"].(string),
// Circulation: "新建",
// Processor: nameValue,
// ProcessorId: userInfo.Id,
// }).Error
// if err != nil {
// tx.Rollback()
// err = fmt.Errorf("新建历史记录失败,%v", err.Error())
// return
// }
//
// tx.Commit()
//
// // 执行任务
// var taskList []string
// err = json.Unmarshal(workOrderValue.Tasks, &taskList)
// if err != nil {
// Response(c, code.InternalServerError, nil, err.Error())
// return
// }
// go service.ExecTask(taskList)
//
// Response(c, nil, nil, "")
//}
//
//// 工单列表
//func WorkOrderList(c *gin.Context) {
// /*
// 1. 待办工单
// 2. 我创建的
// 3. 我相关的
// 4. 所有工单
// */
//
// var (
// result interface{}
// err error
// classifyInt int
// )
//
// classify := c.DefaultQuery("classify", "0")
// if classify == "" {
// Response(c, code.ParamError, nil, "参数错误请确认classify是否传递")
// return
// }
//
// classifyInt, _ = strconv.Atoi(classify)
// result, err = service.WorkOrderList(c, classifyInt)
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单数据失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, result, "")
//}
//
//// 处理工单
//func ProcessWorkOrder(c *gin.Context) {
// var (
// err error
// userAuthority bool
// handle service.Handle
// params struct {
// Tasks []string
// TargetState string `json:"target_state"` // 目标状态
// SourceState string `json:"source_state"` // 源状态
// WorkOrderId int `json:"work_order_id"` // 工单ID
// Circulation string `json:"circulation"` // 流转ID
// FlowProperties int `json:"flow_properties"` // 流转类型 0 拒绝1 同意2 其他
// }
// )
//
// err = c.ShouldBind(&params)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// // 处理工单
// userAuthority, err = service.JudgeUserAuthority(c, params.WorkOrderId, params.SourceState)
// if err != nil {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
// return
// }
// if !userAuthority {
// err = errors.New("当前用户没有权限进行此操作")
// return
// }
//
// err = handle.HandleWorkOrder(
// c,
// params.WorkOrderId, // 工单ID
// params.Tasks, // 任务列表
// params.TargetState, // 目标节点
// params.SourceState, // 源节点
// params.Circulation, // 流转标题
// params.FlowProperties, // 流转属性
// )
// if err != nil {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("处理工单失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
//
//// 结束工单
//func UnityWorkOrder(c *gin.Context) {
// var (
// err error
// workOrderId string
// workOrderInfo workOrder.Info
// )
//
// workOrderId = c.DefaultQuery("work_oroder_id", "")
// if workOrderId == "" {
// Response(c, code.InternalServerError, nil, "参数不正确work_oroder_id")
// return
// }
//
// tx := connection.DB.Self.Begin()
//
// // 查询工单信息
// err = connection.DB.Self.Model(&workOrderInfo).
// Where("id = ?", workOrderId).
// Find(&workOrderInfo).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单失败,%v", err.Error()))
// return
// }
// if workOrderInfo.IsEnd == 1 {
// Response(c, code.UpdateError, nil, "工单已结束")
// return
// }
//
// // 更新工单状态
// err = tx.Model(&workOrder.Info{}).
// Where("id = ?", workOrderId).
// Update("is_end", 1).
// Error
// if err != nil {
// tx.Rollback()
// Response(c, code.UpdateError, nil, fmt.Sprintf("结束工单失败,%v", err.Error()))
// return
// }
//
// // 写入历史
// tx.Create(&workOrder.CirculationHistory{
// Title: workOrderInfo.Title,
// WorkOrder: workOrderInfo.Id,
// State: "结束工单",
// Circulation: "结束",
// Processor: c.GetString("nickname"),
// ProcessorId: c.GetInt("userId"),
// Remarks: "手动结束工单。",
// })
//
// tx.Commit()
//
// Response(c, nil, nil, "")
//}
//
//// 转交工单
//func InversionWorkOrder(c *gin.Context) {
// var (
// err error
// workOrderInfo workOrder.Info
// stateList []map[string]interface{}
// stateValue []byte
// currentState map[string]interface{}
// userInfo user.Info
// params struct {
// WorkOrderId int `json:"work_order_id"`
// NodeId string `json:"node_id"`
// UserId int `json:"user_id"`
// Remarks string `json:"remarks"`
// }
// )
//
// err = c.ShouldBind(&params)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// // 查询工单信息
// err = connection.DB.Self.Model(&workOrderInfo).
// Where("id = ?", params.WorkOrderId).
// Find(&workOrderInfo).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单信息失败,%v", err.Error()))
// return
// }
//
// // 序列化节点数据
// err = json.Unmarshal(workOrderInfo.State, &stateList)
// if err != nil {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("节点数据反序列化失败,%v", err.Error()))
// return
// }
//
// for _, s := range stateList {
// if s["id"].(string) == params.NodeId {
// s["processor"] = []interface{}{params.UserId}
// s["process_method"] = "person"
// currentState = s
// break
// }
// }
//
// stateValue, err = json.Marshal(stateList)
// if err != nil {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("节点数据序列化失败,%v", err.Error()))
// return
// }
//
// tx := connection.DB.Self.Begin()
//
// // 更新数据
// err = tx.Model(&workOrder.Info{}).
// Where("id = ?", params.WorkOrderId).
// Update("state", stateValue).Error
// if err != nil {
// Response(c, code.UpdateError, nil, fmt.Sprintf("更新节点信息失败,%v", err.Error()))
// return
// }
//
// // 查询用户信息
// err = connection.DB.Self.Model(&user.Info{}).
// Where("id = ?", params.UserId).
// Find(&userInfo).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
// return
// }
//
// // 添加转交历史
// tx.Create(&workOrder.CirculationHistory{
// Title: workOrderInfo.Title,
// WorkOrder: workOrderInfo.Id,
// State: currentState["label"].(string),
// Circulation: "转交",
// Processor: c.GetString("nickname"),
// ProcessorId: c.GetInt("userId"),
// Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.Nickname),
// })
//
// tx.Commit()
//
// Response(c, nil, nil, "")
//}
import (
"encoding/json"
"errors"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/system"
. "ferry/pkg/response/response"
"ferry/pkg/service"
"ferry/tools"
"ferry/tools/app"
"fmt"
"strconv"
"github.com/gin-gonic/gin"
)
/*
@Author : lanyulei
*/
// 流程结构包括节点,流转和模版
func ProcessStructure(c *gin.Context) {
processId := c.DefaultQuery("processId", "")
if processId == "" {
app.Error(c, -1, errors.New("参数不正确请确定参数processId是否传递"), "")
return
}
workOrderId := c.DefaultQuery("workOrderId", "0")
if workOrderId == "" {
app.Error(c, -1, errors.New("参数不正确请确定参数workOrderId是否传递"), "")
return
}
workOrderIdInt, _ := strconv.Atoi(workOrderId)
processIdInt, _ := strconv.Atoi(processId)
result, err := service.ProcessStructure(c, processIdInt, workOrderIdInt)
if err != nil {
app.Error(c, -1, err, "")
return
}
if workOrderIdInt != 0 {
currentState := result["workOrder"].(service.WorkOrderData).CurrentState
userAuthority, err := service.JudgeUserAuthority(c, workOrderIdInt, currentState)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
return
}
result["userAuthority"] = userAuthority
}
app.OK(c, result, "数据获取成功")
}
// 新建工单
func CreateWorkOrder(c *gin.Context) {
var (
userInfo system.SysUser
workOrderValue struct {
process.WorkOrderInfo
Tpls map[string][]interface{} `json:"tpls"`
SourceState string `json:"source_state"`
Tasks json.RawMessage `json:"tasks"`
Source string `json:"source"`
}
)
err := c.ShouldBind(&workOrderValue)
if err != nil {
app.Error(c, -1, err, "")
return
}
relatedPerson, err := json.Marshal([]int{tools.GetUserId(c)})
if err != nil {
app.Error(c, -1, err, "")
return
}
// 创建工单数据
tx := orm.Eloquent.Begin()
var workOrderInfo = process.WorkOrderInfo{
Title: workOrderValue.Title,
Process: workOrderValue.Process,
Classify: workOrderValue.Classify,
State: workOrderValue.State,
RelatedPerson: relatedPerson,
Creator: tools.GetUserId(c),
}
err = tx.Create(&workOrderInfo).Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("创建工单失败,%v", err.Error()))
return
}
// 创建工单模版关联数据
for i := 0; i < len(workOrderValue.Tpls["form_structure"]); i++ {
formDataJson, err := json.Marshal(workOrderValue.Tpls["form_data"][i])
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("生成json字符串错误%v", err.Error()))
return
}
formStructureJson, err := json.Marshal(workOrderValue.Tpls["form_structure"][i])
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("生成json字符串错误%v", err.Error()))
return
}
formData := process.TplData{
WorkOrder: workOrderInfo.Id,
FormStructure: formStructureJson,
FormData: formDataJson,
}
err = tx.Create(&formData).Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("创建工单模版关联数据失败,%v", err.Error()))
return
}
}
// 获取当前用户信息
err = tx.Model(&system.SysUser{}).Where("user_id = ?", tools.GetUserId(c)).Find(&userInfo).Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
return
}
nameValue := userInfo.NickName
if nameValue == "" {
nameValue = userInfo.Username
}
// 创建历史记录
var stateList []map[string]interface{}
err = json.Unmarshal(workOrderInfo.State, &stateList)
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("Json序列化失败%v", err.Error()))
return
}
err = tx.Create(&process.CirculationHistory{
Title: workOrderValue.Title,
WorkOrder: workOrderInfo.Id,
State: workOrderValue.SourceState,
Source: workOrderValue.Source,
Target: stateList[0]["id"].(string),
Circulation: "新建",
Processor: nameValue,
ProcessorId: userInfo.UserId,
}).Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("新建历史记录失败,%v", err.Error()))
return
}
tx.Commit()
// 执行任务
var taskList []string
err = json.Unmarshal(workOrderValue.Tasks, &taskList)
if err != nil {
app.Error(c, -1, err, "")
return
}
go service.ExecTask(taskList)
app.OK(c, "", "成功提交工单申请")
}
// 工单列表
func WorkOrderList(c *gin.Context) {
/*
1. 待办工单
2. 我创建的
3. 我相关的
4. 所有工单
*/
var (
result interface{}
err error
classifyInt int
)
classify := c.DefaultQuery("classify", "0")
if classify == "" {
app.Error(c, -1, errors.New("参数错误请确认classify是否传递"), "")
return
}
classifyInt, _ = strconv.Atoi(classify)
result, err = service.WorkOrderList(c, classifyInt)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("查询工单数据失败,%v", err.Error()))
return
}
app.OK(c, result, "")
}
// 处理工单
func ProcessWorkOrder(c *gin.Context) {
var (
err error
userAuthority bool
handle service.Handle
params struct {
Tasks []string
TargetState string `json:"target_state"` // 目标状态
SourceState string `json:"source_state"` // 源状态
WorkOrderId int `json:"work_order_id"` // 工单ID
Circulation string `json:"circulation"` // 流转ID
FlowProperties int `json:"flow_properties"` // 流转类型 0 拒绝1 同意2 其他
}
)
err = c.ShouldBind(&params)
if err != nil {
app.Error(c, -1, err, "")
return
}
// 处理工单
userAuthority, err = service.JudgeUserAuthority(c, params.WorkOrderId, params.SourceState)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
return
}
if !userAuthority {
app.Error(c, -1, errors.New("当前用户没有权限进行此操作"), "")
return
}
err = handle.HandleWorkOrder(
c,
params.WorkOrderId, // 工单ID
params.Tasks, // 任务列表
params.TargetState, // 目标节点
params.SourceState, // 源节点
params.Circulation, // 流转标题
params.FlowProperties, // 流转属性
)
if err != nil {
app.Error(c, -1, nil, fmt.Sprintf("处理工单失败,%v", err.Error()))
return
}
app.OK(c, nil, "工单处理完成")
}
// 结束工单
func UnityWorkOrder(c *gin.Context) {
var (
err error
workOrderId string
workOrderInfo process.WorkOrderInfo
)
workOrderId = c.DefaultQuery("work_oroder_id", "")
if workOrderId == "" {
app.Error(c, -1, errors.New("参数不正确work_oroder_id"), "")
return
}
tx := orm.Eloquent.Begin()
// 查询工单信息
err = tx.Model(&workOrderInfo).
Where("id = ?", workOrderId).
Find(&workOrderInfo).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("查询工单失败,%v", err.Error()))
return
}
if workOrderInfo.IsEnd == 1 {
app.Error(c, -1, errors.New("工单已结束"), "")
return
}
// 更新工单状态
err = tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", workOrderId).
Update("is_end", 1).
Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("结束工单失败,%v", err.Error()))
return
}
// 写入历史
tx.Create(&process.CirculationHistory{
Title: workOrderInfo.Title,
WorkOrder: workOrderInfo.Id,
State: "结束工单",
Circulation: "结束",
Processor: c.GetString("nickname"),
ProcessorId: tools.GetUserId(c),
Remarks: "手动结束工单。",
})
tx.Commit()
app.OK(c, nil, "工单已结束")
}
// 转交工单
func InversionWorkOrder(c *gin.Context) {
var (
err error
workOrderInfo process.WorkOrderInfo
stateList []map[string]interface{}
stateValue []byte
currentState map[string]interface{}
userInfo system.SysUser
params struct {
WorkOrderId int `json:"work_order_id"`
NodeId string `json:"node_id"`
UserId int `json:"user_id"`
Remarks string `json:"remarks"`
}
)
err = c.ShouldBind(&params)
if err != nil {
app.Error(c, -1, err, "")
return
}
// 查询工单信息
err = orm.Eloquent.Model(&workOrderInfo).
Where("id = ?", params.WorkOrderId).
Find(&workOrderInfo).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("查询工单信息失败,%v", err.Error()))
return
}
// 序列化节点数据
err = json.Unmarshal(workOrderInfo.State, &stateList)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("节点数据反序列化失败,%v", err.Error()))
return
}
for _, s := range stateList {
if s["id"].(string) == params.NodeId {
s["processor"] = []interface{}{params.UserId}
s["process_method"] = "person"
currentState = s
break
}
}
stateValue, err = json.Marshal(stateList)
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("节点数据序列化失败,%v", err.Error()))
return
}
tx := orm.Eloquent.Begin()
// 更新数据
err = tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", params.WorkOrderId).
Update("state", stateValue).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("更新节点信息失败,%v", err.Error()))
return
}
// 查询用户信息
err = tx.Model(&system.SysUser{}).
Where("user_id = ?", params.UserId).
Find(&userInfo).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
return
}
// 添加转交历史
tx.Create(&process.CirculationHistory{
Title: workOrderInfo.Title,
WorkOrder: workOrderInfo.Id,
State: currentState["label"].(string),
Circulation: "转交",
Processor: c.GetString("nickname"),
ProcessorId: tools.GetUserId(c),
Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.NickName),
})
tx.Commit()
app.OK(c, nil, "工单已手动结单")
}

View File

@ -1,3 +1,5 @@
script:
path: ./public/scripts
settings:
application:
domain: localhost:8000

View File

@ -24,3 +24,5 @@ settings:
password: 123456
port: 3306
username: root
script:
path: ./public/scripts

View File

@ -120,7 +120,7 @@ func LogOut(c *gin.Context) {
loginlog.Platform = ua.Platform()
loginlog.Username = tools.GetUserName(c)
loginlog.Msg = "退出成功"
loginlog.Create()
_, _ = loginlog.Create()
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": "退出成功",

View File

@ -1,8 +1,8 @@
package service
import (
"ferry/models/user"
"ferry/pkg/connection"
"ferry/global/orm"
"ferry/models/system"
"strings"
)
@ -20,22 +20,17 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
var principalList []string
switch processMethod {
case "person":
err = connection.DB.Self.Model(&user.Info{}).
err = orm.Eloquent.Model(&system.SysUser{}).
Where("id in (?)", processor).
Pluck("nickname", &principalList).Error
if err != nil {
return
}
case "persongroup":
err = connection.DB.Self.Model(&user.Group{}).Where("id in (?)", processor).Pluck("nickname", &principalList).Error
if err != nil {
return
}
case "department":
err = connection.DB.Self.Model(&user.Dept{}).Where("id in (?)", processor).Pluck("nickname", &principalList).Error
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 "variable":
for _, p := range processor {
switch p {

View File

@ -3,10 +3,10 @@ package service
import (
"encoding/json"
"errors"
"ferry/global/orm"
"ferry/models/base"
"ferry/models/process"
"ferry/models/workOrder"
"ferry/pkg/connection"
"ferry/tools"
"fmt"
"reflect"
"time"
@ -37,13 +37,13 @@ import (
*/
type Handle struct {
cirHistoryList []workOrder.CirculationHistory
cirHistoryList []process.CirculationHistory
workOrderId int
updateValue map[string]interface{}
stateValue map[string]interface{}
targetStateValue map[string]interface{}
workOrderData [][]byte
workOrderDetails workOrder.Info
workOrderDetails process.WorkOrderInfo
endHistory bool
flowProperties int
circulationValue string
@ -86,7 +86,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
break
}
for _, processor := range currentState["processor"].([]interface{}) {
if cirHistoryValue.ProcessorId != c.GetInt("userId") &&
if cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == int(processor.(float64)) {
cirHistoryCount += 1
@ -114,7 +114,7 @@ func (h *Handle) circulation() (err error) {
return
}
err = h.tx.Model(&workOrder.Info{}).
err = h.tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", h.workOrderId).
Updates(map[string]interface{}{
"state": stateValue,
@ -321,8 +321,8 @@ func (h *Handle) HandleWorkOrder(
var (
execTasks []string
relatedPersonList []int
cirHistoryValue []workOrder.CirculationHistory
cirHistoryData workOrder.CirculationHistory
cirHistoryValue []process.CirculationHistory
cirHistoryData process.CirculationHistory
costDurationValue string
sourceEdges []map[string]interface{}
targetEdges []map[string]interface{}
@ -347,13 +347,13 @@ func (h *Handle) HandleWorkOrder(
}()
// 获取工单信息
err = connection.DB.Self.Model(&workOrder.Info{}).Where("id = ?", workOrderId).Find(&h.workOrderDetails).Error
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).Where("id = ?", workOrderId).Find(&h.workOrderDetails).Error
if err != nil {
return
}
// 获取流程信息
err = connection.DB.Self.Model(&process.Info{}).Where("id = ?", h.workOrderDetails.Process).Find(&processInfo).Error
err = orm.Eloquent.Model(&process.Info{}).Where("id = ?", h.workOrderDetails.Process).Find(&processInfo).Error
if err != nil {
return
}
@ -375,7 +375,7 @@ func (h *Handle) HandleWorkOrder(
}
// 获取工单数据
err = connection.DB.Self.Model(&workOrder.TplData{}).
err = orm.Eloquent.Model(&process.TplData{}).
Where("work_order = ?", workOrderId).
Pluck("form_data", &h.workOrderData).Error
if err != nil {
@ -383,7 +383,7 @@ func (h *Handle) HandleWorkOrder(
}
// 根据处理人查询出需要会签的条数
err = connection.DB.Self.Model(&workOrder.CirculationHistory{}).
err = orm.Eloquent.Model(&process.CirculationHistory{}).
Where("work_order = ?", workOrderId).
Order("id desc").
Find(&h.cirHistoryList).Error
@ -397,13 +397,13 @@ func (h *Handle) HandleWorkOrder(
}
relatedPersonStatus := false
for _, r := range relatedPersonList {
if r == c.GetInt("userId") {
if r == tools.GetUserId(c) {
relatedPersonStatus = true
break
}
}
if !relatedPersonStatus {
relatedPersonList = append(relatedPersonList, c.GetInt("userId"))
relatedPersonList = append(relatedPersonList, tools.GetUserId(c))
}
relatedPersonValue, err = json.Marshal(relatedPersonList)
@ -416,7 +416,7 @@ func (h *Handle) HandleWorkOrder(
}
// 开启事务
h.tx = connection.DB.Self.Begin()
h.tx = orm.Eloquent.Begin()
stateValue := map[string]interface{}{
"label": h.targetStateValue["label"].(string),
@ -591,7 +591,7 @@ func (h *Handle) HandleWorkOrder(
h.tx.Rollback()
return
}
err = h.tx.Model(&workOrder.Info{}).
err = h.tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", h.workOrderId).
Update("is_end", 1).Error
if err != nil {
@ -601,7 +601,7 @@ func (h *Handle) HandleWorkOrder(
}
// 流转历史写入
err = connection.DB.Self.Model(&cirHistoryValue).
err = orm.Eloquent.Model(&cirHistoryValue).
Where("work_order = ?", workOrderId).
Find(&cirHistoryValue).
Order("create_time desc").Error
@ -616,7 +616,7 @@ func (h *Handle) HandleWorkOrder(
}
}
cirHistoryData = workOrder.CirculationHistory{
cirHistoryData = process.CirculationHistory{
Model: base.Model{},
Title: h.workOrderDetails.Title,
WorkOrder: h.workOrderDetails.Id,
@ -625,7 +625,7 @@ func (h *Handle) HandleWorkOrder(
Target: h.targetStateValue["id"].(string),
Circulation: circulationValue,
Processor: c.GetString("nickname"),
ProcessorId: c.GetInt("userId"),
ProcessorId: tools.GetUserId(c),
CostDuration: costDurationValue,
}
@ -637,14 +637,14 @@ func (h *Handle) HandleWorkOrder(
// 判断目标是否是结束节点
if h.targetStateValue["clazz"] == "end" && h.endHistory == true {
err = h.tx.Create(&workOrder.CirculationHistory{
err = h.tx.Create(&process.CirculationHistory{
Model: base.Model{},
Title: h.workOrderDetails.Title,
WorkOrder: h.workOrderDetails.Id,
State: h.targetStateValue["label"].(string),
Source: h.targetStateValue["id"].(string),
Processor: c.GetString("nickname"),
ProcessorId: c.GetInt("userId"),
ProcessorId: tools.GetUserId(c),
Circulation: "结束",
}).Error
if err != nil {

View File

@ -3,10 +3,9 @@ package service
import (
"encoding/json"
"errors"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/tpl"
"ferry/models/workOrder"
"ferry/pkg/connection"
"ferry/tools"
"fmt"
"strconv"
@ -18,7 +17,7 @@ import (
*/
type WorkOrderData struct {
workOrder.Info
process.WorkOrderInfo
CurrentState string `json:"current_state"`
}
@ -27,14 +26,14 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
processValue process.Info
processStructureDetails map[string]interface{}
processNode []map[string]interface{}
tplDetails []*tpl.Info
tplDetails []*process.TplInfo
workOrderInfo WorkOrderData
workOrderTpls []*workOrder.TplData
workOrderHistory []*workOrder.CirculationHistory
workOrderTpls []*process.TplData
workOrderHistory []*process.CirculationHistory
stateList []map[string]interface{}
)
err = connection.DB.Self.Model(&processValue).Where("id = ?", processId).Find(&processValue).Error
err = orm.Eloquent.Model(&processValue).Where("id = ?", processId).Find(&processValue).Error
if err != nil {
err = fmt.Errorf("查询流程失败,%v", err.Error())
return
@ -77,7 +76,7 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
}
// 获取历史记录
err = connection.DB.Self.Model(&workOrder.CirculationHistory{}).
err = orm.Eloquent.Model(&process.CirculationHistory{}).
Where("work_order = ?", workOrderId).
Order("id desc").
Find(&workOrderHistory).Error
@ -94,7 +93,7 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
err = fmt.Errorf("json转map失败%v", err.Error())
return
}
err = connection.DB.Self.Model(&tplDetails).
err = orm.Eloquent.Model(&tplDetails).
Where("id in (?)", tplIdList).
Find(&tplDetails).Error
if err != nil {
@ -104,7 +103,7 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
result["tpls"] = tplDetails
} else {
// 查询工单信息
err = connection.DB.Self.Model(&workOrder.Info{}).
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).
Where("id = ?", workOrderId).
Scan(&workOrderInfo).Error
if err != nil {
@ -145,7 +144,7 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
for _, processNodeValue := range processStructureDetails["nodes"].([]interface{}) {
if stateValue["id"].(string) == processNodeValue.(map[string]interface{})["id"] {
for _, userId := range stateValue["processor"].([]interface{}) {
if int(userId.(float64)) == c.GetInt("userId") {
if int(userId.(float64)) == tools.GetUserId(c) {
workOrderInfo.CurrentState = stateValue["id"].(string)
break breakStateTag
}
@ -162,7 +161,7 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
result["workOrder"] = workOrderInfo
// 查询工单表单数据
err = connection.DB.Self.Model(&workOrderTpls).
err = orm.Eloquent.Model(&workOrderTpls).
Where("work_order = ?", workOrderId).
Find(&workOrderTpls).Error
if err != nil {

View File

@ -2,10 +2,9 @@ package service
import (
"encoding/json"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/user"
"ferry/models/workOrder"
"ferry/pkg/connection"
"ferry/tools"
"github.com/gin-gonic/gin"
)
@ -22,10 +21,10 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
variable 变量
*/
var (
workOrderInfo workOrder.Info
userInfo user.Info
userDept user.Dept
cirHistoryList []workOrder.CirculationHistory
workOrderInfo process.WorkOrderInfo
//userInfo system.SysUser
//userDept system.Dept
cirHistoryList []process.CirculationHistory
stateValue map[string]interface{}
processInfo process.Info
processState ProcessState
@ -33,7 +32,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
currentStateValue map[string]interface{}
)
// 获取工单信息
err = connection.DB.Self.Model(&workOrderInfo).
err = orm.Eloquent.Model(&workOrderInfo).
Where("id = ?", workOrderId).
Find(&workOrderInfo).Error
if err != nil {
@ -41,7 +40,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
}
// 获取流程信息
err = connection.DB.Self.Model(&process.Info{}).Where("id = ?", workOrderInfo.Process).Find(&processInfo).Error
err = orm.Eloquent.Model(&process.Info{}).Where("id = ?", workOrderInfo.Process).Find(&processInfo).Error
if err != nil {
return
}
@ -71,7 +70,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
if currentStateValue["processor"] != nil && len(currentStateValue["processor"].([]interface{})) > 1 {
if isCounterSign, ok := stateValue["isCounterSign"]; ok {
if isCounterSign.(bool) {
err = connection.DB.Self.Model(&workOrder.CirculationHistory{}).
err = orm.Eloquent.Model(&process.CirculationHistory{}).
Where("work_order = ?", workOrderId).
Order("id desc").
Find(&cirHistoryList).Error
@ -82,7 +81,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
if cirHistoryValue.Source != stateValue["id"] {
break
}
if cirHistoryValue.Source == stateValue["id"] && cirHistoryValue.ProcessorId == c.GetInt("userId") {
if cirHistoryValue.Source == stateValue["id"] && cirHistoryValue.ProcessorId == tools.GetUserId(c) {
return
}
}
@ -93,54 +92,54 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
switch currentStateValue["process_method"].(string) {
case "person":
for _, processorValue := range currentStateValue["processor"].([]interface{}) {
if int(processorValue.(float64)) == c.GetInt("userId") {
if int(processorValue.(float64)) == tools.GetUserId(c) {
status = true
}
}
case "persongroup":
var persongroupCount int
err = connection.DB.Self.Model(&user.UserGroup{}).
Where("group in (?) and user = ?", currentStateValue["processor"].([]interface{}), c.GetInt("userId")).
Count(&persongroupCount).Error
if err != nil {
return
}
if persongroupCount > 0 {
status = true
}
case "department":
var departmentCount int
err = connection.DB.Self.Model(&user.Info{}).
Where("dept in (?) and id = ?", currentStateValue["processor"].([]interface{}), c.GetInt("userId")).
Count(&departmentCount).Error
if err != nil {
return
}
if departmentCount > 0 {
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 "variable":
for _, p := range currentStateValue["processor"].([]interface{}) {
switch int(p.(float64)) {
case 1:
if workOrderInfo.Creator == c.GetInt("userId") {
status = true
}
case 2:
err = connection.DB.Self.Model(&userInfo).Where("id = ?", workOrderInfo.Creator).Find(&userInfo).Error
if err != nil {
return
}
err = connection.DB.Self.Model(&userDept).Where("id = ?", userInfo.Dept).Find(&userDept).Error
if err != nil {
return
}
if userDept.Approver == c.GetInt("userId") {
status = true
} else if userDept.Leader == c.GetInt("userId") {
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
// }
}
}
}

View File

@ -2,12 +2,12 @@ package service
import (
"encoding/json"
"ferry/models/user"
"ferry/models/workOrder"
"ferry/pkg/connection"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/system"
"ferry/pkg/pagination"
"ferry/tools"
"fmt"
"strings"
"github.com/gin-gonic/gin"
)
@ -18,21 +18,21 @@ import (
func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error) {
type workOrderInfo struct {
workOrder.Info
process.WorkOrderInfo
Principals string `json:"principals"`
DataClassify int `json:"data_classify"`
}
var (
workOrderInfoList []workOrderInfo
principals string
userInfo user.Info
userInfo system.SysUser
StateList []map[string]interface{}
)
title := c.DefaultQuery("title", "")
db := connection.DB.Self.Model(&workOrder.Info{}).Where("title like ?", fmt.Sprintf("%%%v%%", title))
db := orm.Eloquent.Model(&process.WorkOrderInfo{}).Where("title like ?", fmt.Sprintf("%%%v%%", title))
err = connection.DB.Self.Model(&user.Info{}).Where("id = ?", c.GetInt("userId")).Find(&userInfo).Error
err = orm.Eloquent.Model(&system.SysUser{}).Where("id = ?", tools.GetUserId(c)).Find(&userInfo).Error
if err != nil {
return
}
@ -42,47 +42,51 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
case 1:
// 待办工单
// 1. 个人
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", c.GetInt("userId"))
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", tools.GetUserId(c))
// 2. 小组
groupList := make([]int, 0)
err = connection.DB.Self.Model(&user.UserGroup{}).
Where("user = ?", c.GetInt("userId")).
Pluck("`group`", &groupList).Error
if err != nil {
return
}
groupSqlList := make([]string, 0)
if len(groupList) > 0 {
for _, group := range groupList {
groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', %v))", group))
}
} else {
groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 0))"))
}
personGroupSelect := fmt.Sprintf(
"((%v) and %v)",
strings.Join(groupSqlList, " or "),
"JSON_CONTAINS(state, JSON_OBJECT('process_method', 'persongroup'))",
)
//groupList := make([]int, 0)
//err = orm.Eloquent.Model(&user.UserGroup{}).
// Where("user = ?", tools.GetUserId(c)).
// Pluck("`group`", &groupList).Error
//if err != nil {
// return
//}
//groupSqlList := make([]string, 0)
//if len(groupList) > 0 {
// for _, group := range groupList {
// groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', %v))", group))
// }
//} else {
// groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 0))"))
//}
//
//personGroupSelect := fmt.Sprintf(
// "((%v) and %v)",
// strings.Join(groupSqlList, " or "),
// "JSON_CONTAINS(state, JSON_OBJECT('process_method', 'persongroup'))",
//)
// 3. 部门
departmentSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'department')))", userInfo.Dept)
//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) or (%v))",
fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 1)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'variable')) and creator = %v", c.GetInt("userId")),
fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 2)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'variable')) and creator = %v", userInfo.Dept),
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),
//)
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 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))
case 2:
// 我创建的
db = db.Where("creator = ?", c.GetInt("userId"))
db = db.Where("creator = ?", tools.GetUserId(c))
case 3:
// 我相关的
db = db.Where(fmt.Sprintf("JSON_CONTAINS(related_person, '%v')", c.GetInt("userId")))
db = db.Where(fmt.Sprintf("JSON_CONTAINS(related_person, '%v')", tools.GetUserId(c)))
case 4:
// 所有工单
default:

View File

@ -15,7 +15,7 @@ import (
func RegisterProcessRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
processRouter := v1.Group("/process").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
//processRouter.GET("/classify", process.ClassifyProcessList)
processRouter.GET("/classify", process.ClassifyProcessList)
processRouter.GET("", process.ProcessList)
processRouter.POST("", process.CreateProcess)
processRouter.PUT("", process.UpdateProcess)

View File

@ -1,6 +1,8 @@
package process
import (
"ferry/apis/process"
"ferry/middleware"
jwt "ferry/pkg/jwtauth"
"github.com/gin-gonic/gin"
@ -11,12 +13,12 @@ import (
*/
func RegisterTaskRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
//taskRouter := v1.Group("/task").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
//{
// taskRouter.GET("", process.TaskList)
// taskRouter.GET("/details", process.TaskDetails)
// taskRouter.POST("", process.CreateTask)
// taskRouter.PUT("", process.UpdateTask)
// taskRouter.DELETE("", process.DeleteTask)
//}
taskRouter := v1.Group("/task").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
taskRouter.GET("", process.TaskList)
taskRouter.GET("/details", process.TaskDetails)
taskRouter.POST("", process.CreateTask)
taskRouter.PUT("", process.UpdateTask)
taskRouter.DELETE("", process.DeleteTask)
}
}

View File

@ -5,19 +5,21 @@
package process
import (
"ferry/apis/process"
"ferry/middleware"
jwt "ferry/pkg/jwtauth"
"github.com/gin-gonic/gin"
)
func RegisterWorkOrderRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
//workOrderRouter := v1.Group("/work-order").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
//{
// workOrderRouter.GET("/process-structure", process.ProcessStructure)
// workOrderRouter.POST("/create", process.CreateWorkOrder)
// workOrderRouter.GET("/list", process.WorkOrderList)
// workOrderRouter.POST("/handle", process.ProcessWorkOrder)
// workOrderRouter.GET("/unity", process.UnityWorkOrder)
// workOrderRouter.POST("/inversion", process.InversionWorkOrder)
//}
workOrderRouter := v1.Group("/work-order").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
workOrderRouter.GET("/process-structure", process.ProcessStructure)
workOrderRouter.POST("/create", process.CreateWorkOrder)
workOrderRouter.GET("/list", process.WorkOrderList)
workOrderRouter.POST("/handle", process.ProcessWorkOrder)
workOrderRouter.GET("/unity", process.UnityWorkOrder)
workOrderRouter.POST("/inversion", process.InversionWorkOrder)
}
}