feat: message notify

This commit is contained in:
meilin.huang
2025-04-15 21:42:31 +08:00
parent 3c0292b56e
commit 1b40d345eb
104 changed files with 2681 additions and 288 deletions

View File

@@ -4,4 +4,6 @@ import "mayfly-go/pkg/ioc"
func InitIoc() {
ioc.Register(new(Msg))
ioc.Register(new(MsgChannel))
ioc.Register(new(MsgTmpl))
}

View File

@@ -0,0 +1,35 @@
package form
import (
"mayfly-go/internal/msg/msgx"
"mayfly-go/pkg/model"
)
type MsgChannel struct {
model.ExtraData
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required"`
Url string `json:"url"`
Remark string `json:"remark"`
Status int8 `json:"status" binding:"required"`
}
type MsgTmpl struct {
model.ExtraData
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"`
Title string `json:"title"`
Tmpl string `json:"tmpl" binding:"required"`
MsgType msgx.MsgType `json:"msgType" binding:"required"`
Remark string `json:"remark"`
Status int8 `json:"status" binding:"required"`
ChannelIds []uint64 `json:"channelIds"`
}
type SendMsg struct {
Parmas string `json:"params"`
ReceiverIds []uint64 `json:"receiverIds"`
}

View File

@@ -0,0 +1,54 @@
package api
import (
"mayfly-go/internal/msg/api/form"
"mayfly-go/internal/msg/application"
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/internal/msg/imsg"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"strings"
"github.com/may-fly/cast"
)
type MsgChannel struct {
msgChannelApp application.MsgChannel `inject:"T"`
}
func (m *MsgChannel) ReqConfs() *req.Confs {
basePermCode := "msg:channel:base"
reqs := [...]*req.Conf{
req.NewGet("", m.GetMsgChannels).RequiredPermissionCode(basePermCode),
req.NewPost("", m.SaveMsgChannels).Log(req.NewLogSaveI(imsg.LogMsgChannelSave)).RequiredPermissionCode("msg:channel:save"),
req.NewDelete("", m.DelMsgChannels).Log(req.NewLogSaveI(imsg.LogMsgChannelDelete)).RequiredPermissionCode("msg:channel:del"),
}
return req.NewConfs("/msg/channels", reqs[:]...)
}
func (m *MsgChannel) GetMsgChannels(rc *req.Ctx) {
condition := &entity.MsgChannel{}
res, err := m.msgChannelApp.GetPageList(condition, rc.GetPageParam(), new([]entity.MsgChannel))
biz.ErrIsNil(err)
rc.ResData = res
}
func (m *MsgChannel) SaveMsgChannels(rc *req.Ctx) {
form := &form.MsgChannel{}
rc.ReqParam = form
channel := req.BindJsonAndCopyTo(rc, form, new(entity.MsgChannel))
err := m.msgChannelApp.SaveChannel(rc.MetaCtx, channel)
biz.ErrIsNil(err)
}
func (m *MsgChannel) DelMsgChannels(rc *req.Ctx) {
idsStr := rc.Query("id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
biz.ErrIsNil(m.msgChannelApp.DeleteChannel(rc.MetaCtx, cast.ToUint64(v)))
}
}

View File

@@ -0,0 +1,86 @@
package api
import (
"mayfly-go/internal/msg/api/form"
"mayfly-go/internal/msg/application"
"mayfly-go/internal/msg/application/dto"
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/internal/msg/imsg"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/collx"
"mayfly-go/pkg/utils/jsonx"
"strings"
"github.com/may-fly/cast"
)
type MsgTmpl struct {
msgTmplApp application.MsgTmpl `inject:"T"`
}
func (m *MsgTmpl) ReqConfs() *req.Confs {
basePermCode := "msg:tmpl:base"
reqs := [...]*req.Conf{
req.NewGet("", m.GetMsgTmpls).RequiredPermissionCode(basePermCode),
req.NewGet(":id/channels", m.GetMsgTmplChannels).RequiredPermissionCode(basePermCode),
req.NewPost("", m.SaveMsgTmpl).Log(req.NewLogSaveI(imsg.LogMsgTmplSave)).RequiredPermissionCode("msg:tmpl:save"),
req.NewDelete("", m.DelMsgTmpls).Log(req.NewLogSaveI(imsg.LogMsgTmplDelete)).RequiredPermissionCode("msg:tmpl:del"),
req.NewPost(":code/send", m.SendMsg).Log(req.NewLogSaveI(imsg.LogMsgTmplSave)).RequiredPermissionCode("msg:tmpl:send"),
}
return req.NewConfs("/msg/tmpls", reqs[:]...)
}
func (m *MsgTmpl) GetMsgTmpls(rc *req.Ctx) {
condition := &entity.MsgTmpl{
Code: rc.Query("code"),
}
condition.Id = cast.ToUint64(rc.QueryInt("id"))
res, err := m.msgTmplApp.GetPageList(condition, rc.GetPageParam(), new([]entity.MsgTmpl))
biz.ErrIsNil(err)
rc.ResData = res
}
func (m *MsgTmpl) GetMsgTmplChannels(rc *req.Ctx) {
channels, err := m.msgTmplApp.GetTmplChannels(rc.MetaCtx, cast.ToUint64(rc.PathParamInt("id")))
biz.ErrIsNil(err)
rc.ResData = collx.ArrayMap(channels, func(val *entity.MsgChannel) collx.M {
return collx.M{
"id": val.Id,
"name": val.Name,
"type": val.Type,
"code": val.Code,
}
})
}
func (m *MsgTmpl) SaveMsgTmpl(rc *req.Ctx) {
form := &form.MsgTmpl{}
rc.ReqParam = form
channel := req.BindJsonAndCopyTo(rc, form, new(dto.MsgTmplSave))
biz.ErrIsNil(m.msgTmplApp.SaveTmpl(rc.MetaCtx, channel))
}
func (m *MsgTmpl) DelMsgTmpls(rc *req.Ctx) {
idsStr := rc.Query("id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
biz.ErrIsNil(m.msgTmplApp.DeleteTmpl(rc.MetaCtx, cast.ToUint64(v)))
}
}
func (m *MsgTmpl) SendMsg(rc *req.Ctx) {
code := rc.PathParam("code")
form := &form.SendMsg{}
req.BindJsonAndValid(rc, form)
rc.ReqParam = form
params, err := jsonx.ToMap(form.Parmas)
biz.ErrIsNil(err)
biz.ErrIsNil(m.msgTmplApp.Send(rc.MetaCtx, code, params, form.ReceiverIds...))
}