package com.gxwebsoft.hjm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.hjm.mapper.HjmChoicesMapper;
import com.gxwebsoft.hjm.service.HjmChoicesService;
import com.gxwebsoft.hjm.entity.HjmChoices;
import com.gxwebsoft.hjm.param.HjmChoicesParam;
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 HjmChoicesServiceImpl extends ServiceImpl<HjmChoicesMapper, HjmChoices> implements HjmChoicesService {

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

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

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

}
