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

44 lines
1.1 KiB
Go
Raw Normal View History

2021-09-11 14:04:09 +08:00
package application
import (
"mayfly-go/internal/sys/domain/entity"
"mayfly-go/internal/sys/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 interface{}, orderBy ...string) *model.PageResult
Create(msg *entity.Msg)
// 创建消息并通过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
}
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
}
func (a *msgAppImpl) Create(msg *entity.Msg) {
a.msgRepo.Insert(msg)
}
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)
}