<?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.DcEventTrafficCongestionMapper">
    
    <resultMap type="com.zc.business.domain.DcEventTrafficCongestion" id="DcEventTrafficCongestionResult">
        <result property="id"    column="id"    />
        <result property="congestionMileage"    column="congestion_mileage"    />
        <result property="congestionCause"    column="congestion_cause"    />
        <result property="facilityId"    column="facility_id"    />
        <result property="rampId"    column="ramp_id"    />
        <result property="location"    column="location"    />
        <result property="maxCongestionMileage"    column="max_congestion_mileage"    />

        <result property="dcFacility.facilityName"    column="facility_name"    />
        <result property="dcFacility.facilityType"    column="facility_type"    />
        <result property="dcFacility.direction"    column="direction"    />
        <result property="dcFacility.stakeMark"    column="stake_mark"    />
        <result property="dcFacility.remark"    column="remark"    />
        <result property="dcFacility.otherConfig"    column="other_config"    />

    </resultMap>

    <sql id="selectDcEventTrafficCongestionVo">
        select id, congestion_mileage, congestion_cause, facility_id, ramp_id, location,max_congestion_mileage from dc_event_traffic_congestion
    </sql>
    <!--     -->
    <sql id="selectDcEventTrafficCongestionVoById">
        SELECT
            dc_event_traffic_congestion.congestion_cause as congestion_cause,
            dc_event_traffic_congestion.congestion_mileage as congestion_mileage,
            dc_event_traffic_congestion.facility_id as facility_id,
            dc_event_traffic_congestion.id as id,
            dc_event_traffic_congestion.location as location,
            dc_event_traffic_congestion.ramp_id as ramp_id,
            dc_event_traffic_congestion.max_congestion_mileage as max_congestion_mileage,

            dc_facility.other_config as other_config,
            dc_facility.remark as remark,
            dc_facility.stake_mark as stake_mark,
            dc_facility.facility_type as facility_type,
            dc_facility.facility_name as facility_name,
            dc_facility.direction as direction

        FROM dc_event_traffic_congestion    </sql>

    <select id="selectDcEventTrafficCongestionList" parameterType="DcEventTrafficCongestion" resultMap="DcEventTrafficCongestionResult">
        <include refid="selectDcEventTrafficCongestionVo"/>
        <where>  
            <if test="congestionMileage != null "> and congestion_mileage = #{congestionMileage}</if>
            <if test="congestionCause != null "> and congestion_cause = #{congestionCause}</if>
            <if test="facilityId != null "> and facility_id = #{facilityId}</if>
            <if test="rampId != null "> and ramp_id = #{rampId}</if>
            <if test="location != null "> and location = #{location}</if>
        </where>
    </select>
    
    <select id="selectDcEventTrafficCongestionById" parameterType="String" resultMap="DcEventTrafficCongestionResult">
        <include refid="selectDcEventTrafficCongestionVoById"/>
        LEFT JOIN dc_facility ON dc_event_traffic_congestion.facility_id = dc_facility.id
        where dc_event_traffic_congestion.id = #{id}
    </select>
        
    <insert id="insertDcEventTrafficCongestion" parameterType="DcEventTrafficCongestion">
        insert into dc_event_traffic_congestion
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="congestionMileage != null">congestion_mileage,</if>
            <if test="congestionCause != null">congestion_cause,</if>
            <if test="facilityId != null">facility_id,</if>
            <if test="rampId != null">ramp_id,</if>
            <if test="location != null">location,</if>
            <if test="maxCongestionMileage != null">max_congestion_mileage,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="congestionMileage != null">#{congestionMileage},</if>
            <if test="congestionCause != null">#{congestionCause},</if>
            <if test="facilityId != null">#{facilityId},</if>
            <if test="rampId != null">#{rampId},</if>
            <if test="location != null">#{location},</if>
            <if test="maxCongestionMileage != null">#{maxCongestionMileage},</if>
         </trim>
    </insert>

    <update id="updateDcEventTrafficCongestion" parameterType="DcEventTrafficCongestion">
        update dc_event_traffic_congestion
        <trim prefix="SET" suffixOverrides=",">
            <if test="congestionMileage != null">congestion_mileage = #{congestionMileage},</if>
            <if test="congestionCause != null">congestion_cause = #{congestionCause},</if>
            <if test="facilityId != null">facility_id = #{facilityId},</if>
            <if test="rampId != null">ramp_id = #{rampId},</if>
            <if test="location != null">location = #{location},</if>
            <if test="maxCongestionMileage != null">max_congestion_mileage = #{maxCongestionMileage},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDcEventTrafficCongestionById" parameterType="String">
        delete from dc_event_traffic_congestion where id = #{id}
    </delete>

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