2021-09-11 14:04:09 +08:00
|
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2023-11-07 21:05:21 +08:00
|
|
|
|
"context"
|
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-10-26 17:15:49 +08:00
|
|
|
|
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
2021-09-11 14:04:09 +08:00
|
|
|
|
|
2023-11-07 21:05:21 +08:00
|
|
|
|
Create(ctx context.Context, 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
|
|
|
|
type msgAppImpl struct {
|
2024-12-16 23:29:18 +08:00
|
|
|
|
msgRepo repository.Msg `inject:"T"`
|
2021-09-11 14:04:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-26 17:15:49 +08:00
|
|
|
|
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
2024-12-16 23:29:18 +08:00
|
|
|
|
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
|
2021-09-11 14:04:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-07 21:05:21 +08:00
|
|
|
|
func (a *msgAppImpl) Create(ctx context.Context, msg *entity.Msg) {
|
2024-12-16 23:29:18 +08:00
|
|
|
|
a.msgRepo.Insert(ctx, msg)
|
2021-09-11 14:04:09 +08:00
|
|
|
|
}
|
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}
|
2024-12-16 23:29:18 +08:00
|
|
|
|
a.msgRepo.Insert(context.TODO(), msg)
|
2023-10-19 19:00:23 +08:00
|
|
|
|
ws.SendJsonMsg(ws.UserId(la.Id), wmsg.ClientId, wmsg)
|
2021-11-11 15:56:02 +08:00
|
|
|
|
}
|