<?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.ruoyi.system.mapper.BomanReservatMapper">
    
    <resultMap type="BomanReservat" id="BomanReservatResult">
        <result property="reservatId"    column="reservat_id"    />
        <result property="appointmentId"    column="appointment_id"    />
        <result property="appointmentName"    column="appointment_name"    />
        <result property="appointmentSite"    column="appointment_site"    />
        <result property="visitName"    column="visit_name"    />
        <result property="reservatConfigTimeId"    column="reservat_config_time_id"    />
        <result property="visitPhone"    column="visit_phone"    />
        <result property="visitIdCard"    column="visit_id_card"    />
        <result property="visitNum"    column="visit_num"    />
        <result property="visitReason"    column="visit_reason"    />
        <result property="visitRemark"    column="visit_remark"    />
        <result property="visitDate"    column="visit_date"    />
        <result property="visitTime"    column="visit_time"    />
        <result property="visitDateTime"    column="visit_date_time"    />
        <result property="visitQr"    column="visit_qr"    />
        <result property="visitType"    column="visit_type"    />
        <result property="visitStatus"    column="visit_status"    />
        <result property="humanFaceData"    column="human_face_data"    />
        <result property="accessPassword"    column="access_password"    />
        <result property="createDept"    column="create_dept"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBomanReservatVo">
        select reservat_id, appointment_id, appointment_name,appointment_site, visit_name, reservat_config_time_id, visit_phone, visit_id_card, visit_num, visit_reason, visit_remark, visit_date, visit_time, visit_date_time, visit_qr, visit_type, visit_status, human_face_data, access_password, create_dept, create_by, create_time, update_by, update_time, remark from boman_reservat
    </sql>

    <select id="selectBomanReservatList" parameterType="BomanReservat" resultMap="BomanReservatResult">
        <include refid="selectBomanReservatVo"/>
        <where>  
            <if test="appointmentId != null "> and appointment_id = #{appointmentId}</if>
            <if test="appointmentName != null  and appointmentName != ''"> and appointment_name like concat('%', #{appointmentName}, '%')</if>
            <if test="appointmentSite != null  and appointmentSite != ''"> and appointment_site like concat('%', #{appointmentSite}, '%')</if>
            <if test="visitName != null  and visitName != ''"> and visit_name like concat('%', #{visitName}, '%')</if>
            <if test="reservatConfigTimeId != null "> and reservat_config_time_id = #{reservatConfigTimeId}</if>
            <if test="visitPhone != null  and visitPhone != ''"> and visit_phone = #{visitPhone}</if>
            <if test="visitIdCard != null  and visitIdCard != ''"> and visit_id_card = #{visitIdCard}</if>
            <if test="visitNum != null  and visitNum != ''"> and visit_num = #{visitNum}</if>
            <if test="visitReason != null  and visitReason != ''"> and visit_reason = #{visitReason}</if>
            <if test="visitRemark != null  and visitRemark != ''"> and visit_remark = #{visitRemark}</if>
            <if test="visitDate != null "> and visit_date = #{visitDate}</if>
            <if test="visitTime != null  and visitTime != ''"> and visit_time = #{visitTime}</if>
            <if test="visitDateTime != null "> and visit_date_time = #{visitDateTime}</if>
            <if test="visitQr != null  and visitQr != ''"> and visit_qr = #{visitQr}</if>
            <if test="visitType != null  and visitType != ''"> and visit_type = #{visitType}</if>
            <if test="visitStatus != null  and visitStatus != ''"> and visit_status = #{visitStatus}</if>
            <if test="humanFaceData != null  and humanFaceData != ''"> and human_face_data = #{humanFaceData}</if>
            <if test="accessPassword != null  and accessPassword != ''"> and access_password = #{accessPassword}</if>
            <if test="createDept != null "> and create_dept = #{createDept}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectBomanReservatByReservatId" parameterType="Long" resultMap="BomanReservatResult">
        <include refid="selectBomanReservatVo"/>
        where reservat_id = #{reservatId}
    </select>

    <select id="selectBomanReservatTimeList" parameterType="BomanReservat" resultMap="BomanReservatResult">
        <include refid="selectBomanReservatVo"/>
        <where>
            <if test="visitStatus != null  and visitStatus != ''"> and visit_status = #{visitStatus}</if>

            <if test="visitDate != null  and visitDate != ''">
                AND date_format(visit_date,'%y%m') = date_format(#{visitDate},'%y%m')
            </if>

            <if test="startTime != null and startTime != ''"><!-- 开始时间检索 -->
                AND visit_date &gt;= #{startTime}
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND visit_date &lt;= #{endTime}
            </if>
        </where>
    </select>

    <insert id="insertBomanReservat" parameterType="BomanReservat" useGeneratedKeys="true" keyProperty="reservatId">
        insert into boman_reservat
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appointmentId != null">appointment_id,</if>
            <if test="appointmentName != null">appointment_name,</if>
            <if test="appointmentSite != null "> appointment_site,</if>
            <if test="visitName != null">visit_name,</if>
            <if test="reservatConfigTimeId != null">reservat_config_time_id,</if>
            <if test="visitPhone != null">visit_phone,</if>
            <if test="visitIdCard != null">visit_id_card,</if>
            <if test="visitNum != null">visit_num,</if>
            <if test="visitReason != null">visit_reason,</if>
            <if test="visitRemark != null">visit_remark,</if>
            <if test="visitDate != null">visit_date,</if>
            <if test="visitTime != null">visit_time,</if>
            <if test="visitDateTime != null">visit_date_time,</if>
            <if test="visitQr != null">visit_qr,</if>
            <if test="visitType != null">visit_type,</if>
            <if test="visitStatus != null">visit_status,</if>
            <if test="humanFaceData != null">human_face_data,</if>
            <if test="accessPassword != null">access_password,</if>
            <if test="createDept != null">create_dept,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appointmentId != null">#{appointmentId},</if>
            <if test="appointmentName != null">#{appointmentName},</if>
            <if test="appointmentSite != null "> #{appointmentSite},</if>
            <if test="visitName != null">#{visitName},</if>
            <if test="reservatConfigTimeId != null">#{reservatConfigTimeId},</if>
            <if test="visitPhone != null">#{visitPhone},</if>
            <if test="visitIdCard != null">#{visitIdCard},</if>
            <if test="visitNum != null">#{visitNum},</if>
            <if test="visitReason != null">#{visitReason},</if>
            <if test="visitRemark != null">#{visitRemark},</if>
            <if test="visitDate != null">#{visitDate},</if>
            <if test="visitTime != null">#{visitTime},</if>
            <if test="visitDateTime != null">#{visitDateTime},</if>
            <if test="visitQr != null">#{visitQr},</if>
            <if test="visitType != null">#{visitType},</if>
            <if test="visitStatus != null">#{visitStatus},</if>
            <if test="humanFaceData != null">#{humanFaceData},</if>
            <if test="accessPassword != null">#{accessPassword},</if>
            <if test="createDept != null">#{createDept},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateBomanReservat" parameterType="BomanReservat">
        update boman_reservat
        <trim prefix="SET" suffixOverrides=",">
            <if test="appointmentId != null">appointment_id = #{appointmentId},</if>
            <if test="appointmentName != null">appointment_name = #{appointmentName},</if>
            <if test="appointmentSite != null "> appointment_site = #{appointmentSite},</if>
            <if test="visitName != null">visit_name = #{visitName},</if>
            <if test="reservatConfigTimeId != null">reservat_config_time_id = #{reservatConfigTimeId},</if>
            <if test="visitPhone != null">visit_phone = #{visitPhone},</if>
            <if test="visitIdCard != null">visit_id_card = #{visitIdCard},</if>
            <if test="visitNum != null">visit_num = #{visitNum},</if>
            <if test="visitReason != null">visit_reason = #{visitReason},</if>
            <if test="visitRemark != null">visit_remark = #{visitRemark},</if>
            <if test="visitDate != null">visit_date = #{visitDate},</if>
            <if test="visitTime != null">visit_time = #{visitTime},</if>
            <if test="visitDateTime != null">visit_date_time = #{visitDateTime},</if>
            <if test="visitQr != null">visit_qr = #{visitQr},</if>
            <if test="visitType != null">visit_type = #{visitType},</if>
            <if test="visitStatus != null">visit_status = #{visitStatus},</if>
            <if test="humanFaceData != null">human_face_data = #{humanFaceData},</if>
            <if test="accessPassword != null">access_password = #{accessPassword},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where reservat_id = #{reservatId}
    </update>

    <delete id="deleteBomanReservatByReservatId" parameterType="Long">
        delete from boman_reservat where reservat_id = #{reservatId}
    </delete>

    <delete id="deleteBomanReservatByReservatIds" parameterType="String">
        delete from boman_reservat where reservat_id in 
        <foreach item="reservatId" collection="array" open="(" separator="," close=")">
            #{reservatId}
        </foreach>
    </delete>
</mapper>