<?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.ningdatech.carapi.car.rpt.mapper.RptOtherSpecialOverspeedMapper">
    <select id="report" resultType="com.ningdatech.carapi.car.rpt.model.po.RptOtherSpecialOverspeedPO">
        SELECT
        car_plate,
        company_id,
        company_name,
        region_id,
        overspeedStartTime,
        overspeedEndTime,
        max_speed,
        limit_speed,
        overspeedRate,
        address,
        road,
        longtitudeLatitude
        FROM(
        SELECT
        o.car_plate,
        o.company_id,
        c.NAME company_name,
        o.region_id,
        o.start_time overspeedStartTime,
        o.end_time overspeedEndTime,
        o.max_speed,
        o.limit_speed,
        IFNULL(round((o.max_speed - o.limit_speed)/o.limit_speed*100),2) overspeedRate,
        o.address,
        o.way_section road,
        if(o.longitude is not null and o.latitude is not null,concat(o.longitude,',',o.latitude),null) longtitudeLatitude
        FROM
        nd_vehicle_overspeed_info o
        LEFT JOIN nd_vehicle_base_info b ON o.car_plate = b.car_plate
        LEFT JOIN nd_region r ON o.region_id = r.id
        LEFT JOIN nd_company_info c ON o.company_id = c.id
        where b.deleted = 0 and b.audit_state = 2 and b.vehicle_type in (1,2,3,4)
        <if test="param.carPlate != null and param.carPlate != ''">
            and o.car_plate like concat('%',#{param.carPlate},'%')
        </if>
        <if test="param.companyName != null and param.companyName != ''">
            and c.name like concat('%',#{param.companyName},'%')
        </if>
        <if test="param.startTime != null">
            and o.overspeed_date &gt;= #{param.startTime}
        </if>
        <if test="param.endTime != null">
            and o.overspeed_date &lt;= #{param.endTime}
        </if>
        ${param.dataScopeSql}
        ORDER BY IFNULL(round((o.max_speed - o.limit_speed)/o.limit_speed*100),2) desc
        ) ew
        where 1 = 1
        <if test="param.startRate != null">
            and overspeedRate &gt;= #{param.startRate}
        </if>
        <if test="param.endRate != null">
            and overspeedRate &lt;= #{param.endRate}
        </if>
    </select>

    <select id="reportPage" resultType="com.ningdatech.carapi.car.rpt.model.po.RptOtherSpecialOverspeedPO">
        SELECT
        car_plate,
        company_id,
        company_name,
        region_id,
        overspeedStartTime,
        overspeedEndTime,
        max_speed,
        limit_speed,
        overspeedRate,
        address,
        road,
        longtitudeLatitude
        FROM(
        SELECT
        o.car_plate,
        o.company_id,
        c.NAME company_name,
        o.region_id,
        o.start_time overspeedStartTime,
        o.end_time overspeedEndTime,
        o.max_speed,
        o.limit_speed,
        IFNULL(round((o.max_speed - o.limit_speed)/o.limit_speed*100),2) overspeedRate,
        o.address,
        o.way_section road,
        if(o.longitude is not null and o.latitude is not null,concat(o.longitude,',',o.latitude),null) longtitudeLatitude
        FROM
        nd_vehicle_overspeed_info o
        LEFT JOIN nd_vehicle_base_info b ON o.car_plate = b.car_plate
        LEFT JOIN nd_region r ON o.region_id = r.id
        LEFT JOIN nd_company_info c ON o.company_id = c.id
        where b.deleted = 0 and b.audit_state = 2 and b.vehicle_type in (1,2,3,4)
        <if test="param.carPlate != null and param.carPlate != ''">
            and o.car_plate like concat('%',#{param.carPlate},'%')
        </if>
        <if test="param.companyName != null and param.companyName != ''">
            and c.name like concat('%',#{param.companyName},'%')
        </if>
        <if test="param.startTime != null">
            and o.overspeed_date &gt;= #{param.startTime}
        </if>
        <if test="param.endTime != null">
            and o.overspeed_date &lt;= #{param.endTime}
        </if>
        ${param.dataScopeSql}
        ORDER BY IFNULL(round((o.max_speed - o.limit_speed)/o.limit_speed*100),2) desc
        ) ew
        where 1 = 1
        <if test="param.startRate != null">
            and overspeedRate &gt;= #{param.startRate}
        </if>
        <if test="param.endRate != null">
            and overspeedRate &lt;= #{param.endRate}
        </if>
    </select>
</mapper>
