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

    <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>

    <resultMap type="com.zhongzheng.modules.activity.vo.ActivityGradePrivilegeVo" id="ActivityGradePrivilegeVoResult">
        <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="endTimeSum" column="end_time_sum"/>
        <result property="quantity" column="quantity"/>
        <result property="status" column="status"/>
        <collection property="courseVo" ofType="Long">
            <constructor>
                <arg column="eid" />
            </constructor>
        </collection>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.course.domain.Course" id="CourseResult">
        <result property="courseId" column="eid"/>
    </resultMap>



    <select id="selectGradePriList" parameterType="Long" resultMap="ActivityGradePrivilegeVoResult">
        SELECT
            c.*,
            e.course_id as eid
        FROM
            activity_grade_privilege c
                LEFT JOIN activity_grade_privilege_coures f ON c.id = f.privilege_id
                LEFT JOIN course e ON f.course_id = e.course_id
        WHERE c.grade_id = #{id,jdbcType=INTEGER} and c.status != 0
    </select>


    <update id="deleteByGrade" parameterType="Long" >
        UPDATE activity_grade_privilege SET `status` =0 where grade_id=#{id}
    </update>
</mapper>