package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsDocsMapper;
import com.gxwebsoft.cms.service.CmsDocsService;
import com.gxwebsoft.cms.entity.CmsDocs;
import com.gxwebsoft.cms.param.CmsDocsParam;
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 CmsDocsServiceImpl extends ServiceImpl<CmsDocsMapper, CmsDocs> implements CmsDocsService {

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

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

    @Override
    public CmsDocs getByIdRel(Integer docsId) {
        CmsDocsParam param = new CmsDocsParam();
        param.setDocsId(docsId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
