<?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.ics.admin.mapper.meeting.RoomContentMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.RoomContent" id="RoomContentResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="meetingName"    column="meeting_name"    />
        <result property="capacityNum"    column="capacity_num"    />
        <result property="expandNum"    column="expand_num"    />
        <result property="indoorPicUrl"    column="indoor_pic_url"    />
        <result property="address"    column="address"    />
        <result property="startTime"    column="start_time"    />
        <result property="endDate"    column="end_date"    />
        <result property="duration"    column="duration"    />
        <result property="shape"    column="shape"    />
        <result property="money"    column="money"    />
        <result property="isShow"    column="is_show"    />
        <result property="headName"    column="head_name"    />
        <result property="headPhone"    column="head_phone"    />
        <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="version"    column="version"    />
        <result property="deleteFlag"    column="delete_flag"    />
        <result property="roomId"    column="room_id"    />
        <result property="isToll"    column="is_toll"    />
        <result property="isTicket"    column="is_ticket"    />
        <result property="content"    column="content"    />
        <result property="remake"    column="remake"    />
    </resultMap>



    <sql id="selectRoomContentVo">
        SELECT id, type, meeting_name, capacity_num, expand_num,remake, indoor_pic_url, address, start_time, end_date, duration, shape, money, is_show, head_name, head_phone, create_by, create_time, update_by, update_time, version, delete_flag, room_id, is_toll, is_ticket, content FROM tb_room_content
    </sql>

    <select id="selectRoomContentList" parameterType="RoomContent" resultMap="RoomContentResult">
        <include refid="selectRoomContentVo"/>
        <where>  
            <if test="meetingName != null  and meetingName != ''"> AND meeting_name LIKE CONCAT('%', #{meetingName}, '%')</if>
            <if test="type != null  and type != ''"> AND `type`= #{type}</if>
            <if test="capacityNum != null  and capacityNum != ''"> AND capacity_num =#{capacityNum}</if>
            <if test="shape != null  and shape != ''"> AND shape =#{shape}</if>
            <if test="parkId != null  and parkId != ''"> AND park_id =#{parkId}</if>
            <if test="tenantId != null  and tenantId != ''"> AND tenant_id =#{tenantId}</if>
            and  is_show = 0
        </where>
        order by create_time asc

    </select>
    
    <select id="selectRoomContentById" parameterType="Long" resultMap="RoomContentResult">
        <include refid="selectRoomContentVo"/>
        WHERE id = #{id}
    </select>
    <select id="todayMeeting" resultType="com.ics.admin.domain.meeting.RoomContent">
        <include refid="selectRoomContentVo"/>
        WHERE
        (
        DATE_FORMAT( start_time, '%Y-%m-%d' ) =
        DATE_FORMAT( NOW(), '%Y-%m-%d' ))
        and
        (
        DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:%S' ) &lt;
            DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' ))
        OR (
        DATE_FORMAT( end_date, '%Y-%m-%d %H:%i:%S' ) &gt;
        DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' )
        AND DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:%S' ) &gt;
        DATE_FORMAT( NOW(), '%Y-%m-%d %H:%i:%S' ))
        and id =#{id}
        ORDER BY start_time ASC


    </select>

    <insert id="insertRoomContent" parameterType="RoomContent">
        INSERT INTO tb_room_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null  and type != ''">type,</if>
            <if test="meetingName != null  and meetingName != ''">meeting_name,</if>
            <if test="capacityNum != null ">capacity_num,</if>
            <if test="expandNum != null ">expand_num,</if>
            <if test="indoorPicUrl != null  and indoorPicUrl != ''">indoor_pic_url,</if>
            <if test="address != null  and address != ''">address,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endDate != null ">end_date,</if>
            <if test="duration != null ">duration,</if>
            <if test="shape != null  and shape != ''">shape,</if>
            <if test="money != null  and money != ''">money,</if>
            <if test="isShow != null ">is_show,</if>
            <if test="headName != null  and headName != ''">head_name,</if>
            <if test="headPhone != null  and headPhone != ''">head_phone,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="version != null ">version,</if>
            <if test="deleteFlag != null ">delete_flag,</if>
            <if test="roomId != null ">room_id,</if>
            <if test="isToll != null ">is_toll,</if>
            <if test="isTicket != null ">is_ticket,</if>
            <if test="content != null  and content != ''">content,</if>
            <if test="remake != null  and remake != ''">remake,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null  and type != ''">#{type},</if>
            <if test="meetingName != null  and meetingName != ''">#{meetingName},</if>
            <if test="capacityNum != null ">#{capacityNum},</if>
            <if test="expandNum != null ">#{expandNum},</if>
            <if test="indoorPicUrl != null  and indoorPicUrl != ''">#{indoorPicUrl},</if>
            <if test="address != null  and address != ''">#{address},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="endDate != null ">#{endDate},</if>
            <if test="duration != null ">#{duration},</if>
            <if test="shape != null  and shape != ''">#{shape},</if>
            <if test="money != null  and money != ''">#{money},</if>
            <if test="isShow != null ">#{isShow},</if>
            <if test="headName != null  and headName != ''">#{headName},</if>
            <if test="headPhone != null  and headPhone != ''">#{headPhone},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="version != null ">#{version},</if>
            <if test="deleteFlag != null ">#{deleteFlag},</if>
            <if test="roomId != null ">#{roomId},</if>
            <if test="isToll != null ">#{isToll},</if>
            <if test="isTicket != null ">#{isTicket},</if>
            <if test="content != null  and content != ''">#{content},</if>
            <if test="remake != null  and remake != ''">#{remake},</if>
        </trim>
    </insert>

    <update id="updateRoomContent" parameterType="RoomContent">
        UPDATE tb_room_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null  and type != ''">type = #{type},</if>
            <if test="meetingName != null  and meetingName != ''">meeting_name = #{meetingName},</if>
            <if test="capacityNum != null ">capacity_num = #{capacityNum},</if>
            <if test="expandNum != null ">expand_num = #{expandNum},</if>
            <if test="indoorPicUrl != null  and indoorPicUrl != ''">indoor_pic_url = #{indoorPicUrl},</if>
            <if test="address != null  and address != ''">address = #{address},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endDate != null ">end_date = #{endDate},</if>
            <if test="duration != null ">duration = #{duration},</if>
            <if test="shape != null  and shape != ''">shape = #{shape},</if>
            <if test="money != null  and money != ''">money = #{money},</if>
            <if test="isShow != null ">is_show = #{isShow},</if>
            <if test="headName != null  and headName != ''">head_name = #{headName},</if>
            <if test="headPhone != null  and headPhone != ''">head_phone = #{headPhone},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="version != null ">version = #{version},</if>
            <if test="deleteFlag != null ">delete_flag = #{deleteFlag},</if>
            <if test="roomId != null ">room_id = #{roomId},</if>
            <if test="isToll != null ">is_toll = #{isToll},</if>
            <if test="isTicket != null ">is_ticket = #{isTicket},</if>
            <if test="content != null  and content != ''">content = #{content},</if>
            <if test="remake != null  and remake != ''">remake = #{remake},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteRoomContentById" parameterType="Long">
        DELETE FROM tb_room_content WHERE id = #{id}
    </delete>

    <delete id="deleteRoomContentByIds" parameterType="String">
        DELETE FROM tb_room_content where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>