<?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.RptDailyOperatorVehiclesLaunchRateMapper">
    <select id="report"
            resultType="com.ningdatech.carapi.car.rpt.model.po.RptDailyOperatorVehiclesLaunchRatePO">
        SELECT
            count(b.car_plate) vehicle_nums,
            count(b.car_plate) monitored_vehicle_nums,
            (count(b.car_plate) - count(b.car_plate)) unmonitored_vehicle_nums,
            count(o2.car_plate) onlineVehicleNum,
            (count(b.car_plate) - count(o2.car_plate)) offlineVehicleNum,
            IFNULL(convert(count(o2.car_plate)/count(b.car_plate) * 100,decimal(10,2)),0) launch_rate,
            op.name operator_name
        FROM `nd_vehicle_base_info` b
                 left join (
            select o.car_plate from ${po.tableName} o
                                        left join nd_region r on o.region_id = r.id
                                        left join nd_company_info c on o.company_id = c.id
            where o.year = year(#{po.date}) and o.month = month(#{po.date}) and o.day = day(#{po.date})
            ${po.dataScopeSql}
        group by o.car_plate
            ) o on b.car_plate = o.car_plate
            left join (
            select o.car_plate from ${po.tableName} o
            left join nd_region r on o.region_id = r.id
            left join nd_company_info c on o.company_id = c.id
            where o.year = year(#{po.date}) and o.month = month(#{po.date}) and o.day = day(#{po.date})
            and status = 1
            ${po.dataScopeSql}
            group by o.car_plate
            ) o2 on b.car_plate = o2.car_plate
            left join nd_region r on b.region_id = r.id
            left join nd_company_info c on b.company_id = c.id
            left join nd_operator_info op on b.operator_id = op.id
--         where b.vehicle_type in (1,2,3,4)
        where b.deleted = 0 and b.audit_state = 2 ${po.dataScopeSql}
        group by op.name
    </select>
</mapper>
