<?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.example.his.api.db.dao.AppointmentRestrictionDao">

    <resultMap id="BaseResultMap" type="com.example.his.api.db.pojo.AppointmentRestrictionEntity">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="date" column="date" jdbcType="DATE"/>
            <result property="num1" column="num_1" jdbcType="INTEGER"/>
            <result property="num2" column="num_2" jdbcType="INTEGER"/>
            <result property="num3" column="num_3" jdbcType="INTEGER"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>


    <!-- 查询60天范围内每日体检人数量和限流人数 -->
    <select id="searchScheduleInRange" parameterType="Map" resultType="HashMap">
        SELECT date,
               num_1,
               num_2,
               num_3
        FROM tb_appointment_restriction
        WHERE date BETWEEN #{startDate} AND #{endDate}
    </select>


    <!-- 更新实际预约人数 -->
    <insert id="saveOrUpdateRealNum" parameterType="Map">
        INSERT INTO tb_appointment_restriction
        SET date = #{date},
            num_1 = #{num_1},
            num_2 = #{num_2},
            num_3 = #{num_3}
        ON DUPLICATE KEY  UPDATE num_3 = num_3 + 1
    </insert>


</mapper>
