<?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.bank.mapper.QuestionBankMapper">

    <resultMap type="com.zhongzheng.modules.bank.domain.QuestionBank" id="QuestionBankResult">
        <result property="bankId" column="bank_id"/>
        <result property="categoryId" column="category_id"/>
        <result property="bankName" column="bank_name"/>
        <result property="price" column="price"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <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="typeId" column="type_id"/>
        <result property="teacherIds" column="teacher_ids"/>
        <result property="categoryName" column="category_name"/>
        <result property="questionNum" column="question_num"/>
        <result property="sort" column="sort"/>
    </resultMap>

    <select id="selectBankList" parameterType="com.zhongzheng.modules.bank.bo.QuestionBankQueryBo"  resultMap="QuestionBankResult">
        SELECT qb.*,mc.category_name FROM question_bank qb LEFT JOIN major_category mc on qb.category_id = mc.category_id
        WHERE 1=1
        <if test="status != null and status.size()!=0 ">
            AND qb.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="bankName != null and bankName != ''">
            AND qb.bank_name like concat('%', #{bankName}, '%')
        </if>
        <if test="categoryId != null and categoryId != ''">
            AND qb.category_id = #{categoryId}
        </if>
        <if test="typeId != null and typeId != ''">
            AND qb.type_id = #{typeId}
        </if>
        ORDER BY qb.sort DESC
    </select>

    <select id="queryRecommendList" parameterType="com.zhongzheng.modules.bank.bo.QuestionBankQueryBo"  resultMap="QuestionBankResult">
        SELECT
        bank_id,bank_name,cover_url,price
        FROM
        question_bank
        WHERE
        STATUS = 1
        <if test="bankId != null and bankId != ''">
            AND bank_id != #{bankId}
        </if>
        ORDER BY
        RAND()
        LIMIT 4
    </select>

</mapper>
