<?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.project.ticket.mapper.TDelayPermitMapper">

    <resultMap type="TDelayPermit" id="TDelayPermitResult">
        <result property="id" column="id"/>
        <result property="vId" column="v_id"/>
        <result property="aId" column="a_id"/>
        <result property="hId" column="h_id"/>
        <result property="cId" column="c_id"/>
        <result property="otherId" column="other_id"/>
    </resultMap>

    <sql id="selectTDelayPermitVo">
        select d.id, d.v_id, d.a_id, d.h_id, d.c_id, d.other_id
        from t_delay_permit d
    </sql>

    <select id="selectDelayCount" parameterType="TDelayPermit" resultMap="TDelayPermitResult">
        <include refid="selectTDelayPermitVo"/>
        <where>
            <if test="vId != null ">and v_id = #{vId}</if>
            <if test="aId != null ">and a_id = #{aId}</if>
            <if test="hId != null ">and h_id = #{hId}</if>
            <if test="cId != null ">and c_id = #{cId}</if>
            <if test="otherId != null ">and other_id = #{otherId}</if>
        </where>
        order by v_id
    </select>

    <select id="selectTDelayPermitList" parameterType="TDelayPermit" resultMap="TDelayPermitResult">
        <include refid="selectTDelayPermitVo"/>
        <where>
            <if test="vId != null ">and v_id = #{vId}</if>
            <if test="aId != null ">and a_id = #{aId}</if>
            <if test="hId != null ">and h_id = #{hId}</if>
            <if test="cId != null ">and c_id = #{cId}</if>
            <if test="otherId != null ">and other_id = #{otherId}</if>
        </where>
    </select>

    <select id="selectTDelayPermitById" parameterType="Long" resultMap="TDelayPermitResult">
        <include refid="selectTDelayPermitVo"/>
        where v_id = #{id}
        and rownum = 1
    </select>

    <select id="selectVid" resultType="Long">
        SELECT seq_t_delay_permit_vid.NEXTVAL as id
        FROM DUAL
    </select>

    <insert id="insertTDelayPermit" parameterType="TDelayPermit">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_delay_permit.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_delay_permit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="vId != null">v_id,</if>
            <if test="aId != null">a_id,</if>
            <if test="hId != null">h_id,</if>
            <if test="cId != null">c_id,</if>
            <if test="otherId != null">other_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="vId != null">#{vId},</if>
            <if test="aId != null">#{aId},</if>
            <if test="hId != null">#{hId},</if>
            <if test="cId != null">#{cId},</if>
            <if test="otherId != null">#{otherId},</if>
        </trim>
    </insert>

    <update id="updateTDelayPermit" parameterType="TDelayPermit">
        update t_delay_permit
        <trim prefix="SET" suffixOverrides=",">
            <if test="vId != null">v_id = #{vId},</if>
            <if test="aId != null">a_id = #{aId},</if>
            <if test="hId != null">h_id = #{hId},</if>
            <if test="cId != null">c_id = #{cId},</if>
            <if test="otherId != null">other_id = #{otherId},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTDelayPermitById" parameterType="Long">
        update t_delay_permit
        set del_flag = 2
        where id = #{id}
    </update>

    <update id="deleteTDelayPermitByIds" parameterType="String">
        update t_delay_permit set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
