<?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.zhongzheng.modules.activity.mapper.ActivityTaskTimeMapper">

    <resultMap type="com.zhongzheng.modules.activity.domain.ActivityTaskTime" id="ActivityTaskTimeResult">
        <result property="taskId" column="task_id"/>
        <result property="startRange" column="start_range"/>
        <result property="endRange" column="end_range"/>
        <result property="integral" column="integral"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.activity.vo.ActivityTaskTimeVo" id="ActivityTaskTimeVoResult">
        <result property="taskId" column="task_id"/>
        <result property="startRange" column="start_range"/>
        <result property="endRange" column="end_range"/>
        <result property="integral" column="integral"/>
    </resultMap>

    <insert id="inserTaskTime" parameterType="map">
        insert into activity_task_time (
            task_id,
            start_range,
            end_range,
            integral
        )values(
                   #{taskId},
                   #{startRange},
                   #{endRange},
                   #{integral}
               )
    </insert>

    <select id="queryPractice" parameterType="com.zhongzheng.modules.activity.bo.ActivityTaskUserAddBo" resultMap="ActivityTaskTimeVoResult">
        SELECT
            *
        FROM
            activity_task_time
        WHERE
            1 = 1
        <if test="taskId != null" >
            AND task_id = #{taskId}
        </if>
        <if test="score != null" >
            AND #{score} BETWEEN start_range AND end_range
        </if>
        LIMIT 1
    </select>
</mapper>