<?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.FsIllnessLibraryMapper">

    <resultMap type="FsIllnessLibrary" id="FsIllnessLibraryResult">
        <result property="illnessId"    column="illness_id"    />
        <result property="illnessName"    column="illness_name"    />
        <result property="symptom"    column="symptom"    />
        <result property="tongueVein"    column="tongue_vein"    />
        <result property="therapy"    column="therapy"    />
        <result property="formulaName"    column="formula_name"    />
        <result property="formulaDescs"    column="Formula_descs"    />
    </resultMap>

    <sql id="selectFsIllnessLibraryVo">
        select illness_id, illness_name, symptom, tongue_vein, therapy, formula_name, Formula_descs from fs_illness_library
    </sql>

    <select id="selectFsIllnessLibraryList" parameterType="FsIllnessLibrary" resultMap="FsIllnessLibraryResult">
        <include refid="selectFsIllnessLibraryVo"/>
        <where>
            <if test="illnessName != null  and illnessName != ''"> and illness_name like concat('%', #{illnessName}, '%')</if>
            <if test="formulaName != null  and formulaName != ''"> and formula_name like concat('%', #{formulaName}, '%')</if>
        </where>
    </select>

    <select id="selectFsIllnessLibraryByIllnessId" parameterType="Long" resultMap="FsIllnessLibraryResult">
        <include refid="selectFsIllnessLibraryVo"/>
        where illness_id = #{illnessId}
    </select>

    <insert id="insertFsIllnessLibrary" parameterType="FsIllnessLibrary">
        insert into fs_illness_library
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="illnessId != null">illness_id,</if>
            <if test="illnessName != null and illnessName != ''">illness_name,</if>
            <if test="symptom != null and symptom != ''">symptom,</if>
            <if test="tongueVein != null and tongueVein != ''">tongue_vein,</if>
            <if test="therapy != null and therapy != ''">therapy,</if>
            <if test="formulaName != null and formulaName != ''">formula_name,</if>
            <if test="formulaDescs != null and formulaDescs != ''">Formula_descs,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="illnessId != null">#{illnessId},</if>
            <if test="illnessName != null and illnessName != ''">#{illnessName},</if>
            <if test="symptom != null and symptom != ''">#{symptom},</if>
            <if test="tongueVein != null and tongueVein != ''">#{tongueVein},</if>
            <if test="therapy != null and therapy != ''">#{therapy},</if>
            <if test="formulaName != null and formulaName != ''">#{formulaName},</if>
            <if test="formulaDescs != null and formulaDescs != ''">#{formulaDescs},</if>
         </trim>
    </insert>

    <update id="updateFsIllnessLibrary" parameterType="FsIllnessLibrary">
        update fs_illness_library
        <trim prefix="SET" suffixOverrides=",">
            <if test="illnessName != null and illnessName != ''">illness_name = #{illnessName},</if>
            <if test="symptom != null and symptom != ''">symptom = #{symptom},</if>
            <if test="tongueVein != null and tongueVein != ''">tongue_vein = #{tongueVein},</if>
            <if test="therapy != null and therapy != ''">therapy = #{therapy},</if>
            <if test="formulaName != null and formulaName != ''">formula_name = #{formulaName},</if>
            <if test="formulaDescs != null and formulaDescs != ''">Formula_descs = #{formulaDescs},</if>
        </trim>
        where illness_id = #{illnessId}
    </update>

    <delete id="deleteFsIllnessLibraryByIllnessId" parameterType="Long">
        delete from fs_illness_library where illness_id = #{illnessId}
    </delete>

    <delete id="deleteFsIllnessLibraryByIllnessIds" parameterType="String">
        delete from fs_illness_library where illness_id in
        <foreach item="illnessId" collection="array" open="(" separator="," close=")">
            #{illnessId}
        </foreach>
    </delete>
</mapper>
