FlowMapper.xml 5.07 KB
<?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.viontech.fanxing.query.mapper.FlowMapper">
    <resultMap id="baseMap" type="com.viontech.fanxing.query.model.TrafficFlowEventModel">
        <result column="id" property="id"/>
        <result column="event_dt" property="event_dt"/>
    </resultMap>

    <resultMap id="dataMap" type="com.viontech.fanxing.query.model.TrafficFlowDataModel">
        <result column="flow_event_id" property="eventId"/>
        <result column="event_time" property="eventTime"/>
        <result column="road" property="road"/>
        <result column="device_name" property="deviceName"/>
        <result column="location_name" property="locationName"/>
        <result column="velocity" property="velocity"/>
        <result column="occupy" property="occupy"/>
        <result column="distance" property="distance"/>
        <result column="sample_dura" property="sampleDura"/>
        <result column="queue_length" property="queueLength"/>
        <result column="sample_num" property="sampleNum"/>
        <result column="direction" property="direction"/>
        <result column="time_occupy" property="timeOccupy"/>
        <result column="dist_time" property="distTime"/>
    </resultMap>

    <select id="selectEvents" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo" resultMap="baseMap">
        select date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as event_dt,
               date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as gevent_dt,
               te.id
        from d_flow_event te
           , d_flow_data
        <where>
            and d_flow_data.flow_event_id = te.id
                AND d_flow_data.road_code != '0'
            <if test="task_id != null and task_id != ''">
                and te.task_id = #{task_id}
            </if>
            <if test="vchan_refid != null and vchan_refid != ''">
                and te.channel_unid = #{vchan_refid}
            </if>
            <if test="event_dt__gte != null and event_dt__lt != null">
                and te.event_time <![CDATA[>=]]> #{event_dt__gte}
                and te.event_time <![CDATA[<=]]> #{event_dt__lt}
            </if>
        </where>
        GROUP BY gevent_dt, te.id
        <if test="statistic_type == 'road'">
            , d_flow_data.road_code
        </if>
        order by event_dt desc
        <if test="offset != null and limit != null">
            LIMIT #{limit} offset #{offset}
        </if>
    </select>

    <select id="counts" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo" resultType="int">
        select count(1) as count  from (
                select date_format(te.event_time, '%Y-%m-%d %H:%i:%s') as gevent_dt
                from d_flow_event te
                   , d_flow_data
        <where>
            and d_flow_data.flow_event_id = te.id
                AND d_flow_data.road_code != '0'

            <if test="task_id != null and task_id != ''">
                and te.task_id = #{task_id}
            </if>
            <if test="vchan_refid != null and vchan_refid != ''">
                and te.channel_unid = #{vchan_refid}
            </if>
            <if test="event_dt__gte != null and event_dt__lt != null">
                and te.event_time <![CDATA[>=]]> #{event_dt__gte}
                and te.event_time <![CDATA[<=]]> #{event_dt__lt}
            </if>
        </where>
        GROUP BY gevent_dt, te.id
                ) as con
    </select>

    <select id="flowstatistics" parameterType="com.viontech.fanxing.query.model.TrafficFlowRequestVo"
            resultMap="dataMap">
        select ${column_List}
        from d_flow_event te,
             d_flow_data td
        <where>
            <if test="idSet != null">
                and td.flow_event_id in
                <foreach collection="idSet" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            and te.id = td.flow_event_id
            <if test="task_id != null">
                and td.task_id = #{task_id}
            </if>
            <if test="vchan_refid != null and vchan_refid != ''">
                and te.channel_unid = #{vchan_refid}
            </if>
            <if test="detection_type != null and detection_type.size > 0">
                and detection_type in
                <foreach item="item" index="index" collection="detection_type" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="vehicle_type != null and vehicle_type.length != 0">
                and td.detection_type in
                <foreach item="item" index="index" collection="vehicle_type"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            and road_code != '0'
        </where>

        GROUP BY ${groupByClause}
        ORDER BY ${orderByClause}
        <if test="limit != null">
            LIMIT #{limit}
        </if>
    </select>
</mapper>