<?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.TInvoiceBookingworkticketMapper">
    
    <resultMap type="TInvoiceBookingworkticket" id="TInvoiceBookingworkticketResult">
        <result property="id"    column="id"    />
        <result property="workUnit"    column="work_unit"    />
        <result property="workArea"    column="work_area"    />
        <result property="unitNumber"    column="unit_number"    />
        <result property="floorLocation"    column="floor_location"    />
        <result property="workStartTime"    column="work_start_time"    />
        <result property="workEndTime"    column="work_end_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="contact"    column="contact"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="status"    column="status"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userMg"    column="user_mg"    />
        <result property="deptName" column="dept_name" />
        <result property="reservationNumber"    column="reservation_number"    />
        <result property="filename"    column="filename"    />
        <result property="userUnit"    column="user_unit"    />
    </resultMap>

    <sql id="selectTInvoiceBookingworkticketVo">
        select d.id, d.work_unit, d.work_area, d.unit_number, d.floor_location, d.work_start_time, d.work_end_time, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.contact, d.phonenumber, d.status, d.dept_id, d.user_mg ,s.dept_name,d.filename,d.reservation_number from t_invoice_bookingworkticket d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTInvoiceBookingworkticketList" parameterType="TInvoiceBookingworkticket" resultMap="TInvoiceBookingworkticketResult">
        <include refid="selectTInvoiceBookingworkticketVo"/>
        <where>  
            <if test="workUnit != null "> and work_unit = #{workUnit}</if>
            <if test="workArea != null "> and work_area = #{workArea}</if>
            <if test="unitNumber != null "> and unit_number = #{unitNumber}</if>
            <if test="floorLocation != null "> and floor_location = #{floorLocation}</if>
            <if test="workStartTime != null "> and work_start_time = #{workStartTime}</if>
            <if test="workEndTime != null "> and work_end_time = #{workEndTime}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="contact != null  and contact != ''"> and contact = #{contact}</if>
            <if test="phonenumber != null  and phonenumber != ''"> and phonenumber = #{phonenumber}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userMg != null "> and user_mg = #{userMg}</if>
            <if test="userUnit != null "> and user_unit = #{userUnit}</if>
            <if test="reservationNumber != null "> and reservation_number = #{reservationNumber}</if>
            <if test="filename != null  and filename != ''"> and filename like concat(concat('%', #{filename}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTInvoiceBookingworkticketById" parameterType="Long" resultMap="TInvoiceBookingworkticketResult">
        <include refid="selectTInvoiceBookingworkticketVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTInvoiceBookingworkticket" parameterType="TInvoiceBookingworkticket" useGeneratedKeys = "true" keyProperty = "id">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT t_bookingworkticket_seq.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_invoice_bookingworkticket
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="workUnit != null">work_unit,</if>
            <if test="workArea != null">work_area,</if>
            <if test="unitNumber != null">unit_number,</if>
            <if test="floorLocation != null">floor_location,</if>
            <if test="workStartTime != null">work_start_time,</if>
            <if test="workEndTime != null">work_end_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="contact != null">contact,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="status != null">status,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userMg != null">user_mg,</if>
            <if test="userUnit != null">user_unit,</if>
            <if test="reservationNumber != null">reservation_number,</if>
            <if test="filename != null">filename,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="workUnit != null">#{workUnit},</if>
            <if test="workArea != null">#{workArea},</if>
            <if test="unitNumber != null">#{unitNumber},</if>
            <if test="floorLocation != null">#{floorLocation},</if>
            <if test="workStartTime != null">#{workStartTime},</if>
            <if test="workEndTime != null">#{workEndTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="contact != null">#{contact},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="status != null">#{status},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userMg != null">#{userMg},</if>
            <if test="userUnit != null">#{userUnit},</if>
            <if test="reservationNumber != null">reservation_number = #{reservationNumber},</if>
            <if test="filename != null">#{filename},</if>
         </trim>
    </insert>

    <update id="updateTInvoiceBookingworkticket" parameterType="TInvoiceBookingworkticket">
        update t_invoice_bookingworkticket
        <trim prefix="SET" suffixOverrides=",">
            <if test="workUnit != null">work_unit = #{workUnit},</if>
            <if test="workArea != null">work_area = #{workArea},</if>
            <if test="unitNumber != null">unit_number = #{unitNumber},</if>
            <if test="floorLocation != null">floor_location = #{floorLocation},</if>
            <if test="workStartTime != null">work_start_time = #{workStartTime},</if>
            <if test="workEndTime != null">work_end_time = #{workEndTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="contact != null">contact = #{contact},</if>
            <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userMg != null">user_mg = #{userMg},</if>
            <if test="userUnit != null">user_unit = #{userUnit},</if>
            <if test="reservationNumber != null">reservation_number = #{reservationNumber},</if>
            <if test="filename != null">filename = #{filename},</if>
        </trim>
        where id = #{id}
    </update>

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

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