<?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.yida.data.school.exam.mapper.CoreExaminationPublishGradeConvertTypeMapper">
    <resultMap id="BaseResultMap"
               type="com.yida.data.common.core.entity.exam.CoreExaminationPublishGradeConvertType">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="core_examination_id" property="coreExaminationId" jdbcType="INTEGER"/>
        <result column="core_examination_publish_id" property="coreExaminationPublishId" jdbcType="INTEGER"/>
        <result column="level" property="level" jdbcType="VARCHAR"/>
        <result column="max_score" property="maxScore" jdbcType="INTEGER"/>
        <result column="min_score" property="minScore" jdbcType="INTEGER"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
    </resultMap>

    <!--根据分数查询对应的成绩等级-->
    <select id="findGradeRank"
            parameterType="com.yida.data.common.core.entity.exam.CoreExaminationPublishRecord"
            resultType="java.lang.String">
        SELECT
        ct.`level` AS grade_level
        FROM
        core_examination_publish cep
        LEFT JOIN core_examination_publish_grade_convert_type ct ON cep.id = ct.core_examination_publish_id
        WHERE
        cep.del_flag = '0'
        AND ct.del_flag = '0'
        AND cep.core_examination_id = #{examId}
        AND ROUND(#{total} * ct.min_score / 100, 2) &lt;= #{score}
        AND #{score} &lt;= ROUND(#{total} * ct.max_score / 100, 2)
    </select>

    <select id="listType"
            resultType="com.yida.data.common.core.entity.exam.CoreExaminationPublishGradeConvertType">
        select ct.*
        from core_examination_publish cep
        inner join core_examination_publish_grade_convert_type ct
        on cep.id = ct.core_examination_publish_id
        where
        cep.del_flag = '0'
        AND ct.del_flag = '0'
        AND cep.core_examination_id = #{examId}
        order by ct.id desc
    </select>
</mapper>