<?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.ShowroomRecordMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.ShowroomRecord" id="ShowroomRecordResult">
        <result property="id"    column="id"    />
        <result property="showroomId"    column="showroom_id"    />
        <result property="userId"    column="user_id"    />
        <result property="title"    column="title"    />
        <result property="status"    column="status"    />
        <result property="reservationNumber"    column="reservation_number"    />
        <result property="cancelTime"    column="cancel_time"    />
        <result property="cancelResaon"    column="cancel_resaon"    />
        <result property="explainNeedType"    column="explain_need_type"    />
        <result property="meetingNeedType"    column="meeting_need_type"    />
        <result property="photographType"    column="photograph_type"    />
        <result property="persons"    column="persons"    />
        <result property="visitType"    column="visit_type"    />
        <result property="startTime"    column="start_time"    />
        <result property="endDate"    column="end_date"    />
        <result property="deleteFlag"    column="delete_flag"    />
        <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="remake"    column="remake"    />
    </resultMap>

    <sql id="selectShowroomRecordVo">
        SELECT id, showroom_id, user_id, title, status, reservation_number,, explain_need_type, meeting_need_type,  photograph_type, cancel_time, cancel_resaon, start_time, end_date, delete_flag, create_by, create_time, update_by, update_time, remake FROM tb_showroom_record
    </sql>

    <select id="selectShowroomRecordList" parameterType="ShowroomRecord" resultMap="ShowroomRecordResult">
        <include refid="selectShowroomRecordVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectShowroomRecordById" parameterType="Long" resultMap="ShowroomRecordResult">
        <include refid="selectShowroomRecordVo"/>
        WHERE id = #{id}
    </select>
    <select id="selectListByDate" resultType="java.util.Date">
        select  date_format(start_time, '%Y-%m-%d') from tb_showroom_record where start_time >= date_format(now(), '%Y-%m-%d')
                                                                          and showroom_id = #{showroomId} and status != 4
                                                                            group by date_format(start_time, '%Y-%m-%d');
    </select>

    <insert id="insertShowroomRecord" parameterType="ShowroomRecord" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO tb_showroom_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="showroomId != null ">showroom_id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="title != null  and title != ''">title,</if>
            <if test="status != null ">status,</if>
            <if test="reservationNumber != null  and reservationNumber != ''">reservation_number,</if>
            <if test="cancelTime != null ">cancel_time,</if>
            <if test="cancelResaon != null  and cancelResaon != ''">cancel_resaon,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endDate != null ">end_date,</if>
            <if test="explainNeedType != null  and explainNeedType != ''">explain_need_type,</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">meeting_need_type,</if>
            <if test="photographType != null  and photographType != ''">photograph_type,</if>
            <if test="persons != null  and persons != ''">persons,</if>
            <if test="visitType != null  and visitType != ''">visit_type,</if>
            <if test="deleteFlag != null ">delete_flag,</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="remake != null  and remake != ''">remake,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="showroomId != null ">#{showroomId},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="title != null  and title != ''">#{title},</if>
            <if test="status != null ">#{status},</if>
            <if test="reservationNumber != null  and reservationNumber != ''">#{reservationNumber},</if>
            <if test="cancelTime != null ">#{cancelTime},</if>
            <if test="cancelResaon != null  and cancelResaon != ''">#{cancelResaon},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="explainNeedType != null  and explainNeedType != ''">#{explainNeedType},</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">#{meetingNeedType},</if>
            <if test="photographType != null  and photographType != ''">#{photographType},</if>
            <if test="persons != null  and persons != ''">#{persons},</if>
            <if test="visitType != null  and visitType != ''">#{visitType},</if>
            <if test="endDate != null ">#{endDate},</if>
            <if test="deleteFlag != null ">#{deleteFlag},</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="remake != null  and remake != ''">#{remake},</if>
         </trim>
    </insert>

    <update id="updateShowroomRecord" parameterType="ShowroomRecord">
        UPDATE tb_showroom_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="showroomId != null ">showroom_id = #{showroomId},</if>
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="title != null  and title != ''">title = #{title},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="reservationNumber != null  and reservationNumber != ''">reservation_number = #{reservationNumber},</if>
            <if test="cancelTime != null ">cancel_time = #{cancelTime},</if>
            <if test="cancelResaon != null  and cancelResaon != ''">cancel_resaon = #{cancelResaon},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="explainNeedType != null  and explainNeedType != ''">explain_need_type = #{explainNeedType},</if>
            <if test="meetingNeedType != null  and meetingNeedType != ''">meeting_need_type = #{meetingNeedType},</if>
            <if test="photographType != null  and photographType != ''">photograph_type = #{photographType},</if>
            <if test="persons != null  and persons != ''">persons = #{persons},</if>
            <if test="visitType != null  and visitType != ''">visit_type = #{visitType},</if>
            <if test="endDate != null ">end_date = #{endDate},</if>
            <if test="deleteFlag != null ">delete_flag = #{deleteFlag},</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="remake != null  and remake != ''">remake = #{remake},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteShowroomRecordById" parameterType="Long">
        DELETE FROM tb_showroom_record WHERE id = #{id}
    </delete>

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