ExerciseDoneHistoryMapper.xml 8.19 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.ExerciseDoneHistoryMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.meishu.model.ExerciseDoneHistoryDO">
        <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="subject_id" property="subjectId" />
        <result column="exercise_id" property="exerciseId" />
        <result column="answer" property="answer" />
        <result column="result" property="result" />
        <result column="length" property="length" />
    </resultMap>

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

    <select id="perStudentRelateExes" parameterType="com.meishu.dto.task.PerStudentExesDTO" resultType="com.meishu.vo.task.PerStuExeDoneResponseVO">
    SELECT
        t.id as userId,
        t.study_code,
    	t.user_name,
        ifnull(t5.rights,0) as rightCounts,
        ifnull(t5.length,0) as length,
        ifnull(t5.totalCounts,0) as totalCounts,
        t5.submit_date
    FROM
        user_role t
        left join classes_user_mapping t4 on t4.user_id = t.id
        left join classes_dict t3 on t4.classes_id = t3.id
        LEFT JOIN subject_dict t2 ON  t3.grade = t2.grade
        AND t3.classes = t2.classes
        AND t3.`session` = t2.`session`
        LEFT JOIN (
        SELECT
            t.user_id,
            t2.user_name,
            sum( result ) AS rights,
            sum( length ) AS length,
            sum(1) as totalCounts,
            max(t.create_date) submit_date
        FROM
            exercise_done_history t
            left join user_role t2
		    on t.user_id = t2.id
        WHERE
            task_subject_id = #{taskId}
             AND exercise_type = 0
            AND content_id = #{treeId}
            and class_type = 0
        GROUP BY
            t.user_id
        ) t5 ON t.id = t5.user_id
    	where
	t2.id = #{subjectId}
	order by t.study_code
    </select>


    <select id="classDoneInfo" parameterType="com.meishu.dto.task.ClassDoneInfoDTO" resultType="com.meishu.vo.task.ClassDoneInfoVO">
        SELECT
            t.exercise_id,
            sum( length ) AS length,
            sum( result ) AS result
        FROM
            exercise_done_history t
        WHERE
            t.class_type = 0
          AND task_subject_id = #{taskId}
          AND exercise_type = #{exerciseType}
          AND content_id = #{treeId}
          and done_type = '已完成'
        GROUP BY
            exercise_id
    </select>

    <select id="exesDoneInfo" parameterType="com.meishu.dto.task.ExesDoneInfoPO" resultType="com.meishu.vo.task.ClassDoneInfoVO">
        SELECT
        t.exercise_id,
        sum( length ) AS length,
        sum( result ) AS result,
        count(1) as countNum
        FROM
        exercise_done_history t
        WHERE 1=1 and t.exercise_id in
        <foreach collection="exeIds" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY
        exercise_id
    </select>

    <select id="getRelateExeDoneInfo" parameterType="com.meishu.vo.task.GetClassExeDoneInfoRequestVO" resultType="com.meishu.vo.task.GetClassExeDoneInfoResponseVO">
       SELECT
        t.exercise_id,
        t.exercise_type,
        t.tree_id,
        t.title,
        t.answer,
        t.right_answer,
        t.result,
        t.length,
        t.exeType,
        ifnull( t3.result, 0 ) AS classResult,
        ifnull( t3.length, 0 ) AS classLength
    FROM
        (
        SELECT
            t.*,
            t4.title,
            t4.right_answer,
            t4.tree_id,
            t4.exercise_type as exeType
        FROM
            exercise_done_history t
            LEFT JOIN exercise_dict t4 ON t.exercise_id = t4.id
        WHERE
            t.user_id = #{userId}
            AND t.class_type = 0
            AND task_subject_id = #{taskId}
            AND t.exercise_type = 0
            and t.done_type = '已完成'
            AND content_id = #{treeId}
        ) t
        LEFT JOIN (
        SELECT
            t.exercise_id,
            sum( length ) AS length,
            sum( result ) AS result
        FROM
            exercise_done_history t
        WHERE
            t.class_type = 0
            AND task_subject_id = #{taskId}
            AND exercise_type = 0
            and done_type = '已完成'
            AND content_id = #{treeId}
        GROUP BY
        exercise_id
        ) t3 ON t.exercise_id = t3.exercise_id
    </select>

    <select id="getExpandingExeDoneInfo" parameterType="com.meishu.vo.task.GetClassExeDoneInfoRequestVO" resultType="com.meishu.vo.task.GetClassExeDoneInfoResponseVO">
        SELECT
        t1.exercise_id,
        t1.exeType,
        t1.tree_id,
        t1.title,
        t1.right_answer,
        t1.result,
        t1.answer,
        t1.length,
        ifnull(t2.length,0) AS classLength,
        ifnull(t2.result,0) AS class_result
        FROM
        (
        SELECT
        exercise_id,
        t2.exercise_type as exeType,
        t2.tree_id,
        t2.title,
        t2.right_answer,
        t.result,
        t.answer,
        t.length
        FROM
        exercise_done_history t
        LEFT JOIN exercise_dict t2 ON t.exercise_id = t2.id
        WHERE
        t.content_id = #{treeId}
        AND t.user_id = #{userId}
        and t.task_subject_id = #{taskId}
        and t.done_type = '已完成'
        and class_type = 0
        ) t1
        LEFT JOIN (
        SELECT
        t.exercise_id,
        sum( t.result ) AS result,
        sum( t.length ) AS length
        FROM
        exercise_done_history t
        WHERE
        t.content_id = #{treeId}
        and t.task_subject_id = #{taskId}
        and t.class_type = 0
        and t.done_type = '已完成'
        AND t.user_id IN
        <foreach collection="userIds" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
        GROUP BY
        exercise_id
        ) t2 ON t1.exercise_id = t2.exercise_id
    </select>

    <select id="perStudentExpandingExes" parameterType="com.meishu.dto.task.PerStudentExesRequestVO" resultType="com.meishu.vo.task.PerStuExeDoneResponseVO">
        SELECT
        t3.id as user_id,
        t3.study_code,
        t3.user_name,
        t2.classes_id,
        ifnull(t2.rightCounts,0) as rightCounts,
        ifnull(t2.length,0) as length,
        t2.submit_date
        FROM
        (
        SELECT
        *
        FROM
        classes_user_mapping t
        WHERE t.delete_date is null and
        t.user_id IN
        <foreach collection="userIds" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
        <if test="classesId!=null">
            AND classes_id = #{classesId}
        </if>
        ) t
        left join user_role t3 on t.user_id = t3.id
        LEFT JOIN (
        SELECT
        t1.user_id,
        t2.study_code,
        t2.user_name,
        classes_id,
        ifnull( t1.rights, 0 ) AS rightCounts,
        ifnull( t1.length, 0 ) AS length,
        t1.submit_date
        FROM
        (
        SELECT
        t.user_id,
        sum( result ) AS rights,
        sum( length ) AS length,
        max( update_date ) AS submit_date
        FROM
        exercise_done_history t
        WHERE
        t.task_subject_id = #{taskId}
--         and t.done_type = '已完成'
        AND t.content_id = #{treeId}
        GROUP BY
        t.user_id
        ) t1
        LEFT JOIN (
        SELECT
        t4.study_code,
        t3.user_id as user_role_id,
        t3.classes_id,
        t4.user_name
        FROM
        classes_user_mapping t3
        LEFT JOIN user_role t4 ON t3.user_id = t4.id
        ) t2 ON t1.user_id = t2.user_role_id
        ) t2 ON t.user_id = t2.user_id
        AND t.classes_id = t2.classes_id
    </select>
</mapper>