<?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.approvalFlow.mapper.AuditPathsActsMapper">

    <resultMap type="AuditPathsActs" id="AuditPathsActsResult">
        <result property="id" column="id"/>
        <result property="branchId" column="branch_id"/>
        <result property="actId" column="act_id"/>
        <result property="reviewConditions" column="review_conditions"/>
        <result property="pathId" column="path_id"/>
    </resultMap>

    <sql id="selectAuditPathsActsVo">
        select id, branch_id, act_id, review_conditions, path_id from audit_paths_acts
    </sql>

    <select id="selectAuditPathsActsList" parameterType="AuditPathsActs" resultMap="AuditPathsActsResult">
        <include refid="selectAuditPathsActsVo"/>
        <where>
            <if test="branchId != null ">and branch_id = #{branchId}</if>
            <if test="actId != null ">and act_id = #{actId}</if>
            <if test="reviewConditions != null  and reviewConditions != ''">and review_conditions =
                #{reviewConditions}
            </if>
            <if test="pathId != null ">and path_id = #{pathId}</if>
        </where>
    </select>

    <select id="selectAuditPathsActsCount" parameterType="AuditPathsActs" resultType="int">
        select
            COUNT(id)
        from
            audit_paths_acts
        <where>
            <if test="branchId != null ">and branch_id = #{branchId}</if>
            <if test="actId != null ">and act_id = #{actId}</if>
            <if test="reviewConditions != null  and reviewConditions != ''">and review_conditions =
                #{reviewConditions}
            </if>
            <if test="pathId != null ">and path_id = #{pathId}</if>
        </where>
    </select>

    <select id="selectCountAuditPathsActs" parameterType="AuditPathsActs" resultType="int">
        SELECT
            COUNT(id)
        FROM
            audit_paths_acts
        <where>
            <if test="pathId != null ">and path_id = #{pathId}</if>
            <if test="actId != null ">and act_id = #{actId}</if>
            <if test="reviewConditions != null  and reviewConditions != ''">and review_conditions =
                #{reviewConditions}
            </if>
            <if test="pathId != null ">and path_id = #{pathId}</if>
        </where>
    </select>

    <select id="selectAuditPathsActsById" parameterType="Long" resultMap="AuditPathsActsResult">
        <include refid="selectAuditPathsActsVo"/>
        where id = #{id}
    </select>

    <insert id="insertAuditPathsActs" parameterType="AuditPathsActs" useGeneratedKeys="true" keyProperty="id">
        insert into audit_paths_acts
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="branchId != null">branch_id,</if>
            <if test="actId != null">act_id,</if>
            <if test="reviewConditions != null">review_conditions,</if>
            <if test="pathId != null">path_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="branchId != null">#{branchId},</if>
            <if test="actId != null">#{actId},</if>
            <if test="reviewConditions != null">#{reviewConditions},</if>
            <if test="pathId != null">#{pathId},</if>
        </trim>
    </insert>

    <update id="updateAuditPathsActs" parameterType="AuditPathsActs">
        update audit_paths_acts
        <trim prefix="SET" suffixOverrides=",">
            <if test="branchId != null">branch_id = #{branchId},</if>
            <if test="actId != null">act_id = #{actId},</if>
            <if test="reviewConditions != null">review_conditions = #{reviewConditions},</if>
            <if test="pathId != null">path_id = #{pathId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAuditPathsActsById" parameterType="Long">
        delete from audit_paths_acts where id = #{id}
    </delete>

    <delete id="deleteAuditPathsActsByIds" parameterType="String">
        delete
            act.*,
            leve.*
         from
          audit_paths_acts act
          left JOIN audit_paths_levels leve ON leve.path_id = act.id
         where
            act.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>