package com.fs.store.mapper;

import com.fs.store.domain.FsDisease;
import com.fs.store.param.FsDiseaseListUParam;
import com.fs.store.vo.FsDiseaseListUVO;
import com.fs.store.vo.FsDiseaseListVO;
import com.fs.store.vo.FsDiseaseVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 疾病Mapper接口
 *
 * @author fs
 * @date 2023-06-01
 */
public interface FsDiseaseMapper
{
    /**
     * 查询疾病
     *
     * @param diseaseId 疾病主键
     * @return 疾病
     */
    public FsDisease selectFsDiseaseByDiseaseId(Long diseaseId);

    /**
     * 查询疾病列表
     *
     * @param fsDisease 疾病
     * @return 疾病集合
     */
    public List<FsDisease> selectFsDiseaseList(FsDisease fsDisease);

    /**
     * 新增疾病
     *
     * @param fsDisease 疾病
     * @return 结果
     */
    public int insertFsDisease(FsDisease fsDisease);

    /**
     * 修改疾病
     *
     * @param fsDisease 疾病
     * @return 结果
     */
    public int updateFsDisease(FsDisease fsDisease);

    /**
     * 删除疾病
     *
     * @param diseaseId 疾病主键
     * @return 结果
     */
    public int deleteFsDiseaseByDiseaseId(Long diseaseId);

    /**
     * 批量删除疾病
     *
     * @param diseaseIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsDiseaseByDiseaseIds(Long[] diseaseIds);

    @Select({"<script> " +
            " select i.disease_id, i.disease_name, i.disease_code,  i.introduction, i.diagnose,  i.`status`, i.create_time ,e.dept_name\n" +
            "        from fs_disease i\n" +
            "        LEFT JOIN fs_department e\n" +
            "        ON i.dept_id = e.dept_id where 1=1\n" +
            "\n" +
            "            <if test=\"diseaseName != null  and diseaseName != ''\"> and i.disease_name like concat('%', #{diseaseName}, '%')</if>\n" +
            "            <if test=\"diseaseCode != null  and diseaseCode != ''\"> and i.disease_code = #{diseaseCode}</if>\n" +
            "            <if test=\"deptId != null \"> and i.dept_id = #{deptId}</if>\n" +
            "            <if test=\"introduction != null  and introduction != ''\"> and i.introduction = #{introduction}</if>\n" +
            "            <if test=\"symptom != null  and symptom != ''\"> and i.symptom = #{symptom}</if>\n" +
            "            <if test=\"diagnose != null  and diagnose != ''\"> and i.diagnose = #{diagnose}</if>\n" +
            "            <if test=\"inspect != null  and inspect != ''\"> and i.inspect = #{inspect}</if>\n" +
            "            <if test=\"status != null \"> and i.status = #{status}</if>\n" +
            "\n" +
            "        ORDER BY disease_id DESC"+


            "</script>"})
    public List<FsDiseaseListVO> selectFsDiseaseListVO(FsDisease fsDisease);

@Select("select * from fs_disease where disease_code =#{diseaseCode}")
    FsDisease selectFsDiseaseBydiseaseCode(String diseaseCode);

    @Select("select i.disease_id, i.disease_name, i.disease_code, i.dept_id, i.introduction, i.symptom, i.diagnose, i.inspect, i.`status`, i.create_time ,e.dept_name\n" +
            "from fs_disease i \n" +
            " LEFT JOIN fs_department e\n" +
            "  ON i.dept_id = e.dept_id where i.disease_id=#{diseaseId}\n" +
            "\t")
    FsDiseaseVO selectFsDiseaseVoById(Long diseaseId);

    @Select({"<script> " +
            "select d.*  from fs_disease d    " +
            "where d.status=1  " +
            "<if test = 'maps.keyword != null     '> " +
            "and d.disease_name like CONCAT('%',#{maps.keyword},'%')" +
            "</if>" +
            "<if test = 'maps.deptId != null and maps.deptId !=0    '> " +
            "and d.dept_id = #{maps.deptId} " +
            "</if>" +
            " order by d.disease_id desc "+
            "</script>"})
    List<FsDiseaseListUVO> selectFsDiseaseListUVO(@Param("maps") FsDiseaseListUParam param);
    @Select("select i.disease_id, i.disease_name, i.disease_code, i.dept_id, i.introduction, i.symptom, i.diagnose, i.inspect, i.`status`, i.create_time ,e.dept_name\n" +
            "from fs_disease i \n" +
            " LEFT JOIN fs_department e\n" +
            "  ON i.dept_id = e.dept_id where i.disease_id=#{diseaseId}\n" +
            "\t")
    FsDiseaseVO selectFsDiseaseVOById(Long diseaseId);
}
