模版管理。

This commit is contained in:
YuleiLan 2020-07-15 17:58:15 +08:00
parent 6f15042888
commit 704c865924
13 changed files with 182 additions and 179 deletions

View File

@ -29,7 +29,7 @@ func CreateClassify(c *gin.Context) {
}
// 判断创建的分类是否存在
err = orm.Eloquent.Table("process_classify").
err = orm.Eloquent.Table("p_process_classify").
Where("name = ?", classifyValue.Name).
Count(&classifyCount).Error
if err != nil {
@ -41,7 +41,7 @@ func CreateClassify(c *gin.Context) {
classifyValue.Creator = tools.GetUserId(c)
err = orm.Eloquent.Table("process_classify").Create(&classifyValue).Error
err = orm.Eloquent.Table("p_process_classify").Create(&classifyValue).Error
if err != nil {
tools.HasError(err, "", -1)
}
@ -66,14 +66,14 @@ func ClassifyList(c *gin.Context) {
"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")
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")
result, err := pagination.Paging(&pagination.Param{
C: c,
DB: db,
}, &classifyList, SearchParams, "process_classify")
}, &classifyList, SearchParams, "p_process_classify")
if err != nil {
tools.HasError(err, "", -1)

View File

@ -34,15 +34,15 @@ package process
//
// 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")
// Joins("left join user_info on user_info.id = p_process_info.creator").
// Joins("left join p_process_classify on p_process_classify.id = p_process_info.classify").
// Select("p_process_info.id, p_process_info.create_time, p_process_info.update_time, p_process_info.name, p_process_info.creator, p_process_classify.name as classify_name, user_info.username as create_user, user_info.nickname as create_name").
// Where("p_process_info.`delete_time` IS NULL")
//
// result, err := pagination.Paging(&pagination.Param{
// C: c,
// DB: db,
// }, &processList, SearchParams, "process_info")
// }, &processList, SearchParams, "p_process_info")
//
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询流程列表失败,%v", err.Error()))

View File

@ -1,154 +1,147 @@
package process
//import (
// "ferry/models/tpl"
// "ferry/pkg/connection"
// "ferry/pkg/pagination"
// "ferry/pkg/response/code"
// . "ferry/pkg/response/response"
// "fmt"
//
// "github.com/gin-gonic/gin"
//)
//
///*
// @Author : lanyulei
//*/
//
//// 模板列表
//func TemplateList(c *gin.Context) {
// type templateUserValue struct {
// tpl.Info
// CreateUser string `json:"create_user"`
// CreateName string `json:"create_name"`
// }
//
// var (
// err error
// templateList []*templateUserValue
// )
//
// SearchParams := map[string]map[string]interface{}{
// "like": pagination.RequestParams(c),
// }
//
// db := connection.DB.Self.Model(&tpl.Info{}).Joins("left join user_info on user_info.id = tpl_info.creator").
// Select("tpl_info.id, tpl_info.create_time, tpl_info.update_time, tpl_info.`name`, tpl_info.`creator`, user_info.username as create_user, user_info.nickname as create_name").Where("tpl_info.`delete_time` IS NULL")
//
// result, err := pagination.Paging(&pagination.Param{
// C: c,
// DB: db,
// }, &templateList, SearchParams, "tpl_info")
//
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询模版失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, result, "")
//}
//
//// 创建模版
//func CreateTemplate(c *gin.Context) {
// var (
// err error
// templateValue tpl.Info
// templateCount int
// )
//
// err = c.ShouldBind(&templateValue)
// if err != nil {
// Response(c, code.BindError, nil, err.Error())
// return
// }
//
// // 确定修改的分类是否存在
// err = connection.DB.Self.Model(&templateValue).
// Where("name = ?", templateValue.Name).
// Count(&templateCount).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询模版数量失败,%v", err.Error()))
// return
// }
// if templateCount > 0 {
// Response(c, code.InternalServerError, nil, "模版名称出现重复,请换一个名称")
// return
// }
//
// templateValue.Creator = c.GetInt("userId") // 当前登陆用户ID
// err = connection.DB.Self.Create(&templateValue).Error
// if err != nil {
// Response(c, code.CreateError, nil, fmt.Sprintf("创建模板失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
//
//// 模版详情
//func TemplateDetails(c *gin.Context) {
// var (
// err error
// templateDetailsValue tpl.Info
// )
//
// templateId := c.DefaultQuery("template_id", "")
// if templateId == "" {
// Response(c, code.ParamError, nil, fmt.Sprintf("参数不正确请确认template_id是否传递"))
// return
// }
//
// err = connection.DB.Self.Model(&templateDetailsValue).Where("id = ?", templateId).Find(&templateDetailsValue).Error
// if err != nil {
// Response(c, code.SelectError, nil, fmt.Sprintf("查询模版数据失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, templateDetailsValue, "")
//}
//
//// 更新模版
//func UpdateTemplate(c *gin.Context) {
// var (
// err error
// templateValue tpl.Info
// )
// err = c.ShouldBind(&templateValue)
// if err != nil {
// Response(c, code.BindError, nil, fmt.Sprintf("参数绑定失败,%v", err.Error()))
// return
// }
//
// err = connection.DB.Self.Model(&templateValue).Where("id = ?", templateValue.Id).Updates(map[string]interface{}{
// "name": templateValue.Name,
// "remarks": templateValue.Remarks,
// "form_structure": templateValue.FormStructure,
// }).Error
// if err != nil {
// Response(c, code.UpdateError, nil, fmt.Sprintf("更新模版失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, templateValue, "")
//}
//
//// 删除模版
//func DeleteTemplate(c *gin.Context) {
// var (
// err error
// )
//
// templateId := c.DefaultQuery("template_id", "")
// if templateId == "" {
// Response(c, code.ParamError, nil, fmt.Sprintf("参数不正确请确认template_id是否传递"))
// return
// }
//
// err = connection.DB.Self.Delete(tpl.Info{}, "id = ?", templateId).Error
// if err != nil {
// Response(c, code.DeleteError, nil, fmt.Sprintf("模版删除失败,%v", err.Error()))
// return
// }
//
// Response(c, nil, nil, "")
//}
import (
"errors"
"ferry/global/orm"
"ferry/models/process"
"ferry/pkg/pagination"
"ferry/tools"
"ferry/tools/app"
"github.com/gin-gonic/gin"
)
/*
@Author : lanyulei
*/
// 模板列表
func TemplateList(c *gin.Context) {
type templateUserValue struct {
process.TplInfo
CreateUser string `json:"create_user"`
CreateName string `json:"create_name"`
}
var (
err error
templateList []*templateUserValue
)
SearchParams := map[string]map[string]interface{}{
"like": pagination.RequestParams(c),
}
db := orm.Eloquent.Model(&process.TplInfo{}).Joins("left join sys_user on sys_user.user_id = p_tpl_info.creator").
Select("p_tpl_info.id, p_tpl_info.create_time, p_tpl_info.update_time, p_tpl_info.`name`, p_tpl_info.`creator`, sys_user.username as create_user, sys_user.nick_name as create_name")
result, err := pagination.Paging(&pagination.Param{
C: c,
DB: db,
}, &templateList, SearchParams, "p_tpl_info")
if err != nil {
tools.HasError(err, "")
}
app.OK(c, result, "获取模版列表成功")
}
// 创建模版
func CreateTemplate(c *gin.Context) {
var (
err error
templateValue process.TplInfo
templateCount int
)
err = c.ShouldBind(&templateValue)
if err != nil {
tools.HasError(err, "")
}
// 确认模版名称是否存在
err = orm.Eloquent.Model(&templateValue).
Where("name = ?", templateValue.Name).
Count(&templateCount).Error
if err != nil {
tools.HasError(err, "")
}
if templateCount > 0 {
tools.HasError(errors.New("模版名称已存在"), "")
}
templateValue.Creator = tools.GetUserId(c) // 当前登陆用户ID
err = orm.Eloquent.Create(&templateValue).Error
if err != nil {
tools.HasError(err, "")
}
app.OK(c, "", "创建模版成功")
}
// 模版详情
func TemplateDetails(c *gin.Context) {
var (
err error
templateDetailsValue process.TplInfo
)
templateId := c.DefaultQuery("template_id", "")
if templateId == "" {
tools.HasError(err, "")
}
err = orm.Eloquent.Model(&templateDetailsValue).
Where("id = ?", templateId).
Find(&templateDetailsValue).Error
if err != nil {
tools.HasError(err, "")
}
app.OK(c, templateDetailsValue, "")
}
// 更新模版
func UpdateTemplate(c *gin.Context) {
var (
err error
templateValue process.TplInfo
)
err = c.ShouldBind(&templateValue)
if err != nil {
tools.HasError(err, "")
}
err = orm.Eloquent.Model(&templateValue).
Where("id = ?", templateValue.Id).
Updates(map[string]interface{}{
"name": templateValue.Name,
"remarks": templateValue.Remarks,
"form_structure": templateValue.FormStructure,
}).Error
if err != nil {
tools.HasError(err, "")
}
app.OK(c, templateValue, "")
}
// 删除模版
func DeleteTemplate(c *gin.Context) {
var (
err error
)
templateId := c.DefaultQuery("templateId", "")
if templateId == "" {
tools.HasError(errors.New("参数不正确请确认templateId是否传递"), "")
}
err = orm.Eloquent.Delete(process.TplInfo{}, "id = ?", templateId).Error
if err != nil {
tools.HasError(err, "")
}
app.OK(c, "", "删除模版成功")
}

View File

@ -23,5 +23,12 @@ func AutoMigrate(db *gorm.DB) error {
// 流程中心
new(process.Classify),
new(process.TplInfo),
new(process.TplData),
new(process.WorkOrderInfo),
new(process.TaskInfo),
new(process.Info),
new(process.History),
new(process.CirculationHistory),
).Error
}

View File

@ -24,5 +24,5 @@ type CirculationHistory struct {
}
func (CirculationHistory) TableName() string {
return "work_order_circulation_history"
return "p_work_order_circulation_history"
}

View File

@ -16,5 +16,5 @@ type Classify struct {
}
func (Classify) TableName() string {
return "process_classify"
return "p_process_classify"
}

View File

@ -19,5 +19,5 @@ type History struct {
}
func (History) TableName() string {
return "task_history"
return "p_task_history"
}

View File

@ -21,5 +21,5 @@ type Info struct {
}
func (Info) TableName() string {
return "process_info"
return "p_process_info"
}

View File

@ -19,5 +19,5 @@ type TaskInfo struct {
}
func (TaskInfo) TableName() string {
return "task_info"
return "p_task_info"
}

View File

@ -19,5 +19,5 @@ type TplInfo struct {
}
func (TplInfo) TableName() string {
return "tpl_info"
return "p_tpl_info"
}

View File

@ -18,5 +18,5 @@ type TplData struct {
}
func (TplData) TableName() string {
return "work_order_tpl_data"
return "p_work_order_tpl_data"
}

View File

@ -22,5 +22,5 @@ type WorkOrderInfo struct {
}
func (WorkOrderInfo) TableName() string {
return "work_order_info"
return "p_work_order_info"
}

View File

@ -5,6 +5,9 @@
package process
import (
"ferry/apis/process"
"ferry/middleware"
//"ferry/apis/process"
//"ferry/middleware"
jwt "ferry/pkg/jwtauth"
@ -13,12 +16,12 @@ import (
)
func RegisterTplRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
//tplRouter := v1.Group("/tpl").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
//{
// tplRouter.GET("", process.TemplateList)
// tplRouter.POST("", process.CreateTemplate)
// tplRouter.PUT("", process.UpdateTemplate)
// tplRouter.DELETE("", process.DeleteTemplate)
// tplRouter.GET("/details", process.TemplateDetails)
//}
tplRouter := v1.Group("/tpl").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
{
tplRouter.GET("", process.TemplateList)
tplRouter.POST("", process.CreateTemplate)
tplRouter.PUT("", process.UpdateTemplate)
tplRouter.DELETE("", process.DeleteTemplate)
tplRouter.GET("/details", process.TemplateDetails)
}
}