<?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.testor.module.train.examinationManage.dao.TTrainExaminationManageDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.train.examinationManage.model.domain.TTrainExaminationManage">
        <id column="id" property="id"/>
        <id column="is_repair" property="isRepair"/>
        <id column="parent_id" property="parentId"/>
        <id column="exam_name" property="examName"/>
        <id column="exam_way" property="examWay"/>
        <id column="exam_type" property="examType"/>
        <id column="exam_start_time" property="examStartTime"/>
        <id column="exam_end_time" property="examEndTime"/>
        <id column="paper_id" property="paperId"/>
        <id column="exam_duration" property="examDuration"/>
        <id column="exam_site" property="examSite"/>
        <id column="should_test_number" property="shouldTestNumber"/>
        <id column="finish_number" property="finishNumber"/>
        <id column="percentage" property="percentage"/>
        <id column="org_name" property="orgName"/>
        <id column="org_id" property="orgId"/>
        <id column="tenant_id" property="tenantId"/>
        <id column="process_id" property="processId"/>
        <id column="process_status" property="processStatus"/>
    </resultMap>

    <select id="getExamAffiliation" parameterType="com.testor.module.train.examinationManage.model.dto.TTrainExaminationManageParam"
            resultType="com.testor.module.train.examinationManage.model.dto.TTrainExaminationManageParam"
            databaseId="mysql">
        select *
        from (select p.exam_name
        , p.id
        , p.exam_way
        , p.exam_type
        , p.should_test_number
        , p.finish_number
--         , my.percentage
        , p.exam_start_time
        , p.exam_end_time
        , p.org_name
        , p.org_id
        , p.qr_code
        , p.create_date
--         , my.person_affiliation
--         , my.company
--         , my.exam_duration
        from t_train_examination_manage p
        left join t_train_my_management my
        on p.id = my.task_id
        where p.status = 0
        <if test="param.examName!=null and param.examName!=''">
            AND p.exam_name LIKE CONCAT('%',#{param.examName},'%')
        </if>
        <if test="param.isRepair!=null and param.isRepair!=''">
            AND p.is_repair = #{param.isRepair}
        </if>
        <if test="param.personAffiliation!=null and param.personAffiliation!=''">
            AND my.person_affiliation =#{param.personAffiliation}
        </if>
        <if test="param.company!=null and param.company!=''">
            AND find_in_set(my.org_id,#{param.company})
        </if>
        <if test="param.StartTime!=null and param.StartTime!=''">
            AND p.exam_start_time =#{param.StartTime}
        </if>
        <if test="param.EndTime!=null and param.EndTime!=''">
            AND p.exam_end_time=#{param.EndTime}
        </if>
            order by p.create_date desc
        ) mm
        where mm.org_id in (select org.org_id
        from t_sys_org org
        where find_in_set(org.org_id, #{parentIds})
        or org.parent_ids like concat('%', #{orgId}, '%')
        or org.org_id = #{orgId}) group by id  order by mm.create_date
    </select>
    <select id="getExamAffiliation" parameterType="com.testor.module.train.examinationManage.model.dto.TTrainExaminationManageParam"
            resultType="com.testor.module.train.examinationManage.model.dto.TTrainExaminationManageParam"
            databaseId="kingbase">
        select p1.exam_name
        , p1.id
        , p1.exam_way
        , p1.exam_type
        , p1.should_test_number
        , p1.finish_number
        , p1.exam_start_time
        , p1.exam_end_time
        , p1.org_name
        , p1.org_id
        , p1.qr_code
        , p1.create_date
        from t_train_examination_manage p1
        where id in (
        select id
        from (select p.exam_name
        , p.id
        , p.exam_way
        , p.exam_type
        , p.should_test_number
        , p.finish_number
        , p.exam_start_time
        , p.exam_end_time
        , p.org_name
        , p.org_id
        , p.qr_code
        , p.create_date
        from t_train_examination_manage p
        left join t_train_my_management my
        on p.id = my.task_id
        where p.status = 0
        <if test="param.examName!=null and param.examName!=''">
            AND p.exam_name LIKE CONCAT('%',#{param.examName},'%')
        </if>
        <if test="param.isRepair!=null and param.isRepair!=''">
            AND p.is_repair = #{param.isRepair}
        </if>
        <if test="param.personAffiliation!=null and param.personAffiliation!=''">
            AND my.person_affiliation =#{param.personAffiliation}
        </if>
        <if test="param.company!=null and param.company!=''">
            AND find_in_set(my.org_id,#{param.company})
        </if>
        <if test="param.StartTime!=null and param.StartTime!=''">
            AND p.exam_start_time =#{param.StartTime}
        </if>
        <if test="param.EndTime!=null and param.EndTime!=''">
            AND p.exam_end_time=#{param.EndTime}
        </if>
        order by p.create_date desc
        ) mm
        where mm.org_id in (select org.org_id
        from t_sys_org org
        where find_in_set(org.org_id, #{parentIds})
        or org.parent_ids like concat('%', #{orgId}, '%')
        or org.org_id = #{orgId}) group by id)  order by p1.create_date
    </select>

    <select id="getExamProjectPerson" resultType="com.testor.module.train.examinationManage.model.dto.TTrainExaminationManageParam">
        select
            p.exam_name
             , p.id
             , p.exam_way
             , p.exam_type
             , p.should_test_number
             , p.finish_number
            , my.percentage
             , p.exam_start_time
             , p.exam_end_time
             , p.org_name
             , p.org_id
             , p.qr_code
             , p.create_date
            , my.person_affiliation
            , my.company
            , my.exam_duration

        from (select
                exam_name
                   , id
                   , exam_way
                   , exam_type
                   , should_test_number
                   , finish_number
                    ,exam_start_time
                    , exam_end_time
                   , org_name
                   , org_id
                   , qr_code
                   , create_date
        from  t_train_examination_manage where id = #{id} ) p
                 join t_train_my_management my on p.id = my.task_id
    </select>
</mapper>