Pu Zhibing
2025-05-09 8580866e175ad0050ee9c5ea3f757856fc242c39
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/taxi/controller/TaxiCallbackController.java
@@ -1,14 +1,9 @@
package com.stylefeng.guns.modular.taxi.controller;
import cn.hutool.json.JSONObject;
import com.stylefeng.guns.modular.system.model.Company;
import com.stylefeng.guns.modular.system.model.Driver;
import com.stylefeng.guns.modular.system.model.PushOrder;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.ICompanyService;
import com.stylefeng.guns.modular.system.service.IDriverService;
import com.stylefeng.guns.modular.system.service.IPushOrderService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.*;
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.PushUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.util.SignVerificationUtil;
@@ -25,6 +20,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * 支付回调控制器
@@ -46,6 +43,10 @@
    private OrderTaxiMapper orderTaxiMapper;
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private ICallingAreaService callingAreaService;
    @Autowired
    private ICompanyCityService companyCityService;
    @ResponseBody
    @PostMapping("/callback")
    @ApiOperation(value = "AI回调", tags = {"AI回调"}, notes = "")
@@ -66,10 +67,11 @@
        // 遍历列表以获取每个结果的地址信息
        OrderTaxi orderTaxi = new OrderTaxi();
        String audioPath = req.getStr("audioPath");
        String phone = req.getStr("phone");
        JSONObject outputParam = req.getJSONObject("outputParam");
        String area = outputParam.getStr("area");
        System.err.println("phone++++"+phone);
        String downloadUrl = ""
;
@@ -91,8 +93,15 @@
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        // 打印或处理地址信息
        System.out.println("地址信息:" + area);
        // 查询电召区域
        CallingArea callingArea = callingAreaService.selectOne(new EntityWrapper<CallingArea>().eq("areaCode", area));
        if(Objects.nonNull(callingArea)){
            // 打印或处理地址信息
            System.out.println("地址信息:" + callingArea.getArea());
            orderTaxi.setStartAddress(callingArea.getArea());
        }else {
            return ResultUtil.error("电召未开通该区域城市");
        }
        //创建订单
        orderTaxi.setAudioLinkUrl(downloadUrl);
        orderTaxi.setInsertTime(new Date());
@@ -103,7 +112,6 @@
        orderTaxi.setPassengersPhone(phone);
        orderTaxi.setTravelTime(new Date());
        orderTaxi.setOrderType(1);
        orderTaxi.setStartAddress(area);
        orderTaxiMapper.insert(orderTaxi);
        new Thread(new Runnable() {
            @Override
@@ -117,7 +125,7 @@
        if(orderTaxi.getState() == 1){
            //推送司机抢单
            try {
                this.pushOrder(orderTaxi);
                this.pushOrder(orderTaxi,callingArea);
            }catch (Exception e){
            }
        }
@@ -132,7 +140,7 @@
    }
    public static List<Integer> orderIds = new ArrayList<>();
    public void pushOrder(OrderTaxi orderTaxi) throws Exception{
    public void pushOrder(OrderTaxi orderTaxi,CallingArea callingArea) throws Exception{
        new Thread(new Runnable() {
            @Override
            public void run() {
@@ -140,16 +148,20 @@
                    orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单
                    Company query = companyService.selectById(1);//获取起点所属分公司
                    List<PushOrder> querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数
                    // 优先查询区域
                    List<Company> companys = companyCityService.queryCall(callingArea.getAreaCode());
                    System.err.println("根据区域查询出来的分公司======"+companys);
                    List<Integer> companyIds = companys.stream().map(Company::getId).collect(Collectors.toList());
                    for(int i = 1; i <= querys.size(); i++){
                        PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
                        //获取空闲司机
                        List<Driver> list = driverService.queryIdleDriverAll(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
                        List<Driver> list = driverService.queryIdleDriverAllCall(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), companyIds);//所有附近空闲司机
//                        List<Driver> list = driverService.queryIdleDriverAll(2, orderTaxi.getStartLon(), orderTaxi.getStartLat(), pushOrder.getPushDistance(), null);//所有附近空闲司机
                        if(list.size() > 0){
                            double driverProportion = pushOrder.getDriverProportion() / 100;//推送占比计算成小数
                            int lastIndex = Double.valueOf(list.size() * driverProportion).intValue();//计算占比转成整数(下标截取)
                            list = list.subList(0, lastIndex);//获取空闲司机中占比数据
                            for(Driver driver : list){//开始进行推送
                                pushUtil.pushOrderStateVedio(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime(),orderTaxi.getAudioLinkUrl());
                            }
                        }