<?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.xinelu.manage.mapper.scheduleplandetail.SchedulePlanDetailMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="schedulePlanId" column="schedule_plan_id" jdbcType="BIGINT"/>
            <result property="doctorId" column="doctor_id" jdbcType="BIGINT"/>
            <result property="doctorName" column="doctor_name" jdbcType="VARCHAR"/>
            <result property="scheduleDate" column="schedule_date" jdbcType="DATE"/>
	        <result property="type" column="type" jdbcType="CHAR"/>
            <result property="scheduleStartTime" column="schedule_start_time" jdbcType="TIME"/>
            <result property="scheduleEndTime" column="schedule_end_time" jdbcType="TIME"/>
	        <result property="status" column="status" jdbcType="CHAR"/>
            <result property="applyState" column="apply_state" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,schedule_plan_id,doctor_id,
        doctor_name,schedule_date,`type`,schedule_start_time,
        schedule_end_time,status,apply_state
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from schedule_plan_detail
        where  id = #{id,jdbcType=BIGINT} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from schedule_plan_detail
        where  id = #{id,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail" useGeneratedKeys="true">
        insert into schedule_plan_detail
        ( id,schedule_plan_id,doctor_id
        ,doctor_name,schedule_date,`type`,schedule_start_time
        ,schedule_end_time,status,apply_state)
        values (#{id,jdbcType=BIGINT},#{schedulePlanId,jdbcType=BIGINT},#{doctorId,jdbcType=BIGINT}
        ,#{doctorName,jdbcType=VARCHAR},#{scheduleDate,jdbcType=DATE},#{type,jdbcType=CHAR},#{scheduleStartTime,jdbcType=TIME}
        ,#{scheduleEndTime,jdbcType=TIME},#{status,jdbcType=CHAR},#{applyState,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail" useGeneratedKeys="true">
        insert into schedule_plan_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="schedulePlanId != null">schedule_plan_id,</if>
                <if test="doctorId != null">doctor_id,</if>
                <if test="doctorName != null">doctor_name,</if>
                <if test="scheduleDate != null">schedule_date,</if>
	        	<if test="type != null">type,</if>
                <if test="scheduleStartTime != null">schedule_start_time,</if>
                <if test="scheduleEndTime != null">schedule_end_time,</if>
	        	<if test="status != null">status,</if>
                <if test="applyState != null">apply_state,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=BIGINT},</if>
                <if test="schedulePlanId != null">#{schedulePlanId,jdbcType=BIGINT},</if>
                <if test="doctorId != null">#{doctorId,jdbcType=BIGINT},</if>
                <if test="doctorName != null">#{doctorName,jdbcType=VARCHAR},</if>
                <if test="scheduleDate != null">#{scheduleDate,jdbcType=DATE},</if>
		        <if test="type != null">#{type,jdbcType=CHAR},</if>
	            <if test="scheduleStartTime != null">#{scheduleStartTime,jdbcType=TIME},</if>
                <if test="scheduleEndTime != null">#{scheduleEndTime,jdbcType=TIME},</if>
	        	<if test="status != null">#{status,jdbcType=CHAR},</if>
                <if test="applyState != null">#{applyState,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail">
        update schedule_plan_detail
        <set>
                <if test="schedulePlanId != null">
                    schedule_plan_id = #{schedulePlanId,jdbcType=BIGINT},
                </if>
                <if test="doctorId != null">
                    doctor_id = #{doctorId,jdbcType=BIGINT},
                </if>
                <if test="doctorName != null">
                    doctor_name = #{doctorName,jdbcType=VARCHAR},
                </if>
                <if test="scheduleDate != null">
                    schedule_date = #{scheduleDate,jdbcType=DATE},
                </if>
		        <if test="type != null">
			        `type` = #{type,jdbcType=CHAR},
		        </if>
                <if test="scheduleStartTime != null">
                    schedule_start_time = #{scheduleStartTime,jdbcType=TIME},
                </if>
                <if test="scheduleEndTime != null">
                    schedule_end_time = #{scheduleEndTime,jdbcType=TIME},
                </if>
		        <if test="status != null">
			        status = #{status,jdbcType=CHAR},
		        </if>
                <if test="applyState != null">
                    apply_state = #{applyState,jdbcType=VARCHAR},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail">
        update schedule_plan_detail
        set 
            schedule_plan_id =  #{schedulePlanId,jdbcType=BIGINT},
            doctor_id =  #{doctorId,jdbcType=BIGINT},
            doctor_name =  #{doctorName,jdbcType=VARCHAR},
            schedule_date =  #{scheduleDate,jdbcType=DATE},
            type =  #{type,jdbcType=CHAR},
            schedule_start_time =  #{scheduleStartTime,jdbcType=TIME},
            schedule_end_time =  #{scheduleEndTime,jdbcType=TIME},
            status =  #{status,jdbcType=CHAR},
            apply_state =  #{applyState,jdbcType=VARCHAR}
        where   id = #{id,jdbcType=BIGINT} 
    </update>
	<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail" useGeneratedKeys="true">
		insert into schedule_plan_detail
		(schedule_plan_id,doctor_id
		,doctor_name,schedule_date,type,schedule_start_time
		,schedule_end_time,status,apply_state) values
		<foreach item="item" index="index" collection="list" separator=",">
			 (#{item.schedulePlanId},#{item.doctorId}
			,#{item.doctorName},#{item.scheduleDate},#{item.type},#{item.scheduleStartTime}
			,#{item.scheduleEndTime},#{item.status},#{item.applyState})
		</foreach>
	</insert>

	<select id="getList" parameterType="com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from schedule_plan_detail
		<where>
			<if test="schedulePlanId != null">
				and schedule_plan_id = #{schedulePlanId,jdbcType=BIGINT}
			</if>
			<if test="doctorId != null">
				and doctor_id = #{doctorId,jdbcType=BIGINT}
			</if>
			<if test="scheduleDate != null">
				and schedule_date = #{scheduleDate,jdbcType=DATE}
			</if>
			<if test="type != null">
				and `type` = #{type,jdbcType=CHAR}
			</if>
			<if test="scheduleStartTime != null">
				and DATE_FORMAT(schedule_start_time, '%H%i') &lt;= DATE_FORMAT(#{scheduleStartTime}, '%H%i')
			</if>
			<if test="scheduleEndTime != null">
				and DATE_FORMAT(schedule_end_time, '%H%i') >= DATE_FORMAT(#{scheduleEndTime}, '%H%i')
			</if>
			<if test="after != null">
				and DATE_FORMAT(schedule_start_time, '%H%i') > DATE_FORMAT(now(), '%H%i')
			</if>
			<if test="status != null">
				status =  #{status,jdbcType=CHAR}
			</if>
		</where>
	</select>
</mapper>
