<?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.exam.mapper.ExamNoteMapper">

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamNote" id="ExamNoteResult">
        <result property="fileId" column="file_id"/>
        <result property="categoryId" column="category_id"/>
        <result property="name" column="name"/>
        <result property="teacherIds" column="teacher_ids"/>
        <result property="price" column="price"/>
        <result property="coverUrl" column="cover_url"/>
        <result property="introduction" column="introduction"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="fileUrls" column="file_urls"/>
        <result property="sort" column="sort"/>
        <result property="categoryName" column="category_name"/>
    </resultMap>

    <select id="selectExamNoteList" parameterType="com.zhongzheng.modules.exam.bo.ExamNoteQueryBo" resultMap="ExamNoteResult">
        SELECT en.*,mc.category_name from exam_note en LEFT JOIN major_category mc on en.category_id = mc.category_id
        <if test="status != null and status.size()!=0 ">
            WHERE en.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="name != null and name != ''">
            AND en.name like concat('%', #{name}, '%')
        </if>
        <if test="categoryId != null and categoryId != ''">
            AND en.category_id = #{categoryId}
        </if>
    </select>

    <select id="queryRecommendList" parameterType="com.zhongzheng.modules.exam.bo.ExamNoteQueryBo" resultMap="ExamNoteResult">
        SELECT
            file_id,name,cover_url,price
        FROM
            exam_note
        WHERE
            STATUS = 1
        <if test="fileId != null and fileId != ''">
            AND file_id != #{fileId}
        </if>
        ORDER BY
            RAND()
            LIMIT 4
    </select>

</mapper>
