添加流程申请。

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

View File

@ -1,230 +1,235 @@
package process package process
//import ( import (
// "ferry/pkg/pagination" "errors"
// "ferry/pkg/response/code" "ferry/pkg/pagination"
// . "ferry/pkg/response/response" "ferry/tools"
// "fmt" "ferry/tools/app"
// "io/ioutil" "fmt"
// "os" "io/ioutil"
// "strings" "os"
// "strings"
// "github.com/gin-gonic/gin"
// uuid "github.com/satori/go.uuid" "github.com/gin-gonic/gin"
// "github.com/spf13/viper" uuid "github.com/satori/go.uuid"
//) "github.com/spf13/viper"
// )
///*
// @Author : lanyulei /*
//*/ @Author : lanyulei
// */
//// 任务列表
//func TaskList(c *gin.Context) { // 任务列表
// var ( func TaskList(c *gin.Context) {
// err error var (
// pageValue pagination.ListRequest err error
// taskName string pageValue pagination.ListRequest
// taskData []map[string]interface{} taskName string
// total_count int taskData []map[string]interface{}
// ) totalCount int
// taskName = c.DefaultQuery("name", "") )
// taskName = c.DefaultQuery("name", "")
// err = c.ShouldBind(&pageValue)
// if err != nil { err = c.ShouldBind(&pageValue)
// Response(c, code.BindError, nil, err.Error()) if err != nil {
// return app.Error(c, -1, err, "")
// } return
// }
// getFileDetails := func(fn string) map[string]interface{} {
// file := make(map[string]interface{}) if pageValue.Page == 0 {
// fileClassify := strings.Split(fn, ".") pageValue.Page = 1
// fileDetails := strings.Split(fileClassify[0], "-") }
// switch fileClassify[1] {
// case "py": if pageValue.PerPage == 0 {
// file["classify"] = "Python" pageValue.PerPage = 10
// case "sh": }
// file["classify"] = "Shell"
// default: getFileDetails := func(fn string) map[string]interface{} {
// file["classify"] = "Other" file := make(map[string]interface{})
// } fileClassify := strings.Split(fn, ".")
// if len(fileDetails) == 3 { fileDetails := strings.Split(fileClassify[0], "-")
// file["name"] = fileDetails[0] switch fileClassify[1] {
// file["uuid"] = fileDetails[1] case "py":
// file["creator"] = fileDetails[2] file["classify"] = "Python"
// } case "sh":
// file["full_name"] = fn file["classify"] = "Shell"
// return file default:
// } file["classify"] = "Other"
// files, _ := ioutil.ReadDir(viper.GetString("script.path")) }
// var endIndex int if len(fileDetails) == 3 {
// if taskName != "" { file["name"] = fileDetails[0]
// for _, f := range files { file["uuid"] = fileDetails[1]
// if strings.Contains(strings.Split(f.Name(), "-")[0], taskName) { file["creator"] = fileDetails[2]
// taskData = append(taskData, getFileDetails(f.Name())) }
// } file["full_name"] = fn
// } return file
// total_count = len(taskData) }
// if pageValue.Page*pageValue.PerPage > len(taskData) { files, _ := ioutil.ReadDir(viper.GetString("script.path"))
// endIndex = len(taskData) var endIndex int
// } else { if taskName != "" {
// endIndex = pageValue.Page * pageValue.PerPage for _, f := range files {
// } if strings.Contains(strings.Split(f.Name(), "-")[0], taskName) {
// taskData = taskData[(pageValue.Page-1)*pageValue.PerPage : endIndex] taskData = append(taskData, getFileDetails(f.Name()))
// } else { }
// if pageValue.Page*pageValue.PerPage > len(files) { }
// endIndex = len(files) totalCount = len(taskData)
// } else { if pageValue.Page*pageValue.PerPage > len(taskData) {
// endIndex = pageValue.Page * pageValue.PerPage endIndex = len(taskData)
// } } else {
// for _, f := range files[(pageValue.Page-1)*pageValue.PerPage : endIndex] { endIndex = pageValue.Page * pageValue.PerPage
// taskData = append(taskData, getFileDetails(f.Name())) }
// } taskData = taskData[(pageValue.Page-1)*pageValue.PerPage : endIndex]
// total_count = len(files) } else {
// } if pageValue.Page*pageValue.PerPage > len(files) {
// endIndex = len(files)
// Response(c, nil, map[string]interface{}{ } else {
// "data": taskData, endIndex = pageValue.Page * pageValue.PerPage
// "page": pageValue.Page, }
// "per_page": pageValue.PerPage, for _, f := range files[(pageValue.Page-1)*pageValue.PerPage : endIndex] {
// "total_count": total_count, taskData = append(taskData, getFileDetails(f.Name()))
// }, "") }
//} totalCount = len(files)
// }
//// 创建任务
//func CreateTask(c *gin.Context) { app.OK(c, map[string]interface{}{
// type Task struct { "data": taskData,
// Name string `json:"name"` "page": pageValue.Page,
// Classify string `json:"classify"` "per_page": pageValue.PerPage,
// Content string `json:"content"` "total_count": totalCount,
// } }, "")
// }
// var (
// err error // 创建任务
// taskValue Task func CreateTask(c *gin.Context) {
// ) var (
// err error
// err = c.ShouldBind(&taskValue) taskValue struct {
// if err != nil { Name string `json:"name"`
// Response(c, code.BindError, nil, err.Error()) Classify string `json:"classify"`
// return Content string `json:"content"`
// } }
// )
// uuidValue := uuid.Must(uuid.NewV4(), err)
// fileName := fmt.Sprintf("%v/%v-%v-%v", err = c.ShouldBind(&taskValue)
// viper.GetString("script.path"), if err != nil {
// taskValue.Name, app.Error(c, -1, err, "")
// strings.Split(uuidValue.String(), "-")[4], return
// c.GetString("username"), }
// )
// if taskValue.Classify == "python" { uuidValue := uuid.Must(uuid.NewV4(), err)
// fileName = fileName + ".py" fileName := fmt.Sprintf("%v/%v-%v-%v",
// } else if taskValue.Classify == "shell" { viper.GetString("script.path"),
// fileName = fileName + ".sh" taskValue.Name,
// } strings.Split(uuidValue.String(), "-")[4],
// tools.GetUserName(c),
// err = ioutil.WriteFile(fileName, []byte(taskValue.Content), 0666) )
// if err != nil { if taskValue.Classify == "python" {
// Response(c, code.BindError, nil, fmt.Sprintf("创建任务脚本失败: %v", err.Error())) fileName = fileName + ".py"
// return } else if taskValue.Classify == "shell" {
// } fileName = fileName + ".sh"
// }
// Response(c, nil, nil, "")
//} err = ioutil.WriteFile(fileName, []byte(taskValue.Content), 0666)
// if err != nil {
//// 更新任务 app.Error(c, -1, err, fmt.Sprintf("创建任务脚本失败: %v", err.Error()))
//func UpdateTask(c *gin.Context) { return
// type fileDetails struct { }
// Name string `json:"name"`
// FullName string `json:"full_name"` app.OK(c, "", "任务创建成功")
// Classify string `json:"classify"` }
// Content string `json:"content"`
// } // 更新任务
// func UpdateTask(c *gin.Context) {
// var ( var (
// err error err error
// file fileDetails file struct {
// ) Name string `json:"name"`
// FullName string `json:"full_name"`
// err = c.ShouldBind(&file) Classify string `json:"classify"`
// if err != nil { Content string `json:"content"`
// Response(c, code.BindError, nil, "") }
// return )
// }
// err = c.ShouldBind(&file)
// fullNameList := strings.Split(file.FullName, "-") if err != nil {
// if fullNameList[0] != file.Name { app.Error(c, -1, err, "")
// fullNameList[0] = file.Name return
// } }
// var suffixName string
// if strings.ToLower(file.Classify) == "python" { fullNameList := strings.Split(file.FullName, "-")
// suffixName = ".py" if fullNameList[0] != file.Name {
// } else if strings.ToLower(file.Classify) == "shell" { fullNameList[0] = file.Name
// suffixName = ".sh" }
// } var suffixName string
// if strings.ToLower(file.Classify) == "python" {
// if fullNameList[len(fullNameList)-1][len(fullNameList[len(fullNameList)-1])-3:len(fullNameList[len(fullNameList)-1])] != suffixName { suffixName = ".py"
// tList := strings.Split(fullNameList[len(fullNameList)-1], ".") } else if strings.ToLower(file.Classify) == "shell" {
// tList[len(tList)-1] = suffixName[1:len(suffixName)] suffixName = ".sh"
// fullNameList[len(fullNameList)-1] = strings.Join(tList, ".") }
// }
// if fullNameList[len(fullNameList)-1][len(fullNameList[len(fullNameList)-1])-3:len(fullNameList[len(fullNameList)-1])] != suffixName {
// fileFullName := strings.Join(fullNameList, "-") tList := strings.Split(fullNameList[len(fullNameList)-1], ".")
// tList[len(tList)-1] = suffixName[1:len(suffixName)]
// // 修改文件内容 fullNameList[len(fullNameList)-1] = strings.Join(tList, ".")
// 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())) fileFullName := strings.Join(fullNameList, "-")
// return
// } // 修改文件内容
// err = ioutil.WriteFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName), []byte(file.Content), 0666)
// // 修改文件名称 if err != nil {
// err = os.Rename( app.Error(c, -1, err, fmt.Sprintf("更新脚本文件失败,%v", err.Error()))
// fmt.Sprintf("%v/%v", viper.GetString("script.path"), file.FullName), return
// fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName), }
// )
// if err != nil { // 修改文件名称
// Response(c, code.BindError, nil, fmt.Sprintf("更改脚本文件名称失败,%v", err.Error())) err = os.Rename(
// return fmt.Sprintf("%v/%v", viper.GetString("script.path"), file.FullName),
// } fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileFullName),
// )
// Response(c, nil, nil, "") if err != nil {
//} app.Error(c, -1, err, fmt.Sprintf("更改脚本文件名称失败,%v", err.Error()))
// return
//// 删除任务 }
//func DeleteTask(c *gin.Context) {
// fullName := c.DefaultQuery("full_name", "") app.OK(c, "", "更新成功")
// if fullName == "" { }
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数full_name是否传递")
// return // 删除任务
// } func DeleteTask(c *gin.Context) {
// fullName := c.DefaultQuery("full_name", "")
// err := os.Remove(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fullName)) if fullName == "" {
// if err != nil { app.Error(c, -1, errors.New("参数不正确请确定参数full_name是否传递"), "")
// Response(c, code.DeleteError, nil, fmt.Sprintf("删除文件失败,%v", err.Error())) return
// return }
// }
// err := os.Remove(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fullName))
// Response(c, nil, nil, "") if err != nil {
//} app.Error(c, -1, err, fmt.Sprintf("删除文件失败,%v", err.Error()))
// return
//// 任务详情 }
//func TaskDetails(c *gin.Context) {
// var ( app.OK(c, nil, "任务删除成功")
// err error }
// fileName string
// content []byte // 任务详情
// ) func TaskDetails(c *gin.Context) {
// var (
// fileName = c.DefaultQuery("file_name", "") err error
// if fileName == "" { fileName string
// Response(c, code.ParamError, nil, "参数不正确请确认file_name参数是否存在") content []byte
// return )
// }
// fileName = c.DefaultQuery("file_name", "")
// content, err = ioutil.ReadFile(fmt.Sprintf("%v/%v", viper.GetString("script.path"), fileName)) if fileName == "" {
// if err != nil { app.Error(c, -1, errors.New("参数不正确请确认file_name参数是否存在"), "")
// return return
// } }
//
// Response(c, nil, string(content), "") 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 package process
//import ( import (
// "encoding/json" "encoding/json"
// "errors" "errors"
// "ferry/models/user" "ferry/global/orm"
// "ferry/models/workOrder" "ferry/models/process"
// "ferry/pkg/connection" "ferry/models/system"
// "ferry/pkg/response/code" . "ferry/pkg/response/response"
// . "ferry/pkg/response/response" "ferry/pkg/service"
// "ferry/pkg/service" "ferry/tools"
// "fmt" "ferry/tools/app"
// "strconv" "fmt"
// "strconv"
// "github.com/gin-gonic/gin"
//) "github.com/gin-gonic/gin"
// )
///*
// @Author : lanyulei /*
//*/ @Author : lanyulei
// */
//// 流程结构包括节点,流转和模版
//func ProcessStructure(c *gin.Context) { // 流程结构包括节点,流转和模版
// processId := c.DefaultQuery("processId", "") func ProcessStructure(c *gin.Context) {
// if processId == "" { processId := c.DefaultQuery("processId", "")
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数processId是否传递") if processId == "" {
// return app.Error(c, -1, errors.New("参数不正确请确定参数processId是否传递"), "")
// } return
// workOrderId := c.DefaultQuery("workOrderId", "0") }
// if processId == "" { workOrderId := c.DefaultQuery("workOrderId", "0")
// Response(c, code.InternalServerError, nil, "参数不正确请确定参数processId是否传递") if workOrderId == "" {
// return app.Error(c, -1, errors.New("参数不正确请确定参数workOrderId是否传递"), "")
// } return
// workOrderIdInt, _ := strconv.Atoi(workOrderId) }
// processIdInt, _ := strconv.Atoi(processId) workOrderIdInt, _ := strconv.Atoi(workOrderId)
// result, err := service.ProcessStructure(c, processIdInt, workOrderIdInt) processIdInt, _ := strconv.Atoi(processId)
// if err != nil { result, err := service.ProcessStructure(c, processIdInt, workOrderIdInt)
// Response(c, code.SelectError, nil, err.Error()) if err != nil {
// return app.Error(c, -1, err, "")
// } return
// }
// if workOrderIdInt != 0 {
// currentState := result["workOrder"].(service.WorkOrderData).CurrentState if workOrderIdInt != 0 {
// userAuthority, err := service.JudgeUserAuthority(c, workOrderIdInt, currentState) currentState := result["workOrder"].(service.WorkOrderData).CurrentState
// if err != nil { userAuthority, err := service.JudgeUserAuthority(c, workOrderIdInt, currentState)
// Response(c, code.InternalServerError, nil, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error())) if err != nil {
// return app.Error(c, -1, err, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
// } return
// result["userAuthority"] = userAuthority }
// } result["userAuthority"] = userAuthority
// }
// Response(c, nil, result, "")
//} app.OK(c, result, "数据获取成功")
// }
//// 新建工单
//func CreateWorkOrder(c *gin.Context) { // 新建工单
// var workOrderValue struct { func CreateWorkOrder(c *gin.Context) {
// workOrder.Info var (
// Tpls map[string][]interface{} `json:"tpls"` userInfo system.SysUser
// SourceState string `json:"source_state"` workOrderValue struct {
// Tasks json.RawMessage `json:"tasks"` process.WorkOrderInfo
// Source string `json:"source"` Tpls map[string][]interface{} `json:"tpls"`
// } SourceState string `json:"source_state"`
// Tasks json.RawMessage `json:"tasks"`
// err := c.ShouldBind(&workOrderValue) Source string `json:"source"`
// if err != nil { }
// Response(c, code.BindError, nil, err.Error()) )
// return
// } err := c.ShouldBind(&workOrderValue)
// if err != nil {
// relatedPerson, err := json.Marshal([]int{c.GetInt("userId")}) app.Error(c, -1, err, "")
// if err != nil { return
// Response(c, code.BindError, nil, err.Error()) }
// return
// } relatedPerson, err := json.Marshal([]int{tools.GetUserId(c)})
// if err != nil {
// // 创建工单数据 app.Error(c, -1, err, "")
// tx := connection.DB.Self.Begin() return
// var workOrderInfo = workOrder.Info{ }
// Title: workOrderValue.Title,
// Process: workOrderValue.Process, // 创建工单数据
// Classify: workOrderValue.Classify, tx := orm.Eloquent.Begin()
// State: workOrderValue.State, var workOrderInfo = process.WorkOrderInfo{
// RelatedPerson: relatedPerson, Title: workOrderValue.Title,
// Creator: c.GetInt("userId"), Process: workOrderValue.Process,
// } Classify: workOrderValue.Classify,
// err = tx.Create(&workOrderInfo).Error State: workOrderValue.State,
// if err != nil { RelatedPerson: relatedPerson,
// tx.Rollback() Creator: tools.GetUserId(c),
// Response(c, code.CreateError, nil, fmt.Sprintf("创建工单失败,%v", err.Error())) }
// return err = tx.Create(&workOrderInfo).Error
// } if err != nil {
// tx.Rollback()
// // 创建工单模版关联数据 app.Error(c, -1, err, fmt.Sprintf("创建工单失败,%v", err.Error()))
// for i := 0; i < len(workOrderValue.Tpls["form_structure"]); i++ { return
// 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())) for i := 0; i < len(workOrderValue.Tpls["form_structure"]); i++ {
// return formDataJson, err := json.Marshal(workOrderValue.Tpls["form_data"][i])
// } if err != nil {
// formStructureJson, err := json.Marshal(workOrderValue.Tpls["form_structure"][i]) tx.Rollback()
// if err != nil { app.Error(c, -1, err, fmt.Sprintf("生成json字符串错误%v", err.Error()))
// tx.Rollback() return
// 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()
// formData := workOrder.TplData{ app.Error(c, -1, err, fmt.Sprintf("生成json字符串错误%v", err.Error()))
// WorkOrder: workOrderInfo.Id, return
// FormStructure: formStructureJson, }
// FormData: formDataJson,
// } formData := process.TplData{
// WorkOrder: workOrderInfo.Id,
// err = tx.Create(&formData).Error FormStructure: formStructureJson,
// if err != nil { FormData: formDataJson,
// tx.Rollback() }
// Response(c, code.CreateError, nil, fmt.Sprintf("创建工单模版关联数据失败,%v", err.Error()))
// return err = tx.Create(&formData).Error
// } if err != nil {
// } tx.Rollback()
// app.Error(c, -1, err, 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())) err = tx.Model(&system.SysUser{}).Where("user_id = ?", tools.GetUserId(c)).Find(&userInfo).Error
// return if err != nil {
// } tx.Rollback()
// app.Error(c, -1, err, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
// nameValue := userInfo.Nickname return
// if nameValue == "" { }
// nameValue = userInfo.Username
// } nameValue := userInfo.NickName
// if nameValue == "" {
// // 创建历史记录 nameValue = userInfo.Username
// var stateList []map[string]interface{} }
// err = json.Unmarshal(workOrderInfo.State, &stateList)
// if err != nil { // 创建历史记录
// tx.Rollback() var stateList []map[string]interface{}
// Response(c, code.InternalServerError, nil, fmt.Sprintf("Json序列化失败%v", err.Error())) err = json.Unmarshal(workOrderInfo.State, &stateList)
// return if err != nil {
// } tx.Rollback()
// err = tx.Create(&workOrder.CirculationHistory{ app.Error(c, -1, err, fmt.Sprintf("Json序列化失败%v", err.Error()))
// Title: workOrderValue.Title, return
// WorkOrder: workOrderInfo.Id, }
// State: workOrderValue.SourceState, err = tx.Create(&process.CirculationHistory{
// Source: workOrderValue.Source, Title: workOrderValue.Title,
// Target: stateList[0]["id"].(string), WorkOrder: workOrderInfo.Id,
// Circulation: "新建", State: workOrderValue.SourceState,
// Processor: nameValue, Source: workOrderValue.Source,
// ProcessorId: userInfo.Id, Target: stateList[0]["id"].(string),
// }).Error Circulation: "新建",
// if err != nil { Processor: nameValue,
// tx.Rollback() ProcessorId: userInfo.UserId,
// err = fmt.Errorf("新建历史记录失败,%v", err.Error()) }).Error
// return if err != nil {
// } tx.Rollback()
// app.Error(c, -1, err, fmt.Sprintf("新建历史记录失败,%v", err.Error()))
// tx.Commit() return
// }
// // 执行任务
// var taskList []string tx.Commit()
// err = json.Unmarshal(workOrderValue.Tasks, &taskList)
// if err != nil { // 执行任务
// Response(c, code.InternalServerError, nil, err.Error()) var taskList []string
// return err = json.Unmarshal(workOrderValue.Tasks, &taskList)
// } if err != nil {
// go service.ExecTask(taskList) app.Error(c, -1, err, "")
// return
// Response(c, nil, nil, "") }
//} go service.ExecTask(taskList)
//
//// 工单列表 app.OK(c, "", "成功提交工单申请")
//func WorkOrderList(c *gin.Context) { }
// /*
// 1. 待办工单 // 工单列表
// 2. 我创建的 func WorkOrderList(c *gin.Context) {
// 3. 我相关的 /*
// 4. 所有工单 1. 待办工单
// */ 2. 我创建的
// 3. 我相关的
// var ( 4. 所有工单
// result interface{} */
// err error
// classifyInt int var (
// ) result interface{}
// err error
// classify := c.DefaultQuery("classify", "0") classifyInt int
// if classify == "" { )
// Response(c, code.ParamError, nil, "参数错误请确认classify是否传递")
// return classify := c.DefaultQuery("classify", "0")
// } if classify == "" {
// app.Error(c, -1, errors.New("参数错误请确认classify是否传递"), "")
// classifyInt, _ = strconv.Atoi(classify) return
// result, err = service.WorkOrderList(c, classifyInt) }
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单数据失败,%v", err.Error())) classifyInt, _ = strconv.Atoi(classify)
// return result, err = service.WorkOrderList(c, classifyInt)
// } if err != nil {
// app.Error(c, -1, err, fmt.Sprintf("查询工单数据失败,%v", err.Error()))
// Response(c, nil, result, "") return
//} }
//
//// 处理工单 app.OK(c, result, "")
//func ProcessWorkOrder(c *gin.Context) { }
// var (
// err error // 处理工单
// userAuthority bool func ProcessWorkOrder(c *gin.Context) {
// handle service.Handle var (
// params struct { err error
// Tasks []string userAuthority bool
// TargetState string `json:"target_state"` // 目标状态 handle service.Handle
// SourceState string `json:"source_state"` // 源状态 params struct {
// WorkOrderId int `json:"work_order_id"` // 工单ID Tasks []string
// Circulation string `json:"circulation"` // 流转ID TargetState string `json:"target_state"` // 目标状态
// FlowProperties int `json:"flow_properties"` // 流转类型 0 拒绝1 同意2 其他 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 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 {
// Response(c, code.InternalServerError, nil, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error())) // 处理工单
// return userAuthority, err = service.JudgeUserAuthority(c, params.WorkOrderId, params.SourceState)
// } if err != nil {
// if !userAuthority { app.Error(c, -1, err, fmt.Sprintf("判断用户是否有权限失败,%v", err.Error()))
// err = errors.New("当前用户没有权限进行此操作") return
// return }
// } if !userAuthority {
// app.Error(c, -1, errors.New("当前用户没有权限进行此操作"), "")
// err = handle.HandleWorkOrder( return
// c, }
// params.WorkOrderId, // 工单ID
// params.Tasks, // 任务列表 err = handle.HandleWorkOrder(
// params.TargetState, // 目标节点 c,
// params.SourceState, // 源节点 params.WorkOrderId, // 工单ID
// params.Circulation, // 流转标题 params.Tasks, // 任务列表
// params.FlowProperties, // 流转属性 params.TargetState, // 目标节点
// ) params.SourceState, // 源节点
// if err != nil { params.Circulation, // 流转标题
// Response(c, code.InternalServerError, nil, fmt.Sprintf("处理工单失败,%v", err.Error())) params.FlowProperties, // 流转属性
// return )
// } if err != nil {
// app.Error(c, -1, nil, fmt.Sprintf("处理工单失败,%v", err.Error()))
// Response(c, nil, nil, "") return
//} }
//
//// 结束工单 app.OK(c, nil, "工单处理完成")
//func UnityWorkOrder(c *gin.Context) { }
// var (
// err error // 结束工单
// workOrderId string func UnityWorkOrder(c *gin.Context) {
// workOrderInfo workOrder.Info var (
// ) err error
// workOrderId string
// workOrderId = c.DefaultQuery("work_oroder_id", "") workOrderInfo process.WorkOrderInfo
// if workOrderId == "" { )
// Response(c, code.InternalServerError, nil, "参数不正确work_oroder_id")
// return workOrderId = c.DefaultQuery("work_oroder_id", "")
// } if workOrderId == "" {
// app.Error(c, -1, errors.New("参数不正确work_oroder_id"), "")
// tx := connection.DB.Self.Begin() return
// }
// // 查询工单信息
// err = connection.DB.Self.Model(&workOrderInfo). tx := orm.Eloquent.Begin()
// Where("id = ?", workOrderId).
// Find(&workOrderInfo).Error // 查询工单信息
// if err != nil { err = tx.Model(&workOrderInfo).
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单失败,%v", err.Error())) Where("id = ?", workOrderId).
// return Find(&workOrderInfo).Error
// } if err != nil {
// if workOrderInfo.IsEnd == 1 { app.Error(c, -1, err, fmt.Sprintf("查询工单失败,%v", err.Error()))
// Response(c, code.UpdateError, nil, "工单已结束") return
// return }
// } if workOrderInfo.IsEnd == 1 {
// app.Error(c, -1, errors.New("工单已结束"), "")
// // 更新工单状态 return
// err = tx.Model(&workOrder.Info{}). }
// Where("id = ?", workOrderId).
// Update("is_end", 1). // 更新工单状态
// Error err = tx.Model(&process.WorkOrderInfo{}).
// if err != nil { Where("id = ?", workOrderId).
// tx.Rollback() Update("is_end", 1).
// Response(c, code.UpdateError, nil, fmt.Sprintf("结束工单失败,%v", err.Error())) Error
// return if err != nil {
// } tx.Rollback()
// app.Error(c, -1, err, fmt.Sprintf("结束工单失败,%v", err.Error()))
// // 写入历史 return
// tx.Create(&workOrder.CirculationHistory{ }
// Title: workOrderInfo.Title,
// WorkOrder: workOrderInfo.Id, // 写入历史
// State: "结束工单", tx.Create(&process.CirculationHistory{
// Circulation: "结束", Title: workOrderInfo.Title,
// Processor: c.GetString("nickname"), WorkOrder: workOrderInfo.Id,
// ProcessorId: c.GetInt("userId"), State: "结束工单",
// Remarks: "手动结束工单。", Circulation: "结束",
// }) Processor: c.GetString("nickname"),
// ProcessorId: tools.GetUserId(c),
// tx.Commit() Remarks: "手动结束工单。",
// })
// Response(c, nil, nil, "")
//} tx.Commit()
//
//// 转交工单 app.OK(c, nil, "工单已结束")
//func InversionWorkOrder(c *gin.Context) { }
// var (
// err error // 转交工单
// workOrderInfo workOrder.Info func InversionWorkOrder(c *gin.Context) {
// stateList []map[string]interface{} var (
// stateValue []byte err error
// currentState map[string]interface{} workOrderInfo process.WorkOrderInfo
// userInfo user.Info stateList []map[string]interface{}
// params struct { stateValue []byte
// WorkOrderId int `json:"work_order_id"` currentState map[string]interface{}
// NodeId string `json:"node_id"` userInfo system.SysUser
// UserId int `json:"user_id"` params struct {
// Remarks string `json:"remarks"` 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 = c.ShouldBind(&params)
// } if err != nil {
// app.Error(c, -1, err, "")
// // 查询工单信息 return
// err = connection.DB.Self.Model(&workOrderInfo). }
// Where("id = ?", params.WorkOrderId).
// Find(&workOrderInfo).Error // 查询工单信息
// if err != nil { err = orm.Eloquent.Model(&workOrderInfo).
// Response(c, code.SelectError, nil, fmt.Sprintf("查询工单信息失败,%v", err.Error())) Where("id = ?", params.WorkOrderId).
// return 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 {
// Response(c, code.InternalServerError, nil, 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()))
// for _, s := range stateList { return
// if s["id"].(string) == params.NodeId { }
// s["processor"] = []interface{}{params.UserId}
// s["process_method"] = "person" for _, s := range stateList {
// currentState = s if s["id"].(string) == params.NodeId {
// break 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 stateValue, err = json.Marshal(stateList)
// } if err != nil {
// app.Error(c, -1, err, fmt.Sprintf("节点数据序列化失败,%v", err.Error()))
// tx := connection.DB.Self.Begin() return
// }
// // 更新数据
// err = tx.Model(&workOrder.Info{}). tx := orm.Eloquent.Begin()
// Where("id = ?", params.WorkOrderId).
// Update("state", stateValue).Error // 更新数据
// if err != nil { err = tx.Model(&process.WorkOrderInfo{}).
// Response(c, code.UpdateError, nil, fmt.Sprintf("更新节点信息失败,%v", err.Error())) Where("id = ?", params.WorkOrderId).
// return Update("state", stateValue).Error
// } if err != nil {
// app.Error(c, -1, err, fmt.Sprintf("更新节点信息失败,%v", err.Error()))
// // 查询用户信息 return
// err = connection.DB.Self.Model(&user.Info{}). }
// Where("id = ?", params.UserId).
// Find(&userInfo).Error // 查询用户信息
// if err != nil { err = tx.Model(&system.SysUser{}).
// Response(c, code.SelectError, nil, fmt.Sprintf("查询用户信息失败,%v", err.Error())) Where("user_id = ?", params.UserId).
// return Find(&userInfo).Error
// } if err != nil {
// app.Error(c, -1, err, fmt.Sprintf("查询用户信息失败,%v", err.Error()))
// // 添加转交历史 return
// tx.Create(&workOrder.CirculationHistory{ }
// Title: workOrderInfo.Title,
// WorkOrder: workOrderInfo.Id, // 添加转交历史
// State: currentState["label"].(string), tx.Create(&process.CirculationHistory{
// Circulation: "转交", Title: workOrderInfo.Title,
// Processor: c.GetString("nickname"), WorkOrder: workOrderInfo.Id,
// ProcessorId: c.GetInt("userId"), State: currentState["label"].(string),
// Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.Nickname), Circulation: "转交",
// }) Processor: c.GetString("nickname"),
// ProcessorId: tools.GetUserId(c),
// tx.Commit() Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.NickName),
// })
// Response(c, nil, nil, "")
//} tx.Commit()
app.OK(c, nil, "工单已手动结单")
}

View File

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

View File

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

View File

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

View File

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

View File

@ -3,10 +3,10 @@ package service
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"ferry/global/orm"
"ferry/models/base" "ferry/models/base"
"ferry/models/process" "ferry/models/process"
"ferry/models/workOrder" "ferry/tools"
"ferry/pkg/connection"
"fmt" "fmt"
"reflect" "reflect"
"time" "time"
@ -37,13 +37,13 @@ import (
*/ */
type Handle struct { type Handle struct {
cirHistoryList []workOrder.CirculationHistory cirHistoryList []process.CirculationHistory
workOrderId int workOrderId int
updateValue map[string]interface{} updateValue map[string]interface{}
stateValue map[string]interface{} stateValue map[string]interface{}
targetStateValue map[string]interface{} targetStateValue map[string]interface{}
workOrderData [][]byte workOrderData [][]byte
workOrderDetails workOrder.Info workOrderDetails process.WorkOrderInfo
endHistory bool endHistory bool
flowProperties int flowProperties int
circulationValue string circulationValue string
@ -86,7 +86,7 @@ func (h *Handle) Countersign(c *gin.Context) (err error) {
break break
} }
for _, processor := range currentState["processor"].([]interface{}) { for _, processor := range currentState["processor"].([]interface{}) {
if cirHistoryValue.ProcessorId != c.GetInt("userId") && if cirHistoryValue.ProcessorId != tools.GetUserId(c) &&
cirHistoryValue.Source == currentState["id"].(string) && cirHistoryValue.Source == currentState["id"].(string) &&
cirHistoryValue.ProcessorId == int(processor.(float64)) { cirHistoryValue.ProcessorId == int(processor.(float64)) {
cirHistoryCount += 1 cirHistoryCount += 1
@ -114,7 +114,7 @@ func (h *Handle) circulation() (err error) {
return return
} }
err = h.tx.Model(&workOrder.Info{}). err = h.tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", h.workOrderId). Where("id = ?", h.workOrderId).
Updates(map[string]interface{}{ Updates(map[string]interface{}{
"state": stateValue, "state": stateValue,
@ -321,8 +321,8 @@ func (h *Handle) HandleWorkOrder(
var ( var (
execTasks []string execTasks []string
relatedPersonList []int relatedPersonList []int
cirHistoryValue []workOrder.CirculationHistory cirHistoryValue []process.CirculationHistory
cirHistoryData workOrder.CirculationHistory cirHistoryData process.CirculationHistory
costDurationValue string costDurationValue string
sourceEdges []map[string]interface{} sourceEdges []map[string]interface{}
targetEdges []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 { if err != nil {
return 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 { if err != nil {
return 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). Where("work_order = ?", workOrderId).
Pluck("form_data", &h.workOrderData).Error Pluck("form_data", &h.workOrderData).Error
if err != nil { 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). Where("work_order = ?", workOrderId).
Order("id desc"). Order("id desc").
Find(&h.cirHistoryList).Error Find(&h.cirHistoryList).Error
@ -397,13 +397,13 @@ func (h *Handle) HandleWorkOrder(
} }
relatedPersonStatus := false relatedPersonStatus := false
for _, r := range relatedPersonList { for _, r := range relatedPersonList {
if r == c.GetInt("userId") { if r == tools.GetUserId(c) {
relatedPersonStatus = true relatedPersonStatus = true
break break
} }
} }
if !relatedPersonStatus { if !relatedPersonStatus {
relatedPersonList = append(relatedPersonList, c.GetInt("userId")) relatedPersonList = append(relatedPersonList, tools.GetUserId(c))
} }
relatedPersonValue, err = json.Marshal(relatedPersonList) 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{}{ stateValue := map[string]interface{}{
"label": h.targetStateValue["label"].(string), "label": h.targetStateValue["label"].(string),
@ -591,7 +591,7 @@ func (h *Handle) HandleWorkOrder(
h.tx.Rollback() h.tx.Rollback()
return return
} }
err = h.tx.Model(&workOrder.Info{}). err = h.tx.Model(&process.WorkOrderInfo{}).
Where("id = ?", h.workOrderId). Where("id = ?", h.workOrderId).
Update("is_end", 1).Error Update("is_end", 1).Error
if err != nil { 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). Where("work_order = ?", workOrderId).
Find(&cirHistoryValue). Find(&cirHistoryValue).
Order("create_time desc").Error Order("create_time desc").Error
@ -616,7 +616,7 @@ func (h *Handle) HandleWorkOrder(
} }
} }
cirHistoryData = workOrder.CirculationHistory{ cirHistoryData = process.CirculationHistory{
Model: base.Model{}, Model: base.Model{},
Title: h.workOrderDetails.Title, Title: h.workOrderDetails.Title,
WorkOrder: h.workOrderDetails.Id, WorkOrder: h.workOrderDetails.Id,
@ -625,7 +625,7 @@ func (h *Handle) HandleWorkOrder(
Target: h.targetStateValue["id"].(string), Target: h.targetStateValue["id"].(string),
Circulation: circulationValue, Circulation: circulationValue,
Processor: c.GetString("nickname"), Processor: c.GetString("nickname"),
ProcessorId: c.GetInt("userId"), ProcessorId: tools.GetUserId(c),
CostDuration: costDurationValue, CostDuration: costDurationValue,
} }
@ -637,14 +637,14 @@ func (h *Handle) HandleWorkOrder(
// 判断目标是否是结束节点 // 判断目标是否是结束节点
if h.targetStateValue["clazz"] == "end" && h.endHistory == true { if h.targetStateValue["clazz"] == "end" && h.endHistory == true {
err = h.tx.Create(&workOrder.CirculationHistory{ err = h.tx.Create(&process.CirculationHistory{
Model: base.Model{}, Model: base.Model{},
Title: h.workOrderDetails.Title, Title: h.workOrderDetails.Title,
WorkOrder: h.workOrderDetails.Id, WorkOrder: h.workOrderDetails.Id,
State: h.targetStateValue["label"].(string), State: h.targetStateValue["label"].(string),
Source: h.targetStateValue["id"].(string), Source: h.targetStateValue["id"].(string),
Processor: c.GetString("nickname"), Processor: c.GetString("nickname"),
ProcessorId: c.GetInt("userId"), ProcessorId: tools.GetUserId(c),
Circulation: "结束", Circulation: "结束",
}).Error }).Error
if err != nil { if err != nil {

View File

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

View File

@ -2,10 +2,9 @@ package service
import ( import (
"encoding/json" "encoding/json"
"ferry/global/orm"
"ferry/models/process" "ferry/models/process"
"ferry/models/user" "ferry/tools"
"ferry/models/workOrder"
"ferry/pkg/connection"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -22,10 +21,10 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
variable 变量 variable 变量
*/ */
var ( var (
workOrderInfo workOrder.Info workOrderInfo process.WorkOrderInfo
userInfo user.Info //userInfo system.SysUser
userDept user.Dept //userDept system.Dept
cirHistoryList []workOrder.CirculationHistory cirHistoryList []process.CirculationHistory
stateValue map[string]interface{} stateValue map[string]interface{}
processInfo process.Info processInfo process.Info
processState ProcessState processState ProcessState
@ -33,7 +32,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
currentStateValue map[string]interface{} currentStateValue map[string]interface{}
) )
// 获取工单信息 // 获取工单信息
err = connection.DB.Self.Model(&workOrderInfo). err = orm.Eloquent.Model(&workOrderInfo).
Where("id = ?", workOrderId). Where("id = ?", workOrderId).
Find(&workOrderInfo).Error Find(&workOrderInfo).Error
if err != nil { 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 { if err != nil {
return 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 currentStateValue["processor"] != nil && len(currentStateValue["processor"].([]interface{})) > 1 {
if isCounterSign, ok := stateValue["isCounterSign"]; ok { if isCounterSign, ok := stateValue["isCounterSign"]; ok {
if isCounterSign.(bool) { if isCounterSign.(bool) {
err = connection.DB.Self.Model(&workOrder.CirculationHistory{}). err = orm.Eloquent.Model(&process.CirculationHistory{}).
Where("work_order = ?", workOrderId). Where("work_order = ?", workOrderId).
Order("id desc"). Order("id desc").
Find(&cirHistoryList).Error Find(&cirHistoryList).Error
@ -82,7 +81,7 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
if cirHistoryValue.Source != stateValue["id"] { if cirHistoryValue.Source != stateValue["id"] {
break break
} }
if cirHistoryValue.Source == stateValue["id"] && cirHistoryValue.ProcessorId == c.GetInt("userId") { if cirHistoryValue.Source == stateValue["id"] && cirHistoryValue.ProcessorId == tools.GetUserId(c) {
return return
} }
} }
@ -93,54 +92,54 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s
switch currentStateValue["process_method"].(string) { switch currentStateValue["process_method"].(string) {
case "person": case "person":
for _, processorValue := range currentStateValue["processor"].([]interface{}) { for _, processorValue := range currentStateValue["processor"].([]interface{}) {
if int(processorValue.(float64)) == c.GetInt("userId") { if int(processorValue.(float64)) == tools.GetUserId(c) {
status = true status = true
} }
} }
case "persongroup": //case "persongroup":
var persongroupCount int // var persongroupCount int
err = connection.DB.Self.Model(&user.UserGroup{}). // err = orm.Eloquent.Model(&user.UserGroup{}).
Where("group in (?) and user = ?", currentStateValue["processor"].([]interface{}), c.GetInt("userId")). // Where("group in (?) and user = ?", currentStateValue["processor"].([]interface{}), tools.GetUserId(c)).
Count(&persongroupCount).Error // Count(&persongroupCount).Error
if err != nil { // if err != nil {
return // return
} // }
if persongroupCount > 0 { // if persongroupCount > 0 {
status = true // status = true
} // }
case "department": //case "department":
var departmentCount int // var departmentCount int
err = connection.DB.Self.Model(&user.Info{}). // err = orm.Eloquent.Model(&system.SysUser{}).
Where("dept in (?) and id = ?", currentStateValue["processor"].([]interface{}), c.GetInt("userId")). // Where("dept in (?) and id = ?", currentStateValue["processor"].([]interface{}), tools.GetUserId(c)).
Count(&departmentCount).Error // Count(&departmentCount).Error
if err != nil { // if err != nil {
return // return
} // }
if departmentCount > 0 { // if departmentCount > 0 {
status = true // status = true
} // }
case "variable": case "variable":
for _, p := range currentStateValue["processor"].([]interface{}) { for _, p := range currentStateValue["processor"].([]interface{}) {
switch int(p.(float64)) { switch int(p.(float64)) {
case 1: case 1:
if workOrderInfo.Creator == c.GetInt("userId") { if workOrderInfo.Creator == tools.GetUserId(c) {
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") {
status = true 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 ( import (
"encoding/json" "encoding/json"
"ferry/models/user" "ferry/global/orm"
"ferry/models/workOrder" "ferry/models/process"
"ferry/pkg/connection" "ferry/models/system"
"ferry/pkg/pagination" "ferry/pkg/pagination"
"ferry/tools"
"fmt" "fmt"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -18,21 +18,21 @@ import (
func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error) { func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error) {
type workOrderInfo struct { type workOrderInfo struct {
workOrder.Info process.WorkOrderInfo
Principals string `json:"principals"` Principals string `json:"principals"`
DataClassify int `json:"data_classify"` DataClassify int `json:"data_classify"`
} }
var ( var (
workOrderInfoList []workOrderInfo workOrderInfoList []workOrderInfo
principals string principals string
userInfo user.Info userInfo system.SysUser
StateList []map[string]interface{} StateList []map[string]interface{}
) )
title := c.DefaultQuery("title", "") 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 { if err != nil {
return return
} }
@ -42,47 +42,51 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
case 1: case 1:
// 待办工单 // 待办工单
// 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. 小组 // 2. 小组
groupList := make([]int, 0) //groupList := make([]int, 0)
err = connection.DB.Self.Model(&user.UserGroup{}). //err = orm.Eloquent.Model(&user.UserGroup{}).
Where("user = ?", c.GetInt("userId")). // Where("user = ?", tools.GetUserId(c)).
Pluck("`group`", &groupList).Error // Pluck("`group`", &groupList).Error
if err != nil { //if err != nil {
return // return
} //}
groupSqlList := make([]string, 0) //groupSqlList := make([]string, 0)
if len(groupList) > 0 { //if len(groupList) > 0 {
for _, group := range groupList { // for _, group := range groupList {
groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', %v))", group)) // groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', %v))", group))
} // }
} else { //} else {
groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 0))")) // groupSqlList = append(groupSqlList, fmt.Sprintf("JSON_CONTAINS(state, JSON_OBJECT('processor', 0))"))
} //}
//
personGroupSelect := fmt.Sprintf( //personGroupSelect := fmt.Sprintf(
"((%v) and %v)", // "((%v) and %v)",
strings.Join(groupSqlList, " or "), // strings.Join(groupSqlList, " or "),
"JSON_CONTAINS(state, JSON_OBJECT('process_method', 'persongroup'))", // "JSON_CONTAINS(state, JSON_OBJECT('process_method', 'persongroup'))",
) //)
// 3. 部门 // 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. 变量 // 4. 变量
variableSelect := fmt.Sprintf("((%v) or (%v))", 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", c.GetInt("userId")), 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),
) )
//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: case 2:
// 我创建的 // 我创建的
db = db.Where("creator = ?", c.GetInt("userId")) db = db.Where("creator = ?", tools.GetUserId(c))
case 3: 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: case 4:
// 所有工单 // 所有工单
default: default:

View File

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

View File

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

View File

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