<?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.zbf.system.mapper.ActRuExecutionMapper">

    <resultMap type="ActRuExecution" id="ActRuExecutionResult">
        <result property="id"    column="ID_"    />
        <result property="rev"    column="REV_"    />
        <result property="procInstId"    column="PROC_INST_ID_"    />
        <result property="businessKey"    column="BUSINESS_KEY_"    />
        <result property="parentId"    column="PARENT_ID_"    />
        <result property="procDefId"    column="PROC_DEF_ID_"    />
        <result property="superExec"    column="SUPER_EXEC_"    />
        <result property="rootProcInstId"    column="ROOT_PROC_INST_ID_"    />
        <result property="actId"    column="ACT_ID_"    />
        <result property="isActive"    column="IS_ACTIVE_"    />
        <result property="isConcurrent"    column="IS_CONCURRENT_"    />
        <result property="isScope"    column="IS_SCOPE_"    />
        <result property="isEventScope"    column="IS_EVENT_SCOPE_"    />
        <result property="isMiRoot"    column="IS_MI_ROOT_"    />
        <result property="suspensionState"    column="SUSPENSION_STATE_"    />
        <result property="cachedEntState"    column="CACHED_ENT_STATE_"    />
        <result property="tenantId"    column="TENANT_ID_"    />
        <result property="name"    column="NAME_"    />
        <result property="startTime"    column="START_TIME_"    />
        <result property="startUserId"    column="START_USER_ID_"    />
        <result property="lockTime"    column="LOCK_TIME_"    />
        <result property="isCountEnabled"    column="IS_COUNT_ENABLED_"    />
        <result property="evtSubscrCount"    column="EVT_SUBSCR_COUNT_"    />
        <result property="taskCount"    column="TASK_COUNT_"    />
        <result property="jobCount"    column="JOB_COUNT_"    />
        <result property="timerJobCount"    column="TIMER_JOB_COUNT_"    />
        <result property="suspJobCount"    column="SUSP_JOB_COUNT_"    />
        <result property="deadletterJobCount"    column="DEADLETTER_JOB_COUNT_"    />
        <result property="varCount"    column="VAR_COUNT_"    />
        <result property="idLinkCount"    column="ID_LINK_COUNT_"    />
    </resultMap>

    <sql id="selectActRuExecutionVo">
        select ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PARENT_ID_, PROC_DEF_ID_, SUPER_EXEC_, ROOT_PROC_INST_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, IS_EVENT_SCOPE_, IS_MI_ROOT_, SUSPENSION_STATE_, CACHED_ENT_STATE_, TENANT_ID_, NAME_, START_TIME_, START_USER_ID_, LOCK_TIME_, IS_COUNT_ENABLED_, EVT_SUBSCR_COUNT_, TASK_COUNT_, JOB_COUNT_, TIMER_JOB_COUNT_, SUSP_JOB_COUNT_, DEADLETTER_JOB_COUNT_, VAR_COUNT_, ID_LINK_COUNT_ from ACT_RU_EXECUTION
    </sql>

    <select id="selectActRuExecutionList" parameterType="ActRuExecution" resultMap="ActRuExecutionResult">
        <include refid="selectActRuExecutionVo"/>
        <where>
            <if test="rev != null "> and REV_ = #{rev}</if>
            <if test="procInstId != null  and procInstId != ''"> and PROC_INST_ID_ = #{procInstId}</if>
            <if test="businessKey != null  and businessKey != ''"> and BUSINESS_KEY_ = #{businessKey}</if>
            <if test="parentId != null  and parentId != ''"> and PARENT_ID_ = #{parentId}</if>
            <if test="procDefId != null  and procDefId != ''"> and PROC_DEF_ID_ = #{procDefId}</if>
            <if test="superExec != null  and superExec != ''"> and SUPER_EXEC_ = #{superExec}</if>
            <if test="rootProcInstId != null  and rootProcInstId != ''"> and ROOT_PROC_INST_ID_ = #{rootProcInstId}</if>
            <if test="actId != null  and actId != ''"> and ACT_ID_ = #{actId}</if>
            <if test="isActive != null "> and IS_ACTIVE_ = #{isActive}</if>
            <if test="isConcurrent != null "> and IS_CONCURRENT_ = #{isConcurrent}</if>
            <if test="isScope != null "> and IS_SCOPE_ = #{isScope}</if>
            <if test="isEventScope != null "> and IS_EVENT_SCOPE_ = #{isEventScope}</if>
            <if test="isMiRoot != null "> and IS_MI_ROOT_ = #{isMiRoot}</if>
            <if test="suspensionState != null "> and SUSPENSION_STATE_ = #{suspensionState}</if>
            <if test="cachedEntState != null "> and CACHED_ENT_STATE_ = #{cachedEntState}</if>
            <if test="tenantId != null  and tenantId != ''"> and TENANT_ID_ = #{tenantId}</if>
            <if test="name != null  and name != ''"> and NAME_ = #{name}</if>
            <if test="startTime != null "> and START_TIME_ = #{startTime}</if>
            <if test="startUserId != null  and startUserId != ''"> and START_USER_ID_ = #{startUserId}</if>
            <if test="lockTime != null "> and LOCK_TIME_ = #{lockTime}</if>
            <if test="isCountEnabled != null "> and IS_COUNT_ENABLED_ = #{isCountEnabled}</if>
            <if test="evtSubscrCount != null "> and EVT_SUBSCR_COUNT_ = #{evtSubscrCount}</if>
            <if test="taskCount != null "> and TASK_COUNT_ = #{taskCount}</if>
            <if test="jobCount != null "> and JOB_COUNT_ = #{jobCount}</if>
            <if test="timerJobCount != null "> and TIMER_JOB_COUNT_ = #{timerJobCount}</if>
            <if test="suspJobCount != null "> and SUSP_JOB_COUNT_ = #{suspJobCount}</if>
            <if test="deadletterJobCount != null "> and DEADLETTER_JOB_COUNT_ = #{deadletterJobCount}</if>
            <if test="varCount != null "> and VAR_COUNT_ = #{varCount}</if>
            <if test="idLinkCount != null "> and ID_LINK_COUNT_ = #{idLinkCount}</if>
        </where>
    </select>

    <select id="selectActRuExecutionListByProcessName" resultMap="ActRuExecutionResult">
        SELECT
        ACT_RU_EXECUTION.*
        FROM
        ACT_RU_EXECUTION
                LEFT JOIN ACT_RE_PROCDEF ON ACT_RU_EXECUTION.PROC_DEF_ID_ = ACT_RE_PROCDEF.ID_
        WHERE
            1=1
        <if test="name != null ">
            and ACT_RE_PROCDEF.NAME_ = #{name}
        </if>
        order by proc_inst_id_
    </select>

    <select id="selectActRuExecutionById" parameterType="String" resultMap="ActRuExecutionResult">
        <include refid="selectActRuExecutionVo"/>
        where ID_ = #{id}
    </select>

    <insert id="insertActRuExecution" parameterType="ActRuExecution">
        insert into ACT_RU_EXECUTION
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">ID_,</if>
            <if test="rev != null">REV_,</if>
            <if test="procInstId != null">PROC_INST_ID_,</if>
            <if test="businessKey != null">BUSINESS_KEY_,</if>
            <if test="parentId != null">PARENT_ID_,</if>
            <if test="procDefId != null">PROC_DEF_ID_,</if>
            <if test="superExec != null">SUPER_EXEC_,</if>
            <if test="rootProcInstId != null">ROOT_PROC_INST_ID_,</if>
            <if test="actId != null">ACT_ID_,</if>
            <if test="isActive != null">IS_ACTIVE_,</if>
            <if test="isConcurrent != null">IS_CONCURRENT_,</if>
            <if test="isScope != null">IS_SCOPE_,</if>
            <if test="isEventScope != null">IS_EVENT_SCOPE_,</if>
            <if test="isMiRoot != null">IS_MI_ROOT_,</if>
            <if test="suspensionState != null">SUSPENSION_STATE_,</if>
            <if test="cachedEntState != null">CACHED_ENT_STATE_,</if>
            <if test="tenantId != null">TENANT_ID_,</if>
            <if test="name != null">NAME_,</if>
            <if test="startTime != null">START_TIME_,</if>
            <if test="startUserId != null">START_USER_ID_,</if>
            <if test="lockTime != null">LOCK_TIME_,</if>
            <if test="isCountEnabled != null">IS_COUNT_ENABLED_,</if>
            <if test="evtSubscrCount != null">EVT_SUBSCR_COUNT_,</if>
            <if test="taskCount != null">TASK_COUNT_,</if>
            <if test="jobCount != null">JOB_COUNT_,</if>
            <if test="timerJobCount != null">TIMER_JOB_COUNT_,</if>
            <if test="suspJobCount != null">SUSP_JOB_COUNT_,</if>
            <if test="deadletterJobCount != null">DEADLETTER_JOB_COUNT_,</if>
            <if test="varCount != null">VAR_COUNT_,</if>
            <if test="idLinkCount != null">ID_LINK_COUNT_,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="rev != null">#{rev},</if>
            <if test="procInstId != null">#{procInstId},</if>
            <if test="businessKey != null">#{businessKey},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="procDefId != null">#{procDefId},</if>
            <if test="superExec != null">#{superExec},</if>
            <if test="rootProcInstId != null">#{rootProcInstId},</if>
            <if test="actId != null">#{actId},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="isConcurrent != null">#{isConcurrent},</if>
            <if test="isScope != null">#{isScope},</if>
            <if test="isEventScope != null">#{isEventScope},</if>
            <if test="isMiRoot != null">#{isMiRoot},</if>
            <if test="suspensionState != null">#{suspensionState},</if>
            <if test="cachedEntState != null">#{cachedEntState},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="name != null">#{name},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="startUserId != null">#{startUserId},</if>
            <if test="lockTime != null">#{lockTime},</if>
            <if test="isCountEnabled != null">#{isCountEnabled},</if>
            <if test="evtSubscrCount != null">#{evtSubscrCount},</if>
            <if test="taskCount != null">#{taskCount},</if>
            <if test="jobCount != null">#{jobCount},</if>
            <if test="timerJobCount != null">#{timerJobCount},</if>
            <if test="suspJobCount != null">#{suspJobCount},</if>
            <if test="deadletterJobCount != null">#{deadletterJobCount},</if>
            <if test="varCount != null">#{varCount},</if>
            <if test="idLinkCount != null">#{idLinkCount},</if>
         </trim>
    </insert>

    <update id="updateActRuExecution" parameterType="ActRuExecution">
        update ACT_RU_EXECUTION
        <trim prefix="SET" suffixOverrides=",">
            <if test="rev != null">REV_ = #{rev},</if>
            <if test="procInstId != null">PROC_INST_ID_ = #{procInstId},</if>
            <if test="businessKey != null">BUSINESS_KEY_ = #{businessKey},</if>
            <if test="parentId != null">PARENT_ID_ = #{parentId},</if>
            <if test="procDefId != null">PROC_DEF_ID_ = #{procDefId},</if>
            <if test="superExec != null">SUPER_EXEC_ = #{superExec},</if>
            <if test="rootProcInstId != null">ROOT_PROC_INST_ID_ = #{rootProcInstId},</if>
            <if test="actId != null">ACT_ID_ = #{actId},</if>
            <if test="isActive != null">IS_ACTIVE_ = #{isActive},</if>
            <if test="isConcurrent != null">IS_CONCURRENT_ = #{isConcurrent},</if>
            <if test="isScope != null">IS_SCOPE_ = #{isScope},</if>
            <if test="isEventScope != null">IS_EVENT_SCOPE_ = #{isEventScope},</if>
            <if test="isMiRoot != null">IS_MI_ROOT_ = #{isMiRoot},</if>
            <if test="suspensionState != null">SUSPENSION_STATE_ = #{suspensionState},</if>
            <if test="cachedEntState != null">CACHED_ENT_STATE_ = #{cachedEntState},</if>
            <if test="tenantId != null">TENANT_ID_ = #{tenantId},</if>
            <if test="name != null">NAME_ = #{name},</if>
            <if test="startTime != null">START_TIME_ = #{startTime},</if>
            <if test="startUserId != null">START_USER_ID_ = #{startUserId},</if>
            <if test="lockTime != null">LOCK_TIME_ = #{lockTime},</if>
            <if test="isCountEnabled != null">IS_COUNT_ENABLED_ = #{isCountEnabled},</if>
            <if test="evtSubscrCount != null">EVT_SUBSCR_COUNT_ = #{evtSubscrCount},</if>
            <if test="taskCount != null">TASK_COUNT_ = #{taskCount},</if>
            <if test="jobCount != null">JOB_COUNT_ = #{jobCount},</if>
            <if test="timerJobCount != null">TIMER_JOB_COUNT_ = #{timerJobCount},</if>
            <if test="suspJobCount != null">SUSP_JOB_COUNT_ = #{suspJobCount},</if>
            <if test="deadletterJobCount != null">DEADLETTER_JOB_COUNT_ = #{deadletterJobCount},</if>
            <if test="varCount != null">VAR_COUNT_ = #{varCount},</if>
            <if test="idLinkCount != null">ID_LINK_COUNT_ = #{idLinkCount},</if>
        </trim>
        where ID_ = #{id}
    </update>

    <delete id="deleteActRuExecutionById" parameterType="String">
        delete from ACT_RU_EXECUTION where ID_ = #{id}
    </delete>

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

</mapper>
