package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.mapper.ClinicPatientUserMapper;
import com.gxwebsoft.clinic.service.ClinicPatientUserService;
import com.gxwebsoft.clinic.entity.ClinicPatientUser;
import com.gxwebsoft.clinic.param.ClinicPatientUserParam;
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 ClinicPatientUserServiceImpl extends ServiceImpl<ClinicPatientUserMapper, ClinicPatientUser> implements ClinicPatientUserService {

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

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

    @Override
    public ClinicPatientUser getByIdRel(Integer id) {
        ClinicPatientUserParam param = new ClinicPatientUserParam();
        param.setUserId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
