mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
增加获取工作流详细页面信息的接口和对应调用
This commit is contained in:
@@ -186,6 +186,7 @@ func GetMyStated(c *gin.Context) {
|
||||
errStr := err.Error()
|
||||
global.GVA_LOG.Error(errStr)
|
||||
response.FailWithMessage(errStr, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"wfms": wfms}, c)
|
||||
}
|
||||
@@ -210,7 +211,29 @@ func GetMyNeed(c *gin.Context) {
|
||||
errStr := err.Error()
|
||||
global.GVA_LOG.Error(errStr)
|
||||
response.FailWithMessage(errStr, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"wfms": wfms}, c)
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 根据id获取当前节点详情和历史
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "根据id获取当前节点详情和过往"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /workflowProcess/getWorkflowMoveByID [get]
|
||||
func GetWorkflowMoveByID(c *gin.Context) {
|
||||
var req request.GetById
|
||||
_ = c.ShouldBindQuery(&req)
|
||||
err, move, moves := service.GetWorkflowMoveByID(req.Id)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
global.GVA_LOG.Error(errStr)
|
||||
response.FailWithMessage(errStr, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"move": move, "moves": moves}, c)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,8 @@ var Apis = []model.SysApi{
|
||||
{global.GVA_MODEL{ID: 74, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/findWorkflowStep", "获取工作流步骤", "workflowProcess", "GET"},
|
||||
{global.GVA_MODEL{ID: 75, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/startWorkflow", "启动工作流", "workflowProcess", "POST"},
|
||||
{global.GVA_MODEL{ID: 76, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getMyStated", "获取我发起的工作流", "workflowProcess", "GET"},
|
||||
{global.GVA_MODEL{ID: 77, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/GetMyNeed", "获取我的待办", "workflowProcess", "GET"},
|
||||
{global.GVA_MODEL{ID: 77, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getMyNeed", "获取我的待办", "workflowProcess", "GET"},
|
||||
{global.GVA_MODEL{ID: 78, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getWorkflowMoveByID", "根据id获取当前节点详情和历史", "workflowProcess", "GET"},
|
||||
}
|
||||
|
||||
func InitSysApi(db *gorm.DB) {
|
||||
|
||||
@@ -84,7 +84,8 @@ var Carbines = []gormadapter.CasbinRule{
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/findWorkflowStep", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/startWorkflow", V2: "POST"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/getMyStated", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/GetMyNeed", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/getMyNeed", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowMoveByID", 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"},
|
||||
|
||||
+28
-19
@@ -20,6 +20,7 @@ type WorkflowBase struct {
|
||||
BusinessID uint `gorm:"<-:false;column:id"` // 业务对应ID(businessID)的返回
|
||||
BusinessType string `json:"businessType" gorm:"-"`
|
||||
PromoterID uint `json:"promoterID" gorm:"-"`
|
||||
OperatorID uint `json:"operatorID" gorm:"-"`
|
||||
WorkflowProcessID string `json:"workflowProcessID" gorm:"-"`
|
||||
WorkflowNodeID string `json:"workflowNodeID" gorm:"-"`
|
||||
Action string `json:"action" gorm:"-"`
|
||||
@@ -29,6 +30,7 @@ func (w WorkflowBase) CreateWorkflowMove() (businessModel *WorkflowMove) {
|
||||
return &WorkflowMove{
|
||||
BusinessType: w.BusinessType,
|
||||
PromoterID: w.PromoterID,
|
||||
OperatorID: w.OperatorID,
|
||||
WorkflowProcessID: w.WorkflowProcessID,
|
||||
WorkflowNodeID: w.WorkflowNodeID,
|
||||
BusinessID: w.BusinessID,
|
||||
@@ -52,29 +54,36 @@ func (w WorkflowBase) GetTableName() string {
|
||||
//定义clazz常量
|
||||
|
||||
const (
|
||||
USER_TASK string = "userTask"
|
||||
SCRIPT_TASK string = "scriptTask"
|
||||
RECEIVE_TASK string = "receiveTask"
|
||||
MAIL_TASK string = "mailTask"
|
||||
TIMER_START string = "timerStart"
|
||||
MESSAGE_START string = "messageStart"
|
||||
GATEWAY string = "gateway"
|
||||
FLOW string = "flow"
|
||||
START string = "start"
|
||||
END string = "end"
|
||||
PROCESS string = "process"
|
||||
USER_TASK string = "userTask"
|
||||
SCRIPT_TASK string = "scriptTask"
|
||||
RECEIVE_TASK string = "receiveTask"
|
||||
MAIL_TASK string = "mailTask"
|
||||
TIMER_START string = "timerStart"
|
||||
MESSAGE_START string = "messageStart"
|
||||
EXCLUSIVE_GATEWAY string = "exclusiveGateway" // 排他网关
|
||||
INCLUSIVE_GATEWAY string = "inclusiveGateway" // 包容网关
|
||||
PARELLEL_GATEWAY string = "parallelGateway" // 并行网关
|
||||
FLOW string = "flow"
|
||||
START string = "start"
|
||||
END string = "end"
|
||||
PROCESS string = "process"
|
||||
)
|
||||
|
||||
type WorkflowMove struct {
|
||||
global.GVA_MODEL
|
||||
WorkflowProcessID string `json:"workflowProcessID" gorm:"comment:工作流模板ID"`
|
||||
WorkflowNodeID string `json:"workflowNodeID" gorm:"comment:工作流节点ID"`
|
||||
BusinessType string `json:"businessType" gorm:"comment:业务标记"`
|
||||
BusinessID uint `json:"businessID" gorm:"comment:业务ID"`
|
||||
PromoterID uint `json:"promoterID" gorm:"comment:当前流转发起人"`
|
||||
Action string `json:"action" gorm:"comment:工作流驱动事件"`
|
||||
Param string `json:"param" gorm:"comment:工作流驱动参数"`
|
||||
IsActive bool `json:"isActive" gorm:"comment:是否是活跃节点 "`
|
||||
WorkflowProcessID string `json:"workflowProcessID" gorm:"comment:工作流模板ID"`
|
||||
WorkflowProcess WorkflowProcess `gorm:"<-:false" json:"workflowProcess" gorm:"comment:工作流模板具体信息"`
|
||||
WorkflowNodeID string `json:"workflowNodeID" gorm:"comment:工作流节点ID"`
|
||||
WorkflowNode WorkflowNode `gorm:"<-:false" json:"workflowNode" gorm:"comment:工作流节点具体信息"`
|
||||
BusinessType string `json:"businessType" gorm:"comment:业务标记"`
|
||||
BusinessID uint `json:"businessID" gorm:"comment:业务ID"`
|
||||
PromoterID uint `json:"promoterID" gorm:"comment:当前流转发起人"`
|
||||
Promoter SysUser `gorm:"<-:false" json:"promoter" gorm:"comment:当前流转发起人信息"`
|
||||
OperatorID uint `json:"operatorID" gorm:"comment:当前流转操作人"`
|
||||
Operator SysUser `gorm:"<-:false" json:"operator" gorm:"comment:当前流转操作人信息"`
|
||||
Action string `json:"action" gorm:"comment:工作流驱动事件"`
|
||||
Param string `json:"param" gorm:"comment:工作流驱动参数"`
|
||||
IsActive bool `json:"isActive" gorm:"comment:是否是活跃节点 "`
|
||||
}
|
||||
|
||||
type WorkflowProcess struct {
|
||||
|
||||
@@ -19,5 +19,6 @@ func InitWorkflowProcessRouter(Router *gin.RouterGroup) {
|
||||
WorkflowProcessRouter.POST("startWorkflow", v1.StartWorkflow) // 开启工作流
|
||||
WorkflowProcessRouter.GET("getMyStated", v1.GetMyStated) // 获取我发起的工作流
|
||||
WorkflowProcessRouter.GET("getMyNeed", v1.GetMyNeed) // 获取我的待办
|
||||
WorkflowProcessRouter.GET("getWorkflowMoveByID", v1.GetWorkflowMoveByID) // 获取我的待办
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gin-vue-admin/global"
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
@@ -42,7 +43,9 @@ func DeleteWorkflowProcess(workflowProcess model.WorkflowProcess) (err error) {
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
txErr = tx.Select("StartPoint", "EndPoint").Delete(&edges).Error
|
||||
if len(edges) > 0 {
|
||||
txErr = tx.Select("StartPoint", "EndPoint").Delete(&edges).Error
|
||||
}
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
@@ -209,14 +212,14 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
if len(Edges) == 1 {
|
||||
//当前节点为初始节点时候
|
||||
if nodeInfo.Clazz == model.START {
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).First(&model.WorkflowMove{}).Update("is_active", false).Error
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).First(&model.WorkflowMove{}).Update("is_active", false).Update("operator_id", wfm.OperatorID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
}
|
||||
//当前节点为流转节点时候
|
||||
if nodeInfo.Clazz == model.USER_TASK {
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).First(&model.WorkflowMove{}).Update("action", "complete").Update("is_active", false).Error
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).First(&model.WorkflowMove{}).Update("action", "complete").Update("is_active", false).Update("operator_id", wfm.OperatorID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
@@ -231,7 +234,7 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
}
|
||||
if len(Edges) > 1 {
|
||||
var needUseTargetNodeID string
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).Update("is_active", false).Error
|
||||
txErr = tx.Where("id = ?", returnWfm.ID).First(&model.WorkflowMove{}).Update("action", "complete").Update("is_active", false).Update("operator_id", wfm.OperatorID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
@@ -248,6 +251,12 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
}
|
||||
// 当target为自动节点时候 需要做一些事情 这里暂时先不处理 后续慢慢完善
|
||||
}
|
||||
} else if nodeInfo.Clazz == model.EXCLUSIVE_GATEWAY {
|
||||
return errors.New("目前只支持start节点和userTask功能,其他功能正在开发中")
|
||||
} else if nodeInfo.Clazz == model.INCLUSIVE_GATEWAY {
|
||||
return errors.New("目前只支持start节点和userTask功能,其他功能正在开发中")
|
||||
} else if nodeInfo.Clazz == model.PARELLEL_GATEWAY {
|
||||
return errors.New("目前只支持start节点和userTask功能,其他功能正在开发中")
|
||||
} else {
|
||||
return errors.New("目前只支持start节点和userTask功能,其他功能正在开发中")
|
||||
}
|
||||
@@ -259,6 +268,7 @@ func createNewWorkflowMove(oldWfm *model.WorkflowMove, targetNodeID string) (new
|
||||
BusinessID: oldWfm.BusinessID,
|
||||
BusinessType: oldWfm.BusinessType,
|
||||
PromoterID: oldWfm.PromoterID,
|
||||
OperatorID: 0,
|
||||
WorkflowNodeID: targetNodeID,
|
||||
WorkflowProcessID: oldWfm.WorkflowProcessID,
|
||||
Action: "",
|
||||
@@ -267,13 +277,30 @@ func createNewWorkflowMove(oldWfm *model.WorkflowMove, targetNodeID string) (new
|
||||
}
|
||||
|
||||
func GetMyStated(userID uint) (err error, wfms []model.WorkflowMove) {
|
||||
err = global.GVA_DB.Find(&wfms, "promoter_id = ? and is_active", userID, true).Error
|
||||
err = global.GVA_DB.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").Joins("INNER JOIN workflow_nodes as node ON workflow_moves.workflow_node_id = node.id").Find(&wfms, "promoter_id = ? and ( is_active = ? OR node.clazz = ?)", userID, true, "end").Error
|
||||
return err, wfms
|
||||
}
|
||||
|
||||
func GetMyNeed(userID uint, AuthorityID string) (err error, wfms []model.WorkflowMove) {
|
||||
user := "%," + strconv.Itoa(int(userID)) + ",%"
|
||||
auth := "%," + AuthorityID + ",%"
|
||||
err = global.GVA_DB.Joins("INNER JOIN workflow_nodes as node ON workflow_moves.workflow_node_id = node.id").Where("(node.assign_type = ? AND node.assign_value LIKE ? ) OR (node.assign_type = ? AND node.assign_value LIKE ? )", "user", user, "authority", auth).Find(&wfms).Error
|
||||
err = global.GVA_DB.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").Joins("INNER JOIN workflow_nodes as node ON workflow_moves.workflow_node_id = node.id").Where("is_active = ? AND (node.assign_type = ? AND node.assign_value LIKE ? ) OR (node.assign_type = ? AND node.assign_value LIKE ? )", true, "user", user, "authority", auth).Find(&wfms).Error
|
||||
return err, wfms
|
||||
}
|
||||
|
||||
func GetWorkflowMoveByID(id float64) (err error, move model.WorkflowMove, moves []model.WorkflowMove) {
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
var txErr error
|
||||
txErr = tx.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").First(&move, "id = ?", id).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
txErr = tx.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").Find(&moves, "business_id = ? AND business_type = ?", move.BusinessID, move.BusinessType).Error
|
||||
fmt.Println(moves)
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err, move, moves
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user