package com.fs.store.mapper;

import java.util.List;
import java.util.Map;

import com.fs.store.domain.FsPatient;
import com.fs.store.param.FsPatientParam;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 病人Mapper接口
 *
 * @author fs
 * @date 2022-03-23
 */
public interface FsPatientMapper
{
    /**
     * 查询病人
     *
     * @param patientId 病人ID
     * @return 病人
     */
    public FsPatient selectFsPatientById(Long patientId);

    /**
     * 查询病人列表
     *
     * @param fsPatient 病人
     * @return 病人集合
     */
    public List<FsPatient> selectFsPatientList(FsPatient fsPatient);

    /**
     * 新增病人
     *
     * @param fsPatient 病人
     * @return 结果
     */
    public int insertFsPatient(FsPatient fsPatient);

    /**
     * 修改病人
     *
     * @param fsPatient 病人
     * @return 结果
     */
    public int updateFsPatient(FsPatient fsPatient);

    /**
     * 删除病人
     *
     * @param patientId 病人ID
     * @return 结果
     */
    public int deleteFsPatientById(Long patientId);

    /**
     * 批量删除病人
     *
     * @param patientIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsPatientByIds(Long[] patientIds);

    @Select("select * from fs_patient where patient_id in (select distinct patient_id from fs_doctor_order o where o.doctor_id=#{doctorId} )")
    List<FsPatient> selectFsPatientListByDoctorId(long doctorId);
    @Select({"<script> " +
            "select * from fs_patient where patient_id in (select distinct patient_id from fs_doctor_order o where o.doctor_id=#{maps.doctorId} )  " +
            "<if test = 'maps.patientName != null and  maps.patientName !=\"\"    '> " +
            "and patient_name like CONCAT('%',#{maps.patientName},'%') " +
            "</if>" +
            "<if test = 'maps.idCard != null and  maps.idCard !=\"\"    '> " +
            "and id_card like CONCAT('%',#{maps.idCard},'%') " +
            "</if>" +
            " order by patient_id desc "+
            "</script>"})
    List<FsPatient> selectFsPatientListByDoctor(@Param("maps")FsPatientParam param);

    @Select("select patient_id,patient_name,id_card from fs_patient")
    @MapKey("patientId")
    Map<Long, FsPatient> queryAllMapping();

}
