Blame view

ExerciseDoneHistoryMapper.xml 8.19 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
<?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>