<?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.MusicGroupSchoolTermCourseDetailDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MusicGroupSchoolTermCourseDetail" id="MusicGroupSchoolTermCourseDetail">
		<result column="id_" property="id" />
		<result column="music_group_id_" property="musicGroupId" />
		<result column="start_course_date_" property="startCourseDate" />
		<result column="start_school_term_" property="startSchoolTerm" />
		<result column="end_school_term_" property="endSchoolTerm" />
		<result column="course_flag_" property="courseFlag" />
		<result column="total_course_time_" property="totalCourseTime" />
		<result column="update_time_" property="updateTime" />
		<result column="create_time_" property="createTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="MusicGroupSchoolTermCourseDetail" >
		SELECT * FROM music_group_school_term_course_detail WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="MusicGroupSchoolTermCourseDetail">
		SELECT * FROM music_group_school_term_course_detail ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupSchoolTermCourseDetail" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO music_group_school_term_course_detail (music_group_id_,start_course_date_,start_school_term_,
	   end_school_term_,course_flag_,total_course_time_,update_time_,create_time_)
	   VALUES(#{musicGroupId},#{startCourseDate},#{startSchoolTerm},#{endSchoolTerm},#{courseFlag},#{totalCourseTime},NOW(),NOW())
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicGroupSchoolTermCourseDetail">
		UPDATE music_group_school_term_course_detail <set>
		<if test="courseFlag != null">
			course_flag_ = #{courseFlag},
		</if>
		<if test="startCourseDate != null">
			start_course_date_ = #{startCourseDate},
		</if>
		<if test="endSchoolTerm != null">
			end_school_term_ = #{endSchoolTerm},
		</if>
		<if test="totalCourseTime != null">
			total_course_time_ = #{totalCourseTime},
		</if>
		<if test="startSchoolTerm != null">
			start_school_term_ = #{startSchoolTerm},
		</if>
		<if test="musicGroupId != null">
			music_group_id_ = #{musicGroupId},
		</if>
			update_time_ = NOW()
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM music_group_school_term_course_detail WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MusicGroupSchoolTermCourseDetail" parameterType="map">
		SELECT * FROM music_group_school_term_course_detail ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM music_group_school_term_course_detail
	</select>
	<select id="findByMusicGroupId" resultMap="MusicGroupSchoolTermCourseDetail">
		SELECT * FROM music_group_school_term_course_detail
		WHERE music_group_id_ = #{musicGroupId}
	</select>
	<select id="findByCourseDateAndMusicGroupId" resultMap="MusicGroupSchoolTermCourseDetail">
		SELECT * FROM music_group_school_term_course_detail
		WHERE music_group_id_ = #{musicGroupId}
		<if test="startCourseDate != null">
			AND (#{startCourseDate} BETWEEN start_school_term_ AND end_school_term_)
		</if>
		<if test="courseFlag != null">
			AND course_flag_ = #{courseFlag}
		</if>
	</select>
    <select id="queryAllNoCourse" resultMap="MusicGroupSchoolTermCourseDetail">
		SELECT * FROM music_group_school_term_course_detail
		WHERE course_flag_ = 0
	</select>
    <select id="queryPushCourseTermMusicIds" resultType="java.lang.String">
		SELECT music_group_id_ FROM music_group_school_term_course_detail
		GROUP BY music_group_id_ HAVING DATEDIFF(MAX(end_school_term_),NOW()) = #{remindCourseTime}
	</select>
</mapper>
