package com.gxwebsoft.hjm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.hjm.mapper.HjmExamLogMapper;
import com.gxwebsoft.hjm.service.HjmExamLogService;
import com.gxwebsoft.hjm.entity.HjmExamLog;
import com.gxwebsoft.hjm.param.HjmExamLogParam;
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-06-05 14:32:03
 */
@Service
public class HjmExamLogServiceImpl extends ServiceImpl<HjmExamLogMapper, HjmExamLog> implements HjmExamLogService {

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

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

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

}
