package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleMapper;
import com.gxwebsoft.cms.service.ArticleService;
import com.gxwebsoft.cms.entity.Article;
import com.gxwebsoft.cms.param.ArticleParam;
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-22 15:47:09
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {

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

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

    @Override
    public Article getByIdRel(Integer articleId) {
        ArticleParam param = new ArticleParam();
        param.setArticleId(articleId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
