package core

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
)

type ListNoticeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListNoticeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListNoticeLogic {
	return &ListNoticeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListNoticeLogic) ListNotice(req *clientCore.ListNoticeReq) (*clientCore.ListNoticeResp, error) {
	var notices []clientCore.NoticeInfo

	var resp clientCore.ListNoticeResp

	//TODO 防止数据量过大，限制查询记录100条
	l.svcCtx.DbEngin.Raw("select * from t_notice order by created_time desc limit 100").Scan(&notices)
	for _, notice := range notices {
		resp.Data = append(resp.Data, notice)
	}
	resp.Code = 200
	resp.Msg = "success"
	return &resp, nil
}
