<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fs.store.mapper.FsDiseaseMapper">

    <resultMap type="FsDisease" id="FsDiseaseResult">
        <result property="diseaseId"    column="disease_id"    />
        <result property="diseaseName"    column="disease_name"    />
        <result property="diseaseCode"    column="disease_code"    />
        <result property="deptId"    column="dept_id"    />
        <result property="introduction"    column="introduction"    />
        <result property="symptom"    column="symptom"    />
        <result property="diagnose"    column="diagnose"    />
        <result property="inspect"    column="inspect"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFsDiseaseVo">
        select disease_id, disease_name, disease_code, dept_id, introduction, symptom, diagnose, inspect, status, create_time from fs_disease
    </sql>

    <select id="selectFsDiseaseList" parameterType="FsDisease" resultMap="FsDiseaseResult">
        <include refid="selectFsDiseaseVo"/>
        <where>
            <if test="diseaseName != null  and diseaseName != ''"> and disease_name like concat('%', #{diseaseName}, '%')</if>
            <if test="diseaseCode != null  and diseaseCode != ''"> and disease_code = #{diseaseCode}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="introduction != null  and introduction != ''"> and introduction = #{introduction}</if>
            <if test="symptom != null  and symptom != ''"> and symptom = #{symptom}</if>
            <if test="diagnose != null  and diagnose != ''"> and diagnose = #{diagnose}</if>
            <if test="inspect != null  and inspect != ''"> and inspect = #{inspect}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        ORDER BY disease_id DESC
    </select>
<!--    <select id="selectFsDiseaseListVo" parameterType="com.fs.his.vo.FsDiseaseVO" resultMap="FsDiseaseResult">-->
<!--        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-->
<!--        from fs_disease i-->
<!--        LEFT JOIN fs_department e-->
<!--        ON i.dept_id = e.dept_id where 1=1-->

<!--            <if test="diseaseName != null  and diseaseName != ''"> and i.disease_name like concat('%', #{diseaseName}, '%')</if>-->
<!--            <if test="diseaseCode != null  and diseaseCode != ''"> and i.disease_code = #{diseaseCode}</if>-->
<!--            <if test="deptId != null "> and dept_id = #{deptId}</if>-->
<!--            <if test="introduction != null  and introduction != ''"> and i.introduction = #{introduction}</if>-->
<!--            <if test="symptom != null  and symptom != ''"> and i.symptom = #{symptom}</if>-->
<!--            <if test="diagnose != null  and diagnose != ''"> and i.diagnose = #{diagnose}</if>-->
<!--            <if test="inspect != null  and inspect != ''"> and i.inspect = #{inspect}</if>-->
<!--            <if test="status != null "> and i.status = #{status}</if>-->

<!--        ORDER BY disease_id DESC-->
<!--    </select>-->
    <select id="selectFsDiseaseByDiseaseId" parameterType="Long" resultMap="FsDiseaseResult">
        <include refid="selectFsDiseaseVo"/>
        where disease_id = #{diseaseId}
    </select>

    <insert id="insertFsDisease" parameterType="FsDisease" useGeneratedKeys="true" keyProperty="diseaseId">
        insert into fs_disease
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="diseaseName != null">disease_name,</if>
            <if test="diseaseCode != null">disease_code,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="introduction != null">introduction,</if>
            <if test="symptom != null">symptom,</if>
            <if test="diagnose != null">diagnose,</if>
            <if test="inspect != null">inspect,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="diseaseName != null">#{diseaseName},</if>
            <if test="diseaseCode != null">#{diseaseCode},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="introduction != null">#{introduction},</if>
            <if test="symptom != null">#{symptom},</if>
            <if test="diagnose != null">#{diagnose},</if>
            <if test="inspect != null">#{inspect},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFsDisease" parameterType="FsDisease">
        update fs_disease
        <trim prefix="SET" suffixOverrides=",">
            <if test="diseaseName != null">disease_name = #{diseaseName},</if>
            <if test="diseaseCode != null">disease_code = #{diseaseCode},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="introduction != null">introduction = #{introduction},</if>
            <if test="symptom != null">symptom = #{symptom},</if>
            <if test="diagnose != null">diagnose = #{diagnose},</if>
            <if test="inspect != null">inspect = #{inspect},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where disease_id = #{diseaseId}
    </update>


    <delete id="deleteFsDiseaseByDiseaseId" parameterType="Long">
        delete from fs_disease where disease_id = #{diseaseId}
    </delete>

    <delete id="deleteFsDiseaseByDiseaseIds" parameterType="String">
        delete from fs_disease where disease_id in
        <foreach item="diseaseId" collection="array" open="(" separator="," close=")">
            #{diseaseId}
        </foreach>
    </delete>
</mapper>
