<?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.ActivityGradeMapper">

    <resultMap type="com.zhongzheng.modules.activity.domain.ActivityGrade" id="ActivityGradeResult">
        <result property="id" column="id"/>
        <result property="grade" column="grade"/>
        <result property="gradeName" column="grade_name"/>
        <result property="needIntegralStart" column="need_integral_start"/>
        <result property="needIntegralEnd" column="need_integral_end"/>
        <result property="remarks" column="remarks"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.activity.vo.ActivityGradeVo" id="ActivityGradeVoResult">
        <result property="id" column="id"/>
        <result property="grade" column="grade"/>
        <result property="gradeName" column="grade_name"/>
        <result property="needIntegralStart" column="need_integral_start"/>
        <result property="needIntegralEnd" column="need_integral_end"/>
        <result property="remarks" column="remarks"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <collection property="activityGradePrivilegesVo" javaType="java.util.List" resultMap="ActivityGradePrivilegeResult"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.activity.domain.ActivityGradePrivilege" id="ActivityGradePrivilegeResult">
        <result property="id" column="id"/>
        <result property="gradeId" column="grade_id"/>
        <result property="priType" column="pri_type"/>
        <result property="couponPrice" column="coupon_price"/>
        <result property="discount" column="discount"/>
        <result property="endTimeSum" column="end_time_sum"/>
        <result property="quantity" column="quantity"/>
    </resultMap>

    <select id="selectGradeList" parameterType="com.zhongzheng.modules.activity.vo.ActivityGradeVo" resultMap="ActivityGradeVoResult">
        SELECT
            c.*,
            f.*
        FROM
            activity_grade c
                LEFT JOIN activity_grade_privilege f ON c.id = f.grade_id
        WHERE 1=1
    </select>

    <select id="queryByInteger" parameterType="Long" resultMap="ActivityGradeVoResult">
        SELECT
            *
        FROM
            activity_grade
        WHERE 1=1
        <if test="bo != null" >
            AND #{bo} BETWEEN need_integral_start AND need_integral_end
        </if>
        limit 1
    </select>

</mapper>