<?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.invoice.mapper.TApproveReserveInvoiceMapper">

    <resultMap type="TApproveReserveInvoice" id="TApproveReserveInvoiceResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="managerconId"    column="managercon_id"    />
        <result property="userSupId"    column="user_sup_id"    />
        <result property="devEngineerId"    column="dev_engineer_id"    />
        <result property="monitorId"    column="monitor_id"    />
        <result property="devType"    column="dev_type"    />
        <result property="approveType"    column="approve_type"    />
        <result property="content"    column="content"    />
        <result property="fileUrls"    column="file_urls"    />
        <result property="status"    column="status"    />
        <result property="creattime"    column="creattime"    />
        <result property="enddate"    column="enddate"    />
        <result property="processId"    column="process_id"    />
        <result property="apNo"    column="ap_no"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="deptId"    column="dept_id"    />
        <result property="devSupId"    column="dev_sup_id"    />
        <result property="deptName" column="dept_name" />
        <result property="invoiceId" column="invoice_id" />
    </resultMap>

    <sql id="selectTApproveReserveInvoiceVo">
        select d.id, d.user_id, d.managercon_id, d.user_sup_id, d.dev_engineer_id, d.monitor_id, d.dev_type, d.approve_type, d.content, d.file_urls, d.status, d.creattime, d.enddate, d.process_id, d.ap_no, d.del_flag, d.dept_id, d.dev_sup_id ,d.invoice_id,s.dept_name from t_approve_reserve_invoice d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTApproveReserveInvoiceList" parameterType="TApproveReserveInvoice" resultMap="TApproveReserveInvoiceResult">
        <include refid="selectTApproveReserveInvoiceVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="managerconId != null "> and managercon_id = #{managerconId}</if>
            <if test="userSupId != null "> and user_sup_id = #{userSupId}</if>
            <if test="devEngineerId != null "> and dev_engineer_id = #{devEngineerId}</if>
            <if test="monitorId != null "> and monitor_id = #{monitorId}</if>
            <if test="devType != null "> and dev_type = #{devType}</if>
            <if test="approveType != null "> and approve_type = #{approveType}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="fileUrls != null  and fileUrls != ''"> and file_urls = #{fileUrls}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="creattime != null "> and creattime = #{creattime}</if>
            <if test="enddate != null "> and enddate = #{enddate}</if>
            <if test="processId != null  and processId != ''"> and process_id = #{processId}</if>
            <if test="apNo != null  and apNo != ''"> and ap_no = #{apNo}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="devSupId != null "> and dev_sup_id = #{devSupId}</if>
            <if test="invoiceId != null "> and invoice_id = #{invoiceId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTApproveReserveInvoiceById" parameterType="Long" resultMap="TApproveReserveInvoiceResult">
        <include refid="selectTApproveReserveInvoiceVo"/>
        where id = #{id}
    </select>

    <select id="selectTApproveReserveInvoiceByinvoiceId" parameterType="String" resultMap="TApproveReserveInvoiceResult">
        <include refid="selectTApproveReserveInvoiceVo"/>
        where d.invoice_id  = #{invoiceId} and d.status!=3
    </select>

    <insert id="insertTApproveReserveInvoice" parameterType="TApproveReserveInvoice">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_approve_reserve_invoice.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_approve_reserve_invoice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="managerconId != null">managercon_id,</if>
            <if test="userSupId != null">user_sup_id,</if>
            <if test="devEngineerId != null">dev_engineer_id,</if>
            <if test="monitorId != null">monitor_id,</if>
            <if test="devType != null">dev_type,</if>
            <if test="approveType != null">approve_type,</if>
            <if test="content != null">content,</if>
            <if test="fileUrls != null">file_urls,</if>
            <if test="status != null">status,</if>
            <if test="creattime != null">creattime,</if>
            <if test="enddate != null">enddate,</if>
            <if test="processId != null">process_id,</if>
            <if test="apNo != null">ap_no,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="devSupId != null">dev_sup_id,</if>
            <if test="invoiceId != null">invoice_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="managerconId != null">#{managerconId},</if>
            <if test="userSupId != null">#{userSupId},</if>
            <if test="devEngineerId != null">#{devEngineerId},</if>
            <if test="monitorId != null">#{monitorId},</if>
            <if test="devType != null">#{devType},</if>
            <if test="approveType != null">#{approveType},</if>
            <if test="content != null">#{content},</if>
            <if test="fileUrls != null">#{fileUrls},</if>
            <if test="status != null">#{status},</if>
            <if test="creattime != null">#{creattime},</if>
            <if test="enddate != null">#{enddate},</if>
            <if test="processId != null">#{processId},</if>
            <if test="apNo != null">#{apNo},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="devSupId != null">#{devSupId},</if>
            <if test="invoiceId != null">#{invoiceId},</if>
         </trim>
    </insert>

    <update id="updateTApproveReserveInvoice" parameterType="TApproveReserveInvoice">
        update t_approve_reserve_invoice
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="managerconId != null">managercon_id = #{managerconId},</if>
            <if test="userSupId != null">user_sup_id = #{userSupId},</if>
            <if test="devEngineerId != null">dev_engineer_id = #{devEngineerId},</if>
            <if test="monitorId != null">monitor_id = #{monitorId},</if>
            <if test="devType != null">dev_type = #{devType},</if>
            <if test="approveType != null">approve_type = #{approveType},</if>
            <if test="content != null">content = #{content},</if>
            <if test="fileUrls != null">file_urls = #{fileUrls},</if>
            <if test="status != null">status = #{status},</if>
            <if test="creattime != null">creattime = #{creattime},</if>
            <if test="enddate != null">enddate = #{enddate},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="apNo != null">ap_no = #{apNo},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="devSupId != null">dev_sup_id = #{devSupId},</if>
            <if test="invoiceId != null">invoice_id = #{invoiceId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
