<?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="cn.iocoder.yudao.module.knowledge.mapper.TCourseRecordsMapper">

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TCourseRecords" id="tCourseRecordsMap">
            <result property="id" column="id"/>
            <result property="userId" column="user_id"/>
            <result property="courseId" column="course_id"/>
            <result property="continueTime" column="continue_time"/>
            <result property="createTime" column="create_time"/>
            <result property="creator" column="creator"/>
            <result property="updateTime" column="update_time"/>
            <result property="deptId" column="dept_id"/>
            <result property="identityId" column="identity_id"/>
            <result property="deleted" column="deleted"/>
            <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <select id="findList" resultMap="tCourseRecordsMap">
        select continue_time,create_time
        from t_course_records
        <where>
            deleted = 0
            and create_time >= CURDATE() - INTERVAL 6 DAY
            <if test="params.userId != null ">and user_id = #{params.userId}</if>
        </where>
        order by create_time desc
    </select>

    <select id="findOne" resultMap="tCourseRecordsMap">
        select continue_time,create_time
        from t_course_records
        <where>
            deleted = 0
            and DATE(create_time) = curdate()
            <if test="userId != null ">and user_id = #{userId}</if>
        </where>
    </select>

    <select id="findByCourseAnuserId" resultMap="tCourseRecordsMap">
        select *
        from t_course_records
        <where>
            deleted = 0
            and DATE(create_time) = curdate()
            <if test="params.userId != null ">and user_id = #{params.userId}</if>
            <if test="params.courseId != null ">and course_id = #{params.courseId}</if>
        </where>
    </select>

</mapper>
