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

    <resultMap type="com.zhongzheng.modules.bank.domain.QuestionBankSection" id="QuestionBankSectionResult">
        <result property="bankSectionId" column="bank_section_id"/>
        <result property="bankChapterId" column="bank_chapter_id"/>
        <result property="name" column="name"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="status" column="status"/>
        <result property="sort" column="sort"/>
        <result property="questionNum" column="question_num"/>
    </resultMap>

    <select id="selectBankSectionList" parameterType="com.zhongzheng.modules.bank.bo.QuestionBankSectionQueryBo"  resultMap="QuestionBankSectionResult">
        SELECT
            qbs.*,
            count( q.question_id ) AS question_num
        FROM
            question_bank_section qbs
                LEFT JOIN question q ON qbs.bank_section_id = q.bank_section_id
        WHERE 1=1
        <if test="status != null and status.size()!=0 ">
            AND qbs.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="name != null and name != ''">
            AND qbs.name like concat('%', #{name}, '%')
        </if>
        <if test="bankChapterId != null and bankChapterId != ''">
            AND qbs.bank_chapter_id = #{bankChapterId}
        </if>
        GROUP BY
            qbs.bank_section_id
    </select>


</mapper>
