Files
mayfly-go/server/internal/msg/application/msg.go

45 lines
1.2 KiB
Go
Raw Normal View History

2021-09-11 14:04:09 +08:00
package application
import (
2023-10-10 17:39:46 +08:00
"mayfly-go/internal/msg/application/dto"
2023-07-03 21:42:04 +08:00
"mayfly-go/internal/msg/domain/entity"
"mayfly-go/internal/msg/domain/repository"
"mayfly-go/pkg/model"
"mayfly-go/pkg/ws"
"time"
2021-09-11 14:04:09 +08:00
)
type Msg interface {
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
2021-09-11 14:04:09 +08:00
Create(msg *entity.Msg)
// 创建消息并通过ws发送
2023-10-10 17:39:46 +08:00
CreateAndSend(la *model.LoginAccount, msg *dto.SysMsg)
2021-09-11 14:04:09 +08:00
}
2022-09-09 18:26:08 +08:00
func newMsgApp(msgRepo repository.Msg) Msg {
return &msgAppImpl{
msgRepo: msgRepo,
}
2021-09-11 14:04:09 +08:00
}
2022-09-09 18:26:08 +08:00
type msgAppImpl struct {
msgRepo repository.Msg
2021-09-11 14:04:09 +08:00
}
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
2021-09-11 14:04:09 +08:00
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
}
func (a *msgAppImpl) Create(msg *entity.Msg) {
a.msgRepo.Insert(msg)
}
2023-10-10 17:39:46 +08:00
func (a *msgAppImpl) CreateAndSend(la *model.LoginAccount, wmsg *dto.SysMsg) {
now := time.Now()
2023-10-10 17:39:46 +08:00
msg := &entity.Msg{Type: 2, Msg: wmsg.Msg, RecipientId: int64(la.Id), CreateTime: &now, CreatorId: la.Id, Creator: la.Username}
a.msgRepo.Insert(msg)
ws.SendJsonMsg(la.ClientUuid, wmsg)
}