package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsDocsContentMapper;
import com.gxwebsoft.cms.service.CmsDocsContentService;
import com.gxwebsoft.cms.entity.CmsDocsContent;
import com.gxwebsoft.cms.param.CmsDocsContentParam;
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 CmsDocsContentServiceImpl extends ServiceImpl<CmsDocsContentMapper, CmsDocsContent> implements CmsDocsContentService {

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

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

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

}
