<?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.grade.mapper.UserPeriodMapper">

    <resultMap type="com.zhongzheng.modules.grade.domain.UserPeriod" id="UserPeriodResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="type" column="type"/>
        <result property="examId" column="exam_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
    </resultMap>

    <select id="checkGoodsChange" parameterType="com.zhongzheng.modules.grade.bo.UserPeriodQueryBo" resultType="Long">
        SELECT
        IFNULL(count(*),0)
        FROM
            user_period up
                LEFT JOIN class_grade_user cgu ON up.grade_id = cgu.grade_id
        WHERE
            cgu.period_status = 1
        <if test="goodsId != null and goodsId != ''">
            and up.goods_id = #{goodsId}
        </if>
        <if test="gradeId != null and gradeId != ''">
            and up.grade_id = #{gradeId}
        </if>

        <if test="userId != null and userId != ''">
            and up.user_id = #{userId}
        </if>
        <if test="sectionId != null ">
            and up.section_id = #{sectionId}
        </if>
        <if test="moduleId != null ">
            and up.module_id = #{moduleId}
        </if>

        <if test="chapterId != null">
            and up.chapter_id = #{chapterId}
        </if>
        <if test="courseId != null ">
            and up.course_id = #{courseId}
        </if>
        <if test="examId != null ">
            and up.exam_id = #{examId}
        </if>
    </select>
</mapper>
