package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DocsContentMapper;
import com.gxwebsoft.cms.service.DocsContentService;
import com.gxwebsoft.cms.entity.DocsContent;
import com.gxwebsoft.cms.param.DocsContentParam;
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-03-23 19:51:37
 */
@Service
public class DocsContentServiceImpl extends ServiceImpl<DocsContentMapper, DocsContent> implements DocsContentService {

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

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

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

}
