package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.mapper.ClinicCaseMapper;
import com.gxwebsoft.clinic.service.ClinicCaseService;
import com.gxwebsoft.clinic.entity.ClinicCase;
import com.gxwebsoft.clinic.param.ClinicCaseParam;
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 LX
 * @since 2025-12-25 17:24:55
 */
@Service
public class ClinicCaseServiceImpl extends ServiceImpl<ClinicCaseMapper, ClinicCase> implements ClinicCaseService {

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

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

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

}
