ExerciseCourseTreeMappingMapper.xml 4.52 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.ExerciseCourseTreeMappingMapper">

<!--    &lt;!&ndash; 通用查询映射结果 &ndash;&gt;-->
<!--    <resultMap id="BaseResultMap" type="com.meishu.model.ExerciseCourseTreeMappingDO">-->
<!--        <id column="id" property="id" />-->
<!--        <result column="create_date" property="createTime" />-->
<!--        <result column="update_date" property="updateTime" />-->
<!--        <result column="delete_date" property="deleteTime" />-->
<!--        <result column="exercise_id" property="exerciseId" />-->
<!--        <result column="status" property="status" />-->
<!--    </resultMap>-->

    <!-- 通用查询结果列 -->
    <select id="queryCourseTreeExercise" parameterType="com.meishu.dto.exercise.QueryCourseTreeExerciseDTO" resultType="com.meishu.vo.exercise.QueryCourseTreeExerciseVO">
        SELECT
        t.id,
        t2.exercise_type,
        t2.title,
        t2.items,
        t2.detail,
        t2.right_answer,
        t2.difficulty,
        t3.user_name,
        t.status,
        t2.create_date as update_date,
        t4.right_cnt ,
        t5.total_cnt,
        ROUND(t4.right_cnt/t5.total_cnt,0) as right_percent
        FROM
        exercise_course_tree_mapping t
        LEFT JOIN exercise_dict t2 ON t.exercise_id = t2.id
        LEFT JOIN administer t3 ON t2.administer_id = t3.id
        LEFT JOIN (
        SELECT
        t.course_id,
        t.exercise_id,
        sum( t.result ) AS right_cnt
        FROM
        course_tree_exercise_student_result t
        GROUP BY
        t.course_id,
        t.exercise_id
        ) t4 ON t.exercise_id = t4.exercise_id
        left join (SELECT
        t.course_id,
        t.exercise_id,
        count( t.result ) AS total_cnt
        FROM
        course_tree_exercise_student_result t
        GROUP BY
        t.course_id,
        t.exercise_id) t5 ON  t.exercise_id = t5.exercise_id
        WHERE
        t.delete_date IS NULL
        AND t2.delete_date IS NULL
        <if test="title!=null and title !=''">
            AND t2.title like concat('%',#{title} ,'%')
        </if>
        <if test="exerciseType!=null and exerciseType!=''">
            and exercise_type = #{exerciseType}
        </if>
        <if test="difficulty !=null and difficulty!=''">
            and difficulty = #{difficulty}
        </if>
        <if test="courseTreeId!=null and courseTreeId !=''">
            AND t.course_tree_id = #{courseTreeId}
        </if>
        AND t.course_id = #{courseId}
    </select>

    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, exercise_id, tree_id, status
    </sql>

    <select id="getParentTreeId" parameterType="long" resultType="com.meishu.model.CourseTreeDO">
        SELECT
            t2.*
        FROM
            exercise_course_tree_mapping t
            LEFT JOIN course_tree t2 ON t.course_tree_id = t2.id
        WHERE
            t.id = #{id}
            and t.delete_date is null
            and t2.delete_date is null
    </select>

    <select id="getExercisesByTree" parameterType="com.meishu.dto.course.GetExercisesByTreeDTO" resultType="com.meishu.model.ExerciseDictDO">
        SELECT
            t3.*
        FROM
            exercise_course_tree_mapping t
            LEFT JOIN course_tree t2 ON t.course_tree_id = t2.id
            LEFT JOIN exercise_dict t3 ON t.exercise_id = t3.id
        WHERE
            t.delete_date IS NULL
            AND t2.delete_date IS NULL
            AND t3.delete_date IS NULL
            AND t2.id = #{treeId}
<!--            AND t3.id not IN-->
<!--            <foreach collection="exerciseIds" item="id" index="index" open="(" close=")" separator=",">-->
<!--                #{id}-->
<!--            </foreach>-->
    </select>

    <select id="queryChapterTest" resultType="com.meishu.vo.student.QueryChapterTestVO">
        SELECT
            t2.id,
            t2.title,
            t2.right_answer,
            t2.items,
            t2.difficulty,
            t2.exercise_type,
            t2.detail,
            t2.advice_length,
            t.length,
            t.result,
            t.answer
        FROM
            course_tree_exercise_student_result t
            LEFT JOIN exercise_dict t2 ON t.exercise_id = t2.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>