feat: i18n

This commit is contained in:
meilin.huang
2024-11-20 22:43:53 +08:00
parent 74ae031853
commit 99a746085b
308 changed files with 8177 additions and 3880 deletions

View File

@@ -11,8 +11,9 @@ import (
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/collx"
"strconv"
"strings"
"github.com/may-fly/cast"
)
type Procdef struct {
@@ -55,8 +56,6 @@ func (p *Procdef) Delete(rc *req.Ctx) {
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")
biz.ErrIsNilAppendErr(p.ProcdefApp.DeleteProcdef(rc.MetaCtx, cast.ToUint64(v)), "delete error: %s")
}
}

View File

@@ -54,7 +54,7 @@ func (p *Procinst) ProcinstCancel(rc *req.Ctx) {
func (p *Procinst) GetProcinstDetail(rc *req.Ctx) {
pi, err := p.ProcinstApp.GetById(uint64(rc.PathParamInt("id")))
biz.ErrIsNil(err, "流程实例不存在")
biz.ErrIsNil(err, "procinst not found")
pivo := new(vo.ProcinstVO)
structx.Copy(pivo, pi)

View File

@@ -36,7 +36,7 @@ func FlowBizHandle(ctx context.Context, bizHandleParam *BizHandleParam) (any, er
flowBizType := bizHandleParam.Procinst.BizType
if handler, ok := handlers[flowBizType]; !ok {
logx.Warnf("flow biz handler not found: bizType=%s", flowBizType)
return nil, errorx.NewBiz("业务处理器不存在")
return nil, errorx.NewBiz("flow biz handler not found")
} else {
return handler.FlowBizHandle(ctx, bizHandleParam)
}

View File

@@ -5,6 +5,7 @@ import (
"mayfly-go/internal/flow/application/dto"
"mayfly-go/internal/flow/domain/entity"
"mayfly-go/internal/flow/domain/repository"
"mayfly-go/internal/flow/imsg"
tagapp "mayfly-go/internal/tag/application"
tagentity "mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/base"
@@ -58,12 +59,12 @@ func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *dto.SaveProc
if def.Id == 0 {
if p.GetByCond(&entity.Procdef{DefKey: def.DefKey}) == nil {
return errorx.NewBiz("该流程实例key已存在")
return errorx.NewBizI(ctx, imsg.ErrProcdefKeyExist)
}
} else {
// 防止误修改key
def.DefKey = ""
if err := p.canModify(def.Id); err != nil {
if err := p.canModify(ctx, def.Id); err != nil {
return err
}
}
@@ -76,7 +77,7 @@ func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *dto.SaveProc
}
func (p *procdefAppImpl) DeleteProcdef(ctx context.Context, defId uint64) error {
if err := p.canModify(defId); err != nil {
if err := p.canModify(ctx, defId); err != nil {
return err
}
return p.DeleteById(ctx, defId)
@@ -105,12 +106,12 @@ func (p *procdefAppImpl) GetProcdefByResource(ctx context.Context, resourceType
}
// 判断该流程实例是否可以执行修改操作
func (p *procdefAppImpl) canModify(prodefId uint64) error {
func (p *procdefAppImpl) canModify(ctx context.Context, prodefId uint64) error {
if activeInstCount := p.procinstApp.CountByCond(&entity.Procinst{ProcdefId: prodefId, Status: entity.ProcinstStatusActive}); activeInstCount > 0 {
return errorx.NewBiz("存在运行中的流程实例,无法操作")
return errorx.NewBizI(ctx, imsg.ErrExistProcinstRunning)
}
if suspInstCount := p.procinstApp.CountByCond(&entity.Procinst{ProcdefId: prodefId, Status: entity.ProcinstStatusSuspended}); suspInstCount > 0 {
return errorx.NewBiz("存在挂起中的流程实例,无法操作")
return errorx.NewBizI(ctx, imsg.ErrExistProcinstSuspended)
}
return nil
}

View File

@@ -6,9 +6,11 @@ import (
"mayfly-go/internal/flow/application/dto"
"mayfly-go/internal/flow/domain/entity"
"mayfly-go/internal/flow/domain/repository"
"mayfly-go/internal/flow/imsg"
"mayfly-go/pkg/base"
"mayfly-go/pkg/contextx"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/i18n"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils/anyx"
@@ -65,11 +67,11 @@ func (p *procinstAppImpl) GetProcinstTasks(condition *entity.ProcinstTaskQuery,
func (p *procinstAppImpl) StartProc(ctx context.Context, procdefId uint64, reqParam *dto.StarProc) (*entity.Procinst, error) {
procdef, err := p.procdefApp.GetById(procdefId)
if err != nil {
return nil, errorx.NewBiz("流程实例[%d]不存在", procdefId)
return nil, errorx.NewBiz("procdef not found")
}
if procdef.Status != entity.ProcdefStatusEnable {
return nil, errorx.NewBiz("该流程定义非启用状态")
return nil, errorx.NewBizI(ctx, imsg.ErrProcdefNotEnable)
}
bizKey := reqParam.BizKey
@@ -99,22 +101,22 @@ func (p *procinstAppImpl) StartProc(ctx context.Context, procdefId uint64, reqPa
func (p *procinstAppImpl) CancelProc(ctx context.Context, procinstId uint64) error {
procinst, err := p.GetById(procinstId)
if err != nil {
return errorx.NewBiz("流程不存在")
return errorx.NewBiz("procinst not found")
}
la := contextx.GetLoginAccount(ctx)
if la == nil {
return errorx.NewBiz("未登录")
return errorx.NewBiz("no login")
}
if procinst.CreatorId != la.Id {
return errorx.NewBiz("只能取消自己创建的流程")
return errorx.NewBizI(ctx, imsg.ErrProcinstCancelSelf)
}
procinst.Status = entity.ProcinstStatusCancelled
procinst.BizStatus = entity.ProcinstBizStatusNo
procinst.SetEnd()
return p.Tx(ctx, func(ctx context.Context) error {
return p.cancelInstTasks(ctx, procinstId, "流程已取消")
return p.cancelInstTasks(ctx, procinstId, i18n.T(imsg.ErrProcinstCancelled))
}, func(ctx context.Context) error {
return p.Save(ctx, procinst)
}, func(ctx context.Context) error {
@@ -239,13 +241,13 @@ func (p *procinstAppImpl) triggerProcinstStatusChangeEvent(ctx context.Context,
if procinst.Status != entity.ProcinstStatusCompleted {
procinst.Status = entity.ProcinstStatusTerminated
procinst.SetEnd()
p.cancelInstTasks(ctx, procinst.Id, "业务处理失败")
p.cancelInstTasks(ctx, procinst.Id, i18n.T(imsg.ErrBizHandlerFail))
}
procinst.BizStatus = entity.ProcinstBizStatusFail
if procinst.BizHandleRes == "" {
procinst.BizHandleRes = err.Error()
} else {
logx.Errorf("流程业务[%s]处理失败: %v", procinst.BizKey, err.Error())
logx.Errorf("process business [%s] processing failed: %v", procinst.BizKey, err.Error())
}
return p.UpdateById(ctx, procinst)
}
@@ -265,12 +267,12 @@ func (p *procinstAppImpl) triggerProcinstStatusChangeEvent(ctx context.Context,
func (p *procinstAppImpl) getAndValidInstTask(ctx context.Context, instTaskId uint64) (*entity.ProcinstTask, error) {
instTask, err := p.procinstTaskRepo.GetById(instTaskId)
if err != nil {
return nil, errorx.NewBiz("流程实例任务不存在")
return nil, errorx.NewBiz("procinst not found")
}
la := contextx.GetLoginAccount(ctx)
if instTask.Assignee != fmt.Sprintf("%d", la.Id) {
return nil, errorx.NewBiz("当前用户不是任务处理人,无法完成任务")
return nil, errorx.NewBiz("the current user is not a task handler and cannot complete the task")
}
return instTask, nil

View File

@@ -0,0 +1,24 @@
package imsg
import "mayfly-go/pkg/i18n"
var En = map[i18n.MsgId]string{
LogProcdefSave: "ProcDef - Save",
LogProcdefDelete: "ProcDef - Delete",
ErrProcdefKeyExist: "the process instance key already exists",
ErrExistProcinstRunning: "There is a running process instance that cannot be manipulated",
ErrExistProcinstSuspended: "There is a pending process instance that cannot be manipulated",
// procinst
LogProcinstStart: "Process - Start",
LogProcinstCancel: "Process - Cancel",
LogCompleteTask: "Process - Completion of task",
LogRejectTask: "Process - Task rejection",
LogBackTask: "Process - Task rejection",
ErrProcdefNotEnable: "The process defines a non-enabled state",
ErrProcinstCancelSelf: "You can only cancel processes you initiated",
ErrProcinstCancelled: "Process has been cancelled",
ErrBizHandlerFail: "Business process failure",
}

View File

@@ -0,0 +1,32 @@
package imsg
import (
"mayfly-go/internal/common/consts"
"mayfly-go/pkg/i18n"
)
func init() {
i18n.AppendLangMsg(i18n.Zh_CN, Zh_CN)
i18n.AppendLangMsg(i18n.En, En)
}
const (
LogProcdefSave = iota + consts.ImsgNumFlow
LogProcdefDelete
ErrProcdefKeyExist
ErrExistProcinstRunning
ErrExistProcinstSuspended
// procinst
LogProcinstStart
LogProcinstCancel
LogCompleteTask
LogRejectTask
LogBackTask
ErrProcdefNotEnable
ErrProcinstCancelSelf
ErrProcinstCancelled
ErrBizHandlerFail
)

View File

@@ -0,0 +1,24 @@
package imsg
import "mayfly-go/pkg/i18n"
var Zh_CN = map[i18n.MsgId]string{
LogProcdefSave: "流程定义-保存",
LogProcdefDelete: "流程定义-删除",
ErrProcdefKeyExist: "该流程实例key已存在",
ErrExistProcinstRunning: "存在运行中的流程实例,无法操作",
ErrExistProcinstSuspended: "存在挂起中的流程实例,无法操作",
// procinst
LogProcinstStart: "流程-启动",
LogProcinstCancel: "流程-取消",
LogCompleteTask: "流程-任务完成",
LogRejectTask: "流程-任务拒绝",
LogBackTask: "流程-任务驳回",
ErrProcdefNotEnable: "该流程定义非启用状态",
ErrProcinstCancelSelf: "只能取消自己发起的流程",
ErrProcinstCancelled: "流程已取消",
ErrBizHandlerFail: "业务处理失败",
}

View File

@@ -2,6 +2,7 @@ package router
import (
"mayfly-go/internal/flow/api"
"mayfly-go/internal/flow/imsg"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ioc"
"mayfly-go/pkg/req"
@@ -20,9 +21,9 @@ func InitProcdefouter(router *gin.RouterGroup) {
req.NewGet("/:resourceType/:resourceCode", p.GetProcdef),
req.NewPost("", p.Save).Log(req.NewLogSave("流程定义-保存")).RequiredPermissionCode("flow:procdef:save"),
req.NewPost("", p.Save).Log(req.NewLogSaveI(imsg.LogProcdefSave)).RequiredPermissionCode("flow:procdef:save"),
req.NewDelete(":id", p.Delete).Log(req.NewLogSave("流程定义-删除")).RequiredPermissionCode("flow:procdef:del"),
req.NewDelete(":id", p.Delete).Log(req.NewLogSaveI(imsg.LogProcdefDelete)).RequiredPermissionCode("flow:procdef:del"),
}
req.BatchSetGroup(reqGroup, reqs[:])

View File

@@ -2,6 +2,7 @@ package router
import (
"mayfly-go/internal/flow/api"
"mayfly-go/internal/flow/imsg"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ioc"
"mayfly-go/pkg/req"
@@ -20,17 +21,17 @@ func InitProcinstRouter(router *gin.RouterGroup) {
req.NewGet("/:id", p.GetProcinstDetail),
req.NewPost("/start", p.ProcinstStart).Log(req.NewLogSave("流程-启动")),
req.NewPost("/start", p.ProcinstStart).Log(req.NewLogSaveI(imsg.LogProcinstStart)),
req.NewPost("/:id/cancel", p.ProcinstCancel).Log(req.NewLogSave("流程-取消")),
req.NewPost("/:id/cancel", p.ProcinstCancel).Log(req.NewLogSaveI(imsg.LogProcinstCancel)),
req.NewGet("/tasks", p.GetTasks),
req.NewPost("/tasks/complete", p.CompleteTask).Log(req.NewLogSave("流程-任务完成")),
req.NewPost("/tasks/complete", p.CompleteTask).Log(req.NewLogSaveI(imsg.LogCompleteTask)),
req.NewPost("/tasks/reject", p.RejectTask).Log(req.NewLogSave("流程-任务拒绝")),
req.NewPost("/tasks/reject", p.RejectTask).Log(req.NewLogSaveI(imsg.LogRejectTask)),
req.NewPost("/tasks/back", p.BackTask).Log(req.NewLogSave("流程-任务驳回")),
req.NewPost("/tasks/back", p.BackTask).Log(req.NewLogSaveI(imsg.LogBackTask)),
}
req.BatchSetGroup(reqGroup, reqs[:])