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

    <resultMap type="com.zhongzheng.modules.user.domain.UserNote" id="UserNoteResult">
        <result property="noteId" column="note_id"/>
        <result property="noteText" column="note_text"/>
        <result property="noteDate" column="note_date"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="goodsId" column="goods_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"/>
        <result property="gradeId" column="grade_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.user.vo.UserNoteVo" id="UserNoteVo">
        <result property="noteId" column="note_id"/>
        <result property="noteText" column="note_text"/>
        <result property="noteDate" column="note_date"/>
        <result property="courseId" column="course_id"/>
        <result property="sectionId" column="section_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="createTime" column="create_time"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="gradeId" column="grade_id"/>
        <result property="sectionName" column="section_name"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.user.vo.UserDateNoteVo" id="UserDateNoteVo">
        <result property="dateNote" column="date_note"/>
    </resultMap>

    <select id="listDate" parameterType="com.zhongzheng.modules.user.bo.UserNoteQueryBo" resultMap="UserDateNoteVo">
        SELECT
            DISTINCT un.note_date as date_note
        FROM
            user_note un
        WHERE 1=1
            AND un.status = 1
        <if test="goodsId != null and goodsId !='' ">
            AND un.goods_id=#{goodsId}
        </if>
        <if test="moduleId != null and moduleId !='' ">
            AND un.module_id=#{moduleId}
        </if>
        <if test="courseId != null and courseId !='' ">
            AND un.course_id =#{courseId}
        </if>
        <if test="sectionId != null and sectionId !='' ">
            AND un.section_id =#{sectionId}
        </if>
        <if test="chapterId != null and chapterId !='' ">
            AND un.chapter_id =#{chapterId}
        </if>
        <if test="gradeId != null and gradeId !='' ">
            AND un.grade_id =#{gradeId}
        </if>
          <if test="userId != null and userId !='' ">
            AND un.user_id =#{userId}
        </if>
        order by un.note_date desc
    </select>

    <select id="listDateSon" parameterType="com.zhongzheng.modules.user.bo.UserNoteQueryBo" resultMap="UserNoteVo">
        SELECT
            un.*,
               (SELECT cs.`name` FROM course_section cs where cs.section_id = un.section_id) as section_name
        FROM
        user_note un
        WHERE 1=1
        AND un.status = 1
        <if test="goodsId != null and goodsId !='' ">
            AND un.goods_id=#{goodsId}
        </if>
        <if test="moduleId != null and moduleId !='' ">
            AND un.module_id=#{moduleId}
        </if>
        <if test="courseId != null and courseId !='' ">
            AND un.course_id =#{courseId}
        </if>
        <if test="sectionId != null and sectionId !='' ">
            AND un.section_id =#{sectionId}
        </if>
        <if test="chapterId != null and chapterId !='' ">
            AND un.chapter_id =#{chapterId}
        </if>
        <if test="gradeId != null and gradeId !='' ">
            AND un.grade_id =#{gradeId}
        </if>
        <if test="userId != null and userId !='' ">
            AND un.user_id =#{userId}
        </if>
        order by un.note_date desc
    </select>
</mapper>
