<?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.MusicGroupPaymentCalenderStudentDetailDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderStudentDetail" id="MusicGroupPaymentCalenderStudentDetail">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId" />
		<result column="phone_" property="phone" />
		<result column="username_" property="username" />
		<result column="course_original_price_" property="courseOriginalPrice" />
		<result column="course_current_price_" property="courseCurrentPrice" />
		<result column="master_sub_course_price_" property="masterSubCoursePrice" />
		<result column="course_type_" property="courseType" />
		<result column="course_time_" property="courseTime" />
		<result column="class_group_id_" property="classGroupId" />
		<result column="batch_no_" property="batchNo" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="MusicGroupPaymentCalenderStudentDetail" >
		SELECT * FROM music_group_payment_calender_student_detail WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="MusicGroupPaymentCalenderStudentDetail">
		SELECT * FROM music_group_payment_calender_student_detail ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderStudentDetail" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO music_group_payment_calender_student_detail (id_,user_id_,phone_,username_,course_original_price_,
																 course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_,master_sub_course_price_)
		VALUES(#{id},#{userId},#{phone},#{username},#{courseOriginalPrice},#{courseCurrentPrice},
			   #{courseType},#{courseTime},#{classGroupId},#{batchNo},NOW(),NOW(),#{masterSubCoursePrice})
	</insert>
	
	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderStudentDetail">
		UPDATE music_group_payment_calender_student_detail <set>
		<if test="userId != null">
		user_id_ = #{userId},
		</if>
		<if test="masterSubCoursePrice != null">
			master_sub_course_price_ = #{masterSubCoursePrice},
		</if>
		<if test="classGroupId != null">
		class_group_id_ = #{classGroupId},
		</if>
		<if test="courseCurrentPrice != null">
		course_current_price_ = #{courseCurrentPrice},
		</if>
		<if test="courseType != null">
		course_type_ = #{courseType},
		</if>
		<if test="courseOriginalPrice != null">
		course_original_price_ = #{courseOriginalPrice},
		</if>
		<if test="batchNo != null">
			batch_no_ = #{batchNo},
		</if>
		<if test="phone != null">
		phone_ = #{phone},
		</if>
		<if test="courseTime != null">
		course_time_ = #{courseTime},
		</if>
		<if test="username != null">
		username_ = #{username},
		</if>
		update_time_ = NOW()
		</set> WHERE id_ = #{id}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM music_group_payment_calender_student_detail WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MusicGroupPaymentCalenderStudentDetail" parameterType="map">
		SELECT * FROM music_group_payment_calender_student_detail ORDER BY id_ <include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM music_group_payment_calender_student_detail
	</select>
	<insert id="batchInsert">
		INSERT INTO music_group_payment_calender_student_detail (user_id_,phone_,username_,course_original_price_,
		course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_,master_sub_course_price_)
		VALUES
		<foreach collection="musicGroupPaymentCalenderStudentDetails" item="item" index="index" separator=",">
			(#{item.userId},#{item.phone},#{item.username},#{item.courseOriginalPrice},#{item.courseCurrentPrice},
			#{item.courseType},#{item.courseTime},#{item.classGroupId},#{batchNo},NOW(),NOW(),#{item.masterSubCoursePrice})
		</foreach>
	</insert>

	<update id="batchUpdate">
		<foreach collection="musicGroupPaymentCalenderStudentDetails" item="item" index="index" open="" close="" separator=";">
			UPDATE music_group_payment_calender_student_detail
		<set>
			<if test="item.courseCurrentPrice != null">
				course_current_price_ = #{item.courseCurrentPrice},
			</if>
			<if test="item.courseOriginalPrice != null">
				course_original_price_ = #{item.courseOriginalPrice},
			</if>
			update_time_ = NOW()
		</set>
			WHERE id_ = #{item.id}
		</foreach>
	</update>
	<update id="updateByCourseType">
		UPDATE music_group_payment_calender_student_detail
		SET course_current_price_ = #{courseCurrentPrice},update_time_ = NOW()
		WHERE course_type_ = #{courseType} AND batch_no_ = #{batchNo} AND user_id_ IN
		<foreach collection="studentIds" separator="," item="userId" open="(" close=")">
			#{userId}
		</foreach>
	</update>

	<select id="findByBatchNo" resultMap="MusicGroupPaymentCalenderStudentDetail">
		SELECT * FROM music_group_payment_calender_student_detail where batch_no_ = #{batchNo}
	</select>
    <select id="findByBatchNoAndUserId" resultMap="MusicGroupPaymentCalenderStudentDetail">
		SELECT * FROM music_group_payment_calender_student_detail where batch_no_ = #{batchNo} AND user_id_ = #{userId}
	</select>

    <delete id="delByBatchNo">
		DELETE FROM music_group_payment_calender_student_detail WHERE batch_no_ = #{batchNo}
	</delete>
</mapper>
