<?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.ym.mec.biz.dal.dao.TeacherRemindDao">

	<resultMap type="com.ym.mec.biz.dal.entity.TeacherRemind" id="TeacherRemind">
		<result column="id_" property="id" />
		<result column="operator_id_" property="operatorId" />
		<result column="operator_name_" property="operatorName" />
		<result column="teacher_id_" property="teacherId" />
		<result column="monday_" property="monday"/>
		<result column="content_" property="content" />
		<result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
		<result column="create_time_" property="createTime" />
        <result column="tenant_id_" property="tenantId"/>
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="TeacherRemind" >
		SELECT * FROM teacher_remind WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="TeacherRemind">
		SELECT * FROM teacher_remind where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.TeacherRemind" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!--
		<selectKey resultClass="int" keyProperty="id" > 
		SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL 
		</selectKey>
		-->
		INSERT INTO teacher_remind (operator_id_,operator_name_,teacher_id_,monday_,content_,type_,create_time_,tenant_id_)
		VALUES(#{operatorId},#{operatorName},#{teacherId},#{monday},#{content},#{type, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},NOW(),#{tenantId})
	</insert>

	<insert id="batchInsert" parameterType="com.ym.mec.biz.dal.entity.TeacherRemind" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO teacher_remind (operator_id_,operator_name_,teacher_id_,monday_,content_,type_,create_time_,tenant_id_)
		VALUE
		<foreach collection="reminds" item="remind" separator=",">
			(#{remind.operatorId},#{remind.operatorName},#{remind.teacherId},#{remind.monday},#{remind.content},
		    #{remind.type, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},NOW(),#{remind.tenantId})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.TeacherRemind">
		UPDATE teacher_remind <set>
		<if test="operatorId != null">
			operator_id_ = #{operatorId},
		</if>
		<if test="operatorName != null">
			operator_name_ = #{operatorName},
		</if>
		<if test="id != null">
			id_ = #{id},
		</if>
		<if test="teacherId != null">
			teacher_id_ = #{teacherId},
		</if>
		<if test="monday != null">
			monday_ = #{monday},
		</if>
		<if test="content != null">
			content_ = #{content},
		</if>
		<if test="type != null">
			type_ = #{type, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
		</if>
	</set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM teacher_remind WHERE id_ = #{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="TeacherRemind" parameterType="map">
		SELECT * FROM teacher_remind where tenant_id_ = #{tenantId} ORDER BY id_ <include refid="global.limit"/>
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM teacher_remind where tenant_id_ = #{tenantId}
	</select>

	<select id="findTeachersRemindWithType" resultMap="TeacherRemind">
		SELECT *
		FROM teacher_remind
		WHERE type_=#{remindType, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
		    AND teacher_id_ IN
			<foreach collection="teacherIds" item="teacherId" open="(" close=")" separator=",">
				#{teacherId}
			</foreach>
			<if test="startDate!=null and endDate!=null">
				AND monday_ BETWEEN #{startDate} AND #{endDate}
			</if>
	</select>
</mapper>
