<?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.xinelu.manage.mapper.basedruginfo.BaseDrugInfoMapper">

    <resultMap type="BaseDrugInfo" id="BaseDrugInfoResult">
            <result property="id" column="id"/>
            <result property="drugName" column="drug_name"/>
            <result property="purpose" column="purpose"/>
            <result property="applyWay" column="apply_way"/>
            <result property="applyFrequency" column="apply_frequency"/>
            <result property="applyRemark" column="apply_remark"/>
            <result property="dosage" column="dosage"/>
            <result property="sideEffects" column="side_effects"/>
            <result property="contraindications" column="contraindications"/>
            <result property="storage" column="storage"/>
            <result property="emergency" column="emergency"/>
            <result property="createTime" column="create_time"/>
            <result property="createBy" column="create_by"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectBaseDrugInfoVo">
        select id, drug_name, purpose, apply_way, apply_frequency, apply_remark, dosage, side_effects, contraindications, storage, emergency, create_time, create_by, update_by, update_time from base_drug_info
    </sql>

    <select id="selectBaseDrugInfoList" parameterType="BaseDrugInfo" resultMap="BaseDrugInfoResult">
        <include refid="selectBaseDrugInfoVo"/>
        <where>
                        <if test="drugName != null  and drugName != ''">
                            and drug_name like concat('%', #{drugName}, '%')
                        </if>
                        <if test="purpose != null  and purpose != ''">
                            and purpose = #{purpose}
                        </if>
                        <if test="applyWay != null  and applyWay != ''">
                            and apply_way = #{applyWay}
                        </if>
                        <if test="applyFrequency != null  and applyFrequency != ''">
                            and apply_frequency = #{applyFrequency}
                        </if>
                        <if test="applyRemark != null  and applyRemark != ''">
                            and apply_remark = #{applyRemark}
                        </if>
                        <if test="dosage != null  and dosage != ''">
                            and dosage = #{dosage}
                        </if>
                        <if test="sideEffects != null  and sideEffects != ''">
                            and side_effects = #{sideEffects}
                        </if>
                        <if test="contraindications != null  and contraindications != ''">
                            and contraindications = #{contraindications}
                        </if>
                        <if test="storage != null  and storage != ''">
                            and storage = #{storage}
                        </if>
                        <if test="emergency != null  and emergency != ''">
                            and emergency = #{emergency}
                        </if>
        </where>
    </select>

    <select id="selectBaseDrugInfoById" parameterType="Long"
            resultMap="BaseDrugInfoResult">
            <include refid="selectBaseDrugInfoVo"/>
            where id = #{id}
    </select>

    <insert id="insertBaseDrugInfo" parameterType="BaseDrugInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into base_drug_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="drugName != null">drug_name,
                    </if>
                    <if test="purpose != null">purpose,
                    </if>
                    <if test="applyWay != null">apply_way,
                    </if>
                    <if test="applyFrequency != null">apply_frequency,
                    </if>
                    <if test="applyRemark != null">apply_remark,
                    </if>
                    <if test="dosage != null">dosage,
                    </if>
                    <if test="sideEffects != null">side_effects,
                    </if>
                    <if test="contraindications != null">contraindications,
                    </if>
                    <if test="storage != null">storage,
                    </if>
                    <if test="emergency != null">emergency,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="drugName != null">#{drugName},
                    </if>
                    <if test="purpose != null">#{purpose},
                    </if>
                    <if test="applyWay != null">#{applyWay},
                    </if>
                    <if test="applyFrequency != null">#{applyFrequency},
                    </if>
                    <if test="applyRemark != null">#{applyRemark},
                    </if>
                    <if test="dosage != null">#{dosage},
                    </if>
                    <if test="sideEffects != null">#{sideEffects},
                    </if>
                    <if test="contraindications != null">#{contraindications},
                    </if>
                    <if test="storage != null">#{storage},
                    </if>
                    <if test="emergency != null">#{emergency},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
        </trim>
    </insert>

    <update id="updateBaseDrugInfo" parameterType="BaseDrugInfo">
        update base_drug_info
        <trim prefix="SET" suffixOverrides=",">
                    <if test="drugName != null">drug_name =
                        #{drugName},
                    </if>
                    <if test="purpose != null">purpose =
                        #{purpose},
                    </if>
                    <if test="applyWay != null">apply_way =
                        #{applyWay},
                    </if>
                    <if test="applyFrequency != null">apply_frequency =
                        #{applyFrequency},
                    </if>
                    <if test="applyRemark != null">apply_remark =
                        #{applyRemark},
                    </if>
                    <if test="dosage != null">dosage =
                        #{dosage},
                    </if>
                    <if test="sideEffects != null">side_effects =
                        #{sideEffects},
                    </if>
                    <if test="contraindications != null">contraindications =
                        #{contraindications},
                    </if>
                    <if test="storage != null">storage =
                        #{storage},
                    </if>
                    <if test="emergency != null">emergency =
                        #{emergency},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBaseDrugInfoById" parameterType="Long">
        delete from base_drug_info where id = #{id}
    </delete>

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