package com.cpxt.biz.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cpxt.biz.domain.BizDriverClock;
import com.cpxt.biz.domain.StatCar;
import org.apache.ibatis.annotations.*;

import java.util.List;
import org.apache.ibatis.annotations.Select;

/**
 * 车辆统计Mapper接口
 * 
 * @author ruoyi
 * @date 2024-12-31
 */
@Mapper
public interface StatCarMapper extends BaseMapper<StatCar>
{

    @Select("select t.car_no from (SELECT car_no,SUM(odometer) sumo FROM `stat_car` where stat_date >= #{startTime} and stat_date <= #{endTime} GROUP BY car_no ORDER BY sumo desc limit 5) t")
    List<String> selectOdometerTop5CarNo(@Param("startTime") String startTime,@Param("endTime") String endTime);

    @Select("select t.sumo from (SELECT car_no,SUM(odometer) sumo FROM `stat_car` where stat_date >= #{startTime} and stat_date <= #{endTime} GROUP BY car_no ORDER BY sumo desc limit 5) t")
    List<Double> selectOdometerTop5Odometer(@Param("startTime")String startTime,@Param("endTime") String endTime);
    @Insert("insert into stat_car (stat_date, car_id, car_no) select #{statDate}, id, car_no from biz_car where status = 1 ")
    void initStatCar(String statDate);

    @Select("select min(odometer) minOdometer, max(odometer) maxOdometer from track_${carId} where car_id = #{carId} and gps_time BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY ")
    Map getTodayOdometer(String carId);

    @Select("select * from stat_car where car_id = #{carId} and stat_date BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY ")
    StatCar selectTodayByCarId(Long carId);

    @Select("select count(id) orderCount from biz_order where car_id = #{carId} and create_time BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY ")
    Map getTodayOrderCount(Long carId);

    @Select("select * from biz_driver_clock where car_id = #{carId} and ((on_time BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY ) or off_time BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY)) ")
    Map getTodayUsetime(Long carId);

    @Select("select driver_id from biz_order where car_id = #{carId} and create_time BETWEEN CURDATE() AND CURDATE() + INTERVAL 1 DAY limit 1 ")
    Map selectDriverByCarId(Long carId);

}
