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

    <resultMap type="com.zkqy.system.entity.BpmProcessConfiguration" id="BpmProcessConfigurationResult">
        <result property="id"    column="id"    />
        <result property="nodeKey"    column="node_key"    />
        <result property="nodeName" column="node_name"/>
        <result property="nodeFormKey"    column="node_form_key"    />
        <result property="nodeFormType" column="node_form_type"/>
        <result property="nodeProcessKey"    column="node_process_key"    />
        <result property="nodeType"    column="node_type"    />
        <result property="nodeExecuteType" column="node_execute_type"/>
        <result property="nodeBefore"    column="node_before"    />
        <result property="nodeAfter"    column="node_after"    />
        <result property="nodeRolePermission"    column="node_role_permission"    />
        <result property="spare1"    column="spare1"    />
        <result property="spare2"    column="spare2"    />
        <result property="spare3"    column="spare3"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBpmProcessConfigurationVo">
        select id,
               node_key,
               node_name,
               node_form_key,
               node_form_type,
               node_process_key,
               node_type,
               node_execute_type,
               node_before,
               node_after,
               node_role_permission,
               spare1,
               spare2,
               spare3,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from bpm_process_configuration
    </sql>

    <select id="selectBpmProcessConfigurationList" parameterType="com.zkqy.system.entity.BpmProcessConfiguration" resultMap="BpmProcessConfigurationResult">
        <include refid="selectBpmProcessConfigurationVo"/>
        where del_flag = '0'
            <if test="nodeKey != null  and nodeKey != ''"> and node_key = #{nodeKey}</if>
            <if test="nodeName != null">  and node_name = #{nodeName}</if>
            <if test="nodeFormKey != null "> and node_form_key = #{nodeFormKey}</if>
            <if test="nodeProcessKey != null "> and node_process_key = #{nodeProcessKey}</if>
            <if test="nodeType != null  and nodeType != ''"> and node_type = #{nodeType}</if>
            <if test="nodeBefore != null  and nodeBefore != ''"> and node_before = #{nodeBefore}</if>
            <if test="nodeAfter != null  and nodeAfter != ''"> and node_after = #{nodeAfter}</if>
            <if test="nodeRolePermission != null  and nodeRolePermission != ''"> and node_role_permission = #{nodeRolePermission}</if>
            <if test="spare1 != null  and spare1 != ''"> and spare1 = #{spare1}</if>
            <if test="spare2 != null  and spare2 != ''"> and spare2 = #{spare2}</if>
            <if test="spare3 != null  and spare3 != ''"> and spare3 = #{spare3}</if>
    </select>

    <select id="selectBpmProcessConfigurationById" parameterType="Long" resultMap="BpmProcessConfigurationResult">
        <include refid="selectBpmProcessConfigurationVo"/>
        where id = #{id}
    </select>

    <insert id="insertBpmProcessConfiguration" parameterType="java.util.List">
        insert into {DBNAME}.bpm_process_configuration(
        node_key,node_name,node_form_key,node_form_type, node_process_key,
        node_type,node_execute_type, node_before, node_after,
        node_role_permission, spare1, spare2,
        spare3, del_flag,create_by_id,create_by,create_time,
        update_by_id,update_by,update_time, remark)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.nodeKey},#{item.nodeName}, #{item.nodeFormKey},#{item.nodeFormType},
            #{item.nodeProcessKey}, #{item.nodeType},#{item.nodeExecuteType}, #{item.nodeBefore},
            #{item.nodeAfter},
            #{item.nodeRolePermission}, #{item.spare1}, #{item.spare2}, #{item.spare3}, '0',
            #{item.createById},
            #{item.createBy},
            #{item.createTime},
            #{item.updateById},#{item.updateBy},
            #{item.updateTime},#{item.remark})
        </foreach>
    </insert>

    <update id="updateBpmProcessConfiguration" parameterType="java.util.List">
        update {DBNAME}.bpm_process_configuration
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeKey != null">node_key = #{nodeKey},</if>
            <if test="nodeName != null">node_name = #{nodeName},</if>
            <if test="nodeFormKey != null">node_form_key = #{nodeFormKey},</if>
            <if test="nodeFormType != null">node_form_type = #{nodeFormType},</if>
            <if test="nodeProcessKey != null">node_process_key = #{nodeProcessKey},</if>
            <if test="nodeType != null">node_type = #{nodeType},</if>
            <if test="nodeExecuteType != null">node_execute_type = #{nodeExecuteType},</if>
            <if test="nodeBefore != null">node_before = #{nodeBefore},</if>
            <if test="nodeAfter != null">node_after = #{nodeAfter},</if>
            <if test="nodeRolePermission != null">node_role_permission = #{nodeRolePermission},</if>
            <if test="spare1 != null">spare1 = #{spare1},</if>
            <if test="spare2 != null">spare2 = #{spare2},</if>
            <if test="spare3 != null">spare3 = #{spare3},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createById != null">create_by_id = #{createById},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateById != null">update_by_id = #{updateById},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBpmProcessConfigurationById" parameterType="Long">
        update bpm_process_configuration set del_flag = '2' where id = #{id}
    </delete>

    <update id="deleteBpmProcessConfigurationByIds" parameterType="map">
        update bpm_process_configuration set del_flag = '2', where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectNodeKeyByIds" resultType="string">
        select node_key from bpm_process_configuration where id in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </select>
</mapper>