package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.ArticleCheckMapper;
import com.gxwebsoft.cms.service.ArticleCheckService;
import com.gxwebsoft.cms.entity.ArticleCheck;
import com.gxwebsoft.cms.param.ArticleCheckParam;
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-11-19 22:01:03
 */
@Service
public class ArticleCheckServiceImpl extends ServiceImpl<ArticleCheckMapper, ArticleCheck> implements ArticleCheckService {

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

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

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

    @Override
    public List<ArticleCheck> listByArticleId(Integer articleId) {
        return list(
                new LambdaQueryWrapper<ArticleCheck>()
                        .eq(ArticleCheck::getArticleId, articleId)
        );
    }

}
