<?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.emergency.dao.TEmergencyRehearsalDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.emergency.model.vo.TEmergencyRehearsalVO">
        <id column="id" property="id"/>
        <id column="org_id" property="orgId"/>
        <id column="rehearsal_plan_name" property="rehearsalPlanName"/>
        <id column="simulation_event_name" property="simulationEventName"/>
        <id column="simulation_event_type" property="simulationEventType"/>
        <id column="simulation_event_object" property="simulationEventObject"/>
        <id column="simulation_event_object_id" property="simulationEventObjectId"/>
        <id column="specific_object_id" property="specificObjectId"/>
        <id column="specific_object" property="specificObject"/>
        <id column="simulation_event_place" property="simulationEventPlace"/>
        <id column="simulation_event_describe" property="simulationEventDescribe"/>
        <id column="rehearsal_type" property="rehearsalType"/>
        <id column="rehearsal_type_key" property="rehearsalTypeKey"/>
        <id column="rehearsal_way" property="rehearsalWay"/>
        <id column="rehearsal_way_key" property="rehearsalWayKey"/>
        <id column="total_command" property="totalCommand"/>
        <id column="total_command_id" property="totalCommandId"/>
        <id column="participant" property="participant"/>
        <id column="participant_ids" property="participantIds"/>
        <id column="process_id" property="processId"/>
        <id column="start_time" property="startTime"/>
        <id column="end_time" property="endTime"/>
        <id column="rehearsal_status" property="rehearsalStatus"/>
        <id column="org_name" property="orgName"/>
    </resultMap>
    <sql id="commName">
        id,
        org_id,
        rehearsal_plan_name,
        simulation_event_name,
        simulation_event_type,
        simulation_event_object,
        simulation_event_object_id,
        specific_object_id,
        specific_object,
        simulation_event_place,
        simulation_event_describe,
        rehearsal_type,
        rehearsal_type_key,
        rehearsal_way,
        rehearsal_way_key,
        total_command,
        total_command_id,
        participant,
        participant_ids,
        process_id,
        start_time,
        end_time,
        rehearsal_status,
        org_name
    </sql>
    <select id="listPage" resultType="com.testor.module.emergency.model.vo.TEmergencyRehearsalVO">
        select
            a.id,
            a.org_id,
            a.rehearsal_plan_name,
            a.simulation_event_name,
            a.simulation_event_type,
            a.simulation_event_object,
            a.simulation_event_object_id,
            a.specific_object_id,
            a.specific_object,
            a.simulation_event_place,
            a.simulation_event_describe,
            a.rehearsal_type,
            a.rehearsal_type_key,
            a.rehearsal_way,
            a.rehearsal_way_key,
            a.total_command,
            a.total_command_id,
            a.participant,
            a.participant_ids,
            a.process_id,
            a.start_time,
            a.end_time,
            a.rehearsal_status,
            b.org_name
        from t_emergency_rehearsal a left join t_sys_org b on a.org_id = b.org_id
        <where>
                a.status = '0'
            <if test="param.orgIdList != null">
                and a.org_id in
                <foreach collection="param.orgIdList" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>

            <if test="param.rehearsalPlanName != null and param.rehearsalPlanName !='' ">
                and a.rehearsal_plan_name like concat('%',#{param.rehearsalPlanName},'%')

            </if>
            <if test="param.rehearsalTypeKey != null and param.rehearsalTypeKey !='' ">
                and a.rehearsal_type_key = #{param.rehearsalTypeKey}
            </if>

            <if test="param.rehearsalWayKey != null and param.rehearsalWayKey !='' ">
                and a.rehearsal_way_key = #{param.rehearsalWayKey}
            </if>

            <if test="param.rehearsalStatus != null and param.rehearsalStatus !='' ">
                and a.rehearsal_status = #{param.rehearsalStatus}
            </if>

            <if test="param.startTime != null and param.endTime !=null ">
                and a.start_time between #{param.startTime} and #{param.endTime}
            </if>
        </where>
        order by a.create_date desc
    </select>
</mapper>