<?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.zhongzheng.modules.user.mapper.UserStudyRecordMapper">

    <resultMap type="com.zhongzheng.modules.user.domain.UserStudyRecord" id="UserStudyRecordResult">
        <result property="recordId" column="record_id"/>
        <result property="userId" column="user_id"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="studyDuration" column="study_duration"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="courseName" column="course_name"/>

    </resultMap>

    <select id="selectList" parameterType="com.zhongzheng.modules.user.bo.UserStudyRecordQueryBo"  resultMap="UserStudyRecordResult">
        SELECT DISTINCT
        temp.course_id,
        c.cover_url,
        c.course_name
        FROM
        ( SELECT course_id FROM user_study_record WHERE 1 = 1
        <if test="userId != null and userId != ''">
            AND  user_id = #{userId}
        </if>
        ORDER BY record_id DESC LIMIT 30 ) temp
        LEFT JOIN course c ON temp.course_id = c.course_id


    </select>

    <select id="selectUserStudy" parameterType="map"  resultMap="UserStudyRecordResult">
        select * FROM user_study_record where 1=1
        <if test="userId != null and userId != ''">
            and user_id =#{userId}
        </if>
        <if test="courseId != null and courseId !=''">
            and course_id = #{courseId}
        </if>
        and study_duration > 360
    </select>
</mapper>
