<?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.dgtis.dorm.manager.db.dao.ReservationRecordMapper">
    
    <resultMap type="com.dgtis.dorm.manager.db.domain.ReservationRecord" id="ReservationRecordResult">
        <result property="id"    column="id"    />
        <result property="serviceId"    column="service_id"    />
        <result property="serviceName"    column="service_name"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="applicantName"    column="applicant_name"    />
        <result property="applicantIdCard"    column="applicant_id_card"    />
        <result property="reservationDate"    column="reservation_date"    />
        <result property="reservationInterval"    column="reservation_interval"    />
        <result property="reservationNumber"    column="reservation_number"    />
        <result property="reservationState"    column="reservation_state"    />
        <result property="addTime"    column="add_time"    />
        <result property="addUser"    column="add_user"    />
        <result property="modifyTime"    column="modify_time"    />
        <result property="modifyUser"    column="modify_user"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>
	
	<sql id="selectReservationRecordVo">
        select id, service_id, service_name, user_id, dept_id, dept_name, applicant_name, applicant_id_card, reservation_date, reservation_interval, reservation_number, reservation_state, add_time, add_user, modify_time, modify_user, del_flag from reservation_record
    </sql>
	
    <select id="selectReservationRecordList" parameterType="com.dgtis.dorm.manager.db.domain.ReservationRecord" resultMap="ReservationRecordResult">
        <include refid="selectReservationRecordVo"/>
        <where>
            del_flag = 0
            <if test="id != null  and id != '' "> and id = #{id}</if>
             <if test="serviceId != null  and serviceId != '' "> and service_id = #{serviceId}</if>
             <if test="serviceName != null  and serviceName != '' "> and service_name = #{serviceName}</if>
             <if test="userId != null  and userId != '' "> and user_id = #{userId}</if>
             <if test="deptId != null  and deptId != '' "> and dept_id = #{deptId}</if>
             <if test="deptName != null  and deptName != '' "> and dept_name = #{deptName}</if>
             <if test="applicantName != null  and applicantName != '' "> and applicant_name = #{applicantName}</if>
             <if test="applicantIdCard != null  and applicantIdCard != '' "> and applicant_id_card = #{applicantIdCard}</if>
             <if test="reservationDate != null "> and reservation_date = #{reservationDate}</if>
             <if test="reservationInterval != null  and reservationInterval != '' "> and reservation_interval = #{reservationInterval}</if>
             <if test="reservationNumber != null "> and reservation_number = #{reservationNumber}</if>
             <if test="reservationState != null  and reservationState != '' "> and reservation_state = #{reservationState}</if>
             <if test="addTime != null "> and add_time = #{addTime}</if>
             <if test="addUser != null  and addUser != '' "> and add_user = #{addUser}</if>
             <if test="modifyTime != null "> and modify_time = #{modifyTime}</if>
             <if test="modifyUser != null  and modifyUser != '' "> and modify_user = #{modifyUser}</if>
         </where>
    </select>
    
    <select id="selectReservationRecordById" parameterType="String" resultMap="ReservationRecordResult">
        <include refid="selectReservationRecordVo"/>
        where id = #{id} and del_flag = 0
    </select>
        
    <insert id="insertReservationRecord" parameterType="com.dgtis.dorm.manager.db.domain.ReservationRecord">
        insert into reservation_record
		<trim prefix="(" suffix=")" suffixOverrides=",">
            add_time,
            modify_time,
            del_flag,
			<if test="id != null  and id != ''  ">id,</if>
			<if test="serviceId != null  and serviceId != ''  ">service_id,</if>
			<if test="serviceName != null  and serviceName != ''  ">service_name,</if>
			<if test="userId != null  and userId != ''  ">user_id,</if>
			<if test="deptId != null  and deptId != ''  ">dept_id,</if>
			<if test="deptName != null  and deptName != ''  ">dept_name,</if>
			<if test="applicantName != null  and applicantName != ''  ">applicant_name,</if>
			<if test="applicantIdCard != null  and applicantIdCard != ''  ">applicant_id_card,</if>
			<if test="reservationDate != null  ">reservation_date,</if>
			<if test="reservationInterval != null  and reservationInterval != ''  ">reservation_interval,</if>
			<if test="reservationNumber != null  ">reservation_number,</if>
			<if test="reservationState != null  and reservationState != ''  ">reservation_state,</if>
			<if test="addUser != null  and addUser != ''  ">add_user,</if>
			<if test="modifyUser != null  and modifyUser != ''  ">modify_user,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            now(),
            now(),
            0,
			<if test="id != null  and id != ''  ">#{id},</if>
			<if test="serviceId != null  and serviceId != ''  ">#{serviceId},</if>
			<if test="serviceName != null  and serviceName != ''  ">#{serviceName},</if>
			<if test="userId != null  and userId != ''  ">#{userId},</if>
			<if test="deptId != null  and deptId != ''  ">#{deptId},</if>
			<if test="deptName != null  and deptName != ''  ">#{deptName},</if>
			<if test="applicantName != null  and applicantName != ''  ">#{applicantName},</if>
			<if test="applicantIdCard != null  and applicantIdCard != ''  ">#{applicantIdCard},</if>
			<if test="reservationDate != null  ">#{reservationDate},</if>
			<if test="reservationInterval != null  and reservationInterval != ''  ">#{reservationInterval},</if>
			<if test="reservationNumber != null  ">#{reservationNumber},</if>
			<if test="reservationState != null  and reservationState != ''  ">#{reservationState},</if>
			<if test="addUser != null  and addUser != ''  ">#{addUser},</if>
			<if test="modifyUser != null  and modifyUser != ''  ">#{modifyUser},</if>
         </trim>
    </insert>
	 
    <update id="updateReservationRecord" parameterType="com.dgtis.dorm.manager.db.domain.ReservationRecord">
        update reservation_record
        <trim prefix="SET" suffixOverrides=",">
            modify_time = now(),
            <if test="serviceId != null  and serviceId != ''  ">service_id = #{serviceId},</if>
            <if test="serviceName != null  and serviceName != ''  ">service_name = #{serviceName},</if>
            <if test="userId != null  and userId != ''  ">user_id = #{userId},</if>
            <if test="deptId != null  and deptId != ''  ">dept_id = #{deptId},</if>
            <if test="deptName != null  and deptName != ''  ">dept_name = #{deptName},</if>
            <if test="applicantName != null  and applicantName != ''  ">applicant_name = #{applicantName},</if>
            <if test="applicantIdCard != null  and applicantIdCard != ''  ">applicant_id_card = #{applicantIdCard},</if>
            <if test="reservationDate != null  ">reservation_date = #{reservationDate},</if>
            <if test="reservationInterval != null  and reservationInterval != ''  ">reservation_interval = #{reservationInterval},</if>
            <if test="reservationNumber != null  ">reservation_number = #{reservationNumber},</if>
            <if test="reservationState != null  and reservationState != ''  ">reservation_state = #{reservationState},</if>
            <if test="addTime != null  ">add_time = #{addTime},</if>
            <if test="addUser != null  and addUser != ''  ">add_user = #{addUser},</if>
            <if test="modifyUser != null  and modifyUser != ''  ">modify_user = #{modifyUser},</if>
            <if test="delFlag != null  and delFlag != ''  ">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    
</mapper>