mirror of
https://gitcode.com/flipped-aurora/gin-vue-admin.git
synced 2026-05-19 13:47:52 +00:00
普通工作流流动完成
This commit is contained in:
@@ -167,6 +167,25 @@ func StartWorkflow(c *gin.Context) {
|
||||
response.OkWithMessage("启动成功", c)
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 提交工作流
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /workflowProcess/completeWorkflowMove [post]
|
||||
func CompleteWorkflowMove(c *gin.Context) {
|
||||
business := c.Query("businessType")
|
||||
wfInfo := model.WorkflowBusinessStruct[business]()
|
||||
c.ShouldBindJSON(wfInfo)
|
||||
err := service.CompleteWorkflowMove(wfInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("启动成功", c)
|
||||
}
|
||||
|
||||
// @Tags WorkflowProcess
|
||||
// @Summary 我发起的工作流
|
||||
// @Security ApiKeyAuth
|
||||
|
||||
@@ -88,6 +88,7 @@ var Apis = []model.SysApi{
|
||||
{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: 78, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/getWorkflowMoveByID", "根据id获取当前节点详情和历史", "workflowProcess", "GET"},
|
||||
{global.GVA_MODEL{ID: 79, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/workflowProcess/completeWorkflowMove", "提交工作流", "workflowProcess", "POST"},
|
||||
}
|
||||
|
||||
func InitSysApi(db *gorm.DB) {
|
||||
|
||||
@@ -83,6 +83,7 @@ var Carbines = []gormadapter.CasbinRule{
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/getWorkflowProcessList", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/findWorkflowStep", V2: "GET"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/startWorkflow", V2: "POST"},
|
||||
{PType: "p", V0: "888", V1: "/workflowProcess/completeWorkflowMove", 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/getWorkflowMoveByID", V2: "GET"},
|
||||
|
||||
@@ -12,24 +12,29 @@ var WorkflowBusinessTable map[string]func() interface{}
|
||||
type GVA_Workflow interface {
|
||||
CreateWorkflowMove() *WorkflowMove
|
||||
GetBusinessType() string
|
||||
GetBusinessID() uint
|
||||
GetWorkflowBase() WorkflowBase
|
||||
}
|
||||
|
||||
type WorkflowBase struct {
|
||||
BusinessID uint `gorm:"<-:false;column:id"` // 业务对应ID(businessID)的返回
|
||||
WorkflowMoveID uint `json:"workflowMoveID" gorm:"-"`
|
||||
BusinessID uint `json:"businessID" 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:"-"`
|
||||
Param string `json:"param" gorm:"-"`
|
||||
Action string `json:"action" gorm:"-"`
|
||||
}
|
||||
|
||||
func (w WorkflowBase) CreateWorkflowMove() (businessModel *WorkflowMove) {
|
||||
return &WorkflowMove{
|
||||
GVA_MODEL: global.GVA_MODEL{ID: w.WorkflowMoveID},
|
||||
BusinessType: w.BusinessType,
|
||||
PromoterID: w.PromoterID,
|
||||
OperatorID: w.OperatorID,
|
||||
Param: w.Param,
|
||||
WorkflowProcessID: w.WorkflowProcessID,
|
||||
WorkflowNodeID: w.WorkflowNodeID,
|
||||
BusinessID: w.BusinessID,
|
||||
@@ -42,6 +47,10 @@ func (w WorkflowBase) GetBusinessType() (businessType string) {
|
||||
return w.BusinessType
|
||||
}
|
||||
|
||||
func (w WorkflowBase) GetBusinessID() (businessID uint) {
|
||||
return w.BusinessID
|
||||
}
|
||||
|
||||
func (w WorkflowBase) GetWorkflowBase() (workflowBase WorkflowBase) {
|
||||
return w
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ func InitWorkflowProcessRouter(Router *gin.RouterGroup) {
|
||||
WorkflowProcessRouter.GET("findWorkflowStep", v1.FindWorkflowStep) // 根据ID获取工作流步骤
|
||||
WorkflowProcessRouter.GET("getWorkflowProcessList", v1.GetWorkflowProcessList) // 获取WorkflowProcess列表
|
||||
WorkflowProcessRouter.POST("startWorkflow", v1.StartWorkflow) // 开启工作流
|
||||
WorkflowProcessRouter.POST("completeWorkflowMove", v1.CompleteWorkflowMove) // 提交工作流
|
||||
WorkflowProcessRouter.GET("getMyStated", v1.GetMyStated) // 获取我发起的工作流
|
||||
WorkflowProcessRouter.GET("getMyNeed", v1.GetMyNeed) // 获取我的待办
|
||||
WorkflowProcessRouter.GET("getWorkflowMoveByID", v1.GetWorkflowMoveByID) // 获取我的待办
|
||||
|
||||
@@ -190,19 +190,33 @@ func StartWorkflow(wfInterface model.GVA_Workflow) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
//func CompleteWorkflowNode(wfInterface model.GVA_Workflow)(err error){
|
||||
//
|
||||
//}
|
||||
func CompleteWorkflowMove(wfInterface model.GVA_Workflow) (err error) {
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
var txErr error
|
||||
tableName := getTable(wfInterface.GetBusinessType()).(schema.Tabler).TableName()
|
||||
txErr = tx.Table(tableName).Where("id = ?", wfInterface.GetBusinessID()).Updates(wfInterface).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
nowWorkflowMove := wfInterface.CreateWorkflowMove()
|
||||
txErr = complete(tx, nowWorkflowMove)
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
var returnWfm model.WorkflowMove
|
||||
var nodeInfo model.WorkflowNode
|
||||
var Edges []model.WorkflowEdge
|
||||
txErr := tx.First(&returnWfm, "business_type = ? and business_id = ? and workflow_process_id = ? and workflow_node_id = ? and is_active = ?", wfm.BusinessType, wfm.BusinessID, wfm.WorkflowProcessID, wfm.WorkflowNodeID, true).Error
|
||||
txErr := tx.First(&returnWfm, "id = ? AND is_active = ?", wfm.ID, true).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
txErr = tx.First(&nodeInfo, "ID = ?", wfm.WorkflowNodeID).Error
|
||||
txErr = tx.First(&nodeInfo, "id = ?", wfm.WorkflowNodeID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
@@ -216,20 +230,7 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
return errors.New("不存在当前节点为起点的后续流程")
|
||||
}
|
||||
if len(Edges) == 1 {
|
||||
//当前节点为初始节点时候
|
||||
if nodeInfo.Clazz == model.START {
|
||||
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).Update("operator_id", wfm.OperatorID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
}
|
||||
txErr = tx.Model(&returnWfm).Update("param", wfm.Param).Update("is_active", false).Update("action", wfm.Action).Update("operator_id", wfm.OperatorID).Error
|
||||
|
||||
newWfm := createNewWorkflowMove(&returnWfm, Edges[0].Target)
|
||||
txErr = tx.Create(newWfm).Error
|
||||
@@ -240,16 +241,20 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
}
|
||||
if len(Edges) > 1 {
|
||||
var needUseTargetNodeID string
|
||||
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
|
||||
}
|
||||
txErr = tx.Model(&returnWfm).Update("param", wfm.Param).Update("is_active", false).Update("action", wfm.Action).Update("operator_id", wfm.OperatorID).Error
|
||||
|
||||
for _, v := range Edges {
|
||||
if v.ConditionExpression == wfm.Param {
|
||||
needUseTargetNodeID = v.Target
|
||||
break
|
||||
}
|
||||
}
|
||||
if needUseTargetNodeID == "" {
|
||||
return errors.New("未发现流转参数,流转失败")
|
||||
}
|
||||
newWfm := createNewWorkflowMove(&returnWfm, needUseTargetNodeID)
|
||||
txErr = tx.Create(newWfm).Error
|
||||
if txErr != nil {
|
||||
@@ -270,6 +275,7 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
|
||||
}
|
||||
|
||||
func createNewWorkflowMove(oldWfm *model.WorkflowMove, targetNodeID string) (newWfm *model.WorkflowMove) {
|
||||
|
||||
return &model.WorkflowMove{
|
||||
BusinessID: oldWfm.BusinessID,
|
||||
BusinessType: oldWfm.BusinessType,
|
||||
@@ -277,6 +283,7 @@ func createNewWorkflowMove(oldWfm *model.WorkflowMove, targetNodeID string) (new
|
||||
OperatorID: 0,
|
||||
WorkflowNodeID: targetNodeID,
|
||||
WorkflowProcessID: oldWfm.WorkflowProcessID,
|
||||
Param: "",
|
||||
Action: "",
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user