<?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.cool.store.mapper.LineCalendarsEventMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.LineCalendarsEventDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="region_id" jdbcType="BIGINT" property="regionId" />
    <result column="line_id" jdbcType="BIGINT" property="lineId" />
    <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
    <result column="event_title" jdbcType="VARCHAR" property="eventTitle" />
    <result column="interview_type" jdbcType="TINYINT" property="interviewType" />
    <result column="interview_date" jdbcType="TIMESTAMP" property="interviewDate" />
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="interviewer_user_id" jdbcType="VARCHAR" property="interviewerUserId" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  
  <select id="getInterviewerLineCalendarsEvent" resultMap="BaseResultMap">
    select start_time, end_time from xfsg_line_calendars_event where interview_date = #{interviewDate} and interviewer_user_id = #{interviewerUserId}
  </select>

  <select id="getRegionLineCalendarsEvent" resultMap="BaseResultMap">
    select start_time, end_time from xfsg_line_calendars_event where interview_date = #{interviewDate} and region_id = #{regionId} and interview_type != '0' and start_time > now()
  </select>
  
  <select id="getOccupiedCount" resultType="integer">
    select
      count(1)
    from
      xfsg_line_calendars_event
    where
      <![CDATA[(start_time = #{startTime} and end_time = #{endTime})]]>
    <if test="interviewType == 0">
      and interviewer_user_id = #{interviewerUserId} and interview_type in ('0')
    </if>
    <if test="interviewType == 1 or interviewType == 2">
      and region_id = #{regionId} and interview_type in ('1', '2')
    </if>
    <if test="excludeInterviewId != null">
      and id != #{excludeInterviewId}
    </if>
  </select>
</mapper>