package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.NoticeMapper;
import com.gxwebsoft.common.system.service.NoticeService;
import com.gxwebsoft.common.system.entity.Notice;
import com.gxwebsoft.common.system.param.NoticeParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 消息记录表Service实现
 *
 * @author 科技小王子
 * @since 2023-10-08 13:22:21
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Override
    public PageResult<Notice> pageRel(NoticeParam param) {
        PageParam<Notice, NoticeParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<Notice> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<Notice> listRel(NoticeParam param) {
        List<Notice> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<Notice, NoticeParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public Notice getByIdRel(Integer noticeId) {
        NoticeParam param = new NoticeParam();
        param.setNoticeId(noticeId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
