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

    <resultMap type="com.zhongzheng.modules.exam.domain.ExamNumber" id="ExamNumberResult">
        <result property="examNumberId" column="exam_number_id"/>
        <result property="code" column="code"/>
        <result property="examNumber" column="exam_number"/>
        <result property="doNumber" column="do_number"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="goodsType" column="goods_type"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="projectId" column="project_id"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.exam.vo.ExamNumberVo" id="ExamNumberVoResult">
        <result property="examNumberId" column="exam_number_id"/>
        <result property="code" column="code"/>
        <result property="examNumber" column="exam_number"/>
        <result property="doNumber" column="do_number"/>
        <result property="status" column="status"/>
        <result property="goodsType" column="goods_type"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="projectId" column="project_id"/>
    </resultMap>

    <select id="ListExamNumber" parameterType="com.zhongzheng.modules.exam.bo.ExamNumberQueryBo" resultMap="ExamNumberVoResult">
        SELECT
            *,
            (SELECT cet.education_name FROM course_education_type cet where cet.id = en.education_type_id) as education_name,
            (SELECT cpt.project_name FROM course_project_type cpt where cpt.id = en.project_id) as project_name,
            (SELECT cb.business_name FROM course_business cb where cb.id = en.business_id) as business_name
        FROM
            exam_number en
        <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="examNumberId != null and examNumberId != ''">
            AND en.exam_number_id = #{examNumberId}
        </if>
        <if test="goodsId != null and goodsId != ''">
            AND  AND  (SELECT COUNT(eng.id) FROM exam_number_goods eng where eng.goods_id =#{goodsId}) > 0
        </if>
    </select>
</mapper>
