<?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.BpmExecuteNodeFormMapper">

    <resultMap type="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm" id="BpmExecuteNodeFormResult">
        <result property="id" column="id"/>
        <result property="taskProcessKey" column="task_process_key"/>
        <result property="taskNodeKey" column="task_node_key"/>
        <result property="taskScriptKey" column="task_script_key"/>
        <result property="taskNodeFormKey" column="task_node_form_key"/>
        <result property="taskNodeFromType" column="task_node_from_type"/>
        <result property="taskNodeFromContent" column="task_node_from_content"/>
    </resultMap>

    <sql id="selectBpmExecuteNodeFormVo">
        select id,
               task_process_key,
               task_node_key,
               task_script_key,
               task_node_form_key,
               task_node_from_type,
               task_node_from_content
        from bpm_execute_node_form
    </sql>

    <select id="selectBpmExecuteNodeFormList"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm"
            resultMap="BpmExecuteNodeFormResult">
        <include refid="selectBpmExecuteNodeFormVo"/>
        <where>
            <if test="taskProcessKey != null  and taskProcessKey != ''">and task_process_key = #{taskProcessKey}</if>
            <if test="taskNodeKey != null  and taskNodeKey != ''">and task_node_key = #{taskNodeKey}</if>
            <if test="taskScriptKey != null  and taskScriptKey != ''">and task_script_key = #{taskScriptKey}</if>
            <if test="taskNodeFormKey != null  and taskNodeFormKey != ''">and task_node_form_key = #{taskNodeFormKey}
            </if>
            <if test="taskNodeFromType != null  and taskNodeFromType != ''">and task_node_from_type =
                #{taskNodeFromType}
            </if>
            <if test="taskNodeFromContent != null  and taskNodeFromContent != ''">and task_node_from_content =
                #{taskNodeFromContent}
            </if>
        </where>
    </select>

    <select id="selectBpmExecuteNodeFormById" parameterType="Long" resultMap="BpmExecuteNodeFormResult">
        <include refid="selectBpmExecuteNodeFormVo"/>
        where id = #{id}
    </select>

    <insert id="insertBpmExecuteNodeForm"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm">
        insert into bpm_execute_node_form
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="taskProcessKey != null">task_process_key,</if>
            <if test="taskNodeKey != null">task_node_key,</if>
            <if test="taskScriptKey != null">task_script_key,</if>
            <if test="taskNodeFormKey != null">task_node_form_key,</if>
            <if test="taskNodeFromType != null">task_node_from_type,</if>
            <if test="taskNodeFromContent != null">task_node_from_content,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="taskProcessKey != null">#{taskProcessKey},</if>
            <if test="taskNodeKey != null">#{taskNodeKey},</if>
            <if test="taskScriptKey != null">#{taskScriptKey},</if>
            <if test="taskNodeFormKey != null">#{taskNodeFormKey},</if>
            <if test="taskNodeFromType != null">#{taskNodeFromType},</if>
            <if test="taskNodeFromContent != null">#{taskNodeFromContent},</if>
        </trim>
    </insert>

    <update id="updateBpmExecuteNodeForm"
            parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm">
        update bpm_execute_node_form
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskProcessKey != null">task_process_key = #{taskProcessKey},</if>
            <if test="taskNodeKey != null">task_node_key = #{taskNodeKey},</if>
            <if test="taskScriptKey != null">task_script_key = #{taskScriptKey},</if>
            <if test="taskNodeFormKey != null">task_node_form_key = #{taskNodeFormKey},</if>
            <if test="taskNodeFromType != null">task_node_from_type = #{taskNodeFromType},</if>
            <if test="taskNodeFromContent != null">task_node_from_content = #{taskNodeFromContent},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBpmExecuteNodeFormById" parameterType="Long">
        delete
        from bpm_execute_node_form
        where id = #{id}
    </delete>

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

    <select id="selectNodeFromInfos" resultType="map">
        select bpc.node_form_key  as form_key,
               bpc.node_form_type as form_type
        from {DBNAME}.bpm_process_configuration bpc
        where bpc.node_type != "endEvent"
          and bpc.node_type != "startEvent"
          and bpc.node_process_key = #{processKey}
        union
        select bnsr.form_key              as form_key,
               bnsr.script_node_form_type as form_type
        from {DBNAME}.bpm_node_script_relevance bnsr
        where bnsr.script_trigger_type != 1
          and
            bnsr.node_key in (
            select
            bpc.node_key
            from
            {DBNAME}.bpm_process_configuration bpc
            where
            bpc.node_type != "endEvent"
          and bpc.node_type != "startEvent"
          and bpc.node_process_key = #{processKey})
    </select>

    <select id="selectBpmExecuteNodeFormInfo" parameterType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm" resultMap="BpmExecuteNodeFormResult">
        <include refid="selectBpmExecuteNodeFormVo"/>
        <where>
            <if test="taskProcessKey != null  and taskProcessKey != ''"> and task_process_key = #{taskProcessKey}</if>
            <if test="taskNodeKey != null  and taskNodeKey != ''"> and task_node_key = #{taskNodeKey}</if>
            <if test="taskScriptKey != null  and taskScriptKey != ''"> and task_script_key = #{taskScriptKey}</if>
            <if test="taskNodeFormKey != null  and taskNodeFormKey != ''"> and task_node_form_key = #{taskNodeFormKey}</if>
            <if test="taskNodeFromType != null  and taskNodeFromType != ''"> and task_node_from_type = #{taskNodeFromType}</if>
            <if test="taskNodeFromContent != null  and taskNodeFromContent != ''"> and task_node_from_content = #{taskNodeFromContent}</if>
        </where>
    </select>

    <select id="selectBpmExecuteNodeFormByTpKAndTnkAndTsk"
            resultType="com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm">
         <include refid="selectBpmExecuteNodeFormVo"/>
         where task_process_key = #{taskProcessKey} and  task_node_key =#{taskNodeKey}
         <if test="taskScriptKey != null and taskScriptKey!=''"> and task_script_key=#{taskScriptKey}</if>
    </select>

    <select id="tableSql" resultType="java.util.Map">
            ${sql}
    </select>

    <select id="getTableSqlBySqlKey" resultType="java.util.Map">
        select  table_sql from {DBNAME}.table_sql where sql_key=#{sqlKey}
    </select>

    <!--根据sqlKey查询表单结构信息-->
    <select id="getDfFormInfo" resultType="java.util.Map">
          select  * from {DBNAME}.drag_form where sql_key=#{sqlKey}
    </select>

    <select id="executeSql" resultType="java.util.Map" parameterType="string">
        ${tableSql}
    </select>

    <resultMap id="retMap" type="com.zkqy.system.entity.CommonEntity" autoMapping="true">
        <collection property="resultMap" ofType="map" autoMapping="true"
                    javaType="map"></collection>
    </resultMap>



    <!--<select id="getSelectDate">-->
    <!--    select * from {DBNAME}.${tableName}-->
    <!--</select>-->
</mapper>