<?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.miaxis.score.mapper.ScoreInfoMapper">

    <resultMap type="ScoreInfo" id="ScoreInfoResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="type"    column="type"    />
        <result property="kskm"    column="kskm"    />
        <result property="score"    column="score"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectScoreInfoVo">
        select * from score_info
    </sql>

    <select id="selectScoreInfoList" parameterType="ScoreInfo" resultMap="ScoreInfoResult">
        <include refid="selectScoreInfoVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="kskm != null  and kskm != ''"> and kskm = #{kskm}</if>
            <if test="score != null "> and score = #{score}</if>
        </where>
    </select>


    <select id="getLast10Score" parameterType="ScoreInfo" resultType="int">
        select score from
        (select score from score_info s
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
        order by id desc limit 0,10) x order by score
    </select>

    <select id="getAvgScore" parameterType="ScoreInfo" resultType="int">
        select IFNULL(ROUND(avg(score),0),0) from score_info s
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>



    <select id="getMaxScore" parameterType="ScoreInfo" resultType="int">
        select IFNULL(max(score),0) from score_info s
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
    </select>


</mapper>
