mini_system_logic.go
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package message
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
)
type MiniSystemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSystemLogic {
return &MiniSystemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) {
queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)
total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions)
if err != nil {
return nil, err
}
resp = &types.MessageSystemResponse{}
resp.Total = total
resp.List = make([]types.MessageSystemItem, 0)
for _, item := range list {
to := types.MessageSystemItem{
Id: item.Id,
Type: item.Type,
Title: item.Title,
Content: item.Content,
CreatedAt: item.CreatedAt,
}
resp.List = append(resp.List, to)
}
return resp, nil
}
func (l *MiniSystemLogic) CreateMessage(dm *domain.MessageSystem) error {
_, err := l.svcCtx.MessageSystemRepository.Insert(l.ctx, l.svcCtx.DefaultDBConn(), dm)
l.Debugf("")
return err
}
//// CreateSystemMessage 生成一条信息
//func CreateSystemMessage(ctx context.Context, svcCtx *svc.ServiceContext, dm *domain.MessageSystem) error {
// l := NewMiniSystemLogic(ctx, svcCtx)
// err := l.CreateMessage(dm)
// return err
//}