mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-04 05:36:35 +08:00
feat: dbms新增支持工单流程审批
This commit is contained in:
12
server/internal/flow/api/form/procdef.go
Normal file
12
server/internal/flow/api/form/procdef.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package form
|
||||
|
||||
import "mayfly-go/internal/flow/domain/entity"
|
||||
|
||||
type Procdef struct {
|
||||
Id uint64 `json:"id"`
|
||||
Name string `json:"name" binding:"required"` // 名称
|
||||
DefKey string `json:"defKey" binding:"required"`
|
||||
Tasks string `json:"tasks" binding:"required"` // 审批节点任务信息
|
||||
Status entity.ProcdefStatus `json:"status" binding:"required"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
6
server/internal/flow/api/form/procinst.go
Normal file
6
server/internal/flow/api/form/procinst.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package form
|
||||
|
||||
type ProcinstTaskAudit struct {
|
||||
Id uint64 `json:"id" binding:"required"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
50
server/internal/flow/api/procdef.go
Normal file
50
server/internal/flow/api/procdef.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/flow/api/form"
|
||||
"mayfly-go/internal/flow/application"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/req"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Procdef struct {
|
||||
ProcdefApp application.Procdef `inject:""`
|
||||
}
|
||||
|
||||
func (p *Procdef) GetProcdefPage(rc *req.Ctx) {
|
||||
cond, page := req.BindQueryAndPage(rc, new(entity.Procdef))
|
||||
res, err := p.ProcdefApp.GetPageList(cond, page, new([]entity.Procdef))
|
||||
biz.ErrIsNil(err)
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (p *Procdef) GetProcdef(rc *req.Ctx) {
|
||||
defkey := rc.PathParam("key")
|
||||
biz.NotEmpty(defkey, "流程定义key不能为空")
|
||||
|
||||
procdef := &entity.Procdef{DefKey: defkey}
|
||||
biz.ErrIsNil(p.ProcdefApp.GetBy(procdef), "该流程定义不存在")
|
||||
rc.ResData = procdef
|
||||
}
|
||||
|
||||
func (a *Procdef) Save(rc *req.Ctx) {
|
||||
form := &form.Procdef{}
|
||||
procdef := req.BindJsonAndCopyTo(rc, form, new(entity.Procdef))
|
||||
rc.ReqParam = form
|
||||
biz.ErrIsNil(a.ProcdefApp.Save(rc.MetaCtx, procdef))
|
||||
}
|
||||
|
||||
func (p *Procdef) Delete(rc *req.Ctx) {
|
||||
idsStr := rc.PathParam("id")
|
||||
rc.ReqParam = idsStr
|
||||
ids := strings.Split(idsStr, ",")
|
||||
|
||||
for _, v := range ids {
|
||||
value, err := strconv.Atoi(v)
|
||||
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
|
||||
biz.ErrIsNilAppendErr(p.ProcdefApp.DeleteProcdef(rc.MetaCtx, uint64(value)), "删除失败:%s")
|
||||
}
|
||||
}
|
||||
99
server/internal/flow/api/procinst.go
Normal file
99
server/internal/flow/api/procinst.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/internal/common/consts"
|
||||
"mayfly-go/internal/flow/api/form"
|
||||
"mayfly-go/internal/flow/api/vo"
|
||||
"mayfly-go/internal/flow/application"
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"mayfly-go/internal/flow/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"mayfly-go/pkg/utils/structx"
|
||||
)
|
||||
|
||||
type Procinst struct {
|
||||
ProcinstApp application.Procinst `inject:""`
|
||||
ProcdefApp application.Procdef `inject:""`
|
||||
|
||||
ProcinstTaskRepo repository.ProcinstTask `inject:""`
|
||||
}
|
||||
|
||||
func (p *Procinst) GetProcinstPage(rc *req.Ctx) {
|
||||
cond, page := req.BindQueryAndPage(rc, new(entity.ProcinstQuery))
|
||||
// 非管理员只能获取自己申请的流程
|
||||
if laId := rc.GetLoginAccount().Id; laId != consts.AdminId {
|
||||
cond.CreatorId = laId
|
||||
}
|
||||
|
||||
res, err := p.ProcinstApp.GetPageList(cond, page, new([]entity.Procinst))
|
||||
biz.ErrIsNil(err)
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (p *Procinst) ProcinstCancel(rc *req.Ctx) {
|
||||
instId := uint64(rc.PathParamInt("id"))
|
||||
rc.ReqParam = instId
|
||||
biz.ErrIsNil(p.ProcinstApp.CancelProc(rc.MetaCtx, instId))
|
||||
}
|
||||
|
||||
func (p *Procinst) GetProcinstDetail(rc *req.Ctx) {
|
||||
pi, err := p.ProcinstApp.GetById(new(entity.Procinst), uint64(rc.PathParamInt("id")))
|
||||
biz.ErrIsNil(err, "流程实例不存在")
|
||||
pivo := new(vo.ProcinstVO)
|
||||
structx.Copy(pivo, pi)
|
||||
|
||||
// 流程定义信息
|
||||
procdef, _ := p.ProcdefApp.GetById(new(entity.Procdef), pi.ProcdefId)
|
||||
pivo.Procdef = procdef
|
||||
|
||||
// 流程实例任务信息
|
||||
instTasks := new([]*entity.ProcinstTask)
|
||||
biz.ErrIsNil(p.ProcinstTaskRepo.ListByCond(&entity.ProcinstTask{ProcinstId: pi.Id}, instTasks))
|
||||
pivo.ProcinstTasks = *instTasks
|
||||
|
||||
rc.ResData = pivo
|
||||
}
|
||||
|
||||
func (p *Procinst) GetTasks(rc *req.Ctx) {
|
||||
instTaskQuery, page := req.BindQueryAndPage(rc, new(entity.ProcinstTaskQuery))
|
||||
if laId := rc.GetLoginAccount().Id; laId != consts.AdminId {
|
||||
// 赋值操作人为当前登录账号
|
||||
instTaskQuery.Assignee = fmt.Sprintf("%d", rc.GetLoginAccount().Id)
|
||||
}
|
||||
|
||||
taskVos := new([]*vo.ProcinstTask)
|
||||
res, err := p.ProcinstApp.GetProcinstTasks(instTaskQuery, page, taskVos)
|
||||
biz.ErrIsNil(err)
|
||||
|
||||
instIds := collx.ArrayMap[*vo.ProcinstTask, uint64](*taskVos, func(val *vo.ProcinstTask) uint64 { return val.ProcinstId })
|
||||
insts := new([]*entity.Procinst)
|
||||
p.ProcinstApp.GetByIdIn(insts, instIds)
|
||||
instId2Inst := collx.ArrayToMap[*entity.Procinst, uint64](*insts, func(val *entity.Procinst) uint64 { return val.Id })
|
||||
|
||||
// 赋值任务对应的流程实例
|
||||
for _, task := range *taskVos {
|
||||
task.Procinst = instId2Inst[task.ProcinstId]
|
||||
}
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (p *Procinst) CompleteTask(rc *req.Ctx) {
|
||||
auditForm := req.BindJsonAndValid(rc, new(form.ProcinstTaskAudit))
|
||||
rc.ReqParam = auditForm
|
||||
biz.ErrIsNil(p.ProcinstApp.CompleteTask(rc.MetaCtx, auditForm.Id, auditForm.Remark))
|
||||
}
|
||||
|
||||
func (p *Procinst) RejectTask(rc *req.Ctx) {
|
||||
auditForm := req.BindJsonAndValid(rc, new(form.ProcinstTaskAudit))
|
||||
rc.ReqParam = auditForm
|
||||
biz.ErrIsNil(p.ProcinstApp.RejectTask(rc.MetaCtx, auditForm.Id, auditForm.Remark))
|
||||
}
|
||||
|
||||
func (p *Procinst) BackTask(rc *req.Ctx) {
|
||||
auditForm := req.BindJsonAndValid(rc, new(form.ProcinstTaskAudit))
|
||||
rc.ReqParam = auditForm
|
||||
biz.ErrIsNil(p.ProcinstApp.BackTask(rc.MetaCtx, auditForm.Id, auditForm.Remark))
|
||||
}
|
||||
45
server/internal/flow/api/vo/procinst.go
Normal file
45
server/internal/flow/api/vo/procinst.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package vo
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/flow/domain/entity"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ProcinstVO struct {
|
||||
Id uint64 `json:"id"`
|
||||
ProcdefId uint64 `json:"procdefId"` // 流程定义id
|
||||
ProcdefName string `json:"procdefName"` // 流程定义名称
|
||||
|
||||
BizType string `json:"bizType"` // 业务类型
|
||||
BizKey string `json:"bizKey"` // 业务key
|
||||
BizStatus int8 `json:"bizStatus"` // 业务状态
|
||||
BizHandleRes string `json:"bizHandleRes"` // 业务处理结果
|
||||
TaskKey string `json:"taskKey"` // 当前任务key
|
||||
Remark string `json:"remark"`
|
||||
Status int8 `json:"status"`
|
||||
EndTime *time.Time `json:"endTime"`
|
||||
Duration int64 `json:"duration"` // 持续时间(开始到结束)
|
||||
|
||||
Creator string `json:"creator"`
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
UpdateTime *time.Time `json:"updateTime"`
|
||||
|
||||
Procdef *entity.Procdef `json:"procdef"`
|
||||
ProcinstTasks []*entity.ProcinstTask `json:"procinstTasks"`
|
||||
}
|
||||
|
||||
type ProcinstTask struct {
|
||||
Id uint64 `json:"id"`
|
||||
ProcinstId uint64 `json:"procinstId"` // 流程实例id
|
||||
TaskKey string `json:"taskKey"` // 当前任务key
|
||||
TaskName string `json:"taskName"` // 当前任务名称
|
||||
Assignee string `json:"assignee"` // 分配到该任务的用户
|
||||
|
||||
Status entity.ProcinstTaskStatus `json:"status"` // 状态
|
||||
Remark string `json:"remark"`
|
||||
Duration int64 `json:"duration"` // 持续时间(开始到结束)
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
EndTime *time.Time `json:"endTime"`
|
||||
|
||||
Procinst *entity.Procinst `json:"procinst"`
|
||||
}
|
||||
Reference in New Issue
Block a user