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"
|
2022-06-02 17:41:11 +08:00
|
|
|
|
"mayfly-go/pkg/model"
|
|
|
|
|
|
"mayfly-go/pkg/ws"
|
2021-11-11 15:56:02 +08:00
|
|
|
|
"time"
|
2021-09-11 14:04:09 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Msg interface {
|
2023-07-01 14:34:42 +08:00
|
|
|
|
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)
|
2021-11-11 15:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建消息,并通过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
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-01 14:34:42 +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)
|
|
|
|
|
|
}
|
2021-11-11 15:56:02 +08:00
|
|
|
|
|
2023-10-10 17:39:46 +08:00
|
|
|
|
func (a *msgAppImpl) CreateAndSend(la *model.LoginAccount, wmsg *dto.SysMsg) {
|
2021-11-11 15:56:02 +08:00
|
|
|
|
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}
|
2021-11-11 15:56:02 +08:00
|
|
|
|
a.msgRepo.Insert(msg)
|
2023-10-10 17:39:46 +08:00
|
|
|
|
ws.SendJsonMsg(la.Id, wmsg)
|
2021-11-11 15:56:02 +08:00
|
|
|
|
}
|