<?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.srs.staff.mapper.StaffOneStopRoomMapper">

    <resultMap type="StaffOneStopRoom" id="StaffOneStopRoomResult">
        <result property="roomId" column="room_id"/>
        <result property="roomNo" column="room_no"/>
        <result property="roomName" column="room_name"/>
        <result property="roomMatter" column="room_matter"/>
        <result property="roomRule" column="room_rule"/>
        <result property="roomInfo" column="room_info"/>
        <result property="roomPurp" column="room_purp"/>
        <result property="roomStatus" column="room_status"/>
        <result property="roomCapacity" column="room_capacity"/>
        <result property="roomCreatetime" column="room_createTime"/>
        <result property="roomUptime" column="room_upTime"/>
        <result property="roomUpuser" column="room_upuser"/>
        <result property="roomUser" column="room_user"/>
        <result property="roomDepar" column="room_depar"/>
        <result property="roomImgs" column="room_imgs"/>
        <!--查询功能房的预约记录-->
        <collection property="staffOneStopRoomReservationList" column="{roomNo = room_no}"
                    javaType="java.util.ArrayList" select="selectStaffOneStopRoomReservationByRoomNo">
        </collection>

        <!--查询功能房的开放时间-->
        <collection property="staffOneStopRoomOpeningHoursList" column="{roomNo = room_no}"
                    javaType="java.util.ArrayList" select="selectStaffOneStopRoomOpeningHoursByRoomNo">
        </collection>
    </resultMap>

    <!--预约记录-->
    <resultMap type="StaffOneStopRoomReservation" id="StaffOneStopRoomReservationResult">
        <result property="rtId" column="rt_id"/>
        <result property="rtNo" column="rt_no"/>
        <result property="roomNo" column="room_no"/>
        <result property="roomName" column="room_name"/>
        <result property="rtTheme" column="rt_theme"/>
        <result property="rtRole" column="rt_role"/>
        <result property="rtPeople" column="rt_people"/>
        <result property="rtPurpose" column="rt_purpose"/>
        <result property="rtTime" column="rt_time"/>
        <result property="rtTimePeriod" column="rt_time_period"/>
        <result property="rtState" column="rt_state"/>
        <result property="rtImgs" column="rt_imgs"/>
        <result property="rtCreatTime" column="rt_creat_time"/>
        <result property="rtUpTime" column="rt_up_time"/>
        <result property="rtCreatRole" column="rt_creat_role"/>
        <result property="rtDepar" column="rt_depar"/>
        <result property="auditStatus" column="audit_status"/>
        <result property="editOpinion" column="edit_opinion"/>
        <result property="feedback" column="feedback"/>
    </resultMap>

    <!--功能房开放时间-->
    <resultMap type="StaffOneStopRoomOpeningHours" id="StaffOneStopRoomOpeningHoursResult">
        <result property="ohId" column="oh_id"/>
        <result property="roomNo" column="room_no"/>
        <result property="ohWeekday" column="oh_weekday"/>
        <result property="openingHours" column="opening_hours"/>
        <result property="isOccupy" column="is_occupy"/>
        <result property="isDel" column="is_del"/>
        <result property="rtNo" column="rt_no"/>
    </resultMap>

    <!--功能房开放时间字段-->
    <sql id="selectStaffOneStopRoomOpeningHoursVo">
        select oh_id, room_no, oh_weekday, opening_hours, is_occupy, is_del, rt_no
        from staff_one_stop_room_opening_hours
    </sql>

    <!--预约记录字段-->
    <sql id="selectStaffOneStopRoomReservationVo">
        select rt_id,
               rt_no,
               room_no,
               room_name,
               rt_theme,
               rt_role,
               rt_people,
               rt_purpose,
               rt_time,
               rt_time_period,
               rt_state,
               rt_imgs,
               rt_creat_time,
               rt_up_time,
               rt_creat_role,
               rt_depar,
               audit_status,
               edit_opinion,
               feedback
        from staff_one_stop_room_reservation
    </sql>

    <!--预约记录子表的数据-->
    <select id="selectStaffOneStopRoomReservationByRoomNo" resultMap="StaffOneStopRoomReservationResult">
        <include refid="selectStaffOneStopRoomReservationVo"/>
        <where>
            <if test="roomNo != null and roomNo != ''">
                and room_no = #{roomNo}
            </if>
        </where>
        order by rt_creat_time desc
    </select>

    <!--功能房开放时间子表的数据-->
    <select id="selectStaffOneStopRoomOpeningHoursByRoomNo" resultMap="StaffOneStopRoomOpeningHoursResult">
        <include refid="selectStaffOneStopRoomOpeningHoursVo"/>
        <where>
            <if test="roomNo != null and roomNo != ''">
                and room_no = #{roomNo}
            </if>
        </where>
    </select>

    <sql id="selectStaffOneStopRoomVo">
        select room_id,
               room_no,
               room_name,
               room_matter,
               room_rule,
               room_info,
               room_purp,
               room_status,
               room_capacity,
               room_createTime,
               room_upTime,
               room_upuser,
               room_user,
               room_depar,
               room_imgs
        from staff_one_stop_room
    </sql>

    <select id="selectStaffOneStopRoomList" parameterType="StaffOneStopRoom" resultMap="StaffOneStopRoomResult">
        <include refid="selectStaffOneStopRoomVo"/>
        <where>
            <if test="roomNo != null  and roomNo != ''">and room_no = #{roomNo}</if>
            <if test="roomName != null  and roomName != ''">and room_name like concat('%', #{roomName}, '%')</if>
            <if test="roomMatter != null  and roomMatter != ''">and room_matter = #{roomMatter}</if>
            <if test="roomRule != null  and roomRule != ''">and room_rule = #{roomRule}</if>
            <if test="roomInfo != null  and roomInfo != ''">and room_info = #{roomInfo}</if>
            <if test="roomPurp != null  and roomPurp != ''">and room_purp = #{roomPurp}</if>
            <if test="roomStatus != null  and roomStatus != ''">and room_status = #{roomStatus}</if>
            <if test="roomCapacity != null  and roomCapacity != ''">and room_capacity = #{roomCapacity}</if>
            <if test="roomCreatetime != null ">and room_createTime = #{roomCreatetime}</if>
            <if test="roomUptime != null ">and room_upTime = #{roomUptime}</if>
            <if test="roomUpuser != null  and roomUpuser != ''">and room_upuser = #{roomUpuser}</if>
            <if test="roomUser != null  and roomUser != ''">and room_user = #{roomUser}</if>
            <if test="roomDepar != null  and roomDepar != ''">and room_depar = #{roomDepar}</if>
            <if test="roomImgs != null  and roomImgs != ''">and room_imgs = #{roomImgs}</if>
        </where>
    </select>

    <select id="selectStaffOneStopRoomByRoomId" parameterType="Long" resultMap="StaffOneStopRoomResult">
        <include refid="selectStaffOneStopRoomVo"/>
        where room_id = #{roomId}
    </select>

    <select id="selectStaffOneStopRoomByRoomNo" resultMap="StaffOneStopRoomResult">
        <include refid="selectStaffOneStopRoomVo"/>
        where room_no = #{roomNo}
    </select>

    <insert id="insertStaffOneStopRoom" parameterType="StaffOneStopRoom" useGeneratedKeys="true" keyProperty="roomId">
        insert into staff_one_stop_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roomNo != null">room_no,</if>
            <if test="roomName != null and roomName != ''">room_name,</if>
            <if test="roomMatter != null">room_matter,</if>
            <if test="roomRule != null">room_rule,</if>
            <if test="roomInfo != null">room_info,</if>
            <if test="roomPurp != null">room_purp,</if>
            <if test="roomStatus != null and roomStatus != ''">room_status,</if>
            <if test="roomCapacity != null and roomCapacity != ''">room_capacity,</if>
            <if test="roomCreatetime != null">room_createTime,</if>
            <if test="roomUptime != null">room_upTime,</if>
            <if test="roomUpuser != null">room_upuser,</if>
            <if test="roomUser != null">room_user,</if>
            <if test="roomDepar != null">room_depar,</if>
            <if test="roomImgs != null">room_imgs,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roomNo != null">#{roomNo},</if>
            <if test="roomName != null and roomName != ''">#{roomName},</if>
            <if test="roomMatter != null">#{roomMatter},</if>
            <if test="roomRule != null">#{roomRule},</if>
            <if test="roomInfo != null">#{roomInfo},</if>
            <if test="roomPurp != null">#{roomPurp},</if>
            <if test="roomStatus != null and roomStatus != ''">#{roomStatus},</if>
            <if test="roomCapacity != null and roomCapacity != ''">#{roomCapacity},</if>
            <if test="roomCreatetime != null">#{roomCreatetime},</if>
            <if test="roomUptime != null">#{roomUptime},</if>
            <if test="roomUpuser != null">#{roomUpuser},</if>
            <if test="roomUser != null">#{roomUser},</if>
            <if test="roomDepar != null">#{roomDepar},</if>
            <if test="roomImgs != null">#{roomImgs},</if>
        </trim>
    </insert>

    <update id="updateStaffOneStopRoom" parameterType="StaffOneStopRoom">
        update staff_one_stop_room
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomNo != null">room_no = #{roomNo},</if>
            <if test="roomName != null and roomName != ''">room_name = #{roomName},</if>
            <if test="roomMatter != null">room_matter = #{roomMatter},</if>
            <if test="roomRule != null">room_rule = #{roomRule},</if>
            <if test="roomInfo != null">room_info = #{roomInfo},</if>
            <if test="roomPurp != null">room_purp = #{roomPurp},</if>
            <if test="roomStatus != null and roomStatus != ''">room_status = #{roomStatus},</if>
            <if test="roomCapacity != null and roomCapacity != ''">room_capacity = #{roomCapacity},</if>
            <if test="roomCreatetime != null">room_createTime = #{roomCreatetime},</if>
            <if test="roomUptime != null">room_upTime = #{roomUptime},</if>
            <if test="roomUpuser != null">room_upuser = #{roomUpuser},</if>
            <if test="roomUser != null">room_user = #{roomUser},</if>
            <if test="roomDepar != null">room_depar = #{roomDepar},</if>
            <if test="roomImgs != null">room_imgs = #{roomImgs},</if>
        </trim>
        where room_id = #{roomId}
    </update>

    <delete id="deleteStaffOneStopRoomByRoomId" parameterType="Long">
        delete
        from staff_one_stop_room
        where room_id = #{roomId}
    </delete>

    <delete id="deleteStaffOneStopRoomByRoomIds" parameterType="String">
        delete from staff_one_stop_room where room_id in
        <foreach item="roomId" collection="array" open="(" separator="," close=")">
            #{roomId}
        </foreach>
    </delete>
</mapper>