mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: 机器计划任务与流程定义关联至标签
This commit is contained in:
@@ -4,29 +4,47 @@ import (
|
||||
"context"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/internal/flow/domain/repository"
|
||||
tagapp "mayfly-go/internal/tag/application"
|
||||
tagentity "mayfly-go/internal/tag/domain/entity"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type SaveProcdefParam struct {
|
||||
Procdef *entity.Procdef
|
||||
CodePaths []string
|
||||
}
|
||||
|
||||
type Procdef interface {
|
||||
base.App[*entity.Procdef]
|
||||
|
||||
GetPageList(condition *entity.Procdef, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
// 保存流程实例信息
|
||||
Save(ctx context.Context, def *entity.Procdef) error
|
||||
SaveProcdef(ctx context.Context, def *SaveProcdefParam) error
|
||||
|
||||
// 删除流程实例信息
|
||||
DeleteProcdef(ctx context.Context, defId uint64) error
|
||||
|
||||
// GetProcdefIdByCodePath 根据资源编号路径获取对应的流程定义id
|
||||
GetProcdefIdByCodePath(ctx context.Context, codePaths ...string) uint64
|
||||
|
||||
// GetProcdefByResource 根据资源获取对应的流程定义
|
||||
GetProcdefByResource(ctx context.Context, resourceType int8, resourceCode string) *entity.Procdef
|
||||
}
|
||||
|
||||
type procdefAppImpl struct {
|
||||
base.AppImpl[*entity.Procdef, repository.Procdef]
|
||||
|
||||
procinstApp Procinst `inject:"ProcinstApp"`
|
||||
|
||||
tagTreeApp tagapp.TagTree `inject:"TagTreeApp"`
|
||||
tagTreeRelateApp tagapp.TagTreeRelate `inject:"TagTreeRelateApp"`
|
||||
}
|
||||
|
||||
var _ (Procdef) = (*procdefAppImpl)(nil)
|
||||
|
||||
// 注入repo
|
||||
func (p *procdefAppImpl) InjectProcdefRepo(procdefRepo repository.Procdef) {
|
||||
p.Repo = procdefRepo
|
||||
@@ -36,24 +54,29 @@ func (p *procdefAppImpl) GetPageList(condition *entity.Procdef, pageParam *model
|
||||
return p.Repo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *procdefAppImpl) Save(ctx context.Context, def *entity.Procdef) error {
|
||||
func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *SaveProcdefParam) error {
|
||||
def := defParam.Procdef
|
||||
if err := entity.ProcdefStatusEnum.Valid(def.Status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if def.Id == 0 {
|
||||
if p.GetByCond(&entity.Procdef{DefKey: def.DefKey}) == nil {
|
||||
return errorx.NewBiz("该流程实例key已存在")
|
||||
}
|
||||
return p.Insert(ctx, def)
|
||||
} else {
|
||||
// 防止误修改key
|
||||
def.DefKey = ""
|
||||
if err := p.canModify(def.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 防止误修改key
|
||||
def.DefKey = ""
|
||||
if err := p.canModify(def.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.UpdateById(ctx, def)
|
||||
return p.Tx(ctx, func(ctx context.Context) error {
|
||||
return p.Save(ctx, def)
|
||||
}, func(ctx context.Context) error {
|
||||
return p.tagTreeRelateApp.RelateTag(ctx, tagentity.TagRelateTypeFlowDef, def.Id, defParam.CodePaths...)
|
||||
})
|
||||
}
|
||||
|
||||
func (p *procdefAppImpl) DeleteProcdef(ctx context.Context, defId uint64) error {
|
||||
@@ -63,6 +86,31 @@ func (p *procdefAppImpl) DeleteProcdef(ctx context.Context, defId uint64) error
|
||||
return p.DeleteById(ctx, defId)
|
||||
}
|
||||
|
||||
func (p *procdefAppImpl) GetProcdefIdByCodePath(ctx context.Context, codePaths ...string) uint64 {
|
||||
relateIds, err := p.tagTreeRelateApp.GetRelateIds(ctx, tagentity.TagRelateTypeFlowDef, codePaths...)
|
||||
if err != nil || len(relateIds) == 0 {
|
||||
return 0
|
||||
}
|
||||
return relateIds[len(relateIds)-1]
|
||||
}
|
||||
|
||||
func (p *procdefAppImpl) GetProcdefByResource(ctx context.Context, resourceType int8, resourceCode string) *entity.Procdef {
|
||||
resourceCodePaths := p.tagTreeApp.ListTagPathByTypeAndCode(resourceType, resourceCode)
|
||||
procdefId := p.GetProcdefIdByCodePath(ctx, resourceCodePaths...)
|
||||
if procdefId == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
procdef, err := p.GetById(procdefId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if procdef.Status == entity.ProcdefStatusDisable {
|
||||
return nil
|
||||
}
|
||||
return procdef
|
||||
}
|
||||
|
||||
// 判断该流程实例是否可以执行修改操作
|
||||
func (p *procdefAppImpl) canModify(prodefId uint64) error {
|
||||
if activeInstCount := p.procinstApp.CountByCond(&entity.Procinst{ProcdefId: prodefId, Status: entity.ProcinstStatusActive}); activeInstCount > 0 {
|
||||
|
||||
Reference in New Issue
Block a user