<?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.execution.produce.dispersed.mapper.BpmExecuteNodeMiddleMapper">

    <resultMap type="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeMiddle"
               id="BpmExecuteNodeMiddleResult">
        <result property="id" column="id"/>
        <result property="taskProcessKey" column="task_process_key"/>
        <result property="taskNodeKey" column="task_node_key"/>
        <result property="taskVirtuallyRole" column="task_virtually_role"/>
        <result property="taskRealRole" column="task_real_role"/>
        <result property="taskExecuteUserNo" column="task_execute_user_no"/>
        <result property="taskArtificialScriptKey" column="task_artificial_script_key"/>
        <result property="taskAutomaticScriptTriggerType" column="task_automatic_script_trigger_type"/>
        <result property="taskNodeAroundScriptKey" column="task_node_around_script_key"/>
    </resultMap>

    <sql id="selectBpmExecuteNodeMiddleVo">
        select id,
               task_process_key,
               task_node_key,
               task_virtually_role,
               task_real_role,
               task_execute_user_no,
               task_artificial_script_key,
               task_automatic_script_trigger_type,
               task_node_around_script_key
        from bpm_execute_node_middle
    </sql>

    <select id="selectBpmExecuteNodeMiddleList"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeMiddle"
            resultMap="BpmExecuteNodeMiddleResult">
        <include refid="selectBpmExecuteNodeMiddleVo"/>
        <where>
            <if test="taskPrecessKey != null">task_process_key = #{taskProcessKey},</if>
            <if test="taskNodeKey != null  and taskNodeKey != ''">and task_node_key = #{taskNodeKey}</if>
            <if test="taskVirtuallyRole != null  and taskVirtuallyRole != ''">and task_virtually_role =
                #{taskVirtuallyRole}
            </if>
            <if test="taskRealRole != null  and taskRealRole != ''">and task_real_role = #{taskRealRole}</if>
            <if test="taskExecuteUserNo != null  and taskExecuteUserNo != ''">and task_execute_user_no =
                #{taskExecuteUserNo}
            </if>
            <if test="taskArtificialScriptKey != null  and taskArtificialScriptKey != ''">and task_artificial_script_key
                = #{taskArtificialScriptKey}
            </if>
            <if test="taskAutomaticScriptTriggerType != null  and taskAutomaticScriptTriggerType != ''">and
                task_automatic_script_trigger_type = #{taskAutomaticScriptTriggerType}
            </if>
        </where>
    </select>

    <select id="selectBpmExecuteNodeMiddleById" parameterType="Long" resultMap="BpmExecuteNodeMiddleResult">
        <include refid="selectBpmExecuteNodeMiddleVo"/>
        where id = #{id}
    </select>

    <insert id="insertBpmExecuteNodeMiddle"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeMiddle" useGeneratedKeys="true"
            keyProperty="id">
        insert into bpm_execute_node_middle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskProcessKey != null">task_process_key,</if>
            <if test="taskNodeKey != null">task_node_key,</if>
            <if test="taskVirtuallyRole != null">task_virtually_role,</if>
            <if test="taskRealRole != null">task_real_role,</if>
            <if test="taskExecuteUserNo != null">task_execute_user_no,</if>
            <if test="taskArtificialScriptKey != null">task_artificial_script_key,</if>
            <if test="taskAutomaticScriptTriggerType != null">task_automatic_script_trigger_type,</if>
            <if test="taskNodeAroundScriptKey != null">task_node_around_script_key,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskProcessKey != null">#{taskProcessKey},</if>
            <if test="taskNodeKey != null">#{taskNodeKey},</if>
            <if test="taskVirtuallyRole != null">#{taskVirtuallyRole},</if>
            <if test="taskRealRole != null">#{taskRealRole},</if>
            <if test="taskExecuteUserNo != null">#{taskExecuteUserNo},</if>
            <if test="taskArtificialScriptKey != null">#{taskArtificialScriptKey},</if>
            <if test="taskAutomaticScriptTriggerType != null">#{taskAutomaticScriptTriggerType},</if>
            <if test="taskNodeAroundScriptKey != null">#{taskNodeAroundScriptKey},</if>
        </trim>
    </insert>
    <insert id="insertBpmExecuteNodeMiddleList" parameterType="java.util.List">
        insert into bpm_execute_node_middle(task_process_key,task_node_key,
        task_virtually_role,
        task_real_role,
        task_execute_user_no,
        task_artificial_script_key,
        task_automatic_script_trigger_type,
        task_node_around_script_key)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.taskProcessKey},
            #{item.taskNodeKey},
            #{item.taskVirtuallyRole},
            #{item.taskRealRole},
            #{item.taskExecuteUserNo},
            #{item.taskArtificialScriptKey},
            #{item.taskAutomaticScriptTriggerType},
            #{item.taskNodeAroundScriptKey})
        </foreach>
    </insert>

    <update id="updateBpmExecuteNodeMiddle"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeMiddle">
        update bpm_execute_node_middle
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskNodeKey != null">task_node_key = #{taskNodeKey},</if>
            <if test="taskPrecessKey != null">task_process_key = #{taskProcessKey},</if>
            <if test="taskVirtuallyRole != null">task_virtually_role = #{taskVirtuallyRole},</if>
            <if test="taskRealRole != null">task_real_role = #{taskRealRole},</if>
            <if test="taskExecuteUserNo != null">task_execute_user_no = #{taskExecuteUserNo},</if>
            <if test="taskArtificialScriptKey != null">task_artificial_script_key = #{taskArtificialScriptKey},</if>
            <if test="taskAutomaticScriptTriggerType != null">task_automatic_script_trigger_type =
                #{taskAutomaticScriptTriggerType},
            </if>
            <if test="taskNodeAroundScriptKey != null">task_node_around_script_key = #{taskNodeAroundScriptKey},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBpmExecuteNodeMiddleById" parameterType="Long">
        delete
        from bpm_execute_node_middle
        where id = #{id}
    </delete>

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

    <select id="queryBpmExecuteNodeMiddleByTaskNodeKey" parameterType="String" resultMap="BpmExecuteNodeMiddleResult">
        <include refid="selectBpmExecuteNodeMiddleVo"/>
        where task_node_key = #{taskNodeKey} and task_process_key = #{taskProcessKey}
    </select>
</mapper>