package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleContentMapper;
import com.gxwebsoft.cms.service.ArticleContentService;
import com.gxwebsoft.cms.entity.ArticleContent;
import com.gxwebsoft.cms.param.ArticleContentParam;
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-03-13 20:28:29
 */
@Service
public class ArticleContentServiceImpl extends ServiceImpl<ArticleContentMapper, ArticleContent> implements ArticleContentService {

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

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

    @Override
    public ArticleContent getByIdRel(Integer id) {
        ArticleContentParam param = new ArticleContentParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
