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

    <resultMap type="AuditPaths" id="AuditPathsResult">
        <result property="id" column="id"/>
        <result property="pathId" column="path_id"/>
        <result property="pathName" column="path_name"/>
        <result property="opUserId" column="op_user_id"/>
        <result property="opUserName" column="op_user_name"/>
        <result property="opDate" column="op_date"/>
        <result property="branchId" column="branch_id"/>
        <result property="status" column="status"/>
        <result property="remarks" column="remarks"/>
    </resultMap>

    <sql id="selectAuditPathsVo">
        select id, path_id, path_name, op_user_id, op_user_name, op_date, branch_id, status, remarks from audit_paths
    </sql>

    <select id="selectAuditPathsList" parameterType="AuditPaths" resultMap="AuditPathsResult">
        <include refid="selectAuditPathsVo"/>
        <where>
            <if test="pathId != null ">and path_id = #{pathId}</if>
            <if test="pathName != null  and pathName != ''">and path_name like concat('%', #{pathName}, '%')</if>
            <if test="opUserId != null ">and op_user_id = #{opUserId}</if>
            <if test="opUserName != null  and opUserName != ''">and op_user_name like concat('%', #{opUserName}, '%')
            </if>
            <if test="opDate != null ">and op_date = #{opDate}</if>
            <if test="branchId != null ">and branch_id = #{branchId}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="remarks != null  and remarks != ''">and remarks = #{remarks}</if>
        </where>
    </select>

    <select id="selectAuditPathsById" parameterType="Long" resultMap="AuditPathsResult">
        <include refid="selectAuditPathsVo"/>
        where id = #{id}
    </select>

    <insert id="insertAuditPaths" parameterType="AuditPaths" useGeneratedKeys="true" keyProperty="id">
        insert into audit_paths
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pathId != null">path_id,</if>
            <if test="pathName != null">path_name,</if>
            <if test="opUserId != null">op_user_id,</if>
            <if test="opUserName != null">op_user_name,</if>
            <if test="opDate != null">op_date,</if>
            <if test="branchId != null">branch_id,</if>
            <if test="status != null">status,</if>
            <if test="remarks != null">remarks,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pathId != null">#{pathId},</if>
            <if test="pathName != null">#{pathName},</if>
            <if test="opUserId != null">#{opUserId},</if>
            <if test="opUserName != null">#{opUserName},</if>
            <if test="opDate != null">#{opDate},</if>
            <if test="branchId != null">#{branchId},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
        </trim>
    </insert>

    <update id="updateAuditPaths" parameterType="AuditPaths">
        update audit_paths
        <trim prefix="SET" suffixOverrides=",">
            <if test="pathId != null">path_id = #{pathId},</if>
            <if test="pathName != null">path_name = #{pathName},</if>
            <if test="opUserId != null">op_user_id = #{opUserId},</if>
            <if test="opUserName != null">op_user_name = #{opUserName},</if>
            <if test="opDate != null">op_date = #{opDate},</if>
            <if test="branchId != null">branch_id = #{branchId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAuditPathsById" parameterType="Long">
        delete
            audit.*,
            levels.*
         from
            audit_paths audit
            LEFT JOIN audit_paths_levels levels ON levels.path_id = audit.id
         where
            audit.id = #{id}
    </delete>

    <delete id="deleteAuditPathsByIds" parameterType="String">
        delete
            audit.*,
            levels.*
        from
            audit_paths audit
            LEFT JOIN audit_paths_levels levels ON levels.path_id = audit.id
        where
            audit.id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>