package com.cpxt.biz.mapper;

import com.cpxt.biz.domain.BizCustomerRouteState;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

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

/**
* @author LuoJian
* @description 针对表【biz_customer_route_state(路线状态)】的数据库操作Mapper
* @createDate 2025-01-07 10:29:27
* @Entity com.cpxt.biz.domain.BizCustomerRouteState
*/
@Mapper
public interface BizCustomerRouteStateMapper extends BaseMapper<BizCustomerRouteState> {

    @Select("select * from biz_customer_route_state where route_id = #{routeId}")
    BizCustomerRouteState selectOneByRouteId(int routeId);

    @Select("select route_id, ROUND(AVG(TIME_TO_SEC(TIMEDIFF(arrive_time, start_time ))),0) AS avgtimes from biz_order " +
            " where order_status = 3 and start_time is not null and arrive_time is not null group by route_id")
    List<Map> selectAvgTimes();

    @Select("select route_id, count(id) order_count, sum(case when order_status = 3 then 1 else 0 end) finish_count " +
            " from biz_order where order_date = curdate() group by route_id ")
    List<Map> selectOrderCount();

    @Select("select * from (select distinct order_sn,order_status, route_id,car_id, driver_id, copilot_id " +
            " from biz_order where order_date = curdate() and (order_status = '1' or order_status = '2') " +
            " order by create_time asc ) as t group by t.route_id ")
    List<Map> selectCurrentOrder();

}




