package com.gxwebsoft.hjm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.hjm.mapper.HjmCoursesMapper;
import com.gxwebsoft.hjm.service.HjmCoursesService;
import com.gxwebsoft.hjm.entity.HjmCourses;
import com.gxwebsoft.hjm.param.HjmCoursesParam;
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-02 12:59:49
 */
@Service
public class HjmCoursesServiceImpl extends ServiceImpl<HjmCoursesMapper, HjmCourses> implements HjmCoursesService {

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

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

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

}
