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

    <resultMap type="AuditPathsLevels" id="AuditPathsLevelsResult">
        <result property="id" column="id"/>
        <result property="pathId" column="path_id"/>
        <result property="levelId" column="level_id"/>
        <result property="levelName" column="level_name"/>
        <result property="auditUserId" column="audit_user_id"/>
        <result property="iffixAuditUser" column="iffix_audit_user"/>
        <result property="iffinalItem" column="iffinal_item"/>
        <result property="remarks" column="remarks"/>
    </resultMap>

    <sql id="selectAuditPathsLevelsVo">
        select id, path_id, level_id, level_name, audit_user_id, iffix_audit_user, iffinal_item, remarks from audit_paths_levels
    </sql>


    <select id="queryAuditLevels" parameterType="Long" resultMap="AuditPathsLevelsResult">
        SELECT
            lev.id,
            lev.level_id,
            lev.audit_user_id,
            lev.iffix_audit_user,
            lev.iffinal_item,
            lev.remarks
        FROM
            audit_paths_acts act
            LEFT JOIN audit_paths_levels lev ON act.path_id = lev.path_id
        where
            act.act_id = #{actId}
    </select>

    <select id="selectAuditPathsLevelsList" parameterType="AuditPathsLevels" resultMap="AuditPathsLevelsResult">
        <include refid="selectAuditPathsLevelsVo"/>
        <where>
            <if test="pathId != null ">and path_id = #{pathId}</if>
            <if test="levelId != null ">and level_id = #{levelId}</if>
            <if test="levelName != null  and levelName != ''">and level_name like concat('%', #{levelName}, '%')</if>
            <if test="auditUserId != null  and auditUserId != ''">and audit_user_id = #{auditUserId}</if>
            <if test="iffixAuditUser != null  and iffixAuditUser != ''">and iffix_audit_user = #{iffixAuditUser}</if>
            <if test="iffinalItem != null  and iffinalItem != ''">and iffinal_item = #{iffinalItem}</if>
            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectAuditPathsLevelsById" parameterType="Long" resultMap="AuditPathsLevelsResult">
        <include refid="selectAuditPathsLevelsVo"/>
        where id = #{id}
    </select>

    <insert id="insertAuditPathsLevels" parameterType="AuditPathsLevels" useGeneratedKeys="true" keyProperty="id">
        insert into audit_paths_levels
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pathId != null">path_id,</if>
            <if test="levelId != null">level_id,</if>
            <if test="levelName != null">level_name,</if>
            <if test="auditUserId != null">audit_user_id,</if>
            <if test="iffixAuditUser != null">iffix_audit_user,</if>
            <if test="iffinalItem != null">iffinal_item,</if>
            <if test="remarks != null">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pathId != null">#{pathId},</if>
            <if test="levelId != null">#{levelId},</if>
            <if test="levelName != null">#{levelName},</if>
            <if test="auditUserId != null">#{auditUserId},</if>
            <if test="iffixAuditUser != null">#{iffixAuditUser},</if>
            <if test="iffinalItem != null">#{iffinalItem},</if>
            <if test="remarks != null">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateAuditPathsLevels" parameterType="AuditPathsLevels">
        update audit_paths_levels
        <trim prefix="SET" suffixOverrides=",">
            <if test="pathId != null">path_id = #{pathId},</if>
            <if test="levelId != null">level_id = #{levelId},</if>
            <if test="levelName != null">level_name = #{levelName},</if>
            <if test="auditUserId != null">audit_user_id = #{auditUserId},</if>
            <if test="iffixAuditUser != null">iffix_audit_user = #{iffixAuditUser},</if>
            <if test="iffinalItem != null">iffinal_item = #{iffinalItem},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAuditPathsLevelsById" parameterType="Long">
        delete from audit_paths_levels where id = #{id}
    </delete>

    <delete id="deleteAuditPathsLevelsBypathId" parameterType="Long">
        delete from audit_paths_levels where path_id = #{id}
    </delete>

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

</mapper>