<?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.template.mapper.SmartEvaluateTeacherMapper">

    <select id="getAvgLowingScore" resultType="Double">
        select AVG(lowing_score) as lowing_score from `smart_evaluate_teacher`
            where deleted=0 and term=#{term}
    </select>

    <resultMap type="com.template.model.vo.EvaluateTeacherVo" id="smartTopTeacherMap">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
    </resultMap>

    <select id="smartTopTeacherList" resultType="com.template.model.vo.EvaluateTeacherVo" resultMap="smartTopTeacherMap">
        select id,name from smart_evaluate_teacher
        where term in
        (select t.term from(select term from smart_evaluate_teacher
        where deleted = 0 order by term desc
        limit 1) as t) and deleted = 0
        order by total_score desc
    </select>

    <select id="getRankingList" resultType="com.template.model.vo.RankingVo">
        SELECT
            se.name,
            se.total_score as totalScore,
            dense_rank ( ) over ( ORDER BY se.total_score DESC ) AS 'rank' ,
            su.head_image as headImage
        FROM
            `smart_evaluate_teacher`  se
                LEFT JOIN smart_user su on  se.card_no=su.card_no
        WHERE
            se.term = #{term}	AND se.deleted=0
    </select>

    <select id="getRanking" resultType="com.template.model.vo.RankingVo">
        SELECT
            b.`name` as name,
            b.total_score as totalScore,
            b.rank,
            b.head_image as headImage
        FROM
            ( SELECT se.*, su.head_image,dense_rank ( ) over ( ORDER BY total_score DESC ) AS 'rank' FROM `smart_evaluate_teacher` se LEFT JOIN smart_user su on  se.card_no=su.card_no   WHERE term = #{term} and se.deleted = 0 ) b
        WHERE
            b.card_no= #{cardNo}
    </select>


</mapper>
