2025-04-15 21:42:31 +08:00
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"mayfly-go/internal/msg/domain/entity"
|
|
|
|
|
"mayfly-go/internal/msg/domain/repository"
|
|
|
|
|
"mayfly-go/pkg/base"
|
|
|
|
|
"mayfly-go/pkg/model"
|
|
|
|
|
"mayfly-go/pkg/utils/stringx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type MsgChannel interface {
|
|
|
|
|
base.App[*entity.MsgChannel]
|
|
|
|
|
|
2025-05-20 21:04:47 +08:00
|
|
|
GetPageList(condition *entity.MsgChannel, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MsgChannel], error)
|
2025-04-15 21:42:31 +08:00
|
|
|
|
|
|
|
|
SaveChannel(ctx context.Context, msgChannel *entity.MsgChannel) error
|
|
|
|
|
|
|
|
|
|
DeleteChannel(ctx context.Context, id uint64) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type msgChannelAppImpl struct {
|
|
|
|
|
base.AppImpl[*entity.MsgChannel, repository.MsgChannel]
|
|
|
|
|
|
|
|
|
|
msgTempApp MsgTmpl `inject:"T"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ (MsgChannel) = (*msgChannelAppImpl)(nil)
|
|
|
|
|
|
2025-05-20 21:04:47 +08:00
|
|
|
func (m *msgChannelAppImpl) GetPageList(condition *entity.MsgChannel, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MsgChannel], error) {
|
|
|
|
|
return m.Repo.GetPageList(condition, pageParam)
|
2025-04-15 21:42:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *msgChannelAppImpl) SaveChannel(ctx context.Context, msgChannel *entity.MsgChannel) error {
|
|
|
|
|
if msgChannel.Id == 0 {
|
|
|
|
|
msgChannel.Code = stringx.Rand(8)
|
|
|
|
|
}
|
|
|
|
|
return m.Save(ctx, msgChannel)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *msgChannelAppImpl) DeleteChannel(ctx context.Context, id uint64) error {
|
|
|
|
|
return m.Tx(ctx, func(ctx context.Context) error {
|
|
|
|
|
if err := m.DeleteById(ctx, id); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
// 删除渠道关联的模板
|
|
|
|
|
if err := m.msgTempApp.DeleteTmplChannel(ctx, id); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
}
|