<?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.CourseRelationMusicAlbumDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CourseRelationMusicAlbum">
            <result column="id_" property="id" />
	        <result column="course_group_id_" property="courseGroupId" />
	        <result column="course_id_" property="courseId" />
	        <result column="course_type_" property="courseType" />
	        <result column="relation_type_" property="relationType" />
	        <result column="music_album_id_" property="musicAlbumId" />
	        <result column="update_by_" property="updateBy" />
	        <result column="update_time_" property="updateTime" />
	        <result column="create_by_" property="createBy" />
	        <result column="create_time_" property="createTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.course_group_id_ as courseGroupId
        , t.course_id_ as courseId
        , t.course_type_ as courseType
        , t.relation_type_ as relationType
        , t.music_album_id_ as musicAlbumId
        , t.update_by_ as updateBy
        , t.update_time_ as updateTime
        , t.create_by_ as createBy
        , t.create_time_ as createTime
    </sql>

    <!--课程用户购买记录-->
    <select id="selectCoursePurchaseUserInfo" resultType="com.yonge.cooleshow.biz.dal.entity.UserOrder">
        SELECT t1.order_client_, t1.order_no_, t1.update_time_, t1.user_id_
        FROM user_order t1 JOIN <choose><when test="record.courseType.code == 'VIDEO'">video_lesson_purchase_record</when><otherwise>course_schedule_student_payment</otherwise></choose> t2 ON (t1.order_no_ = t2.order_no_)
        <where>
            <if test="record.orderStatus != null">
                AND t1.status_ = #{record.orderStatus}
            </if>
            <choose>
                <when test="record.courseType.code == 'VIDEO'">
                    <if test="record.groupId != null">
                        AND t2.video_lesson_group_id_ = #{record.groupId}
                    </if>
                </when>
                <otherwise>
                    <if test="record.groupId != null">
                        AND t2.course_group_id_ = #{record.groupId}
                    </if>
                    <if test="record.courseType != null">
                        AND t2.course_type_ = #{record.courseType}
                    </if>
                </otherwise>
            </choose>
        </where>
    </select>
    <!--课程用户购买记录-->

</mapper>