mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-01-06 22:55:46 +08:00
refactor: code review
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
var (
|
||||
accountApp = newAccountApp(persistence.GetAccountRepo())
|
||||
configApp = newConfigApp(persistence.GetConfigRepo())
|
||||
msgApp = newMsgApp(persistence.GetMsgRepo())
|
||||
resourceApp = newResourceApp(persistence.GetResourceRepo())
|
||||
roleApp = newRoleApp(persistence.GetRoleRepo())
|
||||
syslogApp = newSyslogApp(persistence.GetSyslogRepo())
|
||||
@@ -21,10 +20,6 @@ func GetConfigApp() Config {
|
||||
return configApp
|
||||
}
|
||||
|
||||
func GetMsgApp() Msg {
|
||||
return msgApp
|
||||
}
|
||||
|
||||
func GetResourceApp() Resource {
|
||||
return resourceApp
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/internal/sys/domain/repository"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/ws"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
||||
|
||||
Create(msg *entity.Msg)
|
||||
|
||||
// 创建消息,并通过ws发送
|
||||
CreateAndSend(la *model.LoginAccount, msg *ws.Msg)
|
||||
}
|
||||
|
||||
func newMsgApp(msgRepo repository.Msg) Msg {
|
||||
return &msgAppImpl{
|
||||
msgRepo: msgRepo,
|
||||
}
|
||||
}
|
||||
|
||||
type msgAppImpl struct {
|
||||
msgRepo repository.Msg
|
||||
}
|
||||
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
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)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (m *syslogAppImpl) GetPageList(condition *entity.Syslog, pageParam *model.P
|
||||
func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
|
||||
lg := req.LoginAccount
|
||||
if lg == nil {
|
||||
return
|
||||
lg = &model.LoginAccount{Id: 0, Username: "-"}
|
||||
}
|
||||
syslog := new(entity.Syslog)
|
||||
syslog.CreateTime = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user