<?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.zc.business.mapper.DcEventMapper">
    <resultMap type="com.zc.business.domain.DcEvent" id="DcEventResult">
        <result property="id"    column="id"    />
        <result property="groupId"    column="group_id"    />
        <result property="stakeMarkId"    column="stake_mark_id"    />
        <result property="direction"    column="direction"    />
        <result property="roadId"    column="road_id"    />
        <result property="handlingPerson"    column="handling_person"    />
        <result property="endStakeMarkId"    column="end_stake_mark_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="eventLevel"    column="event_level"    />
        <result property="eventCategory"    column="event_category"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventName"    column="event_name"    />
        <result property="eventSubclass"    column="event_subclass"    />
        <result property="impactLevel"    column="impact_level"    />
        <result property="eventCause"    column="event_cause"    />
        <result property="description"    column="description"    />
        <result property="handlingResult"    column="handling_result"    />
        <result property="otherConfig"    column="other_config"    />
        <result property="eventSource"    column="event_source"    />
        <result property="eventNature"    column="event_nature"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>
    <resultMap type="com.zc.business.domain.DcEvent" id="DcEventResultListAll">
        <result property="id"    column="id"    />
        <result property="groupId"    column="group_id"    />
        <result property="stakeMarkId"    column="stake_mark_id"    />
        <result property="direction"    column="direction"    />
        <result property="roadId"    column="road_id"    />
        <result property="handlingPerson"    column="handling_person"    />
        <result property="endStakeMarkId"    column="end_stake_mark_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="eventLevel"    column="event_level"    />
        <result property="eventCategory"    column="event_category"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventName"    column="event_name"    />
        <result property="eventSubclass"    column="event_subclass"    />
        <result property="impactLevel"    column="impact_level"    />
        <result property="eventCause"    column="event_cause"    />
        <result property="description"    column="description"    />
        <result property="handlingResult"    column="handling_result"    />
        <result property="otherConfig"    column="other_config"    />
        <result property="eventSource"    column="event_source"    />
        <result property="eventNature"    column="event_nature"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    <!--    <result property="dcProcessConfig.processNode"   column="process_node"    />
        <result property="dcProcessConfig.commonPhrases"   column="common_phrases"    />
        <result property="dcProcessConfig.nodeNode"   column="node_node"    />-->
        <result property="dcEventMap.processNode"   column="process_node"    />
        <result property="dcEventMap.commonPhrases"   column="common_phrases"    />
        <result property="dcEventMap.nodeNode"   column="node_node"    />
        <result property="dcEventMap.dcDispatchId"   column="dc_dispatch_id"    />
        <result property="dcEventMap.organizationId"   column="organization_id"    />
        <result property="dcEventMap.dispatchName"   column="dispatch_name"    />
        <result property="dcEventMap.dispatchStatus"   column="dispatch_status"    />
        <result property="dcEventMap.dcDispatchRemark"   column="dc_dispatch_remark"    />
        <result property="dcEventMap.dcDispatchEndTime"   column="dc_dispatch_end_time"    />
        <result property="dcEventMap.dcDispatchStartTime"   column="dc_dispatch_start_time"    />
        <result property="dcEventMap.eventId"   column="event_id"    />
        <result property="dcEventMap.dcOrganizationId"   column="dc_organization_id"    />
        <result property="dcEventMap.parentId"   column="parent_id"    />
        <result property="dcEventMap.organizationType"   column="organization_type"    />
        <result property="dcEventMap.organizationName"   column="organization_name"    />
        <result property="dcEventMap.organizationAddress"   column="organization_address"    />
        <result property="dcEventMap.dcOrganizationStakeMarkId"   column="dc_organization_stake_mark_id"    />
        <result property="dcEventMap.dcOrganizationDescription"   column="dc_organization_description"    />
        <result property="dcEventMap.vehiclePlate"   column="vehicle_plate"    />
        <result property="dcEventMap.vehicleType"   column="vehicle_type"    />
        <result property="dcEventMap.vehicleStatus"   column="vehicle_status"    />
        <result property="dcEventMap.dcVehiclesRemark"   column="dc_vehicles_remark"    />
        <result property="dcEventMap.postId"   column="post_id"    />
        <result property="dcEventMap.name"   column="name"    />
        <result property="dcEventMap.contactNumber"   column="contact_number"    />

    </resultMap>
    <!-- 定义 eventOtherConfig 字段的结果集映射 -->
<!--    <resultMap id="eventOtherResultMap" type="java.util.HashMap">
    </resultMap>-->
    <sql id="selectDcEventVo">
        select id, group_id, stake_mark_id, direction, road_id, handling_person, end_stake_mark_id, start_time, end_time, event_level, event_category, event_type, event_subclass, impact_level, event_cause, description, handling_result, other_config, event_source, event_nature, remark, create_time, update_time from dc_event
    </sql>
    <sql id="selectDcEventVoList">
        select id, group_id, stake_mark_id, direction, road_id, handling_person, end_stake_mark_id, start_time, end_time, event_level, event_category,dc_event.event_type AS event_type, event_subclass, impact_level, event_cause, description, handling_result, other_config, event_source, event_nature, remark, create_time, update_time,dc_event_type.event_name AS event_name from dc_event
    </sql>
<!--
    根据id查询详情
-->
    <sql id="selectDcEventVoListAll">SELECT
    dc_event.id AS id,
    dc_event.group_id AS group_id,
    dc_event.stake_mark_id,
    dc_event.direction,
    dc_event.road_id,
    dc_event.handling_person,
    dc_event.end_stake_mark_id,
    dc_event.start_time,
    dc_event.end_time,
    dc_event.event_level,
    dc_event.event_category,
    dc_event.event_type AS event_type,
    dc_event.event_subclass,
    dc_event.impact_level,
    dc_event.event_cause,
    dc_event.description,
    dc_event.handling_result,
    dc_event.other_config,
    dc_event.event_source,
    dc_event.event_nature,
    dc_event.remark ,
    dc_event.create_time,
    dc_event.update_time,
    dc_event_type.event_name AS event_name,
    dc_process_config.node_node AS node_node,
    dc_process_config.process_node AS process_node,
    dc_process_config.common_phrases AS common_phrases,

    dc_dispatch.id AS dc_dispatch_id,
    dc_dispatch.organization_id,
    dc_dispatch.dispatch_name,
    dc_dispatch.dispatch_status,
    dc_dispatch.remark as dc_dispatch_remark,
    dc_dispatch.end_time as dc_dispatch_end_time,
    dc_dispatch.start_time as dc_dispatch_start_time,
    dc_dispatch.event_id,

    dc_organization.id as dc_organization_id,
    dc_organization.parent_id,
    dc_organization.organization_type,
    dc_organization.organization_name,
    dc_organization.organization_address,
    dc_organization.stake_mark_id as dc_organization_stake_mark_id,
    dc_organization.rescue_unit,
    dc_organization.description as dc_organization_description,

    dc_vehicles.vehicle_plate,
    dc_vehicles.vehicle_type,
    dc_vehicles.vehicle_status,
    dc_vehicles.remark as dc_vehicles_remark,

    dc_employees.post_id,
    dc_employees.name,
    dc_employees.contact_number
    FROM dc_event</sql>
    <select id="selectDcEventList" parameterType="DcEvent" resultMap="DcEventResult">
        <include refid="selectDcEventVoList"/>

        JOIN dc_event_type ON dc_event.event_type = dc_event_type.event_type
        <where>
            <if test="groupId != null "> and group_id = #{groupId}</if>
            <if test="stakeMarkId != null  and stakeMarkId != ''"> and stake_mark_id BETWEEN #{stakeMarkId} and  #{endStakeMarkId}</if>
            <if test="direction != null  and direction != ''"> and direction = #{direction}</if>
            <if test="roadId != null "> and road_id = #{roadId}</if>
            <if test="handlingPerson != null "> and handling_person = #{handlingPerson}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="eventLevel != null "> and event_level = #{eventLevel}</if>
            <if test="eventCategory != null "> and event_category = #{eventCategory}</if>
            <if test="eventType != null "> and event_type = #{eventType}</if>
            <if test="eventSubclass != null "> and event_subclass = #{eventSubclass}</if>
            <if test="impactLevel != null "> and impact_level = #{impactLevel}</if>
            <if test="eventCause != null  and eventCause != ''"> and event_cause = #{eventCause}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="handlingResult != null "> and handling_result = #{handlingResult}</if>
            <if test="otherConfig != null  and otherConfig != ''"> and other_config = #{otherConfig}</if>
            <if test="eventSource != null "> and event_source = #{eventSource}</if>
            <if test="eventNature != null "> and event_nature = #{eventNature}</if>
        </where>
    </select>


    <select id="selectDcEventById" parameterType="String" resultMap="DcEventResultListAll">
        <include refid="selectDcEventVoListAll"/>
        LEFT JOIN dc_event_type ON dc_event.event_type = dc_event_type.event_type
        LEFT JOIN dc_process_config ON dc_event_type.event_type = dc_process_config.event_type
        -- 	关联调度信息记录表
        LEFT JOIN dc_dispatch ON dc_event.id = dc_dispatch.event_id

        -- 关联资源调度调度记录id关联 调度信息记录表的主键
        LEFT JOIN dc_dispatch_resource ON dc_dispatch.id = dc_dispatch_resource.dispatch_id
        -- 关联车辆
        LEFT JOIN dc_vehicles ON dc_dispatch_resource.resource_id = dc_vehicles.id
        -- 关联机构表
        LEFT JOIN dc_organization ON dc_dispatch.organization_id = dc_organization.id
        -- 关联人员信息表
        LEFT JOIN dc_employees ON dc_dispatch_resource.resource_id = dc_employees.id
        where dc_event.id = #{id}
    </select>

    <insert id="insertDcEvent" parameterType="DcEvent">
        insert into dc_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="stakeMarkId != null and stakeMarkId != ''">stake_mark_id,</if>
            <if test="direction != null and direction != ''">direction,</if>
            <if test="roadId != null">road_id,</if>
            <if test="handlingPerson != null">handling_person,</if>
            <if test="endStakeMarkId != null">end_stake_mark_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="eventLevel != null">event_level,</if>
            <if test="eventCategory != null">event_category,</if>
            <if test="eventType != null">event_type,</if>
            <if test="eventSubclass != null">event_subclass,</if>
            <if test="impactLevel != null">impact_level,</if>
            <if test="eventCause != null">event_cause,</if>
            <if test="description != null">description,</if>
            <if test="handlingResult != null">handling_result,</if>
            <if test="otherConfig != null">other_config,</if>
            <if test="eventSource != null">event_source,</if>
            <if test="eventNature != null">event_nature,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="stakeMarkId != null and stakeMarkId != ''">#{stakeMarkId},</if>
            <if test="direction != null and direction != ''">#{direction},</if>
            <if test="roadId != null">#{roadId},</if>
            <if test="handlingPerson != null">#{handlingPerson},</if>
            <if test="endStakeMarkId != null">#{endStakeMarkId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="eventLevel != null">#{eventLevel},</if>
            <if test="eventCategory != null">#{eventCategory},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="eventSubclass != null">#{eventSubclass},</if>
            <if test="impactLevel != null">#{impactLevel},</if>
            <if test="eventCause != null">#{eventCause},</if>
            <if test="description != null">#{description},</if>
            <if test="handlingResult != null">#{handlingResult},</if>
            <if test="otherConfig != null">#{otherConfig},</if>
            <if test="eventSource != null">#{eventSource},</if>
            <if test="eventNature != null">#{eventNature},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateDcEvent" parameterType="DcEvent">
        update dc_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="stakeMarkId != null and stakeMarkId != ''">stake_mark_id = #{stakeMarkId},</if>
            <if test="direction != null and direction != ''">direction = #{direction},</if>
            <if test="roadId != null">road_id = #{roadId},</if>
            <if test="handlingPerson != null">handling_person = #{handlingPerson},</if>
            <if test="endStakeMarkId != null">end_stake_mark_id = #{endStakeMarkId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="eventLevel != null">event_level = #{eventLevel},</if>
            <if test="eventCategory != null">event_category = #{eventCategory},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="eventSubclass != null">event_subclass = #{eventSubclass},</if>
            <if test="impactLevel != null">impact_level = #{impactLevel},</if>
            <if test="eventCause != null">event_cause = #{eventCause},</if>
            <if test="description != null">description = #{description},</if>
            <if test="handlingResult != null">handling_result = #{handlingResult},</if>
            <if test="otherConfig != null">other_config = #{otherConfig},</if>
            <if test="eventSource != null">event_source = #{eventSource},</if>
            <if test="eventNature != null">event_nature = #{eventNature},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDcEventById" parameterType="String">
        delete from dc_event where id = #{id}
    </delete>

    <delete id="deleteDcEventByIds" parameterType="String">
        delete from dc_event where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>