forked from lanyulei/ferry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
3,276 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package process | ||
|
||
import ( | ||
"errors" | ||
"ferry/global/orm" | ||
process2 "ferry/models/process" | ||
"ferry/pkg/pagination" | ||
"ferry/tools" | ||
"ferry/tools/app" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
/* | ||
@Author : lanyulei | ||
*/ | ||
|
||
// 创建流程分类 | ||
func CreateClassify(c *gin.Context) { | ||
var ( | ||
err error | ||
classifyValue process2.Classify | ||
classifyCount int | ||
) | ||
|
||
err = c.ShouldBind(&classifyValue) | ||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
// 判断创建的分类是否存在 | ||
err = orm.Eloquent.Table("process_classify"). | ||
Where("name = ?", classifyValue.Name). | ||
Count(&classifyCount).Error | ||
if err != nil { | ||
tools.HasError(err, "创建的分类名称已经存在,请修改", -1) | ||
} | ||
if classifyCount > 0 { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
classifyValue.Creator = tools.GetUserId(c) | ||
|
||
err = orm.Eloquent.Table("process_classify").Create(&classifyValue).Error | ||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
app.OK(c, "", "创建流程分类成功") | ||
} | ||
|
||
// 流程分类列表 | ||
func ClassifyList(c *gin.Context) { | ||
type classifyValue struct { | ||
process2.Classify | ||
CreateUser string `json:"create_user"` | ||
CreateName string `json:"create_name"` | ||
} | ||
|
||
var ( | ||
err error | ||
classifyList []*classifyValue | ||
) | ||
|
||
SearchParams := map[string]map[string]interface{}{ | ||
"like": pagination.RequestParams(c), | ||
} | ||
|
||
db := orm.Eloquent.Model(&process2.Classify{}).Joins("left join sys_user on sys_user.user_id = process_classify.creator"). | ||
Select("process_classify.*, sys_user.username as create_user, sys_user.nick_name as create_name"). | ||
Where("process_classify.`delete_time` IS NULL") | ||
|
||
result, err := pagination.Paging(&pagination.Param{ | ||
C: c, | ||
DB: db, | ||
}, &classifyList, SearchParams, "process_classify") | ||
|
||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
app.OK(c, result, "获取分类列表成功") | ||
} | ||
|
||
// 更新流程分类 | ||
func UpdateClassify(c *gin.Context) { | ||
var ( | ||
err error | ||
classifyValue process2.Classify | ||
) | ||
|
||
err = c.ShouldBind(&classifyValue) | ||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
// 更新 | ||
err = orm.Eloquent.Model(&classifyValue). | ||
Where("id = ?", classifyValue.Id). | ||
Update("name", classifyValue.Name).Error | ||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
app.OK(c, classifyValue, "流程分类更新成功") | ||
} | ||
|
||
// 删除流程分类 | ||
func DeleteClassify(c *gin.Context) { | ||
classifyId := c.DefaultQuery("classifyId", "") | ||
if classifyId == "" { | ||
tools.HasError(errors.New("参数传递失败,请确认classifyId是否传递"), "", -1) | ||
} | ||
|
||
err := orm.Eloquent.Delete(process2.Classify{}, "id = ?", classifyId).Error | ||
if err != nil { | ||
tools.HasError(err, "", -1) | ||
} | ||
|
||
app.OK(c, "", "流程分类删除成功") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
package process | ||
|
||
//import ( | ||
// process2 "ferry/models/process" | ||
// "ferry/pkg/connection" | ||
// "ferry/pkg/pagination" | ||
// "ferry/pkg/response/code" | ||
// "fmt" | ||
// | ||
// "github.com/gin-gonic/gin" | ||
//) | ||
// | ||
///* | ||
// @Author : lanyulei | ||
//*/ | ||
// | ||
//// 流程列表 | ||
//func ProcessList(c *gin.Context) { | ||
// type processValue struct { | ||
// process2.Info | ||
// CreateUser string `json:"create_user"` | ||
// CreateName string `json:"create_name"` | ||
// ClassifyName string `json:"classify_name"` | ||
// } | ||
// | ||
// var ( | ||
// err error | ||
// processList []*processValue | ||
// ) | ||
// | ||
// SearchParams := map[string]map[string]interface{}{ | ||
// "like": pagination.RequestParams(c), | ||
// } | ||
// | ||
// db := connection.DB.Self. | ||
// Model(&process2.Info{}). | ||
// Joins("left join user_info on user_info.id = process_info.creator"). | ||
// Joins("left join process_classify on process_classify.id = process_info.classify"). | ||
// Select("process_info.id, process_info.create_time, process_info.update_time, process_info.name, process_info.creator, process_classify.name as classify_name, user_info.username as create_user, user_info.nickname as create_name"). | ||
// Where("process_info.`delete_time` IS NULL") | ||
// | ||
// result, err := pagination.Paging(&pagination.Param{ | ||
// C: c, | ||
// DB: db, | ||
// }, &processList, SearchParams, "process_info") | ||
// | ||
// if err != nil { | ||
// Response(c, code.SelectError, nil, fmt.Sprintf("查询流程列表失败,%v", err.Error())) | ||
// return | ||
// } | ||
// Response(c, nil, result, "") | ||
//} | ||
// | ||
//// 创建流程 | ||
//func CreateProcess(c *gin.Context) { | ||
// var ( | ||
// err error | ||
// processValue process2.Info | ||
// processCount int | ||
// ) | ||
// | ||
// err = c.ShouldBind(&processValue) | ||
// if err != nil { | ||
// Response(c, code.BindError, nil, err.Error()) | ||
// return | ||
// } | ||
// | ||
// // 确定修改的分类是否存在 | ||
// err = connection.DB.Self.Model(&processValue). | ||
// Where("name = ?", processValue.Name). | ||
// Count(&processCount).Error | ||
// if err != nil { | ||
// Response(c, code.SelectError, nil, fmt.Sprintf("查询流程数量失败,%v", err.Error())) | ||
// return | ||
// } | ||
// if processCount > 0 { | ||
// Response(c, code.InternalServerError, nil, "流程名称出现重复,请换一个名称") | ||
// return | ||
// } | ||
// | ||
// processValue.Creator = c.GetInt("userId") | ||
// | ||
// err = connection.DB.Self.Create(&processValue).Error | ||
// if err != nil { | ||
// Response(c, code.CreateError, nil, fmt.Sprintf("创建流程失败,%v", err.Error())) | ||
// return | ||
// } | ||
// | ||
// Response(c, nil, nil, "") | ||
//} | ||
// | ||
//// 更新流程 | ||
//func UpdateProcess(c *gin.Context) { | ||
// var ( | ||
// err error | ||
// processValue process2.Info | ||
// ) | ||
// | ||
// err = c.ShouldBind(&processValue) | ||
// if err != nil { | ||
// Response(c, code.BindError, nil, err.Error()) | ||
// return | ||
// } | ||
// | ||
// err = connection.DB.Self.Model(&process2.Info{}). | ||
// Where("id = ?", processValue.Id). | ||
// Updates(map[string]interface{}{ | ||
// "name": processValue.Name, | ||
// "structure": processValue.Structure, | ||
// "tpls": processValue.Tpls, | ||
// "classify": processValue.Classify, | ||
// "task": processValue.Task, | ||
// }).Error | ||
// if err != nil { | ||
// Response(c, code.UpdateError, nil, fmt.Sprintf("更新流程信息失败,%v", err.Error())) | ||
// return | ||
// } | ||
// | ||
// Response(c, nil, nil, "") | ||
//} | ||
// | ||
//// 删除流程 | ||
//func DeleteProcess(c *gin.Context) { | ||
// processId := c.DefaultQuery("processId", "") | ||
// if processId == "" { | ||
// Response(c, code.InternalServerError, nil, "参数不正确,请确定参数processId是否传递") | ||
// return | ||
// } | ||
// | ||
// err := connection.DB.Self.Delete(process2.Info{}, "id = ?", processId).Error | ||
// if err != nil { | ||
// Response(c, code.DeleteError, nil, fmt.Sprintf("删除流程失败, %v", err.Error())) | ||
// return | ||
// } | ||
// Response(c, nil, nil, "") | ||
//} | ||
// | ||
//// 流程详情 | ||
//func ProcessDetails(c *gin.Context) { | ||
// processId := c.DefaultQuery("processId", "") | ||
// if processId == "" { | ||
// Response(c, code.InternalServerError, nil, "参数不正确,请确定参数processId是否传递") | ||
// return | ||
// } | ||
// | ||
// var processValue process2.Info | ||
// err := connection.DB.Self.Model(&processValue). | ||
// Where("id = ?", processId). | ||
// Find(&processValue).Error | ||
// if err != nil { | ||
// Response(c, code.SelectError, nil, fmt.Sprintf("查询流程详情失败, %v", err.Error())) | ||
// return | ||
// } | ||
// | ||
// Response(c, nil, processValue, "") | ||
//} | ||
// | ||
//// 分类流程列表 | ||
//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, "") | ||
//} |
Oops, something went wrong.