<?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.flowable.mapper.WfBusinessProcessMapper">

    <resultMap type="WfBusinessProcess" id="WfBusinessProcessResult">
        <result property="businessId" column="business_id"/>
        <result property="processId" column="process_id"/>
        <result property="businessProcessType" column="business_process_type"/>
    </resultMap>

    <sql id="selectWfBusinessProcessVo">
        select business_id, process_id, business_process_type
        from wf_business_process
    </sql>

    <select id="selectWfBusinessProcessList" parameterType="WfBusinessProcess" resultMap="WfBusinessProcessResult">
        <include refid="selectWfBusinessProcessVo"/>
        <where>
            <if test="processId != null  and processId != ''">and process_id = #{processId}</if>
            <if test="businessProcessType != null  and businessProcessType != ''">and business_process_type =
                #{businessProcessType}
            </if>
        </where>
    </select>

    <select id="selectWfBusinessProcessByBusinessId" parameterType="String" resultMap="WfBusinessProcessResult">
        <include refid="selectWfBusinessProcessVo"/>
        where business_id = #{businessId}
    </select>

    <select id="selectWfBusinessProcessByProcessId" parameterType="String" resultMap="WfBusinessProcessResult">
        <include refid="selectWfBusinessProcessVo"/>
        where process_id = #{processId}
    </select>

    <select id="selectWfBusinessProcessListByProcessId" resultMap="WfBusinessProcessResult">
        <include refid="selectWfBusinessProcessVo"/>
        where process_id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertWfBusinessProcess" parameterType="WfBusinessProcess">
        insert into wf_business_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="processId != null and processId != ''">process_id,</if>
            <if test="businessProcessType != null">business_process_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="processId != null and processId != ''">#{processId},</if>
            <if test="businessProcessType != null">#{businessProcessType},</if>
        </trim>
    </insert>

    <update id="updateWfBusinessProcess" parameterType="WfBusinessProcess">
        update wf_business_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="processId != null and processId != ''">process_id = #{processId},</if>
            <if test="businessProcessType != null">business_process_type = #{businessProcessType},</if>
        </trim>
        where business_id = #{businessId}
    </update>

    <delete id="deleteWfBusinessProcessByBusinessId" parameterType="String">
        delete
        from wf_business_process
        where business_id = #{businessId}
          and business_process_type = #{type}
    </delete>

    <delete id="deleteWfBusinessProcessByBusinessIds" parameterType="String">
        delete from wf_business_process where business_id in
        <foreach item="businessId" collection="array" open="(" separator="," close=")">
            #{businessId}
        </foreach>
    </delete>
</mapper>
