package com.cpxt.biz.mapper;

import com.cpxt.biz.domain.BizCustomerRouteState;
import com.cpxt.biz.domain.BizCustomerShopState;
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_shop_state(门店状态)】的数据库操作Mapper
* @createDate 2025-01-07 10:30:31
* @Entity com.cpxt.biz.domain.BizCustomerShopState
*/
@Mapper
public interface BizCustomerShopStateMapper extends BaseMapper<BizCustomerShopState> {

    @Select("select * from biz_customer_shop_state where shop_id = #{routeId}")
    BizCustomerShopState selectOneByShopId(int shopId);

    @Select("select shop_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 shop_id")
    List<Map> selectAvgTimes();

    @Select("select shop_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 shop_id ")
    List<Map> selectOrderCount();

    @Select("select * from (select distinct order_sn,order_status, shop_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.shop_id ")
    List<Map> selectCurrentOrder();
}




