package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DocsMapper;
import com.gxwebsoft.cms.service.DocsService;
import com.gxwebsoft.cms.entity.Docs;
import com.gxwebsoft.cms.param.DocsParam;
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-16 11:40:27
 */
@Service
public class DocsServiceImpl extends ServiceImpl<DocsMapper, Docs> implements DocsService {

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

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

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

}
