<?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.inform.mapper.InformExamMapper">

    <resultMap type="com.zhongzheng.modules.inform.domain.InformExam" id="InformExamResult">
        <result property="id" column="id"/>
        <result property="informId" column="inform_id"/>
        <result property="courseId" column="course_id"/>
        <result property="examId" column="exam_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"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.inform.vo.InformExamVo" id="InformExamVo">
        <result property="id" column="id"/>
        <result property="informId" column="inform_id"/>
        <result property="courseId" column="course_id"/>
        <result property="examId" column="exam_id"/>
        <result property="moduleId" column="module_id"/>
        <result property="chapterId" column="chapter_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="subjectName" column="subject_name"/>
        <result property="chapterName" column="chapter_name"/>
        <result property="moduleName" column="module_name"/>
        <result property="examName" column="exam_name"/>
    </resultMap>

    <select id="queryExam" parameterType="long" resultMap="InformExamVo">
        SELECT
        ie.*,
        (SELECT g.goods_name FROM goods g where g.goods_id = ie.goods_id) as goods_name,
        (SELECT cs.subject_name FROM course c LEFT JOIN course_subject cs on c.subject_id=cs.id where c.course_id = ie.course_id) as subject_name,
        (SELECT qc.`name` FROM question_chapter qc where qc.chapter_exam_id = ie.chapter_id) as chapter_name,
        (SELECT qm.module_name FROM question_module qm where qm.module_exam_id = ie.module_id) as module_name,
        (SELECT e.exam_name FROM exam e where e.exam_id = ie.exam_id) as exam_name
        FROM
        inform_exam ie
        WHERE
        1=1
        <if test="informId != null and informId != ''">
           and ie.inform_id =  #{informId}
        </if>
    </select>

</mapper>
