<?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.user.mapper.UserPlanMapper">

    <resultMap type="com.zhongzheng.modules.user.domain.UserPlan" id="UserPlanResult">
        <result property="planId" column="plan_id"/>
        <result property="schedule" column="schedule"/>
        <result property="userId" column="user_id"/>
        <result property="examDate" column="exam_date"/>
        <result property="reminderTime" column="reminder_time"/>
        <result property="studyCount" column="study_count"/>
        <result property="studyDay" column="study_day"/>
        <result property="endTime" column="end_time"/>
        <result property="startTime" column="start_time"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="pitchNum" column="pitch_num"/>
        <result property="studyNum" column="study_num"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.goods.vo.GoodsVo" id="GoodsResultVo">
        <result property="goodsId" column="goods_id"/>
        <result property="year" column="year"/>
        <result property="supplyId" column="supply_id"/>
        <result property="goodsType" column="goods_type"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="schoolId" column="school_id"/>
        <result property="majorId" column="major_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="standPrice" column="stand_price"/>
        <result property="lowestPrice" column="lowest_price"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="validityStartTime" column="validity_start_time"/>
        <result property="validityEndTime" column="validity_end_time"/>
        <result property="studyStartTime" column="study_start_time"/>
        <result property="studyEndTime" column="study_end_time"/>
        <result property="certificateIds" column="certificate_ids"/>
        <result property="introduce" column="introduce"/>
        <result property="suitableObject" column="suitable_object"/>
        <result property="buyNote" column="buy_note"/>
        <result property="pcDetailHtml" column="pc_detail_html"/>
        <result property="mobileDetailHtml" column="mobile_detail_html"/>
        <result property="goodsStatus" column="goods_status"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="classHours" column="class_hours"/>
        <result property="standPriceJson" column="stand_price_json"/>
        <result property="code" column="code"/>
        <result property="projectId" column="project_id"/>
        <result property="goodsAuditionConfig" column="goods_audition_config"/>
        <result property="goodsPhotographConfig" column="goods_photograph_config"/>
        <result property="goodsAuditionExamConfig" column="goods_audition_exam_config"/>
        <result property="goodsPlayConfig" column="goods_play_config"/>
        <result property="goodsExamConfig" column="goods_exam_config"/>

        <result property="supplyName" column="supply_name"/>
        <result property="educationName" column="education_name"/>
        <result property="projectName" column="project_name"/>
        <result property="businessName" column="business_name"/>
        <result property="schoolName" column="school_name"/>
        <result property="categoryName" column="category_name"/>
        <result property="handoutsId" column="handouts_id"/>
        <result property="templateType" column="template_type"/>
        <result property="period" column="period"/>
        <result property="makeStartTime" column="make_start_time"/>
        <result property="makeEndTime" column="make_end_time"/>
        <result property="studyCount" column="study_count"/>
        <result property="makeGoodsName" column="make_goods_name"/>
        <result property="makeGoodsCode" column="make_goods_code"/>
    </resultMap>



    <select id="listGoods" parameterType="com.zhongzheng.modules.user.bo.UserPlanQueryBo"  resultMap="GoodsResultVo">
        SELECT
            g.*
        FROM
            goods g
                LEFT JOIN order_goods og ON g.goods_id = og.goods_id
                LEFT JOIN `order` o ON o.order_sn = og.order_sn
        WHERE
            o.user_id = #{userId}
          AND og.refund_status in (0,3)
          and og.`status`= 1
          and og.pay_status in(2,3)
          and g.goods_type =1
    </select>
    <select id="selectCountGoods" parameterType="com.zhongzheng.modules.user.bo.UserPlanEditBo"  resultType="INTEGER">
        SELECT
        COUNT(up.plan_id)
        FROM
        user_plan up
        LEFT JOIN user_plan_goods upg ON up.plan_id = upg.plan_id
        <if test="goodsId != null and goodsId !=''">
            and upg.source_id in
            <foreach collection="goodsId" open="(" separator="," close=")" item="goodsId">
                #{goodsId}
            </foreach>
        </if>
        <if test="userId != null and userId !=''">
            and up.user_id = #{userId}
        </if>
    </select>

    <select id="selectGoods" parameterType="long"  resultType="Long">
        SELECT
            (
                SELECT
                        COUNT( id )+(
                        SELECT
                            COUNT( n.id )
                        FROM
                            course_chapter_section n
                                LEFT JOIN course_module_chapter p ON n.chapter_id = p.chapter_id
                                LEFT JOIN course_menu m ON m.menu_id = p.module_id
                        WHERE
                            m.course_id = r.course_id
                          AND m.type IN ( 1 ))+(
                            SELECT
                                COUNT( n.id )
                            FROM
                                course_chapter_section n
                                    LEFT JOIN course_menu m ON m.menu_id = n.chapter_id
                            WHERE
                                m.course_id = r.course_id
                              AND m.type IN ( 2 ))
                FROM
                    course_menu m
                WHERE
                    m.course_id = r.course_id
                  AND m.type IN ( 3 )) AS section_num
        FROM
            course r
                LEFT JOIN goods_course c ON c.course_id = r.course_id
        WHERE
            1 = 1
        <if test="goodsId != null">
            and c.goods_id =#{goodsId}
        </if>
    </select>
</mapper>
