<?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.xxfc.platform.order.mapper.OrderVehicleServiceStatisticsMapper" >
  <!--统计车辆服务次数-->
  <select id="countVehicleServiceNum" parameterType="Map" resultType="com.xxfc.platform.order.pojo.CountVehicleServiceNumVo">
      SELECT tmp1.countYear,tmp1.countMonth,tmp1.countDay, tmp1.companyId, tmp1.countWeek, tmp1.countNum as departureNum, tmp2.countNum as arrivalNum from (
      SELECT YEAR(FROM_UNIXTIME(o.crt_time/1000)) as countYear, MONTH(FROM_UNIXTIME(o.crt_time/1000)) AS countMonth, DAY(FROM_UNIXTIME(o.crt_time/1000)) AS countDay, WEEK(FROM_UNIXTIME(o.crt_time/1000))as countWeek, o1.start_company_id as companyId, count(*) as countNum from order_vehicle_crosstown o
      LEFT JOIN order_rent_vehicle_detail o1 on o.order_id = o1.order_id
      where o.type = 1
      <if test="startTime != null">
       and o.crt_time &gt;= #{startTime} and o.crt_time &lt;= #{endTime}
      </if>
      GROUP BY companyId, countYear,countMonth,countDay,countWeek
      ) tmp1
      LEFT JOIN
      (SELECT YEAR(FROM_UNIXTIME(o.crt_time/1000)) as countYear, MONTH(FROM_UNIXTIME(o.crt_time/1000)) AS countMonth, DAY(FROM_UNIXTIME(o.crt_time/1000)) AS countDay, WEEK(FROM_UNIXTIME(o.crt_time/1000))as countWeek, o1.end_company_id as companyId, count(*) as countNum from order_vehicle_crosstown o
      LEFT JOIN order_rent_vehicle_detail o1 on o.order_id = o1.order_id
      where (o.type = 2 or o.type = 3)
      <if test="startTime != null">
        and o.crt_time &gt;= #{startTime} and o.crt_time &lt;= #{endTime}
      </if>
      GROUP BY companyId, countYear,countMonth,countDay,countWeek
      ) tmp2 on tmp1.companyId = tmp2.companyId
  </select>

    <select id="selectByCompanyIdAndDate" resultType="com.xxfc.platform.order.entity.OrderVehicleServiceStatistics" parameterType="com.xxfc.platform.order.entity.OrderVehicleServiceStatistics">
        select * from order_vehicle_service_statistics where company_id = #{companyId} and count_date = #{countDate}
    </select>

</mapper>