<?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.platform.dao.DoctorSchedulesPlanMapper">
  <resultMap id="BaseResultMap" type="com.platform.pojo.DoctorSchedulesPlan">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ID" jdbcType="VARCHAR" property="id" />
    <result column="SCHEDULES_ID" jdbcType="VARCHAR" property="schedulesId" />
    <result column="SCHEDULES_NAME" jdbcType="VARCHAR" property="schedulesName" />
    <result column="DOCTOR_ID" jdbcType="VARCHAR" property="doctorId" />
    <result column="DOCTOR_NAME" jdbcType="VARCHAR" property="doctorName" />
    <result column="SECTION_NO" jdbcType="VARCHAR" property="sectionNo" />
    <result column="SECTION_NAME" jdbcType="VARCHAR" property="sectionName" />
    <result column="START_DATE" jdbcType="TIMESTAMP" property="startDate" />
    <result column="END_DATE" jdbcType="TIMESTAMP" property="endDate" />
    <result column="REGTYPE_ID" jdbcType="VARCHAR" property="regtypeId" />
    <result column="RETAIN_FLAG" jdbcType="VARCHAR" property="retainFlag" />
    <result column="SOURCE_STATUS" jdbcType="VARCHAR" property="sourceStatus" />
    <result column="SORT_NO" jdbcType="VARCHAR" property="sortNo" />
    <result column="REPLACE_DOCTOR_ID" jdbcType="VARCHAR" property="replaceDoctorId" />
    <result column="REPLACE_DOCTOR_NAME" jdbcType="VARCHAR" property="replaceDoctorName" />
    <result column="REPLACE_REASON" jdbcType="VARCHAR" property="replaceReason" />
    <result column="SCHEDULE_DATE" jdbcType="TIMESTAMP" property="scheduleDate" />
    <result column="LOCK_TIME" jdbcType="TIMESTAMP" property="lockTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    ID, SCHEDULES_ID, SCHEDULES_NAME, DOCTOR_ID, DOCTOR_NAME, SECTION_NO, SECTION_NAME, 
    START_DATE, END_DATE, REGTYPE_ID, RETAIN_FLAG, SOURCE_STATUS, SORT_NO, REPLACE_DOCTOR_ID, 
    REPLACE_DOCTOR_NAME, REPLACE_REASON, SCHEDULE_DATE, LOCK_TIME
  </sql>
  <select id="selectByExample" parameterType="com.platform.pojo.DoctorSchedulesPlanExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from DOCTOR_SCHEDULES_PLAN
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from DOCTOR_SCHEDULES_PLAN
    where ID = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from DOCTOR_SCHEDULES_PLAN
    where ID = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.platform.pojo.DoctorSchedulesPlanExample">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from DOCTOR_SCHEDULES_PLAN
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.platform.pojo.DoctorSchedulesPlan">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into DOCTOR_SCHEDULES_PLAN (ID, SCHEDULES_ID, SCHEDULES_NAME, 
      DOCTOR_ID, DOCTOR_NAME, SECTION_NO, 
      SECTION_NAME, START_DATE, END_DATE, 
      REGTYPE_ID, RETAIN_FLAG, SOURCE_STATUS, 
      SORT_NO, REPLACE_DOCTOR_ID, REPLACE_DOCTOR_NAME, 
      REPLACE_REASON, SCHEDULE_DATE, LOCK_TIME
      )
    values (#{id,jdbcType=VARCHAR}, #{schedulesId,jdbcType=VARCHAR}, #{schedulesName,jdbcType=VARCHAR}, 
      #{doctorId,jdbcType=VARCHAR}, #{doctorName,jdbcType=VARCHAR}, #{sectionNo,jdbcType=VARCHAR}, 
      #{sectionName,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP}, #{endDate,jdbcType=TIMESTAMP}, 
      #{regtypeId,jdbcType=VARCHAR}, #{retainFlag,jdbcType=VARCHAR}, #{sourceStatus,jdbcType=VARCHAR}, 
      #{sortNo,jdbcType=VARCHAR}, #{replaceDoctorId,jdbcType=VARCHAR}, #{replaceDoctorName,jdbcType=VARCHAR}, 
      #{replaceReason,jdbcType=VARCHAR}, #{scheduleDate,jdbcType=TIMESTAMP}, #{lockTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyProperty="id" parameterType="com.platform.pojo.DoctorSchedulesPlan" useGeneratedKeys="true">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into DOCTOR_SCHEDULES_PLAN
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        ID,
      </if>
      <if test="schedulesId != null">
        SCHEDULES_ID,
      </if>
      <if test="schedulesName != null">
        SCHEDULES_NAME,
      </if>
      <if test="doctorId != null">
        DOCTOR_ID,
      </if>
      <if test="doctorName != null">
        DOCTOR_NAME,
      </if>
      <if test="sectionNo != null">
        SECTION_NO,
      </if>
      <if test="sectionName != null">
        SECTION_NAME,
      </if>
      <if test="startDate != null">
        START_DATE,
      </if>
      <if test="endDate != null">
        END_DATE,
      </if>
      <if test="regtypeId != null">
        REGTYPE_ID,
      </if>
      <if test="retainFlag != null">
        RETAIN_FLAG,
      </if>
      <if test="sourceStatus != null">
        SOURCE_STATUS,
      </if>
      <if test="sortNo != null">
        SORT_NO,
      </if>
      <if test="replaceDoctorId != null">
        REPLACE_DOCTOR_ID,
      </if>
      <if test="replaceDoctorName != null">
        REPLACE_DOCTOR_NAME,
      </if>
      <if test="replaceReason != null">
        REPLACE_REASON,
      </if>
      <if test="scheduleDate != null">
        SCHEDULE_DATE,
      </if>
      <if test="lockTime != null">
        LOCK_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="schedulesId != null">
        #{schedulesId,jdbcType=VARCHAR},
      </if>
      <if test="schedulesName != null">
        #{schedulesName,jdbcType=VARCHAR},
      </if>
      <if test="doctorId != null">
        #{doctorId,jdbcType=VARCHAR},
      </if>
      <if test="doctorName != null">
        #{doctorName,jdbcType=VARCHAR},
      </if>
      <if test="sectionNo != null">
        #{sectionNo,jdbcType=VARCHAR},
      </if>
      <if test="sectionName != null">
        #{sectionName,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null">
        #{endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="regtypeId != null">
        #{regtypeId,jdbcType=VARCHAR},
      </if>
      <if test="retainFlag != null">
        #{retainFlag,jdbcType=VARCHAR},
      </if>
      <if test="sourceStatus != null">
        #{sourceStatus,jdbcType=VARCHAR},
      </if>
      <if test="sortNo != null">
        #{sortNo,jdbcType=VARCHAR},
      </if>
      <if test="replaceDoctorId != null">
        #{replaceDoctorId,jdbcType=VARCHAR},
      </if>
      <if test="replaceDoctorName != null">
        #{replaceDoctorName,jdbcType=VARCHAR},
      </if>
      <if test="replaceReason != null">
        #{replaceReason,jdbcType=VARCHAR},
      </if>
      <if test="scheduleDate != null">
        #{scheduleDate,jdbcType=TIMESTAMP},
      </if>
      <if test="lockTime != null">
        #{lockTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.platform.pojo.DoctorSchedulesPlanExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from DOCTOR_SCHEDULES_PLAN
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update DOCTOR_SCHEDULES_PLAN
    <set>
      <if test="record.id != null">
        ID = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.schedulesId != null">
        SCHEDULES_ID = #{record.schedulesId,jdbcType=VARCHAR},
      </if>
      <if test="record.schedulesName != null">
        SCHEDULES_NAME = #{record.schedulesName,jdbcType=VARCHAR},
      </if>
      <if test="record.doctorId != null">
        DOCTOR_ID = #{record.doctorId,jdbcType=VARCHAR},
      </if>
      <if test="record.doctorName != null">
        DOCTOR_NAME = #{record.doctorName,jdbcType=VARCHAR},
      </if>
      <if test="record.sectionNo != null">
        SECTION_NO = #{record.sectionNo,jdbcType=VARCHAR},
      </if>
      <if test="record.sectionName != null">
        SECTION_NAME = #{record.sectionName,jdbcType=VARCHAR},
      </if>
      <if test="record.startDate != null">
        START_DATE = #{record.startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.endDate != null">
        END_DATE = #{record.endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.regtypeId != null">
        REGTYPE_ID = #{record.regtypeId,jdbcType=VARCHAR},
      </if>
      <if test="record.retainFlag != null">
        RETAIN_FLAG = #{record.retainFlag,jdbcType=VARCHAR},
      </if>
      <if test="record.sourceStatus != null">
        SOURCE_STATUS = #{record.sourceStatus,jdbcType=VARCHAR},
      </if>
      <if test="record.sortNo != null">
        SORT_NO = #{record.sortNo,jdbcType=VARCHAR},
      </if>
      <if test="record.replaceDoctorId != null">
        REPLACE_DOCTOR_ID = #{record.replaceDoctorId,jdbcType=VARCHAR},
      </if>
      <if test="record.replaceDoctorName != null">
        REPLACE_DOCTOR_NAME = #{record.replaceDoctorName,jdbcType=VARCHAR},
      </if>
      <if test="record.replaceReason != null">
        REPLACE_REASON = #{record.replaceReason,jdbcType=VARCHAR},
      </if>
      <if test="record.scheduleDate != null">
        SCHEDULE_DATE = #{record.scheduleDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.lockTime != null">
        LOCK_TIME = #{record.lockTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update DOCTOR_SCHEDULES_PLAN
    set ID = #{record.id,jdbcType=VARCHAR},
      SCHEDULES_ID = #{record.schedulesId,jdbcType=VARCHAR},
      SCHEDULES_NAME = #{record.schedulesName,jdbcType=VARCHAR},
      DOCTOR_ID = #{record.doctorId,jdbcType=VARCHAR},
      DOCTOR_NAME = #{record.doctorName,jdbcType=VARCHAR},
      SECTION_NO = #{record.sectionNo,jdbcType=VARCHAR},
      SECTION_NAME = #{record.sectionName,jdbcType=VARCHAR},
      START_DATE = #{record.startDate,jdbcType=TIMESTAMP},
      END_DATE = #{record.endDate,jdbcType=TIMESTAMP},
      REGTYPE_ID = #{record.regtypeId,jdbcType=VARCHAR},
      RETAIN_FLAG = #{record.retainFlag,jdbcType=VARCHAR},
      SOURCE_STATUS = #{record.sourceStatus,jdbcType=VARCHAR},
      SORT_NO = #{record.sortNo,jdbcType=VARCHAR},
      REPLACE_DOCTOR_ID = #{record.replaceDoctorId,jdbcType=VARCHAR},
      REPLACE_DOCTOR_NAME = #{record.replaceDoctorName,jdbcType=VARCHAR},
      REPLACE_REASON = #{record.replaceReason,jdbcType=VARCHAR},
      SCHEDULE_DATE = #{record.scheduleDate,jdbcType=TIMESTAMP},
      LOCK_TIME = #{record.lockTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.platform.pojo.DoctorSchedulesPlan">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update DOCTOR_SCHEDULES_PLAN
    <set>
      <if test="schedulesId != null">
        SCHEDULES_ID = #{schedulesId,jdbcType=VARCHAR},
      </if>
      <if test="schedulesName != null">
        SCHEDULES_NAME = #{schedulesName,jdbcType=VARCHAR},
      </if>
      <if test="doctorId != null">
        DOCTOR_ID = #{doctorId,jdbcType=VARCHAR},
      </if>
      <if test="doctorName != null">
        DOCTOR_NAME = #{doctorName,jdbcType=VARCHAR},
      </if>
      <if test="sectionNo != null">
        SECTION_NO = #{sectionNo,jdbcType=VARCHAR},
      </if>
      <if test="sectionName != null">
        SECTION_NAME = #{sectionName,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null">
        START_DATE = #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null">
        END_DATE = #{endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="regtypeId != null">
        REGTYPE_ID = #{regtypeId,jdbcType=VARCHAR},
      </if>
      <if test="retainFlag != null">
        RETAIN_FLAG = #{retainFlag,jdbcType=VARCHAR},
      </if>
      <if test="sourceStatus != null">
        SOURCE_STATUS = #{sourceStatus,jdbcType=VARCHAR},
      </if>
      <if test="sortNo != null">
        SORT_NO = #{sortNo,jdbcType=VARCHAR},
      </if>
      <if test="replaceDoctorId != null">
        REPLACE_DOCTOR_ID = #{replaceDoctorId,jdbcType=VARCHAR},
      </if>
      <if test="replaceDoctorName != null">
        REPLACE_DOCTOR_NAME = #{replaceDoctorName,jdbcType=VARCHAR},
      </if>
      <if test="replaceReason != null">
        REPLACE_REASON = #{replaceReason,jdbcType=VARCHAR},
      </if>
      <if test="scheduleDate != null">
        SCHEDULE_DATE = #{scheduleDate,jdbcType=TIMESTAMP},
      </if>
      <if test="lockTime != null">
        LOCK_TIME = #{lockTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ID = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.platform.pojo.DoctorSchedulesPlan">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update DOCTOR_SCHEDULES_PLAN
    set SCHEDULES_ID = #{schedulesId,jdbcType=VARCHAR},
      SCHEDULES_NAME = #{schedulesName,jdbcType=VARCHAR},
      DOCTOR_ID = #{doctorId,jdbcType=VARCHAR},
      DOCTOR_NAME = #{doctorName,jdbcType=VARCHAR},
      SECTION_NO = #{sectionNo,jdbcType=VARCHAR},
      SECTION_NAME = #{sectionName,jdbcType=VARCHAR},
      START_DATE = #{startDate,jdbcType=TIMESTAMP},
      END_DATE = #{endDate,jdbcType=TIMESTAMP},
      REGTYPE_ID = #{regtypeId,jdbcType=VARCHAR},
      RETAIN_FLAG = #{retainFlag,jdbcType=VARCHAR},
      SOURCE_STATUS = #{sourceStatus,jdbcType=VARCHAR},
      SORT_NO = #{sortNo,jdbcType=VARCHAR},
      REPLACE_DOCTOR_ID = #{replaceDoctorId,jdbcType=VARCHAR},
      REPLACE_DOCTOR_NAME = #{replaceDoctorName,jdbcType=VARCHAR},
      REPLACE_REASON = #{replaceReason,jdbcType=VARCHAR},
      SCHEDULE_DATE = #{scheduleDate,jdbcType=TIMESTAMP},
      LOCK_TIME = #{lockTime,jdbcType=TIMESTAMP}
    where ID = #{id,jdbcType=VARCHAR}
  </update>

  <!--查询当前科室排班记录 by suxinghua 2018-05-03-->
  <select id="selectSections" parameterType="map" resultType="com.platform.pojo.Section">
  	SELECT
		DISTINCT 
		d.SECTION_NO AS sectionNo
		,d.SECTION_NAME AS sectionName
		,si.SECTION_TYPE AS sectionType
	-- 	,d.DOCTOR_ID
	-- 	,d.DOCTOR_NAME
	FROM 
		DOCTOR_SCHEDULES_PLAN d
	 inner join
        section_info si
    on
        d.SECTION_NO = si.SECTION_NO
	WHERE
		1=1
	<if test="startDate != null">
		AND to_char(d.START_DATE,'yyyy-MM-dd') &gt; =#{startDate,jdbcType=VARCHAR}
	</if>
	<if test="endDate != null">
		AND to_char(d.END_DATE,'yyyy-MM-dd') &lt;=#{endDate,jdbcType=VARCHAR}
	</if>
	<if test="timeInterval != null">
		AND d.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
	</if>
	<if test="sectionType != null">
		and si.SECTION_TYPE=#{sectionType,jdbcType=VARCHAR}
	</if>
  </select>
    <!--查询当前医生排班记录 by suxinghua 2018-05-03-->
    <select id="selectDoctors" parameterType="map" resultType="com.platform.pojo.Doctor">
  	SELECT
		DISTINCT
        to_char(d.START_DATE,'yyyy-MM-dd') as schedulesDate
        ,d.REGTYPE_ID as schedulesType
		,d.SECTION_NO AS sectionNo
		,d.SECTION_NAME AS sectionName
	 	,to_char(d.DOCTOR_ID,'fm09999') as doctorNo
	 	,d.DOCTOR_NAME as doctorName
	 	,di.TECHNICAL_ID AS technicalId
	 	,di.TECHNICAL_NAME AS technicalName
	 	,di.JOB_CATEGORY AS jobCaegory
	 	,di.EXPERT_IN AS expertIn
	 	,di.AVATAR_ADDR AS avatarAddr
	FROM 
		DOCTOR_SCHEDULES_PLAN d
	LEFT JOIN
		DOCTOR_INFO di
	ON
		d.DOCTOR_ID=di.DOCTOR_NO
	WHERE
		1=1
    AND
      d.SOURCE_STATUS NOT IN (0,3,7)
	<if test="startDate != null">
		AND to_char(d.START_DATE,'yyyy-MM-dd') &gt; =#{startDate,jdbcType=VARCHAR}
	</if>
	<if test="endDate != null">
		AND to_char(d.END_DATE,'yyyy-MM-dd') &lt;=#{endDate,jdbcType=VARCHAR}
	</if>
	<if test="timeInterval != null">
		AND d.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
	</if>
	<if test="sectionNo != null">
		AND d.SECTION_NO = #{sectionNo,jdbcType=VARCHAR}
	</if>
	</select>
	
	<select id="selectTicketsAll" parameterType="map" resultType="com.platform.pojo.Ticket">
		SELECT
			dsp.ID AS planId
			,dsp.SCHEDULES_ID AS schedulesNo
			,dsp.SCHEDULES_NAME AS schedulesName
			,dsp.DOCTOR_ID AS doctorNo
			,dsp.DOCTOR_NAME AS doctorName
			,dsp.SECTION_NO AS sectionNo
			,dsp.SECTION_NAME AS sectionName
			,to_char(dsp.START_DATE,'YYYY-mm-dd HH24:MI:ss') AS startDate
			,to_char(dsp.END_DATE,'YYYY-mm-dd HH24:MI:ss') AS endDate
			,dsp.REGTYPE_ID AS regType
			,dsp.SOURCE_STATUS AS statusId
			,CASE dsp.SOURCE_STATUS WHEN '0' THEN  '停诊' WHEN '1' THEN '可预约' WHEN '2' THEN '替诊' WHEN '3' THEN '已预约' WHEN '7' THEN '锁号' ELSE '未知' END AS statusName
			,dsp.SORT_NO AS sortNo
			,dsp.REPLACE_DOCTOR_ID AS replaceDoctorNo
			,dsp.REPLACE_DOCTOR_NAME AS replaceDoctorName
			,dsp.REPLACE_REASON AS replaceReason
		FROM
			DOCTOR_SCHEDULES_PLAN dsp
		WHERE
			1=1
		AND
			dsp.SOURCE_STATUS NOT IN (0,3,7)
		<if test="startDate != null">
            AND dsp.START_DATE &gt;=to_date(#{startDate,jdbcType=VARCHAR},'yyyy-MM-dd HH24:MI:ss')
		</if>
		<if test="endDate != null">
            AND dsp.END_DATE &lt;= to_date(#{endDate,jdbcType=VARCHAR},'yyyy-MM-dd HH24:MI:ss')
		</if>
		<if test="sectionNo != null">
			AND dsp.SECTION_NO=#{sectionNo,jdbcType=VARCHAR}
		</if>
		<if test="doctorNo != null">
			AND dsp.DOCTOR_ID=#{doctorNo,jdbcType=VARCHAR}
		</if>
		<if test="timeInterval != null">
			AND dsp.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
		</if>
        ORDER by dsp.SORT_NO asc
	</select>
	
	<select id="selectTicketsNoRetain" parameterType="map" resultType="com.platform.pojo.Ticket">
		SELECT
			dsp.ID AS planId
			,dsp.SCHEDULES_ID AS schedulesNo
			,dsp.SCHEDULES_NAME AS schedulesName
			,dsp.DOCTOR_ID AS doctorNo
			,dsp.DOCTOR_NAME AS doctorName
			,dsp.SECTION_NO AS sectionNo
			,dsp.SECTION_NAME AS sectionName
			,to_char(dsp.START_DATE,'YYYY-mm-dd HH24:MI:ss') AS startDate
			,to_char(dsp.END_DATE,'YYYY-mm-dd HH24:MI:ss') AS endDate
			,dsp.REGTYPE_ID AS regType
			,dsp.SOURCE_STATUS AS statusId
			,CASE dsp.SOURCE_STATUS WHEN '0' THEN  '停诊' WHEN '1' THEN '可预约' WHEN '2' THEN '替诊' WHEN '3' THEN '已预约' WHEN '7' THEN '锁号' ELSE '未知' END AS statusName
			,dsp.SORT_NO AS sortNo
			,dsp.REPLACE_DOCTOR_ID AS replaceDoctorNo
			,dsp.REPLACE_DOCTOR_NAME AS replaceDoctorName
			,dsp.REPLACE_REASON AS replaceReason
		FROM
			DOCTOR_SCHEDULES_PLAN dsp
		WHERE
			1=1
		AND
			dsp.RETAIN_FLAG  &lt;&gt;  '0'
		AND
			dsp.SOURCE_STATUS NOT IN (0,3,7)
        <if test="startDate != null">
            AND dsp.START_DATE &gt;=to_date(#{startDate,jdbcType=VARCHAR},'yyyy-MM-dd HH24:MI:ss')
        </if>
        <if test="endDate != null">
            AND dsp.END_DATE &lt;= to_date(#{endDate,jdbcType=VARCHAR},'yyyy-MM-dd HH24:MI:ss')
        </if>
		<if test="sectionNo != null">
			AND dsp.SECTION_NO=#{sectionNo,jdbcType=VARCHAR}
		</if>
		<if test="doctorNo != null">
			AND dsp.DOCTOR_ID=#{doctorNo,jdbcType=VARCHAR}
		</if>
		<if test="timeInterval != null">
			AND dsp.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
		</if>
        ORDER by dsp.SORT_NO asc
	</select>
	
	<select id="selectTicketsByRegTime" parameterType="map" resultType="com.platform.pojo.Ticket">		
		SELECT
			temp.planId AS planId
			,temp.schedulesNo AS schedulesNo
			,temp.schedulesName AS schedulesName
			,temp.doctorNo AS doctorNo
			,temp.doctorName AS doctorName
			,temp.sectionNo AS sectionNo
			,temp.sectionName AS sectionName
			,to_char(temp.startDate,'YYYY-mm-dd HH24:MI:ss') AS startDate
			,to_char(temp.endDate,'YYYY-mm-dd HH24:MI:ss') AS endDate
			,temp.regType AS regType
			,temp.statusId AS statusId
			,temp.statusName AS statusName
			,temp.sortNo AS sortNo
			,temp.replaceDoctorNo AS replaceDoctorNo
			,temp.replaceDoctorName AS replaceDoctorName
			,temp.replaceReason AS replaceReason
		FROM
		(
		SELECT
			dsp.ID AS planId
			,dsp.SCHEDULES_ID AS schedulesNo
			,dsp.SCHEDULES_NAME AS schedulesName
			,dsp.DOCTOR_ID AS doctorNo
			,dsp.DOCTOR_NAME AS doctorName
			,dsp.SECTION_NO AS sectionNo
			,dsp.SECTION_NAME AS sectionName
			,dsp.START_DATE AS startDate
			,dsp.END_DATE AS endDate
			,dsp.REGTYPE_ID AS regType
			,dsp.SOURCE_STATUS AS statusId
			,CASE dsp.SOURCE_STATUS WHEN '0' THEN  '停诊' WHEN '1' THEN '可预约' WHEN '2' THEN '替诊' WHEN '3' THEN '已预约' WHEN '7' THEN '锁号' ELSE '未知' END AS statusName
			,dsp.SORT_NO AS sortNo
			,dsp.REPLACE_DOCTOR_ID AS replaceDoctorNo
			,dsp.REPLACE_DOCTOR_NAME AS replaceDoctorName
			,dsp.REPLACE_REASON AS replaceReason
		FROM
			DOCTOR_SCHEDULES_PLAN dsp
		WHERE
			1=1
		AND
			dsp.SOURCE_STATUS NOT IN (0,3,7)
		<if test="regTime != null">
			AND to_char(dsp.START_DATE,'yyyy-MM-dd HH24:MI') &lt;=to_char(to_date(#{regTime,jdbcType=VARCHAR}, 'yyyy-mm-dd HH24:MI:SS'),'yyyy-mm-dd HH24:MI')
		</if>
		<if test="regTime != null">
			AND to_char(dsp.END_DATE,'yyyy-MM-dd HH24:MI') &gt;=to_char(to_date(#{regTime,jdbcType=VARCHAR}, 'yyyy-mm-dd HH24:MI:SS'),'yyyy-mm-dd HH24:MI')
		</if>
		<if test="sectionNo != null">
			AND dsp.SECTION_NO=#{sectionNo,jdbcType=VARCHAR}
		</if>
		<if test="doctorNo != null">
			AND dsp.DOCTOR_ID=#{doctorNo,jdbcType=VARCHAR}
		</if>
		<if test="timeInterval != null">
			AND dsp.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
		</if>
		UNION
		SELECT
			dsp.ID AS planId
			,dsp.SCHEDULES_ID AS schedulesNo
			,dsp.SCHEDULES_NAME AS schedulesName
			,dsp.DOCTOR_ID AS doctorNo
			,dsp.DOCTOR_NAME AS doctorName
			,dsp.SECTION_NO AS sectionNo
			,dsp.SECTION_NAME AS sectionName
			,dsp.START_DATE AS startDate
			,dsp.END_DATE AS endDate
			,dsp.REGTYPE_ID AS regType
			,dsp.SOURCE_STATUS AS statusId
			,CASE dsp.SOURCE_STATUS WHEN '0' THEN  '停诊' WHEN '1' THEN '可预约' WHEN '2' THEN '替诊' WHEN '3' THEN '已预约' WHEN '7' THEN '锁号' ELSE '未知' END AS statusName
			,dsp.SORT_NO AS sortNo
			,dsp.REPLACE_DOCTOR_ID AS replaceDoctorNo
			,dsp.REPLACE_DOCTOR_NAME AS replaceDoctorName
			,dsp.REPLACE_REASON AS replaceReason
		FROM
			DOCTOR_SCHEDULES_PLAN dsp
		WHERE
			1=1
		AND
			dsp.SOURCE_STATUS NOT IN (0,3,7)
		<if test="regTime != null">
			AND to_char(dsp.END_DATE,'yyyy-MM-dd') =to_char(to_date(SUBSTR(#{regTime,jdbcType=VARCHAR},1,10), 'yyyy-mm-dd'),'yyyy-mm-dd')
		</if>
		<if test="regTime != null">
			AND to_char(dsp.END_DATE,'HH24:MI') &gt; to_char(to_date(SUBSTR(#{regTime,jdbcType=VARCHAR},11,18), 'HH24:MI:SS'),'HH24:MI')
		</if>
		<if test="sectionNo != null">
			AND dsp.SECTION_NO=#{sectionNo,jdbcType=VARCHAR}
		</if>
		<if test="doctorNo != null">
			AND dsp.DOCTOR_ID=#{doctorNo,jdbcType=VARCHAR}
		</if>
		<if test="timeInterval != null">
			AND dsp.REGTYPE_ID=#{timeInterval,jdbcType=VARCHAR}
		</if>
		) temp
		ORDER BY TO_NUMBER(temp.sortNo) ASC
	</select>

    <select id="selectPreregedTickets" parameterType="map" resultType="com.platform.pojo.OrderTicket">
        SELECT
        org.ID as planId
        ,to_char(dsp.START_DATE,'yyyy-MM-dd') AS visitDate
        ,org.ORDER_SECTION_NO as sectionNo
        ,org.ORDER_SECTION_NAME as sectionName
        ,org.ORDER_DOCTOR_NO as doctorNo
        ,org.ORDER_DOCTOR_NAME as doctorName
        ,di.TECHNICAL_ID AS technicalId
        ,di.TECHNICAL_NAME AS technicalName
        ,dsp.REGTYPE_ID as regTypeId
        ,CASE dsp.REGTYPE_ID when 'AM' then '上午' WHEN  'PM' then '下午' ELSE '未知' END  AS regTypeName
        ,org.REG_STATUS as statusFlag
        ,CASE org.REG_STATUS WHEN '0' THEN  '正常' WHEN '1' then '取号' WHEN '2' THEN  '作废' WHEN '9' THEN '取消' ELSE '未知' END  AS statusName
        FROM
        ORDER_REG org
        INNER JOIN
        DOCTOR_SCHEDULES_PLAN dsp
        ON org.ID=dsp.ID
        inner join
        doctor_info di
        on
        org.ORDER_DOCTOR_NO=di.doctor_no
        WHERE 1=1
        and org.REG_STATUS in (0,1)
        <if test="cardNo != null">
            AND org.PATIENT_CARD_NO=#{cardNo,jdbcType=VARCHAR}
        </if>
        <if test="visitDate != null">
            AND to_char(dsp.START_DATE,'yyyy-MM-dd') =#{visitDate,jdbcType=VARCHAR}
        </if>
    </select>

    <select id="selectPreregedPatient" parameterType="map" resultType="com.platform.pojo.PreregedPatient">
        select
            org.order_name as orderName
            ,org.order_date as orderDate
            ,org.phone_number as phoneNumber
            ,org.order_section_no as orderSectionNo
            ,org.order_section_name as orderSectionName
            ,org.order_doctor_no as orderDoctorNo
            ,org.order_doctor_name as orderDocotorName
            ,org.order_type as orderType
            ,case org.order_type when '1' then '初诊' when '2' then '复诊' else '未知' end as orderTypeName
            ,org.REG_TYPE as regType
            ,case org.reg_type when 'AM' then '上午' when 'PM' then '下午' else '未知' end as regTypeName
            ,org.REG_CATEGORY_NO as regCategoryNo
            ,org.REG_CATEGORY_NAME as regCategoryName
            ,org.order_source as orderSource
            ,org.SORT_NO as sortNo
            ,org.PATIENT_IDCARD_NO as idCardNo
            ,org.PATIENT_CARD_NO as cardNo
            ,org.REG_STATUS as regStatus
            ,case org.reg_status when '0' then '正常' when '1' then '取号' when '2' then '作废' when '9' then '取消' else '未知' end as regStatusName
            ,org.order_time as orderTime
            ,org.visit_date as visitDate
            ,org.visit_time as visitTime
        from
            ORDER_REG org
        where
            1=1
        <if test="doctorNo != null">
            AND org.order_doctor_no=#{doctorNo,jdbcType=VARCHAR}
        </if>
        <if test="startDate != null">
            AND org.ORDER_DATE &gt;=#{startDate,jdbcType=VARCHAR}
        </if>
        <if test="endDate != null">
            AND org.ORDER_DATE &lt;=#{endDate,jdbcType=VARCHAR}
        </if>
    </select>

    <update id="updateStatusFlag" parameterType="map">
        UPDATE ORDER_REG org SET  org.REG_STATUS='1'
        WHERE org.ID=#{planId,jdbcType=VARCHAR}
    </update>

</mapper>