Blame view

CourseTreeExerciseStudentResultMapper.xml 4.1 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?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>