<?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.signroutetriggercondition.SignRouteTriggerConditionMapper">

    <resultMap type="SignRouteTriggerCondition" id="SignRouteTriggerConditionResult">
            <result property="id" column="id"/>
            <result property="patientManageRouteId" column="patient_manage_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="selectSignRouteTriggerConditionVo">
        select id, patient_manage_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 sign_route_trigger_condition
    </sql>

    <select id="selectSignRouteTriggerConditionList" parameterType="SignRouteTriggerCondition" resultMap="SignRouteTriggerConditionResult">
        <include refid="selectSignRouteTriggerConditionVo"/>
        <where>
            <if test="patientManageRouteId != null ">
                and patient_manage_route_id = #{patientManageRouteId}
            </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="selectSignRouteTriggerConditionById" parameterType="Long"
            resultMap="SignRouteTriggerConditionResult">
            <include refid="selectSignRouteTriggerConditionVo"/>
            where id = #{id}
    </select>

    <insert id="insertSignRouteTriggerCondition" parameterType="SignRouteTriggerCondition" useGeneratedKeys="true"
            keyProperty="id">
        insert into sign_route_trigger_condition
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientManageRouteId != null">patient_manage_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="patientManageRouteId != null">#{patientManageRouteId},
                    </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>

    <update id="updateSignRouteTriggerCondition" parameterType="SignRouteTriggerCondition">
        update sign_route_trigger_condition
        <trim prefix="SET" suffixOverrides=",">
                    <if test="patientManageRouteId != null">patient_manage_route_id =
                        #{patientManageRouteId},
                    </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="triggerConditionRemark != null">trigger_condition_remark =
                        #{triggerConditionRemark},
                    </if>
			        <if test="triggerLogic != null">trigger_logic =
				        #{triggerLogic},
			        </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="deleteSignRouteTriggerConditionById" parameterType="Long">
        delete from sign_route_trigger_condition where id = #{id}
    </delete>

    <delete id="deleteSignRouteTriggerConditionByIds" parameterType="String">
        delete from sign_route_trigger_condition where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
	<insert id="insertBatch">
		insert into sign_route_trigger_condition(id,patient_manage_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)
		values
		<foreach collection="signRouteTriggerConditionCollection" item="item" separator=",">
			(#{item.id,jdbcType=NUMERIC},#{item.patientManageRouteId,jdbcType=NUMERIC},#{item.routeName,jdbcType=VARCHAR},
			#{item.triggerConditionCode,jdbcType=VARCHAR},#{item.triggerConditionName,jdbcType=VARCHAR},#{item.triggerConditionOperator,jdbcType=VARCHAR},
			#{item.triggerConditionValue,jdbcType=VARCHAR},#{item.triggerConditionSort,jdbcType=NUMERIC},#{item.triggerLogic,jdbcType=VARCHAR},#{item.triggerConditionRemark,jdbcType=VARCHAR},
			#{item.createBy,jdbcType=VARCHAR},#{item.createTime},
			#{item.updateBy,jdbcType=VARCHAR},#{item.updateTime})
		</foreach>
	</insert>

    <delete id="deleteConditionByPatientManageRouteId" parameterType="Long">
        delete from sign_route_trigger_condition where patient_manage_route_id = #{patientManageRouteId}
    </delete>
</mapper>