package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsArticleMapper;
import com.gxwebsoft.cms.service.CmsArticleService;
import com.gxwebsoft.cms.entity.CmsArticle;
import com.gxwebsoft.cms.param.CmsArticleParam;
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 2024-09-10 20:47:57
 */
@Service
public class CmsArticleServiceImpl extends ServiceImpl<CmsArticleMapper, CmsArticle> implements CmsArticleService {

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

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

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

}
