<?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.schedule.ScheduleMapper">

    <resultMap id="BaseResultMap" type="com.xinelu.manage.domain.schedule.Schedule">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="hospitalId" column="hospital_id" jdbcType="BIGINT"/>
            <result property="hospitalName" column="hospital_name" jdbcType="VARCHAR"/>
            <result property="scheduleName" column="schedule_name" jdbcType="VARCHAR"/>
            <result property="forenoonStartTime" column="forenoon_start_time" jdbcType="TIME"/>
            <result property="forenoonEndTime" column="forenoon_end_time" jdbcType="TIME"/>
            <result property="afternoonStartTime" column="afternoon_start_time" jdbcType="TIME"/>
            <result property="afternoonEndTime" column="afternoon_end_time" jdbcType="TIME"/>
            <result property="status" column="status" jdbcType="CHAR"/>
            <result property="delFlag" column="del_flag" jdbcType="CHAR"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,hospital_id,hospital_name,
        schedule_name,forenoon_start_time,forenoon_end_time,
        afternoon_start_time,afternoon_end_time,status,
        del_flag,create_by,create_time,
        update_by,update_time
    </sql>

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

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from schedule
        where  id = #{id,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.schedule.Schedule" useGeneratedKeys="true">
        insert into schedule
        ( id,hospital_id,hospital_name
        ,schedule_name,forenoon_start_time,forenoon_end_time
        ,afternoon_start_time,afternoon_end_time,status
        ,del_flag,create_by,create_time
        ,update_by,update_time)
        values (#{id,jdbcType=BIGINT},#{hospitalId,jdbcType=BIGINT},#{hospitalName,jdbcType=VARCHAR}
        ,#{scheduleName,jdbcType=VARCHAR},#{forenoonStartTime,jdbcType=TIME},#{forenoonEndTime,jdbcType=TIME}
        ,#{afternoonStartTime,jdbcType=TIME},#{afternoonEndTime,jdbcType=TIME},#{status,jdbcType=CHAR}
        ,#{delFlag,jdbcType=CHAR},#{createBy,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP}
        ,#{updateBy,jdbcType=VARCHAR},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.xinelu.manage.domain.schedule.Schedule" useGeneratedKeys="true">
        insert into schedule
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="hospitalId != null">hospital_id,</if>
                <if test="hospitalName != null">hospital_name,</if>
                <if test="scheduleName != null">schedule_name,</if>
                <if test="forenoonStartTime != null">forenoon_start_time,</if>
                <if test="forenoonEndTime != null">forenoon_end_time,</if>
                <if test="afternoonStartTime != null">afternoon_start_time,</if>
                <if test="afternoonEndTime != null">afternoon_end_time,</if>
                <if test="status != null">status,</if>
                <if test="delFlag != null">del_flag,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=BIGINT},</if>
                <if test="hospitalId != null">#{hospitalId,jdbcType=BIGINT},</if>
                <if test="hospitalName != null">#{hospitalName,jdbcType=VARCHAR},</if>
                <if test="scheduleName != null">#{scheduleName,jdbcType=VARCHAR},</if>
                <if test="forenoonStartTime != null">#{forenoonStartTime,jdbcType=TIME},</if>
                <if test="forenoonEndTime != null">#{forenoonEndTime,jdbcType=TIME},</if>
                <if test="afternoonStartTime != null">#{afternoonStartTime,jdbcType=TIME},</if>
                <if test="afternoonEndTime != null">#{afternoonEndTime,jdbcType=TIME},</if>
                <if test="status != null">#{status,jdbcType=CHAR},</if>
                <if test="delFlag != null">#{delFlag,jdbcType=CHAR},</if>
                <if test="createBy != null">#{createBy,jdbcType=VARCHAR},</if>
                <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
                <if test="updateBy != null">#{updateBy,jdbcType=VARCHAR},</if>
                <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.xinelu.manage.domain.schedule.Schedule">
        update schedule
        <set>
                <if test="hospitalId != null">
                    hospital_id = #{hospitalId,jdbcType=BIGINT},
                </if>
                <if test="hospitalName != null">
                    hospital_name = #{hospitalName,jdbcType=VARCHAR},
                </if>
                <if test="scheduleName != null">
                    schedule_name = #{scheduleName,jdbcType=VARCHAR},
                </if>
                <if test="forenoonStartTime != null">
                    forenoon_start_time = #{forenoonStartTime,jdbcType=TIME},
                </if>
                <if test="forenoonEndTime != null">
                    forenoon_end_time = #{forenoonEndTime,jdbcType=TIME},
                </if>
                <if test="afternoonStartTime != null">
                    afternoon_start_time = #{afternoonStartTime,jdbcType=TIME},
                </if>
                <if test="afternoonEndTime != null">
                    afternoon_end_time = #{afternoonEndTime,jdbcType=TIME},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=CHAR},
                </if>
                <if test="delFlag != null">
                    del_flag = #{delFlag,jdbcType=CHAR},
                </if>
                <if test="createBy != null">
                    create_by = #{createBy,jdbcType=VARCHAR},
                </if>
                <if test="createTime != null">
                    create_time = #{createTime,jdbcType=TIMESTAMP},
                </if>
                <if test="updateBy != null">
                    update_by = #{updateBy,jdbcType=VARCHAR},
                </if>
                <if test="updateTime != null">
                    update_time = #{updateTime,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   id = #{id,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.xinelu.manage.domain.schedule.Schedule">
        update schedule
        set 
            hospital_id =  #{hospitalId,jdbcType=BIGINT},
            hospital_name =  #{hospitalName,jdbcType=VARCHAR},
            schedule_name =  #{scheduleName,jdbcType=VARCHAR},
            forenoon_start_time =  #{forenoonStartTime,jdbcType=TIME},
            forenoon_end_time =  #{forenoonEndTime,jdbcType=TIME},
            afternoon_start_time =  #{afternoonStartTime,jdbcType=TIME},
            afternoon_end_time =  #{afternoonEndTime,jdbcType=TIME},
            status =  #{status,jdbcType=CHAR},
            del_flag =  #{delFlag,jdbcType=CHAR},
            create_by =  #{createBy,jdbcType=VARCHAR},
            create_time =  #{createTime,jdbcType=TIMESTAMP},
            update_by =  #{updateBy,jdbcType=VARCHAR},
            update_time =  #{updateTime,jdbcType=TIMESTAMP}
        where   id = #{id,jdbcType=BIGINT} 
    </update>

	<select id="getList" parameterType="com.xinelu.manage.domain.schedule.Schedule" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List" />
		from schedule
		<where>
		    del_flag = '0'
			<if test="hospitalId != null">
				and hospital_id = #{hospitalId,jdbcType=BIGINT}
			</if>
			<if test="hospitalName != null">
				and hospital_name like concat('%', #{hospitalName}, '%')
			</if>
			<if test="scheduleName != null">
				and schedule_name like concat('%', #{scheduleName}, '%')
			</if>
		</where>
	</select>
</mapper>
