package com.gxwebsoft.docs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.docs.mapper.DocsContentMapper;
import com.gxwebsoft.docs.service.DocsContentService;
import com.gxwebsoft.docs.entity.DocsContent;
import com.gxwebsoft.docs.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 2025-03-26 09:29:15
 */
@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("sort_number asc, 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("sort_number asc, 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));
    }

}
