<?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.ruoyi.system.mapper.BpmProcessMapper">

    <resultMap type="com.ruoyi.system.entity.BpmProcess" id="BpmProcessResult">
        <result property="processId"    column="process_id"    />
        <result property="processName"    column="process_name"    />
        <result property="processKey"    column="process_key"    />
        <result property="processOpneState"    column="process_opne_state"    />
        <result property="processType"    column="process_type"    />
        <result property="processDeployTime"    column="process_deploy_time"    />
        <result property="startEventType"    column="start_event_type"    />
        <result property="note"    column="note"    />
        <result property="processVersion"    column="process_version"    />
        <result property="processXml"    column="process_xml"    />
        <result property="processJson"    column="process_json"    />
        <result property="processXmlContent"    column="process_xml_content"    />
        <result property="processXmlPath"    column="process_xml_path"    />
        <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="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBpmProcessVo">
        select process_id, process_name, process_key, process_opne_state, process_type, process_deploy_time, start_event_type, note, process_version, process_xml, process_json, process_xml_content, process_xml_path, create_by, create_time, update_by, update_time, del_flag, remark from bpm_process
    </sql>

    <select id="selectBpmProcessList" parameterType="com.ruoyi.system.entity.BpmProcess" resultMap="BpmProcessResult">
        <include refid="selectBpmProcessVo"/>
        <where>
            <if test="processName != null  and processName != ''">and process_name like concat('%', #{processName},
                '%')
            </if>
            <if test="processKey != null  and processKey != ''">and process_key = #{processKey}</if>
            <if test="processOpneState != null ">and process_opne_state = #{processOpneState}</if>
            <if test="processType != null ">and process_type = #{processType}</if>
            <if test="processDeployTime != null ">and process_deploy_time = #{processDeployTime}</if>
            <if test="startEventType != null ">and start_event_type = #{startEventType}</if>
            <if test="note != null  and note != ''">and note = #{note}</if>
            <if test="processXml != null  and processXml != ''">and process_xml = #{processXml}</if>
            <if test="processJson != null  and processJson != ''">and process_json = #{processJson}</if>
            <if test="processXmlContent != null  and processXmlContent != ''">and process_xml_content =
                #{processXmlContent}
            </if>
            <if test="processXmlPath != null  and processXmlPath != ''">and process_xml_path = #{processXmlPath}</if>
            <if test="processVersion != null">and process_version = #{processVersion}</if>
            and del_flag = '0'
        </where>
        order by create_time desc
    </select>

    <select id="selectBpmProcessByProcessId" parameterType="Long" resultMap="BpmProcessResult">
        <include refid="selectBpmProcessVo"/>
        where process_id = #{processId}
    </select>
        
    <insert id="insertBpmProcess" parameterType="com.ruoyi.system.entity.BpmProcess" useGeneratedKeys="true" keyProperty="processId">
        insert into bpm_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="processName != null">process_name,</if>
            <if test="processKey != null">process_key,</if>
            <if test="processOpneState != null">process_opne_state,</if>
            <if test="processType != null">process_type,</if>
            <if test="processDeployTime != null">process_deploy_time,</if>
            <if test="startEventType != null">start_event_type,</if>
            <if test="note != null">note,</if>
            <if test="processVersion != null">process_version,</if>
            <if test="processXml != null">process_xml,</if>
            <if test="processJson != null">process_json,</if>
            <if test="processXmlContent != null">process_xml_content,</if>
            <if test="processXmlPath != null">process_xml_path,</if>
            <if test="createById != null">create_by_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            del_flag
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="processName != null">#{processName},</if>
            <if test="processKey != null">#{processKey},</if>
            <if test="processOpneState != null">#{processOpneState},</if>
            <if test="processType != null">#{processType},</if>
            <if test="processDeployTime != null">#{processDeployTime},</if>
            <if test="startEventType != null">#{startEventType},</if>
            <if test="note != null">#{note},</if>
            <if test="processVersion != null">#{processVersion},</if>
            <if test="processXml != null">#{processXml},</if>
            <if test="processJson != null">#{processJson},</if>
            <if test="processXmlContent != null">#{processXmlContent},</if>
            <if test="processXmlPath != null">#{processXmlPath},</if>
            <if test="createById != null">#{createById},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            0
        </trim>
    </insert>

    <update id="updateBpmProcess" parameterType="com.ruoyi.system.entity.BpmProcess">
        update bpm_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="processName != null">process_name = #{processName},</if>
            <if test="processKey != null">process_key = #{processKey},</if>
            <if test="processOpneState != null">process_opne_state = #{processOpneState},</if>
            <if test="processType != null">process_type = #{processType},</if>
            <if test="processDeployTime != null">process_deploy_time = #{processDeployTime},</if>
            <if test="startEventType != null">start_event_type = #{startEventType},</if>
            <if test="note != null">note = #{note},</if>
            <if test="processVersion != null">process_version = #{processVersion},</if>
            <if test="processXml != null">process_xml = #{processXml},</if>
            <if test="processJson != null">process_json = #{processJson},</if>
            <if test="processXmlContent != null">process_xml_content = #{processXmlContent},</if>
            <if test="processXmlPath != null">process_xml_path = #{processXmlPath},</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="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where process_id = #{processId}
    </update>

    <delete id="deleteBpmProcessByProcessId" parameterType="Long">
        update bpm_process
        set del_flag = '2'
        where process_id = #{processId}
    </delete>

    <delete id="deleteBpmProcessByProcessIds" parameterType="String">
        update bpm_process
        set del_flag = '2'
        where process_id in
        <foreach item="processId" collection="array" open="(" separator="," close=")">
            #{processId}
        </foreach>
    </delete>

    <select id="selectBpmProcessByProcessIds" resultMap="BpmProcessResult">
        <include refid="selectBpmProcessVo"/>
        where process_id in
        <foreach collection="list" item="processId" open="(" close=")" separator=",">
            #{processId}
        </foreach>
    </select>

    <select id="selectBpmProcessByProcessKey" resultMap="BpmProcessResult">
        <include refid="selectBpmProcessVo"/>
        where process_key = #{processKey} and process_version = 0 and del_flag = '0'
    </select>
</mapper>