<?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.xjrsoft.module.room.mapper.RoomValueWeekItemMapper">
    <select id="getItemPage" parameterType="com.xjrsoft.module.room.dto.RoomValueWeekPageDto" resultType="com.xjrsoft.module.room.vo.RoomValueWeekPageVo">
        SELECT t1.id,t2.sort_code,t2.start_time,t2.end_time,t1.user_id,t3.name as user_name,t1.post_name,t1.room_type,t1.number_people FROM room_value_week_item t1
        LEFT JOIN room_value_week t2 ON t1.room_value_week_id = t2.id
        LEFT JOIN xjr_user t3 ON t1.user_id = t3.id
        WHERE t2.delete_mark = 0 AND t1.delete_mark = 0
        <if test="dto.startTime != null">
            and t2.start_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null">
            and #{dto.endTime} >= t2.end_time
        </if>
        <if test="dto.userName != null and dto.userName != ''">
            and t3.name like concat('%', #{dto.userName}, '%')
        </if>
        <if test="dto.roomType != null and dto.roomType != ''">
            and t1.room_type = #{dto.roomType}
        </if>
        ORDER BY t2.sort_code,t1.sort_code
    </select>
    <select id="getItemList" parameterType="com.xjrsoft.module.room.dto.RoomValueWeekPageDto" resultType="com.xjrsoft.module.room.vo.RoomValueWeekPageVo">
        SELECT t1.id,t2.sort_code,t2.start_time,t2.end_time,t1.user_id,t3.name as user_name,t1.post_name,t1.room_type,t1.number_people,t1.room_value_week_id FROM room_value_week_item t1
        LEFT JOIN room_value_week t2 ON t1.room_value_week_id = t2.id
        LEFT JOIN xjr_user t3 ON t1.user_id = t3.id
        WHERE t2.delete_mark = 0 AND t1.delete_mark = 0
        <if test="dto.startTime != null">
            and t2.start_time >= #{dto.startTime}
        </if>
        <if test="dto.endTime != null">
            and #{dto.endTime} >= t2.end_time
        </if>
        <if test="dto.userName != null and dto.userName != ''">
            and t3.name like concat('%', #{dto.userName}, '%')
        </if>
        <if test="dto.roomType != null and dto.roomType != ''">
            and t1.room_type = #{dto.roomType}
        </if>
        ORDER BY t2.sort_code,t1.sort_code
    </select>

    <select id="getMaxSortCode" resultType="java.lang.Integer">
        SELECT IFNULL(MAX(sort_code),0) FROM room_value_week_item WHERE delete_mark = 0
    </select>

</mapper>