2021-09-11 14:04:09 +08:00
|
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2022-06-02 17:41:11 +08:00
|
|
|
|
"mayfly-go/internal/sys/domain/entity"
|
|
|
|
|
|
"mayfly-go/internal/sys/domain/repository"
|
|
|
|
|
|
"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-06-01 12:31:32 +08:00
|
|
|
|
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult
|
2021-09-11 14:04:09 +08:00
|
|
|
|
|
|
|
|
|
|
Create(msg *entity.Msg)
|
2021-11-11 15:56:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建消息,并通过ws发送
|
|
|
|
|
|
CreateAndSend(la *model.LoginAccount, msg *ws.Msg)
|
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-06-01 12:31:32 +08:00
|
|
|
|
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
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
|
|
|
|
|
|
|
|
|
|
func (a *msgAppImpl) CreateAndSend(la *model.LoginAccount, wmsg *ws.Msg) {
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
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.SendMsg(la.Id, wmsg)
|
|
|
|
|
|
}
|