package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleCategoryMapper;
import com.gxwebsoft.cms.service.ArticleCategoryService;
import com.gxwebsoft.cms.entity.ArticleCategory;
import com.gxwebsoft.cms.param.ArticleCategoryParam;
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 2022-11-22 17:49:15
 */
@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements ArticleCategoryService {

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

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

    @Override
    public ArticleCategory getByIdRel(Integer categoryId) {
        ArticleCategoryParam param = new ArticleCategoryParam();
        param.setCategoryId(categoryId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
