package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.mapper.ClinicAppointmentMapper;
import com.gxwebsoft.clinic.service.ClinicAppointmentService;
import com.gxwebsoft.clinic.entity.ClinicAppointment;
import com.gxwebsoft.clinic.param.ClinicAppointmentParam;
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-10-19 09:27:04
 */
@Service
public class ClinicAppointmentServiceImpl extends ServiceImpl<ClinicAppointmentMapper, ClinicAppointment> implements ClinicAppointmentService {

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

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

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

}
