package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.DocsBookMapper;
import com.gxwebsoft.cms.service.DocsBookService;
import com.gxwebsoft.cms.entity.DocsBook;
import com.gxwebsoft.cms.param.DocsBookParam;
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:40:02
 */
@Service
public class DocsBookServiceImpl extends ServiceImpl<DocsBookMapper, DocsBook> implements DocsBookService {

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

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

    @Override
    public DocsBook getByIdRel(Integer bookId) {
        DocsBookParam param = new DocsBookParam();
        param.setBookId(bookId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
