ExerciseDoneResultMapper.xml 5.39 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.subsidy.mapper.ExerciseDoneResultMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.subsidy.model.ExerciseDoneResultDO">
        <id column="id" property="id" />
        <result column="create_date" property="createDate" />
        <result column="update_date" property="updateDate" />
        <result column="delete_date" property="deleteDate" />
        <result column="member_id" property="memberId" />
        <result column="course_id" property="courseId" />
        <result column="right_counts" property="rightCounts" />
        <result column="total_counts" property="totalCounts" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        create_date,
        update_date,
        delete_date,
        id, member_id, course_id, right_counts, total_counts
    </sql>

    <select id="queryExerciseDoneResult" resultType="com.subsidy.vo.administer.GetMemberPapersVO">
        SELECT
            t.id,
            t.paper_id,
            right_counts,
            total_counts,
            score,
            result,
            create_date
        FROM
            exercise_done_result t
        WHERE
            t.delete_date is null
            and t.member_id = #{memberId}
            <if test="classId != null and classId !=''">
                AND t.class_id = #{classId}
            </if>
            <if test="paperId != null and paperId !=''">
                AND t.paper_id = #{paperId}
            </if>
            order by t.score desc
    </select>

    <select id="getPaperDetail" resultType="com.subsidy.vo.administer.GetPaperDetailVO">
        SELECT
            t2.title,
            t.result,
            t.answer,
            t2.right_answer,
            t2.items,
            t2.detail
        FROM
            exercise_done_history 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.done_id = #{doneId}
            AND t.member_id = #{memberId}
    </select>

    <select id="getDoneDetail" parameterType="long" resultType="com.subsidy.vo.exercise.GetDoneDetailVO">
        SELECT
            right_counts,
            total_counts,
            result,
            create_date
        FROM
            exercise_done_result t
            where t.delete_date is null
            and t.id = #{id}
    </select>

    <select id="getMaxScore" resultType="com.subsidy.vo.done.GetMaxScoreVO">
        SELECT
            t.paper_id,
            t2.paper_name,
            max( t.score ) AS score
        FROM
            exercise_done_result t
            left join paper_dict t2 on t.paper_id = t2.id
        WHERE
            t.delete_date is null
            and t.member_id = #{memberId}
            AND t.class_id = #{classId}
        GROUP BY
            t.class_id,
            t.paper_id,
            t.member_id
    </select>

    <select id="getMaxScorePaper" resultType="com.subsidy.model.ExerciseDoneResultDO">
        SELECT
            t2.right_counts,
            t2.total_counts,
            t2.result,
            t2.score
        FROM
            (
            SELECT
                max( t.score ) AS score
            FROM
                exercise_done_result t
            WHERE
                t.delete_date IS NULL
                AND t.paper_id = #{paperId}
                AND t.member_id = #{memberId}
                and t.class_id = #{classId}
            ) t1
            LEFT JOIN exercise_done_result t2 ON t1.score = t2.score
        WHERE
            t2.paper_id = #{paperId}
            AND t2.member_id = #{memberId}
    </select>

    <select id="testScoreInfo" resultType="com.subsidy.vo.done.TestScoreInfoVO">
        SELECT
            t.paper_id,
            max( t.score ) AS score,
            count( 1 ) AS cnt,
        IF
            ( max( t.score )>= 60, '合格', '不合格' ) AS result
        FROM
            exercise_done_result t
            LEFT JOIN paper_dict t2 ON t.paper_id = t2.id
        WHERE
            t.delete_date IS NULL
            AND t.member_id = #{memberId}
            AND t.paper_id = #{paperId}
            and t.class_id = #{classId}
        GROUP BY
            t.class_id,
            t.paper_id,
            t.member_id
    </select>

    <select id="getClassTestPassRate" parameterType="long" resultType="integer">
        SELECT
	        IFNULL( sum( t11.result ), 0 )
        FROM
            (
            SELECT
            IF
                ( sum( cnt ) = sum( result ), 1, 0 ) AS result
            FROM
                (
                SELECT
                    t.paper_id,
                    t.member_id,
                    max( t.score ) AS score,
                    1 AS cnt,
                IF
                    ( max( t.score )>= 60, '1', '0' ) AS result
                FROM
                    exercise_done_result t
                    LEFT JOIN paper_dict t2 ON t.paper_id = t2.id
                WHERE
                    t.delete_date IS NULL
                    AND t.class_id = #{classId}
                GROUP BY
                    t.class_id,
                    t.paper_id,
                    t.member_id
                ) t10
            GROUP BY
            t10.member_id
            ) t11
    </select>
</mapper>