<?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.yonge.cooleshow.biz.dal.dao.VideoLessonPurchaseRecordDao">

	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.VideoLessonPurchaseRecord">
	     <id column="id_" jdbcType="BIGINT" property="id" />
		 <result column="video_lesson_group_id_" jdbcType="BIGINT" property="videoLessonGroupId" />
		 <result column="student_id_" jdbcType="BIGINT" property="studentId" />
		 <result column="purchase_time_" jdbcType="TIMESTAMP" property="purchaseTime" />
		 <result column="pay_money_" jdbcType="DECIMAL" property="payMoney" />
		 <result column="order_no_" jdbcType="VARCHAR" property="orderNo" />
		 <result column="order_status_" jdbcType="VARCHAR" property="orderStatus" />
	</resultMap>

	<sql id="Base_Column_List">
		id_, video_lesson_group_id_, student_id_, purchase_time_, pay_money_, order_no_, order_status_
	</sql>
    <select id="selectStudentByDetail" resultType="java.lang.Long" parameterType="java.lang.Long">
		SELECT student_id_ FROM video_lesson_purchase_record
		WHERE video_lesson_group_id_=
		(SELECT video_lesson_group_id_ FROM video_lesson_group_detail WHERE id_=#{videoId})
	</select>
	<select id="selectTeacherByDetail" resultType="java.lang.Long" parameterType="java.lang.Long">
		SELECT teacher_id_ FROM video_lesson_group
		WHERE id_=
		(SELECT video_lesson_group_id_ FROM video_lesson_group_detail WHERE id_=#{videoId})
	</select>
	<update id="updateStatus" parameterType="java.lang.String">
		UPDATE video_lesson_purchase_record SET order_status_=#{status} WHERE order_no_=#{orderNo}
	</update>
	
	<select id="queryByVideoLessonGroupId" resultMap="BaseResultMap">
		SELECT * FROM video_lesson_purchase_record WHERE video_lesson_group_id_ = #{videoLessonGroupId} and order_status_  = #{orderStatus}
	</select>
</mapper>