2020-07-15 01:40:56 +08:00
|
|
|
|
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 {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断创建的分类是否存在
|
2020-07-15 17:58:15 +08:00
|
|
|
|
err = orm.Eloquent.Table("p_process_classify").
|
2020-07-15 01:40:56 +08:00
|
|
|
|
Where("name = ?", classifyValue.Name).
|
2020-07-19 10:47:20 +08:00
|
|
|
|
Where("`delete_time` IS NULL").
|
2020-07-15 01:40:56 +08:00
|
|
|
|
Count(&classifyCount).Error
|
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
if classifyCount > 0 {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, errors.New("创建的分类名称已经存在"), "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
classifyValue.Creator = tools.GetUserId(c)
|
|
|
|
|
|
2020-07-15 17:58:15 +08:00
|
|
|
|
err = orm.Eloquent.Table("p_process_classify").Create(&classifyValue).Error
|
2020-07-15 01:40:56 +08:00
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 17:58:15 +08:00
|
|
|
|
db := orm.Eloquent.Model(&process2.Classify{}).Joins("left join sys_user on sys_user.user_id = p_process_classify.creator").
|
|
|
|
|
Select("p_process_classify.*, sys_user.username as create_user, sys_user.nick_name as create_name").
|
|
|
|
|
Where("p_process_classify.`delete_time` IS NULL")
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
result, err := pagination.Paging(&pagination.Param{
|
|
|
|
|
C: c,
|
|
|
|
|
DB: db,
|
2020-07-15 17:58:15 +08:00
|
|
|
|
}, &classifyList, SearchParams, "p_process_classify")
|
2020-07-15 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
app.OK(c, result, "获取分类列表成功")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新流程分类
|
|
|
|
|
func UpdateClassify(c *gin.Context) {
|
|
|
|
|
var (
|
|
|
|
|
err error
|
|
|
|
|
classifyValue process2.Classify
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
err = c.ShouldBind(&classifyValue)
|
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
|
err = orm.Eloquent.Model(&classifyValue).
|
|
|
|
|
Where("id = ?", classifyValue.Id).
|
|
|
|
|
Update("name", classifyValue.Name).Error
|
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.OK(c, classifyValue, "流程分类更新成功")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除流程分类
|
|
|
|
|
func DeleteClassify(c *gin.Context) {
|
|
|
|
|
classifyId := c.DefaultQuery("classifyId", "")
|
|
|
|
|
if classifyId == "" {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, errors.New("参数传递失败,请确认classifyId是否传递"), "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := orm.Eloquent.Delete(process2.Classify{}, "id = ?", classifyId).Error
|
|
|
|
|
if err != nil {
|
2020-07-16 01:22:01 +08:00
|
|
|
|
app.Error(c, -1, err, "")
|
|
|
|
|
return
|
2020-07-15 01:40:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.OK(c, "", "流程分类删除成功")
|
|
|
|
|
}
|