
package com.pavis.admin.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.pavis.admin.common.context.UserContextHolder;
import com.pavis.admin.system.mapper.NoticeMapper;
import com.pavis.admin.system.model.entity.NoticeDO;
import com.pavis.admin.system.model.query.NoticeQuery;
import com.pavis.admin.system.model.req.NoticeReq;
import com.pavis.admin.system.model.resp.NoticeDetailResp;
import com.pavis.admin.system.model.resp.NoticeResp;
import com.pavis.admin.system.model.resp.dashboard.DashboardNoticeResp;
import com.pavis.admin.system.service.NoticeService;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseServiceImpl;

import java.util.List;

/**
 * 公告业务实现
 *
 *
 * @since 2023/8/20 10:55
 */
@Service
@RequiredArgsConstructor
public class NoticeServiceImpl extends BaseServiceImpl<NoticeMapper, NoticeDO, NoticeResp, NoticeDetailResp, NoticeQuery, NoticeReq> implements NoticeService {

    @Override
    public PageResp<NoticeResp> page(NoticeQuery query, PageQuery pageQuery) {
        IPage<NoticeDetailResp> page = baseMapper.selectNoticePage(new Page<>(pageQuery.getPage(), pageQuery
            .getSize()), query);
        PageResp<NoticeResp> pageResp = PageResp.build(page, super.getListClass());
        pageResp.getList().forEach(this::fill);
        return pageResp;
    }

    @Override
    public List<DashboardNoticeResp> listDashboard() {
        Long userId = UserContextHolder.getUserId();
        return baseMapper.selectDashboardList(userId);
    }
}