自动化接口填充以及初始化数据制作
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/global/response"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
resp "gin-vue-admin/model/response"
|
||||
"gin-vue-admin/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 创建WorkflowProcess
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.WorkflowProcess true "创建WorkflowProcess"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /workflowProcess/createWorkflowProcess [post]
|
||||
func CreateWorkflowProcess(c *gin.Context) {
|
||||
var workflowProcess model.WorkflowProcess
|
||||
_ = c.ShouldBindJSON(&workflowProcess)
|
||||
err := service.CreateWorkflowProcess(workflowProcess)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 删除WorkflowProcess
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.WorkflowProcess true "删除WorkflowProcess"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /workflowProcess/deleteWorkflowProcess [delete]
|
||||
func DeleteWorkflowProcess(c *gin.Context) {
|
||||
var workflowProcess model.WorkflowProcess
|
||||
_ = c.ShouldBindJSON(&workflowProcess)
|
||||
err := service.DeleteWorkflowProcess(workflowProcess)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 批量删除WorkflowProcess
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除WorkflowProcess"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /workflowProcess/deleteWorkflowProcessByIds [delete]
|
||||
func DeleteWorkflowProcessByIds(c *gin.Context) {
|
||||
var IDS request.IdsReq
|
||||
_ = c.ShouldBindJSON(&IDS)
|
||||
err := service.DeleteWorkflowProcessByIds(IDS)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 更新WorkflowProcess
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.WorkflowProcess true "更新WorkflowProcess"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /workflowProcess/updateWorkflowProcess [put]
|
||||
func UpdateWorkflowProcess(c *gin.Context) {
|
||||
var workflowProcess model.WorkflowProcess
|
||||
_ = c.ShouldBindJSON(&workflowProcess)
|
||||
err := service.UpdateWorkflowProcess(&workflowProcess)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 用id查询WorkflowProcess
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body model.WorkflowProcess true "用id查询WorkflowProcess"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /workflowProcess/findWorkflowProcess [get]
|
||||
func FindWorkflowProcess(c *gin.Context) {
|
||||
var workflowProcess model.WorkflowProcess
|
||||
_ = c.ShouldBindQuery(&workflowProcess)
|
||||
err, reworkflowProcess := service.GetWorkflowProcess(workflowProcess.ID)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithData(gin.H{"reworkflowProcess": reworkflowProcess}, c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 分页获取WorkflowProcess列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.WorkflowProcessSearch true "分页获取WorkflowProcess列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /workflowProcess/getWorkflowProcessList [get]
|
||||
func GetWorkflowProcessList(c *gin.Context) {
|
||||
var pageInfo request.WorkflowProcessSearch
|
||||
_ = c.ShouldBindQuery(&pageInfo)
|
||||
err, list, total := service.GetWorkflowProcessInfoList(pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
} else {
|
||||
response.OkWithData(resp.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Page,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,12 @@ var Apis = []model.SysApi{
|
||||
{gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"},
|
||||
{gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"},
|
||||
{gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"},
|
||||
{gorm.Model{ID: 68, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/createWorkflowProcess", "新建工作流", "workflowProcess", "POST"},
|
||||
{gorm.Model{ID: 69, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/deleteWorkflowProcess", "删除工作流", "workflowProcess", "DELETE"},
|
||||
{gorm.Model{ID: 70, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/deleteWorkflowProcessByIds", "批量删除工作流", "workflowProcess", "DELETE"},
|
||||
{gorm.Model{ID: 71, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/updateWorkflowProcess", "更新工作流", "workflowProcess", "PUT"},
|
||||
{gorm.Model{ID: 72, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/findWorkflowProcess", "根据ID获取工作流", "workflowProcess", "GET"},
|
||||
{gorm.Model{ID: 73, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getWorkflowProcessList", "获取工作流", "workflowProcess", "GET"},
|
||||
}
|
||||
|
||||
func InitSysApi(db *gorm.DB) (err error) {
|
||||
|
||||
@@ -39,6 +39,7 @@ var AuthorityMenus = []SysAuthorityMenus{
|
||||
{"888", 27},
|
||||
{"888", 28},
|
||||
{"888", 29},
|
||||
{"888", 30},
|
||||
{"8881", 1},
|
||||
{"8881", 2},
|
||||
{"8881", 8},
|
||||
|
||||
@@ -73,6 +73,12 @@ var Carbines = []gormadapter.CasbinRule{
|
||||
{PType: "p", V0: "888", V1: "/simpleUploader/upload", V2: "POST"},
|
||||
{PType: "p", V0: "888", V1: "/simpleUploader/checkFileMd5", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/simpleUploader/mergeFileMd5", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/createWorkflowProcess", V2: "POST"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/deleteWorkflowProcess", V2: "DELETE"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/deleteWorkflowProcessByIds", V2: "DELETE"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/updateWorkflowProcess", V2: "PUT"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/findWorkflowProcess", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowProcessList", V2: "GET"},
|
||||
{PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
|
||||
{PType: "p", V0: "8881", V1: "/user/register", V2: "POST"},
|
||||
{PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},
|
||||
|
||||
@@ -37,6 +37,7 @@ var BaseMenus = []model.SysBaseMenu{
|
||||
{Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}},
|
||||
{Model: gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "workflow", Name: "workflow", Hidden: false, Component: "view/workflow/index.vue", Sort: 5, Meta: model.Meta{Title: "工作流功能", Icon: "phone"}},
|
||||
{Model: gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "28", Path: "workflowCreate", Name: "workflowCreate", Hidden: false, Component: "view/workflow/workflowCreate/workflowCreate.vue", Sort: 0, Meta: model.Meta{Title: "工作流绘制", Icon: "circle-plus"}},
|
||||
{Model: gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "28", Path: "workflowProcess", Name: "workflowProcess", Hidden: false, Component: "view/workflow/workflowProcess/workflowProcess.vue", Sort: 0, Meta: model.Meta{Title: "工作流列表", Icon: "s-cooperation"}},
|
||||
}
|
||||
|
||||
func InitSysBaseMenus(db *gorm.DB) (err error) {
|
||||
|
||||
@@ -41,6 +41,7 @@ func Routers() *gin.Engine {
|
||||
router.InitSysDictionaryRouter(ApiGroup) // 字典管理
|
||||
router.InitSysOperationRecordRouter(ApiGroup) // 操作记录
|
||||
router.InitEmailRouter(ApiGroup) // 邮件相关路由
|
||||
router.InitWorkflowProcessRouter(ApiGroup) // 工作流创建相关接口
|
||||
|
||||
global.GVA_LOG.Info("router register success")
|
||||
return Router
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package request
|
||||
|
||||
import "gin-vue-admin/model"
|
||||
|
||||
type WorkflowProcessSearch struct {
|
||||
model.WorkflowProcess
|
||||
PageInfo
|
||||
}
|
||||
+10
-10
@@ -1,15 +1,15 @@
|
||||
package model
|
||||
|
||||
type WorkflowProcess struct {
|
||||
ID string `json:"id" gorm:"comment:流程标识;primaryKey"`
|
||||
Name string `json:"name" gorm:"comment:流程名称"`
|
||||
Category string `json:"category" gorm:"comment:分类"`
|
||||
Clazz string `json:"clazz" gorm:"comment:类型"`
|
||||
Label string `json:"label" gorm:"comment:流程标题"`
|
||||
HideIcon bool `json:"hideIcon" gorm:"comment:是否隐藏图标"`
|
||||
Description bool `json:"description" gorm:"comment:详细介绍"`
|
||||
Nodes []WorkflowNode `json:"nodes"` // 流程节点数据
|
||||
Edges []WorkflowEdge `json:"edges"` // 流程链接数据
|
||||
ID string `json:"id" gorm:"comment:流程标识;primaryKey"`
|
||||
Name string `json:"name" gorm:"comment:流程名称"`
|
||||
Category string `json:"category" gorm:"comment:分类"`
|
||||
Clazz string `json:"clazz" gorm:"comment:类型"`
|
||||
Label string `json:"label" gorm:"comment:流程标题"`
|
||||
HideIcon bool `json:"hideIcon" gorm:"comment:是否隐藏图标"`
|
||||
Description string `json:"description" gorm:"comment:详细介绍"`
|
||||
Nodes []WorkflowNode `json:"nodes"` // 流程节点数据
|
||||
Edges []WorkflowEdge `json:"edges"` // 流程链接数据
|
||||
}
|
||||
|
||||
type WorkflowNode struct {
|
||||
@@ -19,7 +19,7 @@ type WorkflowNode struct {
|
||||
Label string `json:"label" gorm:"comment:节点名称"`
|
||||
Type string `json:"type" gorm:"comment:图标类型"`
|
||||
Shape string `json:"shape" gorm:"comment:形状"`
|
||||
Description bool `json:"description" gorm:"comment:详细介绍"`
|
||||
Description bool `json:"description" gorm:"comment:详细介绍"`
|
||||
X float64 `json:"y" gorm:"comment:x位置"`
|
||||
Y float64 `json:"x" gorm:"comment:y位置"`
|
||||
WaitState string `json:"waitState" gorm:"comment:等待属性"`
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"gin-vue-admin/api/v1"
|
||||
"gin-vue-admin/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitWorkflowProcessRouter(Router *gin.RouterGroup) {
|
||||
WorkflowProcessRouter := Router.Group("workflowProcess").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()).Use(middleware.OperationRecord())
|
||||
{
|
||||
WorkflowProcessRouter.POST("createWorkflowProcess", v1.CreateWorkflowProcess) // 新建WorkflowProcess
|
||||
WorkflowProcessRouter.DELETE("deleteWorkflowProcess", v1.DeleteWorkflowProcess) // 删除WorkflowProcess
|
||||
WorkflowProcessRouter.DELETE("deleteWorkflowProcessByIds", v1.DeleteWorkflowProcessByIds) // 批量删除WorkflowProcess
|
||||
WorkflowProcessRouter.PUT("updateWorkflowProcess", v1.UpdateWorkflowProcess) // 更新WorkflowProcess
|
||||
WorkflowProcessRouter.GET("findWorkflowProcess", v1.FindWorkflowProcess) // 根据ID获取WorkflowProcess
|
||||
WorkflowProcessRouter.GET("getWorkflowProcessList", v1.GetWorkflowProcessList) // 获取WorkflowProcess列表
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
)
|
||||
|
||||
// @title CreateWorkflowProcess
|
||||
// @description create a WorkflowProcess
|
||||
// @param workflowProcess model.WorkflowProcess
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @return err error
|
||||
|
||||
func CreateWorkflowProcess(workflowProcess model.WorkflowProcess) (err error) {
|
||||
err = global.GVA_DB.Create(&workflowProcess).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// @title DeleteWorkflowProcess
|
||||
// @description delete a WorkflowProcess
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param workflowProcess model.WorkflowProcess
|
||||
// @return error
|
||||
|
||||
func DeleteWorkflowProcess(workflowProcess model.WorkflowProcess) (err error) {
|
||||
err = global.GVA_DB.Delete(workflowProcess).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// @title DeleteWorkflowProcessByIds
|
||||
// @description delete WorkflowProcesss
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param workflowProcess model.WorkflowProcess
|
||||
// @return error
|
||||
|
||||
func DeleteWorkflowProcessByIds(ids request.IdsReq) (err error) {
|
||||
err = global.GVA_DB.Delete(&[]model.WorkflowProcess{}, "id in ?", ids.Ids).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// @title UpdateWorkflowProcess
|
||||
// @description update a WorkflowProcess
|
||||
// @param workflowProcess *model.WorkflowProcess
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @return error
|
||||
|
||||
func UpdateWorkflowProcess(workflowProcess *model.WorkflowProcess) (err error) {
|
||||
err = global.GVA_DB.Save(workflowProcess).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// @title GetWorkflowProcess
|
||||
// @description get the info of a WorkflowProcess
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param id uint
|
||||
// @return error
|
||||
// @return WorkflowProcess WorkflowProcess
|
||||
|
||||
func GetWorkflowProcess(id string) (err error, workflowProcess model.WorkflowProcess) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&workflowProcess).Error
|
||||
return
|
||||
}
|
||||
|
||||
// @title GetWorkflowProcessInfoList
|
||||
// @description get WorkflowProcess list by pagination, 分页获取WorkflowProcess
|
||||
// @auth (2020/04/05 20:22)
|
||||
// @param info PageInfo
|
||||
// @return error
|
||||
|
||||
func GetWorkflowProcessInfoList(info request.WorkflowProcessSearch) (err error, list interface{}, total int64) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
// 创建db
|
||||
db := global.GVA_DB.Model(&model.WorkflowProcess{})
|
||||
var workflowProcesss []model.WorkflowProcess
|
||||
// 如果有条件搜索 下方会自动创建搜索语句
|
||||
if info.Name != "" {
|
||||
db = db.Where("`name` LIKE ?", "%"+info.Name+"%")
|
||||
}
|
||||
if info.Label != "" {
|
||||
db = db.Where("`label` LIKE ?", "%"+info.Label+"%")
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
err = db.Limit(limit).Offset(offset).Find(&workflowProcesss).Error
|
||||
return err, workflowProcesss, total
|
||||
}
|
||||
Reference in New Issue
Block a user