package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.mapper.CmsDocsBookMapper;
import com.gxwebsoft.cms.service.CmsDocsBookService;
import com.gxwebsoft.cms.entity.CmsDocsBook;
import com.gxwebsoft.cms.param.CmsDocsBookParam;
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 CmsDocsBookServiceImpl extends ServiceImpl<CmsDocsBookMapper, CmsDocsBook> implements CmsDocsBookService {

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

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

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

}
