mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
refactor: 消息模块调整 & 样式优化
This commit is contained in:
@@ -234,7 +234,7 @@ func (d *Db) DumpSql(rc *req.Ctx) {
|
||||
rc.GetWriter().Write([]byte(msg))
|
||||
global.EventBus.Publish(rc.MetaCtx, event.EventTopicMsgTmplSend, &msgdto.MsgTmplSendEvent{
|
||||
TmplChannel: msgdto.MsgTmplDbDumpFail,
|
||||
Params: collx.M{"error": msg},
|
||||
Params: collx.M{"dbId": dbConn.Info.Id, "dbName": dbConn.Info.Name, "error": msg},
|
||||
ReceiverIds: []uint64{la.Id},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func (d *dbSqlExecAppImpl) ExecReader(ctx context.Context, execReader *dto.SqlRe
|
||||
|
||||
msgEvent := &msgdto.MsgTmplSendEvent{
|
||||
TmplChannel: msgdto.MsgTmplSqlScriptRunSuccess,
|
||||
Params: collx.M{"filename": filename, "db": dbConn.Info.GetLogDesc()},
|
||||
Params: collx.M{"filename": filename, "dbId": dbConn.Info.Id, "dbName": dbConn.Info.Name},
|
||||
}
|
||||
|
||||
progressMsgEvent := &msgdto.MsgTmplSendEvent{
|
||||
|
||||
@@ -2,7 +2,7 @@ package dbi
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/logx"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"mayfly-go/pkg/utils/stringx"
|
||||
"strings"
|
||||
@@ -98,7 +98,10 @@ func GetLocalSql(file, key string) string {
|
||||
}
|
||||
|
||||
bytes, err := metasql.ReadFile(file)
|
||||
biz.ErrIsNilAppendErr(err, "failed to get the contents of the sql meta file: %s")
|
||||
if err != nil {
|
||||
logx.Error("failed to read sql metadata file: %s, err: %v", file, err)
|
||||
return ""
|
||||
}
|
||||
allSql := string(bytes)
|
||||
|
||||
sqls := strings.Split(allSql, "---------------------------------------")
|
||||
|
||||
@@ -103,17 +103,24 @@ func (u *UserTaskNodeBehavior) Execute(ctx *ExecutionCtx) error {
|
||||
|
||||
// 用户账号类型
|
||||
if !strings.Contains(candidate, ":") {
|
||||
params := map[string]any{
|
||||
"creator": procinst.Creator,
|
||||
"procdefName": procinst.ProcdefName,
|
||||
"bizKey": procinst.BizKey,
|
||||
"taskName": flowNode.Name,
|
||||
"procinstRemark": procinst.Remark,
|
||||
}
|
||||
// 发送通知消息
|
||||
global.EventBus.Publish(ctx, event.EventTopicBizMsgTmplSend, msgdto.BizMsgTmplSend{
|
||||
BizType: FlowTaskNotifyBizKey,
|
||||
BizId: procinst.ProcdefId,
|
||||
Params: map[string]any{
|
||||
"creator": procinst.Creator,
|
||||
"procdefName": procinst.ProcdefName,
|
||||
"bizKey": procinst.BizKey,
|
||||
"taskName": flowNode.Name,
|
||||
"procinstRemark": procinst.Remark,
|
||||
},
|
||||
global.EventBus.Publish(context.Background(), event.EventTopicBizMsgTmplSend, &msgdto.BizMsgTmplSend{
|
||||
BizType: FlowTaskNotifyBizKey,
|
||||
BizId: procinst.ProcdefId,
|
||||
Params: params,
|
||||
ReceiverIds: []uint64{cast.ToUint64(candidate)},
|
||||
})
|
||||
|
||||
global.EventBus.Publish(context.Background(), event.EventTopicMsgTmplSend, &msgdto.MsgTmplSendEvent{
|
||||
TmplChannel: msgdto.MsgTmplFlowUserTaskTodo,
|
||||
Params: params,
|
||||
ReceiverIds: []uint64{cast.ToUint64(candidate)},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (p *procdefAppImpl) SaveProcdef(ctx context.Context, defParam *dto.SaveProc
|
||||
return p.Save(ctx, def)
|
||||
}, func(ctx context.Context) error {
|
||||
// 保存通知消息模板
|
||||
if err := p.msgTmplBizApp.SaveBizTmpl(ctx, msgdto.MsgTmplBizSave{
|
||||
if err := p.msgTmplBizApp.SaveBizTmpl(ctx, &msgdto.MsgTmplBizSave{
|
||||
TmplId: defParam.MsgTmplId,
|
||||
BizType: FlowTaskNotifyBizKey,
|
||||
BizId: def.Id,
|
||||
|
||||
@@ -287,7 +287,7 @@ func (m *MachineFile) UploadFile(rc *req.Ctx) {
|
||||
}
|
||||
if mi != nil {
|
||||
msgEvent.Params["machineName"] = mi.Name
|
||||
msgEvent.Params["machineIp"] = mi.Ip
|
||||
msgEvent.Params["machineCode"] = mi.Code
|
||||
}
|
||||
global.EventBus.Publish(ctx, event.EventTopicMsgTmplSend, msgEvent)
|
||||
|
||||
@@ -364,7 +364,7 @@ func (m *MachineFile) UploadFolder(rc *req.Ctx) {
|
||||
"filename": folderName,
|
||||
"path": basePath,
|
||||
"machineName": mi.Name,
|
||||
"machineIp": mi.Ip,
|
||||
"machineCode": mi.Code,
|
||||
},
|
||||
ReceiverIds: []uint64{rc.GetLoginAccount().Id},
|
||||
}
|
||||
|
||||
@@ -79,6 +79,12 @@ var (
|
||||
},
|
||||
Channels: []*entity.MsgChannel{MsgChannelWs},
|
||||
}
|
||||
|
||||
MsgTmplFlowUserTaskTodo = newMsgTmpl(entity.MsgTypeNotify,
|
||||
entity.MsgSubtypeFlowUserTaskTodo,
|
||||
entity.MsgStatusUnRead,
|
||||
imsg.FlowUserTaskTodoMsg,
|
||||
MsgChannelSite)
|
||||
)
|
||||
|
||||
func newMsgTmpl(mtype entity.MsgType, subtype entity.MsgSubtype, status entity.MsgStatus, msgId i18n.MsgId, channels ...*entity.MsgChannel) *MsgTmplChannel {
|
||||
|
||||
@@ -13,7 +13,7 @@ type MsgTmplBiz interface {
|
||||
base.App[*entity.MsgTmplBiz]
|
||||
|
||||
// SaveBizTmpl 保存消息模板关联业务信息
|
||||
SaveBizTmpl(ctx context.Context, bizTmpl dto.MsgTmplBizSave) error
|
||||
SaveBizTmpl(ctx context.Context, bizTmpl *dto.MsgTmplBizSave) error
|
||||
|
||||
// DeleteByBiz 根据业务删除消息模板业务关联
|
||||
DeleteByBiz(ctx context.Context, bizType string, bizId uint64) error
|
||||
@@ -22,7 +22,7 @@ type MsgTmplBiz interface {
|
||||
DeleteByTmplId(ctx context.Context, tmplId uint64) error
|
||||
|
||||
// Send 发送消息
|
||||
Send(ctx context.Context, sendParam dto.BizMsgTmplSend) error
|
||||
Send(ctx context.Context, sendParam *dto.BizMsgTmplSend) error
|
||||
}
|
||||
|
||||
type msgTmplBizAppImpl struct {
|
||||
@@ -33,7 +33,7 @@ type msgTmplBizAppImpl struct {
|
||||
|
||||
var _ (MsgTmplBiz) = (*msgTmplBizAppImpl)(nil)
|
||||
|
||||
func (m *msgTmplBizAppImpl) SaveBizTmpl(ctx context.Context, bizTmpl dto.MsgTmplBizSave) error {
|
||||
func (m *msgTmplBizAppImpl) SaveBizTmpl(ctx context.Context, bizTmpl *dto.MsgTmplBizSave) error {
|
||||
msgTmplId := bizTmpl.TmplId
|
||||
bizId := bizTmpl.BizId
|
||||
bizType := bizTmpl.BizType
|
||||
@@ -83,7 +83,7 @@ func (m *msgTmplBizAppImpl) DeleteByTmplId(ctx context.Context, tmplId uint64) e
|
||||
return m.DeleteByCond(ctx, &entity.MsgTmplBiz{TmplId: tmplId})
|
||||
}
|
||||
|
||||
func (m *msgTmplBizAppImpl) Send(ctx context.Context, sendParam dto.BizMsgTmplSend) error {
|
||||
func (m *msgTmplBizAppImpl) Send(ctx context.Context, sendParam *dto.BizMsgTmplSend) error {
|
||||
// 获取业务关联的消息模板
|
||||
msgTmplBiz := &entity.MsgTmplBiz{
|
||||
BizId: sendParam.BizId,
|
||||
|
||||
@@ -40,6 +40,9 @@ const (
|
||||
MsgSubtypeDbDumpFail MsgSubtype = "db.dump.fail"
|
||||
MsgSubtypeSqlScriptRunFail MsgSubtype = "db.sqlscript.run.fail"
|
||||
MsgSubtypeSqlScriptRunSuccess MsgSubtype = "db.sqlscript.run.success"
|
||||
|
||||
// flow
|
||||
MsgSubtypeFlowUserTaskTodo MsgSubtype = "flow.usertask.todo" // 用户任务待办
|
||||
)
|
||||
|
||||
type MsgStatus int8
|
||||
|
||||
@@ -12,10 +12,12 @@ var En = map[i18n.MsgId]string{
|
||||
|
||||
LoginMsg: "Log in to [{{.ip}}]-[{{.time}}]",
|
||||
|
||||
MachineFileUploadSuccessMsg: "[{{.filename}}] -> {{.machineName}}[{{.machineIp}}:{{.path}}]",
|
||||
MachineFileUploadFailMsg: "[{{.filename}}] -> {{.machineName}}[{{.machineIp}}:{{.path}}]. error: {{.error}}",
|
||||
MachineFileUploadSuccessMsg: "[{{.filename}}] -> <machine-info code={{.machineCode}}>{{.machineName}}</machine-info> [{{.path}}]",
|
||||
MachineFileUploadFailMsg: "[{{.filename}}] -> <machine-info code={{.machineCode}}>{{.machineName}}</machine-info> [{{.path}}]. error: {{.error}}",
|
||||
|
||||
DbDumpFailMsg: "Database dump failed, error: {{.error}}",
|
||||
SqlScriptRunFailMsg: "Script {{.filename}} execution failed on database {{.db}}, error: {{.error}}",
|
||||
SqlScriptRunSuccessMsg: "Script {{.filename}} executed successfully on database {{.db}}, cost {{.cost}}",
|
||||
DbDumpFailMsg: "Database [<db-info id={{.dbId}}>{{.dbName}}</db-info>] dump failed, error: <error-text>{{.error}}</error-text>",
|
||||
SqlScriptRunFailMsg: "Script {{.filename}} execution failed on database [<db-info id={{.dbId}}>{{.dbName}}</db-info>], error: <error-text>{{.error}}</error-text>",
|
||||
SqlScriptRunSuccessMsg: "Script {{.filename}} executed successfully on database [<db-info id={{.dbId}}>{{.dbName}}</db-info>], cost {{.cost}}",
|
||||
|
||||
FlowUserTaskTodoMsg: "Work order [{{.procdefName}}] submitted by [{{.creator}}] is now at [{{.taskName}}] node. Please process it promptly. <a href='#/flow/procinst-tasks'>Handle it >>></a>",
|
||||
}
|
||||
|
||||
@@ -26,4 +26,6 @@ const (
|
||||
DbDumpFailMsg
|
||||
SqlScriptRunFailMsg
|
||||
SqlScriptRunSuccessMsg
|
||||
|
||||
FlowUserTaskTodoMsg
|
||||
)
|
||||
|
||||
@@ -12,10 +12,12 @@ var Zh_CN = map[i18n.MsgId]string{
|
||||
|
||||
LoginMsg: "于[{{.ip}}]-[{{.time}}]登录",
|
||||
|
||||
MachineFileUploadSuccessMsg: "[{{.filename}}] -> {{.machineName}}[{{.machineIp}}:{{.path}}]",
|
||||
MachineFileUploadFailMsg: "[{{.filename}}] -> {{.machineName}}[{{.machineIp}}:{{.path}}]。错误信息:{{.error}}",
|
||||
MachineFileUploadSuccessMsg: "[{{.filename}}] -> <machine-info code={{.machineCode}}>{{.machineName}}</machine-info>【{{.path}}】",
|
||||
MachineFileUploadFailMsg: "[{{.filename}}] -> <machine-info code={{.machineCode}}>{{.machineName}}</machine-info>【{{.path}}】。错误信息:<error-text>{{.error}}</error-text>",
|
||||
|
||||
DbDumpFailMsg: "数据库dump失败,错误信息:{{.error}}",
|
||||
SqlScriptRunFailMsg: "数据库 {{.db}} 的脚本 {{.filename}} 执行失败,错误:{{.error}}",
|
||||
SqlScriptRunSuccessMsg: "数据库 {{.db}} 的脚本 {{.filename}} 执行成功,耗时 {{.cost}}",
|
||||
DbDumpFailMsg: "数据库【<db-info id={{.dbId}}>{{.dbName}}</db-info>】导出失败,错误信息:<error-text>{{.error}}</error-text>",
|
||||
SqlScriptRunFailMsg: "数据库【<db-info id={{.dbId}}>{{.dbName}}</db-info>】的脚本 {{.filename}} 执行失败,错误:<error-text>{{.error}}</error-text>",
|
||||
SqlScriptRunSuccessMsg: "数据库【<db-info id={{.dbId}}>{{.dbName}}</db-info>】的脚本 {{.filename}} 执行成功,耗时 {{.cost}}",
|
||||
|
||||
FlowUserTaskTodoMsg: "【{{.creator}}】提交的流程【{{.procdefName}}】已进入【{{.taskName}}】节点,请及时处理,去处理 <a href='#/flow/procinst-tasks'> >>></a>",
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"mayfly-go/pkg/eventbus"
|
||||
"mayfly-go/pkg/global"
|
||||
"mayfly-go/pkg/ioc"
|
||||
"mayfly-go/pkg/logx"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -29,15 +30,17 @@ func Init() {
|
||||
msgx.RegisterMsgSender(msgx.ChannelTypeSiteMsg, application.GetMsgApp())
|
||||
|
||||
msgTmplBizApp := ioc.Get[application.MsgTmplBiz]("MsgTmplBizApp")
|
||||
|
||||
global.EventBus.SubscribeAsync(event.EventTopicBizMsgTmplSend, "BizMsgTmplSend", func(ctx context.Context, event *eventbus.Event[any]) error {
|
||||
return msgTmplBizApp.Send(ctx, event.Val.(dto.BizMsgTmplSend))
|
||||
return msgTmplBizApp.Send(ctx, event.Val.(*dto.BizMsgTmplSend))
|
||||
}, false)
|
||||
|
||||
msgTmplApp := ioc.Get[application.MsgTmpl]("MsgTmplApp")
|
||||
|
||||
global.EventBus.SubscribeAsync(event.EventTopicMsgTmplSend, "MsgTmplSend", func(ctx context.Context, event *eventbus.Event[any]) error {
|
||||
eventVal := event.Val.(*dto.MsgTmplSendEvent)
|
||||
eventVal, ok := event.Val.(*dto.MsgTmplSendEvent)
|
||||
if !ok {
|
||||
logx.Error("the event value is not of type *dto.MsgTmplSendEvent")
|
||||
return nil
|
||||
}
|
||||
return msgTmplApp.SendMsg(ctx, &dto.MsgTmplSend{
|
||||
Tmpl: eventVal.TmplChannel.Tmpl,
|
||||
Channels: eventVal.TmplChannel.Channels,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type MsgType int8
|
||||
@@ -70,18 +71,18 @@ type MsgSender interface {
|
||||
Send(ctx context.Context, channel *Channel, msg *Msg) error
|
||||
}
|
||||
|
||||
var messageSenders = make(map[ChannelType]MsgSender)
|
||||
var messageSenders sync.Map
|
||||
|
||||
// RegisterMsgSender 注册消息发送器
|
||||
func RegisterMsgSender(channel ChannelType, sender MsgSender) {
|
||||
messageSenders[channel] = sender
|
||||
messageSenders.Store(channel, sender)
|
||||
}
|
||||
|
||||
// GetMsgSender 获取消息发送器
|
||||
func GetMsgSender(channel ChannelType) (MsgSender, error) {
|
||||
sender, ok := messageSenders[channel]
|
||||
sender, ok := messageSenders.Load(channel)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported message channel %s", channel)
|
||||
}
|
||||
return sender, nil
|
||||
return sender.(MsgSender), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user