<?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.zkqy.system.mapper.BpmNodeScriptRelevanceMapper">

    <resultMap type="com.zkqy.system.entity.BpmNodeScriptRelevance" id="BpmNodeScriptRelevanceResult">
        <result property="id" column="id"/>
        <result property="nodeKey" column="node_key"/>
        <result property="scriptKey" column="script_key"/>
        <result property="scriptTriggerType" column="script_trigger_type"/>
        <result property="formKey" column="form_key"/>
        <result property="scriptNodeName" column="script_node_name"/>
        <result property="scriptNodeFormType" column="script_node_form_type"/>
    </resultMap>

    <sql id="selectBpmNodeScriptRelevanceVo">
        select id, node_key, script_key, script_trigger_type,form_key,script_node_name,script_node_form_type
        from bpm_node_script_relevance
    </sql>

    <select id="selectBpmNodeScriptRelevanceList" parameterType="com.zkqy.system.entity.BpmNodeScriptRelevance"
            resultMap="BpmNodeScriptRelevanceResult">
        <include refid="selectBpmNodeScriptRelevanceVo"/>
        <where>
            <if test="nodeKey != null  and nodeKey != ''">and node_key = #{nodeKey}</if>
            <if test="scriptKey != null  and scriptKey != ''">and script_key = #{scriptKey}</if>
            <if test="scriptTriggerType != null ">and script_trigger_type = #{scriptTriggerType}</if>
            <if test="formKey != null">and form_key = #{formKey},</if>
            <if test="scriptNodeName != null">and script_node_name = #{scriptNodeName},</if>
            <if test="scriptNodeFormType != null">and script_node_form_type = #{scriptNodeFormType},</if>
        </where>
    </select>

    <select id="selectBpmNodeScriptRelevanceById" parameterType="Long" resultMap="BpmNodeScriptRelevanceResult">
        <include refid="selectBpmNodeScriptRelevanceVo"/>
        where id = #{id}
    </select>

    <insert id="insertBpmNodeScriptRelevanceList">
        insert into bpm_node_script_relevance( node_key,script_key,script_trigger_type
        ,form_key,script_node_name,script_node_form_type )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.nodeKey},#{item.scriptKey},#{item.scriptTriggerType},#{item.formKey},#{item.scriptNodeName},#{item.scriptNodeFormType})
        </foreach>
    </insert>
    <!--    <foreach collection="list" item="item" index="index" separator=";">-->
    <insert id="insertBpmNodeScriptRelevance" parameterType="com.zkqy.system.entity.BpmNodeScriptRelevance">
        insert into bpm_node_script_relevance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nodeKey != null">node_key,</if>
            <if test="scriptKey != null">script_key,</if>
            <if test="scriptTriggerType != null">script_trigger_type,</if>
            <if test="formKey != null">form_key,</if>
            <if test="scriptNodeName != null">script_node_name,</if>
            <if test="scriptNodeFormType != null">script_node_form_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nodeKey != null">#{nodeKey},</if>
            <if test="scriptKey != null">#{scriptKey},</if>
            <if test="scriptTriggerType != null">#{scriptTriggerType},</if>
            <if test="formKey != null">#{formKey},</if>
            <if test="scriptNodeName != null">#{scriptNodeName},</if>
            <if test="scriptNodeFormType != null">#{scriptNodeFormType},</if>
        </trim>
    </insert>

    <update id="updateBpmNodeScriptRelevance" parameterType="com.zkqy.system.entity.BpmNodeScriptRelevance">
        update bpm_node_script_relevance
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeKey != null">node_key = #{nodeKey},</if>
            <if test="scriptKey != null">script_key = #{scriptKey},</if>
            <if test="scriptTriggerType != null">script_trigger_type = #{scriptTriggerType},</if>
            <if test="formKey != null">form_key = #{formKey},</if>
            <if test="scriptNodeName != null">script_node_name = #{scriptNodeName},</if>
            <if test="scriptNodeFormType != null">script_node_form_type = #{scriptNodeFormType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBpmNodeScriptRelevanceById" parameterType="Long">
        delete
        from bpm_node_script_relevance
        where id = #{id}
    </delete>

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

    <select id="selectAutoScriptByNodeKey" resultMap="BpmNodeScriptRelevanceResult">
        <include refid="selectBpmNodeScriptRelevanceVo"/>
        where node_key = #{nodeKey} and script_trigger_type = 1
    </select>

    <delete id="deleteBpmNodeScriptRelevanceByNodeKeys" parameterType="string">
        delete from bpm_node_script_relevance where node_key in
        <foreach collection="list" item="nodeKey" open="(" close=")" separator=",">
            #{nodeKey}
        </foreach>
    </delete>

    <select id="selectBpmNodeScriptRelevanceInfo" parameterType="com.zkqy.system.entity.BpmNodeScriptRelevance"
            resultMap="BpmNodeScriptRelevanceResult">
        <include refid="selectBpmNodeScriptRelevanceVo"/>
        <where>
            <if test="nodeKey != null  and nodeKey != ''">and node_key = #{nodeKey}</if>
            <if test="scriptKey != null  and scriptKey != ''">and script_key = #{scriptKey}</if>
            <if test="scriptTriggerType != null ">and script_trigger_type = #{scriptTriggerType}</if>
            <if test="formKey != null">and form_key = #{formKey},</if>
            <if test="scriptNodeName != null">and script_node_name = #{scriptNodeName},</if>
            <if test="scriptNodeFormType != null">and script_node_form_type = #{scriptNodeFormType},</if>
        </where>
    </select>

</mapper>