mini_system_logic.go 1.7 KB
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
//}