CourseTreeExerciseStudentResultMapper.xml 4.1 KB
<?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.meishu.mapper.CourseTreeExerciseStudentResultMapper">

<!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
<!--    <resultMap id="BaseResultMap" type="com.meishu.model.CourseTreeExerciseStudentResultDO">-->
<!--        <id column="id" property="id" />-->
<!--        <result column="create_date" property="createTime" />-->
<!--        <result column="update_date" property="updateTime" />-->
<!--        <result column="create_date" property="deleteTime" />-->
<!--        <result column="student_id" property="studentId" />-->
<!--        <result column="course_id" property="courseId" />-->
<!--        <result column="exercise_id" property="exerciseId" />-->
<!--        <result column="answer" property="answer" />-->
<!--        <result column="length" property="length" />-->
<!--        <result column="result" property="result" />-->
<!--    </resultMap>-->

    <!-- 通用查询结果列 -->
<!--    <sql id="Base_Column_List">-->
<!--        create_date,-->
<!--        update_date,-->
<!--        create_date,-->
<!--        id, student_id, course_id, exercise_id, answer, length, result-->
<!--    </sql>-->

    <select id="studentExercise" resultType="com.meishu.model.CourseTreeExerciseStudentResultDO">
        SELECT
            *
        FROM
            course_tree_exercise_student_result t
        WHERE
            t.delete_date IS NULL
            AND t.student_id = #{studentId}
            AND t.chapter_id = #{chapterId}
    </select>

    <select id="getTreesByExerciseIds" parameterType="long" resultType="com.meishu.model.CourseTreeDO">
        SELECT DISTINCT
            t3.*
        FROM
            exercise_dict t
            LEFT JOIN exercise_related t2 ON t.id = t2.exercise_id
            LEFT JOIN course_tree t3 ON t2.tree_id = t3.id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            AND t3.delete_date IS NULL
            and t3.id is not null
            <if test="longs!=null">
                AND t.id IN
                <foreach collection="longs" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
    </select>

    <select id="getExerciseDetail" resultType="com.meishu.vo.course.GetExerciseDetailVO">
        SELECT
            t2.id,
            t2.exercise_type,
            t2.title,
            t2.right_answer,
            t2.difficulty,
            t2.items,
            t2.advice_length,
            t.answer,
            t.length,
            t.result,
            t3.rightCounts,
            t4.totalCounts,
            round( t3.rightCounts / t4.totalCounts, 2 ) AS rightPercent,
            round( t5.totalLength / t4.totalCounts, 2 ) AS avgLength,
            t.create_date
        FROM
            course_tree_exercise_student_result t
            LEFT JOIN exercise_dict t2 ON t.exercise_id = t2.id
            LEFT JOIN (
            SELECT
                t.exercise_id,
                sum( 1 ) AS rightCounts
            FROM
                course_tree_exercise_student_result t
            WHERE
                t.result = 1
                AND t.delete_date IS NULL
            GROUP BY
                t.exercise_id
            ) t3 ON t.exercise_id = t3.exercise_id
            LEFT JOIN ( SELECT t.exercise_id, sum( 1 ) AS totalCounts FROM course_tree_exercise_student_result t WHERE t.delete_date IS NULL GROUP BY t.exercise_id ) t4 ON t.exercise_id = t4.exercise_id
            LEFT JOIN (
            SELECT
                t.exercise_id,
                sum( t.length ) AS totalLength
            FROM
                course_tree_exercise_student_result t
            WHERE
                t.delete_date IS NULL
            GROUP BY
                t.exercise_id
            ) t5 ON t.exercise_id = t3.exercise_id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            AND t.student_id = #{studentId}
            AND t.chapter_id = #{chapterId}
    </select>


</mapper>