<?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.specialdiseasetriggercondition.SpecialDiseaseTriggerConditionMapper">

    <resultMap type="SpecialDiseaseTriggerCondition" id="SpecialDiseaseTriggerConditionResult">
        <result property="id" column="id"/>
        <result property="routeId" column="route_id"/>
        <result property="routeName" column="route_name"/>
        <result property="triggerConditionCode" column="trigger_condition_code"/>
        <result property="triggerConditionName" column="trigger_condition_name"/>
        <result property="triggerConditionOperator" column="trigger_condition_operator"/>
        <result property="triggerConditionValue" column="trigger_condition_value"/>
        <result property="triggerConditionSort" column="trigger_condition_sort"/>
	    <result property="triggerLogic" column="trigger_logic"/>
        <result property="triggerConditionRemark" column="trigger_condition_remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectSpecialDiseaseTriggerConditionVo">
        select id,
               route_id,
               route_name,
               trigger_condition_code,
               trigger_condition_name,
               trigger_condition_operator,
               trigger_condition_value,
               trigger_condition_sort,
               trigger_logic,
               trigger_condition_remark,
               create_by,
               create_time,
               update_by,
               update_time
        from special_disease_trigger_condition
    </sql>

    <select id="selectSpecialDiseaseTriggerConditionList" parameterType="SpecialDiseaseTriggerCondition"
            resultMap="SpecialDiseaseTriggerConditionResult">
        <include refid="selectSpecialDiseaseTriggerConditionVo"/>
        <where>
            <if test="routeId != null ">
                and route_id = #{routeId}
            </if>
            <if test="routeName != null  and routeName != ''">
                and route_name like concat('%', #{routeName}, '%')
            </if>
            <if test="triggerConditionCode != null  and triggerConditionCode != ''">
                and trigger_condition_code = #{triggerConditionCode}
            </if>
            <if test="triggerConditionName != null  and triggerConditionName != ''">
                and trigger_condition_name like concat('%', #{triggerConditionName}, '%')
            </if>
            <if test="triggerConditionOperator != null  and triggerConditionOperator != ''">
                and trigger_condition_operator = #{triggerConditionOperator}
            </if>
            <if test="triggerConditionValue != null  and triggerConditionValue != ''">
                and trigger_condition_value = #{triggerConditionValue}
            </if>
            <if test="triggerConditionSort != null ">
                and trigger_condition_sort = #{triggerConditionSort}
            </if>
            <if test="triggerConditionRemark != null  and triggerConditionRemark != ''">
                and trigger_condition_remark = #{triggerConditionRemark}
            </if>
        </where>
    </select>

    <select id="selectSpecialDiseaseTriggerConditionById" parameterType="Long"
            resultMap="SpecialDiseaseTriggerConditionResult">
        <include refid="selectSpecialDiseaseTriggerConditionVo"/>
        where id = #{id}
    </select>

    <insert id="insertSpecialDiseaseTriggerCondition" parameterType="SpecialDiseaseTriggerCondition"
            useGeneratedKeys="true"
            keyProperty="id">
        insert into special_disease_trigger_condition
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="routeId != null">route_id,
            </if>
            <if test="routeName != null">route_name,
            </if>
            <if test="triggerConditionCode != null">trigger_condition_code,
            </if>
            <if test="triggerConditionName != null">trigger_condition_name,
            </if>
            <if test="triggerConditionOperator != null">trigger_condition_operator,
            </if>
            <if test="triggerConditionValue != null">trigger_condition_value,
            </if>
            <if test="triggerConditionSort != null">trigger_condition_sort,
            </if>
	        <if test="triggerLogic != null">trigger_logic,
	        </if>
            <if test="triggerConditionRemark != null">trigger_condition_remark,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="routeId != null">#{routeId},
            </if>
            <if test="routeName != null">#{routeName},
            </if>
            <if test="triggerConditionCode != null">#{triggerConditionCode},
            </if>
            <if test="triggerConditionName != null">#{triggerConditionName},
            </if>
            <if test="triggerConditionOperator != null">#{triggerConditionOperator},
            </if>
            <if test="triggerConditionValue != null">#{triggerConditionValue},
            </if>
            <if test="triggerConditionSort != null">#{triggerConditionSort},
            </if>
	        <if test="triggerLogic != null">#{triggerLogic},
	        </if>
            <if test="triggerConditionRemark != null">#{triggerConditionRemark},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertTriggerConditionList">
        insert into special_disease_trigger_condition(
        route_id,
        route_name,
        trigger_condition_code,
        trigger_condition_name,
        trigger_condition_operator,
        trigger_condition_value,
        trigger_condition_sort,
	    trigger_logic,
        trigger_condition_remark,
        create_by,
        create_time
        )values
        <foreach item="triggerConditionList" index="index" collection="list" separator=",">
            (
            #{triggerConditionList.routeId},
            #{triggerConditionList.routeName},
            #{triggerConditionList.triggerConditionCode},
            #{triggerConditionList.triggerConditionName},
            #{triggerConditionList.triggerConditionOperator},
            #{triggerConditionList.triggerConditionValue},
            #{triggerConditionList.triggerConditionSort},
	        #{triggerConditionList.triggerLogic},
            #{triggerConditionList.triggerConditionRemark},
            #{triggerConditionList.createBy},
            #{triggerConditionList.createTime}
            )
        </foreach>
    </insert>

    <update id="updateSpecialDiseaseTriggerCondition" parameterType="SpecialDiseaseTriggerCondition">
        update special_disease_trigger_condition
        <trim prefix="SET" suffixOverrides=",">
            <if test="routeId != null">route_id =
                #{routeId},
            </if>
            <if test="routeName != null">route_name =
                #{routeName},
            </if>
            <if test="triggerConditionCode != null">trigger_condition_code =
                #{triggerConditionCode},
            </if>
            <if test="triggerConditionName != null">trigger_condition_name =
                #{triggerConditionName},
            </if>
            <if test="triggerConditionOperator != null">trigger_condition_operator =
                #{triggerConditionOperator},
            </if>
            <if test="triggerConditionValue != null">trigger_condition_value =
                #{triggerConditionValue},
            </if>
            <if test="triggerConditionSort != null">trigger_condition_sort =
                #{triggerConditionSort},
            </if>
	        <if test="triggerLogic != null">trigger_logic =
		        #{triggerLogic},
	        </if>
            <if test="triggerConditionRemark != null">trigger_condition_remark =
                #{triggerConditionRemark},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSpecialDiseaseTriggerConditionById" parameterType="Long">
        delete
        from special_disease_trigger_condition
        where id = #{id}
    </delete>

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

    <delete id="deleteSpecialDiseaseTriggerConditionByRouteId">
        delete
        from special_disease_trigger_condition
        where route_id = #{routeId}
    </delete>
</mapper>