<?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.system.mapper.ConferenceRoomOrderMapper">

    <resultMap type="ConferenceRoomOrder" id="ConferenceRoomOrderResult">
        <result property="conferenceRoomOrderId" column="conference_room_order_id"/>
        <result property="orderUser" column="order_user"/>
        <result property="orderUserId" column="order_user_id"/>
        <result property="conferenceRoomId" column="conference_room_id"/>
        <result property="conferenceRoomName" column="conference_room_name"/>
        <result property="conferenceRoomAddress" column="conference_room_address"/>
        <result property="conferenceName" column="conference_name"/>
        <result property="conferenceNumber" column="conference_number"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="useXk" column="use_xk"/>
        <result property="createDept" column="create_dept"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectConferenceRoomOrderVo">
        select conference_room_order_id,
               order_user,
               order_user_id,
               conference_room_id,
               conference_room_name,
               conference_room_address,
               conference_name,
               conference_number,
               start_time,
               end_time,
               use_xk,
               create_dept,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from conference_room_order
    </sql>

    <select id="selectConferenceRoomOrderList" parameterType="ConferenceRoomOrder"
            resultMap="ConferenceRoomOrderResult">
        <include refid="selectConferenceRoomOrderVo"/>
        <where>
            <if test="orderUser != null  and orderUser != ''">and order_user = #{orderUser}</if>
            <if test="orderUserId != null ">and order_user_id = #{orderUserId}</if>
            <if test="conferenceRoomId != null ">and conference_room_id = #{conferenceRoomId}</if>
            <if test="conferenceRoomName != null  and conferenceRoomName != ''">and conference_room_name like
                concat('%', #{conferenceRoomName}, '%')
            </if>
            <if test="conferenceRoomAddress != null  and conferenceRoomAddress != ''">and conference_room_address =
                #{conferenceRoomAddress}
            </if>
            <if test="conferenceName != null  and conferenceName != ''">and conference_name like concat('%',
                #{conferenceName}, '%')
            </if>
            <if test="conferenceNumber != null  and conferenceNumber != ''">and conference_number =
                #{conferenceNumber}
            </if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="useXk != null and useXk != ''">and use_xk = #{useXk}</if>
            <if test="createDept != null ">and create_dept = #{createDept}</if>
        </where>
        order by end_time DESC
    </select>


    <select id="selectConferenceRoomOrderListNoPage" parameterType="ConferenceRoomOrder"
            resultMap="ConferenceRoomOrderResult">
        <include refid="selectConferenceRoomOrderVo"/>
        <where>
            <if test="orderUser != null  and orderUser != ''">and order_user = #{orderUser}</if>
            <if test="orderUserId != null ">and order_user_id = #{orderUserId}</if>
            <if test="conferenceRoomId != null ">and conference_room_id = #{conferenceRoomId}</if>
            <if test="conferenceRoomName != null  and conferenceRoomName != ''">and conference_room_name like
                concat('%', #{conferenceRoomName}, '%')
            </if>
            <if test="conferenceRoomAddress != null  and conferenceRoomAddress != ''">and conference_room_address =
                #{conferenceRoomAddress}
            </if>
            <if test="conferenceName != null  and conferenceName != ''">and conference_name like concat('%',
                #{conferenceName}, '%')
            </if>
            <if test="conferenceNumber != null  and conferenceNumber != ''">and conference_number =
                #{conferenceNumber}
            </if>
            <if test="startTime != null ">and #{startTime} &lt; end_time</if>
            <if test="useXk != null and useXk != ''">and use_xk = #{useXk}</if>
            <if test="createDept != null ">and create_dept = #{createDept}</if>
        </where>
        order by end_time DESC
    </select>
    <select id="selectConferenceRoomOrderListType" parameterType="ConferenceRoomOrder"
            resultMap="ConferenceRoomOrderResult">
        <include refid="selectConferenceRoomOrderVo"/>
        <where>
            <if test="conferenceRoomId != null ">and conference_room_id = #{conferenceRoomId}</if>
            <if test="startTime != null ">and #{startTime} BETWEEN start_time and end_time</if>
        </where>
    </select>
    <select id="selectConferenceRoomOrderByStartTime" parameterType="ConferenceRoomOrder"
            resultMap="ConferenceRoomOrderResult">
        <include refid="selectConferenceRoomOrderVo"/>
        <where>
            <if test="conferenceRoomId != null ">and conference_room_id = #{conferenceRoomId}</if>
            <if test="startTime != null ">and #{startTime} &lt; end_time</if>
        </where>
    </select>

    <select id="selectConferenceRoomOrderByConferenceRoomOrderId" parameterType="Long"
            resultMap="ConferenceRoomOrderResult">
        <include refid="selectConferenceRoomOrderVo"/>
        where conference_room_order_id = #{conferenceRoomOrderId}
    </select>

    <insert id="insertConferenceRoomOrder" parameterType="ConferenceRoomOrder" useGeneratedKeys="true"
            keyProperty="conferenceRoomOrderId">
        insert into conference_room_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderUser != null">order_user,</if>
            <if test="orderUserId != null">order_user_id,</if>
            <if test="conferenceRoomId != null">conference_room_id,</if>
            <if test="conferenceRoomName != null">conference_room_name,</if>
            <if test="conferenceRoomAddress != null">conference_room_address,</if>
            <if test="conferenceName != null">conference_name,</if>
            <if test="conferenceNumber != null">conference_number,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="useXk != null">use_xk,</if>
            <if test="createDept != null">create_dept,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderUser != null">#{orderUser},</if>
            <if test="orderUserId != null">#{orderUserId},</if>
            <if test="conferenceRoomId != null">#{conferenceRoomId},</if>
            <if test="conferenceRoomName != null">#{conferenceRoomName},</if>
            <if test="conferenceRoomAddress != null">#{conferenceRoomAddress},</if>
            <if test="conferenceName != null">#{conferenceName},</if>
            <if test="conferenceNumber != null">#{conferenceNumber},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="useXk != null">#{useXk},</if>
            <if test="createDept != null">#{createDept},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateConferenceRoomOrder" parameterType="ConferenceRoomOrder">
        update conference_room_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderUser != null">order_user = #{orderUser},</if>
            <if test="orderUserId != null">order_user_id = #{orderUserId},</if>
            <if test="conferenceRoomId != null">conference_room_id = #{conferenceRoomId},</if>
            <if test="conferenceRoomName != null">conference_room_name = #{conferenceRoomName},</if>
            <if test="conferenceRoomAddress != null">conference_room_address = #{conferenceRoomAddress},</if>
            <if test="conferenceName != null">conference_name = #{conferenceName},</if>
            <if test="conferenceNumber != null">conference_number = #{conferenceNumber},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="useXk != null">use_xk = #{useXk},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where conference_room_order_id = #{conferenceRoomOrderId}
    </update>

    <delete id="deleteConferenceRoomOrderByConferenceRoomOrderId" parameterType="Long">
        delete
        from conference_room_order
        where conference_room_order_id = #{conferenceRoomOrderId}
    </delete>

    <delete id="deleteConferenceRoomOrderByConferenceRoomOrderIds" parameterType="String">
        delete from conference_room_order where conference_room_order_id in
        <foreach item="conferenceRoomOrderId" collection="array" open="(" separator="," close=")">
            #{conferenceRoomOrderId}
        </foreach>
    </delete>
</mapper>