<?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.sqx.modules.course.dao.CourseUserDao">

<!--    <select id="selectLatelyCourse" resultType="com.sqx.modules.course.entity.Course">-->
<!--        select c.*,(select count(*) from course_user cu where cu.course_id=u.course_id) as courseCount,-->
<!--               (select group_concat(avatar) from-->
<!--                   (SELECT tu.avatar,course_id FROM course_user o-->
<!--                    left join tb_user tu on tu.user_id=o.user_id-->
<!--                    GROUP BY course_id,tu.avatar-->
<!--                        limit 3-->
<!--                   ) a where a.course_id=u.course_id ) as avatar from course_user u-->
<!--        left join course c on u.course_id=c.course_id-->
<!--        where u.user_id=#{userId} and c.is_delete=0 order by update_time desc-->
<!--    </select>-->

<!--    <select id="selectCourseByCourseUser" resultType="com.sqx.modules.course.entity.Course">-->
<!--        select c.*,(select count(*) from course_user cu where cu.course_id=u.course_id) as courseCount,-->
<!--               (select group_concat(avatar) from-->
<!--                   (SELECT tu.avatar,course_id FROM course_user o-->
<!--                    left join tb_user tu on tu.user_id=o.user_id-->
<!--                    GROUP BY course_id,tu.avatar-->
<!--                        limit 3-->
<!--                   ) a where a.course_id=u.course_id ) as avatar-->
<!--        from course_user u-->
<!--        left join course c on u.course_id=c.course_id-->
<!--        where u.user_id=#{userId} and c.is_delete=0-->
<!--        order by u.create_time desc-->
<!--    </select>-->

    <select id="selectCourseUser" resultType="com.sqx.modules.course.entity.CourseUser">
     select * from course_user u where u.user_id=#{userId} and u.course_id=#{id} and u.classify=1
    </select>

    <select id="selectCourseUserList" resultType="com.sqx.modules.course.entity.CourseUser">
        select * from course_user u where u.user_id=#{userId} and u.course_id=#{id} and u.classify=2
    </select>

    <select id="selectUserCourseDetailsId" resultType="Long">
        select course_details_id from course_user u where u.user_id=#{userId} and u.course_id=#{id} and u.classify=2
    </select>

    <update id="updateCourseTime">
        update  course_user   set update_time =#{courseUser.updateTime}
    </update>

    <delete id="deleteCourseUserByVipUser">
        delete from course_user where order_id in (select orders_id from orders where user_id= #{userId} and pay_way=5 and status=1)
    </delete>

</mapper>