mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-21 15:19:32 +08:00
调整flow目录结构
This commit is contained in:
83
server/admin/flow/enter.go
Normal file
83
server/admin/flow/enter.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package flow
|
||||
|
||||
import (
|
||||
"x_admin/admin/flow/flow_apply"
|
||||
"x_admin/admin/flow/flow_history"
|
||||
"x_admin/admin/flow/flow_template"
|
||||
"x_admin/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 3. 后台手动添加菜单和按钮
|
||||
// flow_apply:add
|
||||
// flow_apply:edit
|
||||
// flow_apply:del
|
||||
// flow_apply:list
|
||||
// flow_apply:detail
|
||||
|
||||
func FlowApplyRoute(rg *gin.RouterGroup) {
|
||||
|
||||
handle := flow_apply.FlowApplyHandler{}
|
||||
|
||||
rg = rg.Group("/", middleware.TokenAuth())
|
||||
rg.GET("/flow_apply/list", handle.List)
|
||||
rg.GET("/flow_apply/detail", handle.Detail)
|
||||
rg.POST("/flow_apply/add", handle.Add)
|
||||
rg.POST("/flow_apply/edit", handle.Edit)
|
||||
rg.POST("/flow_apply/del", handle.Del)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
3. 后台手动添加菜单和按钮
|
||||
flow_history:add
|
||||
flow_history:edit
|
||||
flow_history:del
|
||||
flow_history:list
|
||||
flow_history:listAll
|
||||
flow_history:detail
|
||||
*/
|
||||
|
||||
// FlowHistoryRoute(rg)
|
||||
func FlowHistoryRoute(rg *gin.RouterGroup) {
|
||||
|
||||
handle := flow_history.FlowHistoryHandler{}
|
||||
|
||||
rg = rg.Group("/", middleware.TokenAuth())
|
||||
rg.GET("/flow_history/list", handle.List)
|
||||
rg.GET("/flow_history/listAll", handle.ListAll)
|
||||
rg.GET("/flow_history/detail", handle.Detail)
|
||||
rg.POST("/flow_history/add", handle.Add)
|
||||
rg.POST("/flow_history/edit", handle.Edit)
|
||||
rg.POST("/flow_history/del", handle.Del)
|
||||
|
||||
rg.POST("/flow_history/pass", handle.Pass)
|
||||
rg.POST("/flow_history/next_node", handle.NextNode)
|
||||
rg.POST("/flow_history/get_approver", handle.GetApprover)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
3. 后台手动添加菜单和按钮
|
||||
flow_template:add
|
||||
flow_template:edit
|
||||
flow_template:del
|
||||
flow_template:list
|
||||
flow_template:listAll
|
||||
flow_template:detail
|
||||
*/
|
||||
|
||||
// FlowTemplateRoute(rg)
|
||||
func FlowTemplateRoute(rg *gin.RouterGroup) {
|
||||
|
||||
handle := flow_template.FlowTemplateHandler{}
|
||||
|
||||
rg = rg.Group("/", middleware.TokenAuth())
|
||||
rg.GET("/flow_template/list", handle.List)
|
||||
rg.GET("/flow_template/listAll", handle.ListAll)
|
||||
rg.GET("/flow_template/detail", handle.Detail)
|
||||
rg.POST("/flow_template/add", handle.Add)
|
||||
rg.POST("/flow_template/edit", handle.Edit)
|
||||
rg.POST("/flow_template/del", handle.Del)
|
||||
}
|
128
server/admin/flow/flow_apply/flow_apply_ctl.go
Normal file
128
server/admin/flow/flow_apply/flow_apply_ctl.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package flow_apply
|
||||
|
||||
import (
|
||||
"x_admin/config"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type FlowApplyHandler struct{}
|
||||
|
||||
// @Summary 申请流程列表
|
||||
// @Tags flow_apply-申请流程
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param templateId query int false "模板"
|
||||
// @Param applyUserId query int false "申请人id"
|
||||
// @Param applyUserNickname query string false "申请人昵称"
|
||||
// @Param flowName query string false "流程名称"
|
||||
// @Param flowGroup query int false "流程分类"
|
||||
// @Param flowRemark query string false "流程描述"
|
||||
// @Param flowFormData query string false "表单配置"
|
||||
// @Param flowProcessData query string false "流程配置"
|
||||
// @Param status query int false "状态:1待提交,2审批中,3审批完成,4审批失败"
|
||||
// @Success 200 {object} []FlowApplyResp "成功"
|
||||
// @Failure 400 {object} string "请求错误"
|
||||
// @Router /api/flow_apply/list [get]
|
||||
func (hd FlowApplyHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq FlowApplyListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 申请流程详情
|
||||
// @Tags flow_apply-申请流程
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id query int false "申请id"
|
||||
// @Success 200 {object} FlowApplyResp "成功"
|
||||
// @Router /api/flow_apply/detail [get]
|
||||
func (hd FlowApplyHandler) Detail(c *gin.Context) {
|
||||
var detailReq FlowApplyDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.Detail(detailReq.Id)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 申请流程新增
|
||||
// @Tags flow_apply-申请流程
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param templateId body int false "模板"
|
||||
// @Param applyUserId body int false "申请人id"
|
||||
// @Param applyUserNickname body string false "申请人昵称"
|
||||
// @Param flowName body string false "流程名称"
|
||||
// @Param flowGroup body int false "流程分类"
|
||||
// @Param flowRemark body string false "流程描述"
|
||||
// @Param flowFormData body string false "表单配置"
|
||||
// @Param flowProcessData body string false "流程配置"
|
||||
// @Param status body int false "状态:1待提交,2审批中,3审批完成,4审批失败"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_apply/add [post]
|
||||
func (hd FlowApplyHandler) Add(c *gin.Context) {
|
||||
var addReq FlowApplyAddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
|
||||
var Nickname = config.AdminConfig.GetNickname(c)
|
||||
var AdminId = config.AdminConfig.GetAdminId(c)
|
||||
addReq.ApplyUserNickname = Nickname
|
||||
addReq.ApplyUserId = int(AdminId)
|
||||
addReq.Status = 1
|
||||
|
||||
response.CheckAndResp(c, Service.Add(addReq))
|
||||
}
|
||||
|
||||
// @Summary 申请流程编辑
|
||||
// @Tags flow_apply-申请流程
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "申请id"
|
||||
// @Param templateId body int false "模板"
|
||||
// @Param applyUserId body int false "申请人id"
|
||||
// @Param applyUserNickname body string false "申请人昵称"
|
||||
// @Param flowName body string false "流程名称"
|
||||
// @Param flowGroup body int false "流程分类"
|
||||
// @Param flowRemark body string false "流程描述"
|
||||
// @Param flowFormData body string false "表单配置"
|
||||
// @Param flowProcessData body string false "流程配置"
|
||||
// @Param status body int false "状态:1待提交,2审批中,3审批完成,4审批失败"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_apply/edit [post]
|
||||
func (hd FlowApplyHandler) Edit(c *gin.Context) {
|
||||
var editReq FlowApplyEditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Edit(editReq))
|
||||
}
|
||||
|
||||
// @Summary 申请流程删除
|
||||
// @Tags flow_apply-申请流程
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "申请id"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_apply/del [post]
|
||||
func (hd FlowApplyHandler) Del(c *gin.Context) {
|
||||
var delReq FlowApplyDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Del(delReq.Id))
|
||||
}
|
77
server/admin/flow/flow_apply/flow_apply_schema.go
Normal file
77
server/admin/flow/flow_apply/flow_apply_schema.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package flow_apply
|
||||
|
||||
import "x_admin/core"
|
||||
|
||||
//FlowApplyListReq 申请流程列表参数
|
||||
type FlowApplyListReq struct {
|
||||
TemplateId int `form:"templateId"` // 模板
|
||||
ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
Status int `form:"status"` // 状态:1待提交,2审批中,3审批完成,4审批失败
|
||||
}
|
||||
|
||||
//FlowApplyDetailReq 申请流程详情参数
|
||||
type FlowApplyDetailReq struct {
|
||||
Id int `form:"id"` //
|
||||
}
|
||||
|
||||
//FlowApplyAddReq 申请流程新增参数
|
||||
type FlowApplyAddReq struct {
|
||||
TemplateId int `form:"templateId"` // 模板
|
||||
ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
// FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
// FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
// FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
// FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
// FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
Status int `form:"status"` // 状态:1待提交,2审批中,3审批完成,4审批失败
|
||||
}
|
||||
|
||||
//FlowApplyEditReq 申请流程新增参数
|
||||
type FlowApplyEditReq struct {
|
||||
Id int `form:"id"` //
|
||||
// TemplateId int `form:"templateId"` // 模板
|
||||
// ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
// ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
// FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
// FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
// FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
// FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
// FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
Status int `form:"status"` // 状态:1待提交,2审批中,3审批完成,4审批失败
|
||||
}
|
||||
|
||||
//FlowApplyDelReq 申请流程新增参数
|
||||
type FlowApplyDelReq struct {
|
||||
Id int `form:"id"` //
|
||||
}
|
||||
|
||||
//FlowApplyResp 申请流程返回信息
|
||||
type FlowApplyResp struct {
|
||||
Id int `json:"id" structs:"id"` //
|
||||
TemplateId int `json:"templateId" structs:"templateId"` // 模板
|
||||
ApplyUserId int `json:"applyUserId" structs:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `json:"applyUserNickname" structs:"applyUserNickname"` // 申请人昵称
|
||||
FlowName string `json:"flowName" structs:"flowName"` // 流程名称
|
||||
FlowGroup int `json:"flowGroup" structs:"flowGroup"` // 流程分类
|
||||
FlowRemark string `json:"flowRemark" structs:"flowRemark"` // 流程描述
|
||||
FlowFormData string `json:"flowFormData" structs:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `json:"flowProcessData" structs:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `json:"flowProcessDataList"` // 流程配置list数据
|
||||
FormValue string `json:"formValue"` // 表单值
|
||||
Status int `json:"status" structs:"status"` // 状态:1待提交,2审批中,3审批完成,4审批失败
|
||||
UpdateTime core.TsTime `json:"updateTime" structs:"updateTime"` // 更新时间
|
||||
CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间
|
||||
}
|
157
server/admin/flow/flow_apply/flow_apply_service.go
Normal file
157
server/admin/flow/flow_apply/flow_apply_service.go
Normal file
@@ -0,0 +1,157 @@
|
||||
package flow_apply
|
||||
|
||||
import (
|
||||
"x_admin/admin/flow/flow_template"
|
||||
"x_admin/core"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type IFlowApplyService interface {
|
||||
List(page request.PageReq, listReq FlowApplyListReq) (res response.PageResp, e error)
|
||||
Detail(id int) (res FlowApplyResp, e error)
|
||||
Add(addReq FlowApplyAddReq) (e error)
|
||||
Edit(editReq FlowApplyEditReq) (e error)
|
||||
Del(id int) (e error)
|
||||
}
|
||||
|
||||
var Service = NewFlowApplyService()
|
||||
|
||||
// NewFlowApplyService 初始化
|
||||
func NewFlowApplyService() *flowApplyService {
|
||||
db := core.GetDB()
|
||||
return &flowApplyService{db: db}
|
||||
}
|
||||
|
||||
// flowApplyService 申请流程服务实现类
|
||||
type flowApplyService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// List 申请流程列表
|
||||
func (Service flowApplyService) List(page request.PageReq, listReq FlowApplyListReq) (res response.PageResp, e error) {
|
||||
// 分页信息
|
||||
limit := page.PageSize
|
||||
offset := page.PageSize * (page.PageNo - 1)
|
||||
// 查询
|
||||
dbModel := Service.db.Model(&model.FlowApply{})
|
||||
if listReq.TemplateId > 0 {
|
||||
dbModel = dbModel.Where("template_id = ?", listReq.TemplateId)
|
||||
}
|
||||
if listReq.ApplyUserId > 0 {
|
||||
dbModel = dbModel.Where("apply_user_id = ?", listReq.ApplyUserId)
|
||||
}
|
||||
if listReq.ApplyUserNickname != "" {
|
||||
dbModel = dbModel.Where("apply_user_nickname like ?", "%"+listReq.ApplyUserNickname+"%")
|
||||
}
|
||||
if listReq.FlowName != "" {
|
||||
dbModel = dbModel.Where("flow_name like ?", "%"+listReq.FlowName+"%")
|
||||
}
|
||||
if listReq.FlowGroup > 0 {
|
||||
dbModel = dbModel.Where("flow_group = ?", listReq.FlowGroup)
|
||||
}
|
||||
if listReq.FlowRemark != "" {
|
||||
dbModel = dbModel.Where("flow_remark = ?", listReq.FlowRemark)
|
||||
}
|
||||
if listReq.FlowFormData != "" {
|
||||
dbModel = dbModel.Where("flow_form_data = ?", listReq.FlowFormData)
|
||||
}
|
||||
if listReq.FlowProcessData != "" {
|
||||
dbModel = dbModel.Where("flow_process_data = ?", listReq.FlowProcessData)
|
||||
}
|
||||
if listReq.Status > 0 {
|
||||
dbModel = dbModel.Where("status = ?", listReq.Status)
|
||||
}
|
||||
// 总数
|
||||
var count int64
|
||||
err := dbModel.Count(&count).Error
|
||||
if e = response.CheckErr(err, "List Count err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 数据
|
||||
var objs []model.FlowApply
|
||||
err = dbModel.Limit(limit).Offset(offset).Order("id desc").Find(&objs).Error
|
||||
if e = response.CheckErr(err, "List Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
resps := []FlowApplyResp{}
|
||||
response.Copy(&resps, objs)
|
||||
return response.PageResp{
|
||||
PageNo: page.PageNo,
|
||||
PageSize: page.PageSize,
|
||||
Count: count,
|
||||
Lists: resps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Detail 申请流程详情
|
||||
func (Service flowApplyService) Detail(id int) (res FlowApplyResp, e error) {
|
||||
var obj model.FlowApply
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Detail First err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, obj)
|
||||
return
|
||||
}
|
||||
|
||||
// Add 申请流程新增
|
||||
func (Service flowApplyService) Add(addReq FlowApplyAddReq) (e error) {
|
||||
var obj model.FlowApply
|
||||
var flow_template_resp, err = flow_template.Service.Detail(addReq.TemplateId)
|
||||
if e = response.CheckErrDBNotRecord(err, "模板不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&obj, addReq)
|
||||
// obj.FlowName = flow_template_resp.FlowName
|
||||
obj.FlowGroup = flow_template_resp.FlowGroup
|
||||
obj.FlowRemark = flow_template_resp.FlowRemark
|
||||
obj.FlowFormData = flow_template_resp.FlowFormData
|
||||
obj.FlowProcessData = flow_template_resp.FlowProcessData
|
||||
obj.FlowProcessDataList = flow_template_resp.FlowProcessDataList
|
||||
|
||||
err = Service.db.Create(&obj).Error
|
||||
e = response.CheckErr(err, "添加失败")
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 申请流程编辑
|
||||
func (Service flowApplyService) Edit(editReq FlowApplyEditReq) (e error) {
|
||||
var obj model.FlowApply
|
||||
err := Service.db.Where("id = ?", editReq.Id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Edit First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 更新
|
||||
response.Copy(&obj, editReq)
|
||||
err = Service.db.Model(&obj).Updates(obj).Error
|
||||
e = response.CheckErr(err, "Edit Updates err")
|
||||
return
|
||||
}
|
||||
|
||||
// Del 申请流程删除
|
||||
func (Service flowApplyService) Del(id int) (e error) {
|
||||
var obj model.FlowApply
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Del First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 删除
|
||||
err = Service.db.Delete(&obj).Error
|
||||
e = response.CheckErr(err, "Del Delete err")
|
||||
return
|
||||
}
|
195
server/admin/flow/flow_history/flow_history_ctl.go
Normal file
195
server/admin/flow/flow_history/flow_history_ctl.go
Normal file
@@ -0,0 +1,195 @@
|
||||
package flow_history
|
||||
|
||||
import (
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type FlowHistoryHandler struct {
|
||||
Service IFlowHistoryService
|
||||
}
|
||||
|
||||
// @Summary 流程历史列表
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param applyId query int false "申请id"
|
||||
// @Param templateId query int false "模板id"
|
||||
// @Param applyUserId query int false "申请人id"
|
||||
// @Param applyUserNickname query string false "申请人昵称"
|
||||
// @Param approverId query int false "审批人id"
|
||||
// @Param approverNickname query string false "审批用户昵称"
|
||||
// @Param nodeId query string false "节点"
|
||||
// @Param formValue query string false "表单值"
|
||||
// @Param passStatus query int false "通过状态:0待处理,1通过,2拒绝"
|
||||
// @Param passRemark query string false "通过备注"
|
||||
// @Success 200 {object} []FlowHistoryResp "成功"
|
||||
// @Failure 400 {object} string "请求错误"
|
||||
// @Router /api/flow_history/list [get]
|
||||
func (hd FlowHistoryHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq = FlowHistoryListReq{
|
||||
PassStatus: -9999,
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程历史列表-所有
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Success 200 {object} []FlowHistoryResp "成功"
|
||||
// @Router /api/flow_history/list [get]
|
||||
func (hd FlowHistoryHandler) ListAll(c *gin.Context) {
|
||||
var listReq FlowHistoryListReq
|
||||
res, err := Service.ListAll(listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程历史详情
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id query int false "历史id"
|
||||
// @Success 200 {object} FlowHistoryResp "成功"
|
||||
// @Router /api/flow_history/detail [get]
|
||||
func (hd FlowHistoryHandler) Detail(c *gin.Context) {
|
||||
var detailReq FlowHistoryDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.Detail(detailReq.Id)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程历史新增
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param applyId body int false "申请id"
|
||||
// @Param templateId body int false "模板id"
|
||||
// @Param applyUserId body int false "申请人id"
|
||||
// @Param applyUserNickname body string false "申请人昵称"
|
||||
// @Param approverId body int false "审批人id"
|
||||
// @Param approverNickname body string false "审批用户昵称"
|
||||
// @Param nodeId body string false "节点"
|
||||
// @Param formValue body string false "表单值"
|
||||
// @Param passStatus body int false "通过状态:0待处理,1通过,2拒绝"
|
||||
// @Param passRemark body string false "通过备注"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_history/add [post]
|
||||
func (hd FlowHistoryHandler) Add(c *gin.Context) {
|
||||
var addReq FlowHistoryAddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Add(addReq))
|
||||
}
|
||||
|
||||
// @Summary 流程历史编辑
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "历史id"
|
||||
// @Param applyId body int false "申请id"
|
||||
// @Param templateId body int false "模板id"
|
||||
// @Param applyUserId body int false "申请人id"
|
||||
// @Param applyUserNickname body string false "申请人昵称"
|
||||
// @Param approverId body int false "审批人id"
|
||||
// @Param approverNickname body string false "审批用户昵称"
|
||||
// @Param nodeId body string false "节点"
|
||||
// @Param formValue body string false "表单值"
|
||||
// @Param passStatus body int false "通过状态:0待处理,1通过,2拒绝"
|
||||
// @Param passRemark body string false "通过备注"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_history/edit [post]
|
||||
func (hd FlowHistoryHandler) Edit(c *gin.Context) {
|
||||
var editReq FlowHistoryEditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Edit(editReq))
|
||||
}
|
||||
|
||||
// @Summary 流程历史删除
|
||||
// @Tags flow_history-流程历史
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "历史id"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_history/del [post]
|
||||
func (hd FlowHistoryHandler) Del(c *gin.Context) {
|
||||
var delReq FlowHistoryDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Del(delReq.Id))
|
||||
}
|
||||
|
||||
// 提交申请
|
||||
//
|
||||
// @Router /api/flow_apply/SubmitApply [post]
|
||||
func (hd FlowHistoryHandler) Pass(c *gin.Context) {
|
||||
var pass PassReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &pass)) {
|
||||
return
|
||||
}
|
||||
err := Service.Pass(pass)
|
||||
response.CheckAndResp(c, err)
|
||||
|
||||
// 申请流程id,
|
||||
// var addReq FlowApplyAddReq
|
||||
// if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
// return
|
||||
// }
|
||||
|
||||
// var Nickname = config.AdminConfig.GetNickname(c)
|
||||
// var AdminId = config.AdminConfig.GetAdminId(c)
|
||||
// addReq.ApplyUserNickname = Nickname
|
||||
// addReq.ApplyUserId = int(AdminId)
|
||||
// 解析json
|
||||
// 查找开始节点
|
||||
// 查找开始的下一级节点
|
||||
// 下一个可能是网关,系统任务,用户任务,结束
|
||||
// 网关,系统任务节点处理后继续向下查找节点,网关只能有一个满足条件
|
||||
|
||||
}
|
||||
|
||||
// 获取下一个审批节点,中间可能存在系统任务节点和网关
|
||||
func (hd FlowHistoryHandler) NextNode(c *gin.Context) {
|
||||
var nextNode NextNodeReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &nextNode)) {
|
||||
return
|
||||
}
|
||||
|
||||
// response.CheckAndResp(c, Service.GetNextNode(nextNode))
|
||||
res, _, _, err := Service.GetNextNode(nextNode.ApplyId)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// 获取节点的可审批用户
|
||||
func (hd FlowHistoryHandler) GetApprover(c *gin.Context) {
|
||||
var node FlowTree
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &node)) {
|
||||
return
|
||||
}
|
||||
|
||||
// response.CheckAndResp(c, Service.GetNextNode(node))
|
||||
res, err := Service.GetApprover(node)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// 同意审批(当前nodeId)
|
||||
|
||||
// 拒绝审批,驳回审批
|
102
server/admin/flow/flow_history/flow_history_schema.go
Normal file
102
server/admin/flow/flow_history/flow_history_schema.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package flow_history
|
||||
|
||||
import "x_admin/core"
|
||||
|
||||
//FlowHistoryListReq 流程历史列表参数
|
||||
type FlowHistoryListReq struct {
|
||||
ApplyId int `form:"applyId"` // 申请id
|
||||
TemplateId int `form:"templateId"` // 模板id
|
||||
ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
ApproverId int `form:"approverId"` // 审批人id
|
||||
ApproverNickname string `form:"approverNickname"` // 审批用户昵称
|
||||
NodeId string `form:"nodeId"` // 节点
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
PassStatus int `form:"passStatus"` // 通过状态:1待处理,2通过,3拒绝
|
||||
PassRemark string `form:"passRemark"` // 通过备注
|
||||
}
|
||||
|
||||
//FlowHistoryDetailReq 流程历史详情参数
|
||||
type FlowHistoryDetailReq struct {
|
||||
Id int `form:"id"` // 历史id
|
||||
}
|
||||
|
||||
//FlowHistoryAddReq 流程历史新增参数
|
||||
type FlowHistoryAddReq struct {
|
||||
ApplyId int `form:"applyId"` // 申请id
|
||||
TemplateId int `form:"templateId"` // 模板id
|
||||
ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
ApproverId int `form:"approverId"` // 审批人id
|
||||
ApproverNickname string `form:"approverNickname"` // 审批用户昵称
|
||||
NodeId string `form:"nodeId"` // 节点
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
PassStatus int `form:"passStatus"` // 通过状态:1待处理,2通过,3拒绝
|
||||
PassRemark string `form:"passRemark"` // 通过备注
|
||||
}
|
||||
|
||||
//FlowHistoryEditReq 流程历史新增参数
|
||||
type FlowHistoryEditReq struct {
|
||||
Id int `form:"id"` // 历史id
|
||||
ApplyId int `form:"applyId"` // 申请id
|
||||
TemplateId int `form:"templateId"` // 模板id
|
||||
ApplyUserId int `form:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `form:"applyUserNickname"` // 申请人昵称
|
||||
ApproverId int `form:"approverId"` // 审批人id
|
||||
ApproverNickname string `form:"approverNickname"` // 审批用户昵称
|
||||
NodeId string `form:"nodeId"` // 节点
|
||||
FormValue string `form:"formValue"` // 表单值
|
||||
PassStatus int `form:"passStatus"` // 通过状态:1待处理,2通过,3拒绝
|
||||
PassRemark string `form:"passRemark"` // 通过备注
|
||||
}
|
||||
|
||||
//FlowHistoryDelReq 流程历史新增参数
|
||||
type FlowHistoryDelReq struct {
|
||||
Id int `form:"id"` // 历史id
|
||||
}
|
||||
|
||||
//FlowHistoryResp 流程历史返回信息
|
||||
type FlowHistoryResp struct {
|
||||
Id int `json:"id" structs:"id"` // 历史id
|
||||
ApplyId int `json:"applyId" structs:"applyId"` // 申请id
|
||||
TemplateId int `json:"templateId" structs:"templateId"` // 模板id
|
||||
ApplyUserId int `json:"applyUserId" structs:"applyUserId"` // 申请人id
|
||||
ApplyUserNickname string `json:"applyUserNickname" structs:"applyUserNickname"` // 申请人昵称
|
||||
ApproverId int `json:"approverId" structs:"approverId"` // 审批人id
|
||||
ApproverNickname string `json:"approverNickname" structs:"approverNickname"` // 审批用户昵称
|
||||
NodeId string `json:"nodeId" structs:"nodeId"` // 节点
|
||||
FormValue string `json:"formValue" structs:"formValue"` // 表单值
|
||||
PassStatus int `json:"passStatus" structs:"passStatus"` // 通过状态:1待处理,2通过,3拒绝
|
||||
PassRemark string `json:"passRemark" structs:"passRemark"` // 通过备注
|
||||
UpdateTime core.TsTime `json:"updateTime" structs:"updateTime"` // 更新时间
|
||||
CreateTime core.TsTime `json:"createTime" structs:"createTime"` // 创建时间
|
||||
}
|
||||
|
||||
type FlowTree struct {
|
||||
Id string `json:"id"`
|
||||
Pid string `json:"pid"`
|
||||
Label string `json:"label"`
|
||||
Type string `json:"type"`
|
||||
|
||||
UserId int `json:"userId"`
|
||||
DeptId int `json:"deptId"`
|
||||
PostId int `json:"postId"`
|
||||
|
||||
FieldAuth map[string]int `json:"fieldAuth"`
|
||||
|
||||
Children *[]FlowTree `json:"children"`
|
||||
}
|
||||
type NextNodeReq struct {
|
||||
ApplyId int `form:"applyId"` // 申请id
|
||||
// CurrentNodeId string `form:"currentNodeId"` // 流程里的节点id
|
||||
// FormValue string `form:"formValue"`
|
||||
// NextNodeAdminId int `form:"nextNodeAdminId"` // 下一个节点的审批用户id
|
||||
}
|
||||
type PassReq struct {
|
||||
ApplyId int `form:"applyId"` // 申请id
|
||||
|
||||
// CurrentNodeId string `form:"currentNodeId"` // 流程里的节点id
|
||||
// FormValue string `form:"formValue"`
|
||||
NextNodeAdminId int `form:"nextNodeAdminId"` // 下一个节点的审批用户id
|
||||
PassRemark string `form:"passRemark"` // 通过备注
|
||||
}
|
374
server/admin/flow/flow_history/flow_history_service.go
Normal file
374
server/admin/flow/flow_history/flow_history_service.go
Normal file
@@ -0,0 +1,374 @@
|
||||
package flow_history
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"x_admin/admin/flow/flow_apply"
|
||||
"x_admin/admin/system/admin"
|
||||
"x_admin/core"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model"
|
||||
"x_admin/model/system_model"
|
||||
"x_admin/util"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type IFlowHistoryService interface {
|
||||
List(page request.PageReq, listReq FlowHistoryListReq) (res response.PageResp, e error)
|
||||
ListAll() (res []FlowHistoryResp, e error)
|
||||
|
||||
Detail(id int) (res FlowHistoryResp, e error)
|
||||
Add(addReq FlowHistoryAddReq) (e error)
|
||||
Edit(editReq FlowHistoryEditReq) (e error)
|
||||
Del(id int) (e error)
|
||||
|
||||
GetNextNode(nextNode NextNodeReq) (e error)
|
||||
}
|
||||
|
||||
var Service = NewFlowHistoryService()
|
||||
|
||||
// NewFlowHistoryService 初始化
|
||||
func NewFlowHistoryService() *flowHistoryService {
|
||||
db := core.GetDB()
|
||||
return &flowHistoryService{db: db}
|
||||
}
|
||||
|
||||
// flowHistoryService 流程历史服务实现类
|
||||
type flowHistoryService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// List 流程历史列表
|
||||
func (Service flowHistoryService) List(page request.PageReq, listReq FlowHistoryListReq) (res response.PageResp, e error) {
|
||||
// 分页信息
|
||||
limit := page.PageSize
|
||||
offset := page.PageSize * (page.PageNo - 1)
|
||||
// 查询
|
||||
dbModel := Service.db.Model(&model.FlowHistory{})
|
||||
if listReq.ApplyId > 0 {
|
||||
dbModel = dbModel.Where("apply_id = ?", listReq.ApplyId)
|
||||
}
|
||||
if listReq.TemplateId > 0 {
|
||||
dbModel = dbModel.Where("template_id = ?", listReq.TemplateId)
|
||||
}
|
||||
if listReq.ApplyUserId > 0 {
|
||||
dbModel = dbModel.Where("apply_user_id = ?", listReq.ApplyUserId)
|
||||
}
|
||||
if listReq.ApplyUserNickname != "" {
|
||||
dbModel = dbModel.Where("apply_user_nickname like ?", "%"+listReq.ApplyUserNickname+"%")
|
||||
}
|
||||
if listReq.ApproverId > 0 {
|
||||
dbModel = dbModel.Where("approver_id = ?", listReq.ApproverId)
|
||||
}
|
||||
if listReq.ApproverNickname != "" {
|
||||
dbModel = dbModel.Where("approver_nickname like ?", "%"+listReq.ApproverNickname+"%")
|
||||
}
|
||||
if listReq.NodeId != "" {
|
||||
dbModel = dbModel.Where("node_id = ?", listReq.NodeId)
|
||||
}
|
||||
if listReq.FormValue != "" {
|
||||
dbModel = dbModel.Where("form_value = ?", listReq.FormValue)
|
||||
}
|
||||
if listReq.PassStatus > 0 {
|
||||
dbModel = dbModel.Where("pass_status = ?", listReq.PassStatus)
|
||||
}
|
||||
if listReq.PassRemark != "" {
|
||||
dbModel = dbModel.Where("pass_remark = ?", listReq.PassRemark)
|
||||
}
|
||||
// 总数
|
||||
var count int64
|
||||
err := dbModel.Count(&count).Error
|
||||
if e = response.CheckErr(err, "List Count err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 数据
|
||||
var objs []model.FlowHistory
|
||||
err = dbModel.Limit(limit).Offset(offset).Order("id desc").Find(&objs).Error
|
||||
if e = response.CheckErr(err, "List Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
resps := []FlowHistoryResp{}
|
||||
response.Copy(&resps, objs)
|
||||
return response.PageResp{
|
||||
PageNo: page.PageNo,
|
||||
PageSize: page.PageSize,
|
||||
Count: count,
|
||||
Lists: resps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListAll 流程历史列表
|
||||
func (Service flowHistoryService) ListAll(listReq FlowHistoryListReq) (res []FlowHistoryResp, e error) {
|
||||
|
||||
// 查询
|
||||
dbModel := Service.db.Model(&model.FlowHistory{})
|
||||
if listReq.ApplyId > 0 {
|
||||
dbModel = dbModel.Where("apply_id = ?", listReq.ApplyId)
|
||||
}
|
||||
// 数据
|
||||
var objs []model.FlowHistory
|
||||
err := dbModel.Find(&objs).Error
|
||||
if e = response.CheckErr(err, "ListAll Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, objs)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Detail 流程历史详情
|
||||
func (Service flowHistoryService) Detail(id int) (res FlowHistoryResp, e error) {
|
||||
var obj model.FlowHistory
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Detail First err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, obj)
|
||||
return
|
||||
}
|
||||
|
||||
// Add 流程历史新增
|
||||
func (Service flowHistoryService) Add(addReq FlowHistoryAddReq) (e error) {
|
||||
var obj model.FlowHistory
|
||||
response.Copy(&obj, addReq)
|
||||
err := Service.db.Create(&obj).Error
|
||||
e = response.CheckErr(err, "Add Create err")
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 流程历史编辑
|
||||
func (Service flowHistoryService) Edit(editReq FlowHistoryEditReq) (e error) {
|
||||
var obj model.FlowHistory
|
||||
err := Service.db.Where("id = ?", editReq.Id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Edit First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 更新
|
||||
response.Copy(&obj, editReq)
|
||||
err = Service.db.Model(&obj).Updates(obj).Error
|
||||
e = response.CheckErr(err, "Edit Updates err")
|
||||
return
|
||||
}
|
||||
|
||||
// Del 流程历史删除
|
||||
func (Service flowHistoryService) Del(id int) (e error) {
|
||||
var obj model.FlowHistory
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Del First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 删除
|
||||
err = Service.db.Delete(&obj).Error
|
||||
e = response.CheckErr(err, "Del Delete err")
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点的审批用户
|
||||
*/
|
||||
func (Service flowHistoryService) GetApprover(node FlowTree) (res []admin.SystemAuthAdminResp, e error) {
|
||||
var userId = node.UserId
|
||||
var deptId = node.DeptId
|
||||
var postId = node.PostId
|
||||
adminTbName := core.DBTableName(&system_model.SystemAuthAdmin{})
|
||||
|
||||
adminModel := Service.db.Table(adminTbName+" AS admin").Where("admin.is_delete = ?", 0)
|
||||
|
||||
dept := map[string]interface{}{}
|
||||
if deptId > 0 {
|
||||
dept["admin.dept_id"] = deptId
|
||||
// adminModel.Or("admin.dept_id =?", deptId)
|
||||
}
|
||||
if postId > 0 {
|
||||
dept["admin.post_id"] = postId
|
||||
// adminModel.Or("admin.post_id =?", postId)
|
||||
}
|
||||
|
||||
var where = Service.db.Where(dept)
|
||||
if userId > 0 {
|
||||
where.Or("admin.id =?", userId)
|
||||
}
|
||||
|
||||
// 数据
|
||||
var adminResp []admin.SystemAuthAdminResp
|
||||
err := adminModel.Where(where).Find(&adminResp).Error
|
||||
if e = response.CheckErr(err, "获取审批用户失败"); e != nil {
|
||||
return
|
||||
}
|
||||
for i := 0; i < len(adminResp); i++ {
|
||||
adminResp[i].Avatar = util.UrlUtil.ToAbsoluteUrl(adminResp[i].Avatar)
|
||||
if adminResp[i].ID == 1 {
|
||||
adminResp[i].Role = "系统管理员"
|
||||
}
|
||||
}
|
||||
return adminResp, nil
|
||||
}
|
||||
|
||||
func (Service flowHistoryService) Pass(pass PassReq) (e error) {
|
||||
nextNodes, applyDetail, LastHistory, err := Service.GetNextNode(pass.ApplyId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
isEnd := false // 是否是最后一个节点
|
||||
|
||||
FormValue := applyDetail.FormValue
|
||||
if LastHistory.Id != 0 {
|
||||
FormValue = LastHistory.FormValue
|
||||
}
|
||||
var flows = []model.FlowHistory{}
|
||||
|
||||
for _, v := range nextNodes {
|
||||
// if v.Type == "bpmn:exclusiveGateway" {
|
||||
// 这里网关不用处理,顶多加一条历史记录
|
||||
// }
|
||||
var flow = model.FlowHistory{
|
||||
ApplyId: applyDetail.Id,
|
||||
NodeId: v.Id,
|
||||
FormValue: FormValue,
|
||||
PassStatus: 1,
|
||||
ApplyUserId: applyDetail.ApplyUserId,
|
||||
TemplateId: applyDetail.TemplateId,
|
||||
ApplyUserNickname: applyDetail.ApplyUserNickname,
|
||||
ApproverId: 0,
|
||||
}
|
||||
if v.Type == "bpmn:serviceTask" {
|
||||
// 发邮件之类的,待完善
|
||||
} else if v.Type == "bpmn:userTask" {
|
||||
flow.ApproverId = pass.NextNodeAdminId
|
||||
flow.PassStatus = 1 //1待处理
|
||||
} else if v.Type == "bpmn:endEvent" {
|
||||
isEnd = true
|
||||
flow.ApproverId = 0
|
||||
flow.PassStatus = 2 //2通过
|
||||
}
|
||||
flows = append(flows, flow)
|
||||
}
|
||||
|
||||
err = Service.db.Transaction(func(tx *gorm.DB) error {
|
||||
// 在事务中执行一些 db 操作(从这里开始,您应该使用 'tx' 而不是 'db')
|
||||
if err := tx.Create(&flows).Error; err != nil {
|
||||
// 返回任何错误都会回滚事务
|
||||
return err
|
||||
}
|
||||
// LastHistory
|
||||
tx.Model(&LastHistory).Update("pass_status", 2)
|
||||
if LastHistory.Id > 0 {
|
||||
LastHistory.PassStatus = 2
|
||||
LastHistory.PassRemark = pass.PassRemark
|
||||
tx.Save(&LastHistory)
|
||||
}
|
||||
|
||||
// 待提交或者有结束节点,修改申请状态
|
||||
if applyDetail.Status == 1 || isEnd {
|
||||
status := 2 //审批中
|
||||
if isEnd {
|
||||
status = 3 //审批通过
|
||||
}
|
||||
tx.Model(&model.FlowApply{}).Where(model.FlowApply{
|
||||
Id: pass.ApplyId,
|
||||
}).Update("status", status)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一批流程,直到审批或结束节点
|
||||
*/
|
||||
func (Service flowHistoryService) GetNextNode(ApplyId int) (res []FlowTree, apply flow_apply.FlowApplyResp, LastHistory model.FlowHistory, e error) {
|
||||
var applyDetail, err = flow_apply.Service.Detail(ApplyId)
|
||||
|
||||
if e = response.CheckErr(err, "获取审批申请失败"); e != nil {
|
||||
return
|
||||
}
|
||||
// 获取最后一条历史记录
|
||||
// var LastHistory model.FlowHistory
|
||||
result := Service.db.Where(model.FlowHistory{
|
||||
ApplyId: ApplyId,
|
||||
}).Limit(1).Last(&LastHistory)
|
||||
|
||||
// start
|
||||
var flowTree []FlowTree
|
||||
json.Unmarshal([]byte(applyDetail.FlowProcessDataList), &flowTree)
|
||||
var formValue map[string]interface{}
|
||||
|
||||
if result.RowsAffected == 1 { //有最新审批记录
|
||||
json.Unmarshal([]byte(LastHistory.FormValue), &formValue)
|
||||
|
||||
} else {
|
||||
json.Unmarshal([]byte(applyDetail.FormValue), &formValue)
|
||||
}
|
||||
|
||||
var next []FlowTree
|
||||
if result.RowsAffected == 0 {
|
||||
// if nextNode.CurrentNodeId == "" {
|
||||
for _, v := range flowTree {
|
||||
if v.Type == "bpmn:startEvent" {
|
||||
next = *v.Children
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, v := range flowTree {
|
||||
if v.Id == LastHistory.NodeId {
|
||||
next = *v.Children
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
var nextNodes []FlowTree
|
||||
res = DeepNextNode(nextNodes, &next, formValue)
|
||||
return res, applyDetail, LastHistory, e
|
||||
}
|
||||
|
||||
// 返回节点数组,最后一个节点为用户或结束节点
|
||||
func DeepNextNode(nextNodes []FlowTree, flowTree *[]FlowTree, formValue map[string]interface{}) []FlowTree {
|
||||
for _, v := range *flowTree {
|
||||
if v.Type == "bpmn:startEvent" {
|
||||
// 开始节点
|
||||
child := DeepNextNode(nextNodes, v.Children, formValue)
|
||||
nextNodes = append(nextNodes, child...)
|
||||
break
|
||||
} else if v.Type == "bpmn:exclusiveGateway" {
|
||||
// 网关
|
||||
|
||||
// 判断formValue值,决定是不是递归这个网关
|
||||
child := DeepNextNode(nextNodes, v.Children, formValue)
|
||||
nextNodes = append(nextNodes, v)
|
||||
nextNodes = append(nextNodes, child...)
|
||||
break
|
||||
} else if v.Type == "bpmn:serviceTask" {
|
||||
// 系统服务
|
||||
child := DeepNextNode(nextNodes, v.Children, formValue)
|
||||
nextNodes = append(nextNodes, v)
|
||||
nextNodes = append(nextNodes, child...)
|
||||
} else if v.Type == "bpmn:userTask" {
|
||||
//用户节点
|
||||
nextNodes = append(nextNodes, v)
|
||||
break
|
||||
} else if v.Type == "bpmn:endEvent" {
|
||||
// 结束节点
|
||||
nextNodes = append(nextNodes, v)
|
||||
break
|
||||
}
|
||||
}
|
||||
return nextNodes
|
||||
}
|
116
server/admin/flow/flow_template/flow_template_ctl.go
Normal file
116
server/admin/flow/flow_template/flow_template_ctl.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package flow_template
|
||||
|
||||
import (
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type FlowTemplateHandler struct{}
|
||||
|
||||
// @Summary 流程模板列表
|
||||
// @Tags flow_template-流程模板
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param flowName query string false "流程名称"
|
||||
// @Param flowGroup query int false "流程分类"
|
||||
// @Param flowRemark query string false "流程描述"
|
||||
// @Param flowFormData query string false "表单配置"
|
||||
// @Param flowProcessData query string false "流程配置"
|
||||
// @Success 200 {object} []FlowTemplateResp "成功"
|
||||
// @Failure 400 {object} string "请求错误"
|
||||
// @Router /api/flow_template/list [get]
|
||||
func (hd FlowTemplateHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq FlowTemplateListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程模板列表-所有
|
||||
// @Tags flow_template-流程模板
|
||||
// @Router /api/flow_template/listAll [get]
|
||||
func (hd FlowTemplateHandler) ListAll(c *gin.Context) {
|
||||
res, err := Service.ListAll()
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程模板详情
|
||||
// @Tags flow_template-流程模板
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id query int false "历史id"
|
||||
// @Success 200 {object} FlowTemplateResp "成功"
|
||||
// @Router /api/flow_template/detail [get]
|
||||
func (hd FlowTemplateHandler) Detail(c *gin.Context) {
|
||||
var detailReq FlowTemplateDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err := Service.Detail(detailReq.Id)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 流程模板新增
|
||||
// @Tags flow_template-流程模板
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param flowName body string false "流程名称"
|
||||
// @Param flowGroup body int false "流程分类"
|
||||
// @Param flowRemark body string false "流程描述"
|
||||
// @Param flowFormData body string false "表单配置"
|
||||
// @Param flowProcessData body string false "流程配置"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_template/add [post]
|
||||
func (hd FlowTemplateHandler) Add(c *gin.Context) {
|
||||
var addReq FlowTemplateAddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Add(addReq))
|
||||
}
|
||||
|
||||
// @Summary 流程模板编辑
|
||||
// @Tags flow_template-流程模板
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "."
|
||||
// @Param flowName body string false "流程名称"
|
||||
// @Param flowGroup body int false "流程分类"
|
||||
// @Param flowRemark body string false "流程描述"
|
||||
// @Param flowFormData body string false "表单配置"
|
||||
// @Param flowProcessData body string false "流程配置"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_template/edit [post]
|
||||
func (hd FlowTemplateHandler) Edit(c *gin.Context) {
|
||||
var editReq FlowTemplateEditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Edit(editReq))
|
||||
}
|
||||
|
||||
// @Summary 流程模板删除
|
||||
// @Tags flow_template-流程模板
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param id body int false "历史id"
|
||||
// @Success 200 {object} response.RespType "成功"
|
||||
// @Router /api/flow_template/del [post]
|
||||
func (hd FlowTemplateHandler) Del(c *gin.Context) {
|
||||
var delReq FlowTemplateDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyBody(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, Service.Del(delReq.Id))
|
||||
}
|
55
server/admin/flow/flow_template/flow_template_schema.go
Normal file
55
server/admin/flow/flow_template/flow_template_schema.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package flow_template
|
||||
|
||||
//FlowTemplateListReq 流程模板列表参数
|
||||
type FlowTemplateListReq struct {
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
}
|
||||
|
||||
//FlowTemplateDetailReq 流程模板详情参数
|
||||
type FlowTemplateDetailReq struct {
|
||||
Id int `form:"id"` //
|
||||
}
|
||||
|
||||
//FlowTemplateAddReq 流程模板新增参数
|
||||
type FlowTemplateAddReq struct {
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
|
||||
}
|
||||
|
||||
//FlowTemplateEditReq 流程模板新增参数
|
||||
type FlowTemplateEditReq struct {
|
||||
Id int `form:"id"` //
|
||||
FlowName string `form:"flowName"` // 流程名称
|
||||
FlowGroup int `form:"flowGroup"` // 流程分类
|
||||
FlowRemark string `form:"flowRemark"` // 流程描述
|
||||
FlowFormData string `form:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `form:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
|
||||
}
|
||||
|
||||
//FlowTemplateDelReq 流程模板新增参数
|
||||
type FlowTemplateDelReq struct {
|
||||
Id int `form:"id"` //
|
||||
}
|
||||
|
||||
//FlowTemplateResp 流程模板返回信息
|
||||
type FlowTemplateResp struct {
|
||||
Id int `json:"id" structs:"id"` //
|
||||
FlowName string `json:"flowName" structs:"flowName"` // 流程名称
|
||||
FlowGroup int `json:"flowGroup" structs:"flowGroup"` // 流程分类
|
||||
FlowRemark string `json:"flowRemark" structs:"flowRemark"` // 流程描述
|
||||
FlowFormData string `json:"flowFormData" structs:"flowFormData"` // 表单配置
|
||||
FlowProcessData string `json:"flowProcessData" structs:"flowProcessData"` // 流程配置
|
||||
FlowProcessDataList string `form:"flowProcessDataList"` // 流程配置list数据
|
||||
}
|
145
server/admin/flow/flow_template/flow_template_service.go
Normal file
145
server/admin/flow/flow_template/flow_template_service.go
Normal file
@@ -0,0 +1,145 @@
|
||||
package flow_template
|
||||
|
||||
import (
|
||||
"x_admin/core"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
"x_admin/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type IFlowTemplateService interface {
|
||||
List(page request.PageReq, listReq FlowTemplateListReq) (res response.PageResp, e error)
|
||||
ListAll() (res []FlowTemplateResp, e error)
|
||||
Detail(id int) (res FlowTemplateResp, e error)
|
||||
Add(addReq FlowTemplateAddReq) (e error)
|
||||
Edit(editReq FlowTemplateEditReq) (e error)
|
||||
Del(id int) (e error)
|
||||
}
|
||||
|
||||
var Service = NewFlowTemplateService()
|
||||
|
||||
// NewFlowTemplateService 初始化
|
||||
func NewFlowTemplateService() *flowTemplateService {
|
||||
db := core.GetDB()
|
||||
return &flowTemplateService{db: db}
|
||||
}
|
||||
|
||||
// flowTemplateService 流程模板服务实现类
|
||||
type flowTemplateService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// List 流程模板列表
|
||||
func (Service flowTemplateService) List(page request.PageReq, listReq FlowTemplateListReq) (res response.PageResp, e error) {
|
||||
// 分页信息
|
||||
limit := page.PageSize
|
||||
offset := page.PageSize * (page.PageNo - 1)
|
||||
// 查询
|
||||
dbModel := Service.db.Model(&model.FlowTemplate{})
|
||||
if listReq.FlowName != "" {
|
||||
dbModel = dbModel.Where("flow_name like ?", "%"+listReq.FlowName+"%")
|
||||
}
|
||||
if listReq.FlowGroup > 0 {
|
||||
dbModel = dbModel.Where("flow_group = ?", listReq.FlowGroup)
|
||||
}
|
||||
if listReq.FlowRemark != "" {
|
||||
dbModel = dbModel.Where("flow_remark = ?", listReq.FlowRemark)
|
||||
}
|
||||
if listReq.FlowFormData != "" {
|
||||
dbModel = dbModel.Where("flow_form_data = ?", listReq.FlowFormData)
|
||||
}
|
||||
if listReq.FlowProcessData != "" {
|
||||
dbModel = dbModel.Where("flow_process_data = ?", listReq.FlowProcessData)
|
||||
}
|
||||
// 总数
|
||||
var count int64
|
||||
err := dbModel.Count(&count).Error
|
||||
if e = response.CheckErr(err, "List Count err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 数据
|
||||
var objs []model.FlowTemplate
|
||||
err = dbModel.Limit(limit).Offset(offset).Order("id desc").Find(&objs).Error
|
||||
if e = response.CheckErr(err, "List Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
resps := []FlowTemplateResp{}
|
||||
response.Copy(&resps, objs)
|
||||
return response.PageResp{
|
||||
PageNo: page.PageNo,
|
||||
PageSize: page.PageSize,
|
||||
Count: count,
|
||||
Lists: resps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListAll 流程模板列表
|
||||
func (Service flowTemplateService) ListAll() (res []FlowTemplateResp, e error) {
|
||||
var objs []model.FlowTemplate
|
||||
err := Service.db.Find(&objs).Error
|
||||
if e = response.CheckErr(err, "ListAll Find err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, objs)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Detail 流程模板详情
|
||||
func (Service flowTemplateService) Detail(id int) (res FlowTemplateResp, e error) {
|
||||
var obj model.FlowTemplate
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Detail First err"); e != nil {
|
||||
return
|
||||
}
|
||||
response.Copy(&res, obj)
|
||||
return
|
||||
}
|
||||
|
||||
// Add 流程模板新增
|
||||
func (Service flowTemplateService) Add(addReq FlowTemplateAddReq) (e error) {
|
||||
var obj model.FlowTemplate
|
||||
response.Copy(&obj, addReq)
|
||||
err := Service.db.Create(&obj).Error
|
||||
e = response.CheckErr(err, "Add Create err")
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 流程模板编辑
|
||||
func (Service flowTemplateService) Edit(editReq FlowTemplateEditReq) (e error) {
|
||||
var obj model.FlowTemplate
|
||||
err := Service.db.Where("id = ?", editReq.Id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Edit First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 更新
|
||||
response.Copy(&obj, editReq)
|
||||
err = Service.db.Model(&obj).Updates(obj).Error
|
||||
e = response.CheckErr(err, "Edit Updates err")
|
||||
return
|
||||
}
|
||||
|
||||
// Del 流程模板删除
|
||||
func (Service flowTemplateService) Del(id int) (e error) {
|
||||
var obj model.FlowTemplate
|
||||
err := Service.db.Where("id = ?", id).Limit(1).First(&obj).Error
|
||||
// 校验
|
||||
if e = response.CheckErrDBNotRecord(err, "数据不存在!"); e != nil {
|
||||
return
|
||||
}
|
||||
if e = response.CheckErr(err, "Del First err"); e != nil {
|
||||
return
|
||||
}
|
||||
// 删除
|
||||
err = Service.db.Delete(&obj).Error
|
||||
e = response.CheckErr(err, "Del Delete err")
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user