From 71a01448f9e6de4a05381a74e415b9f0964cddef Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 24 七月 2025 19:21:23 +0800
Subject: [PATCH] 新增部分三方接口

---
 DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java |  145 ++++++++++++++++++++++++++++++------------------
 1 files changed, 90 insertions(+), 55 deletions(-)

diff --git a/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java b/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java
index cfa2773..d2ac236 100644
--- a/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java
+++ b/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ReassignServiceImpl.java
@@ -1,24 +1,18 @@
 package com.stylefeng.guns.modular.system.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.stylefeng.guns.core.util.ToolUtil;
-import com.stylefeng.guns.modular.account.controller.AppOrderController;
-import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal;
 import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService;
 import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
 import com.stylefeng.guns.modular.account.unionpay.GetOpenBodySig;
 import com.stylefeng.guns.modular.account.unionpay.QrCodeConfiguration;
 import com.stylefeng.guns.modular.account.unionpay.Util;
-import com.stylefeng.guns.modular.account.util.Base64Util;
-import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
-import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
 import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
 import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
 import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
 import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
-import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
 import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
 import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
 import com.stylefeng.guns.modular.system.dao.DispatchMapper;
@@ -29,10 +23,11 @@
 import com.stylefeng.guns.modular.system.util.*;
 import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
-import com.unionpay.upyzt.resp.AllocationResp;
+import com.stylefeng.guns.modular.taxi.service.impl.OrderTaxiServiceImpl;
 import org.apache.commons.lang.time.DateFormatUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Propagation;
@@ -234,16 +229,15 @@
                 Map<String, String> map = new HashMap<>();
                 map.put("orderId", reassign.getOrderId().toString());
                 map.put("orderType", reassign.getOrderType().toString());
-                List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
-                for(Dispatch dispatch : dispatches){
-                    jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
-                }
+//                List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
+//                for(Dispatch dispatch : dispatches){
+//                    jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
+//                }
 
-                // TODO 司机云闪付 改派余额支付,司机电子账簿转账到平台
-                if(BigDecimal.ZERO.compareTo(new BigDecimal(aDouble)) < 0){
-                    cloudPay(reassign.getOriginalDriverId(),aDouble,Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId()));
-                }
-
+                // qyt 改派直接推送
+                pushOrder();
+    
+    
             }
             if(reassign.getPayType() == 4){
                 // TODO 司机云闪付 改派调起云闪付
@@ -255,44 +249,6 @@
         return resultUtil;
     }
 
-    private void cloudPay(Integer uid,Double total_fee,String transaction_id) {
-        System.out.println(uid+"======"+total_fee+"====="+transaction_id);
-        Driver driver = driverService.selectById(uid);
-        if(Objects.isNull(driver)){
-            throw new RuntimeException("该司机不存在!"+uid);
-        }
-        // 查询平台账户
-        Company company = companyService.selectOne(new EntityWrapper<Company>()
-                .eq("type", 1)
-                .last("LIMIT 1"));
-        System.out.println("查询平台账户==============="+company);
-        // 查询平台开户信息
-        TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
-                .eq("companyId", company.getId())); //  替换为公司id
-        System.out.println("查询平台开户信息==============="+enterpriseWithdrawal);
-        // TODO 司机进件信息
-        UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
-                .eq("phone", driver.getPhone())
-                .last("LIMIT 1"));
-        try {
-            AllocationReq allocationReq = new AllocationReq();
-            allocationReq.setOutOrderNo(transaction_id);
-            allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId()); // 发送方
-            allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 接收方
-            BigDecimal multiply = new BigDecimal(100).multiply(new BigDecimal(total_fee));
-            allocationReq.setAmount(multiply.intValue()); // 金额
-            allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
-            allocationReq.setOrderNo(transaction_id);
-            allocationReq.setOrderAmount(multiply.longValue());
-            allocationReq.setProductName("订单改派");
-            allocationReq.setProductCount(1);
-            AllocationResp allocationResp = AllocationExample.create(allocationReq);
-            System.err.println("司机分账信息:"+allocationResp);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-    }
 
     private ResultUtil placeAnOrder(BigDecimal amount, Integer type,Integer orderType,Integer reassignId) throws Exception {
         Reassign reassign = reassignMapper.selectById(reassignId);
@@ -543,6 +499,13 @@
     }
 
 
+
+    public static List<Integer> orderIds = new ArrayList<>();
+
+
+    @Resource
+    private RedisTemplate<String, Object> redisTemplate;
+
     /**
      * 改派支付完成后的操作
      * @param id            改派单id
@@ -598,6 +561,12 @@
                     }
                     systemNoticeService.addSystemNotice(2, "您已使用" + (type == 1 ? "微信" : (type == 2?"支付宝":"云闪付")) + "成功支付改派申请费用!", reassigns.get(0).getOriginalDriverId(), 1);
                     System.out.println("==============跨城修改改派通知状态完毕===================");
+
+
+                    // qyt 新增改派 重新推送
+
+
+
                 }else{
                     System.err.println("预支付数据异常(orderId = "  + id + ")");
                 }
@@ -687,4 +656,70 @@
 
 
     }
+    @Autowired
+    private ICompanyCityService companyCityService;
+
+    @Autowired
+    private IPushOrderService pushOrderService;
+
+    /**
+     * 推送订单给司机抢单
+     * @param orderTaxi
+     * @throws Exception
+     */
+    public void pushOrder(OrderTaxi orderTaxi, Integer type) throws Exception{
+        new Thread(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    orderIds.add(orderTaxi.getId());//添加记录,防止调用接口重复提醒无人接单
+                    String vehicle = (String) redisTemplate.opsForValue().get("VEHICLE");
+                    List<Integer> integers = new ArrayList<>();
+                    if (ToolUtil.isNotEmpty(vehicle)) {
+                        integers = JSON.parseArray(vehicle).toJavaList(Integer.class);
+                    }
+                    Company query = companyCityService.query(String.valueOf(orderTaxi.getStartLon()), String.valueOf(orderTaxi.getStartLat()));//获取起点所属分公司
+                    List<PushOrder> querys = pushOrderService.querys(null, 2, query.getId());//获取需要推送的次数
+                    for (int i = 1; i <= querys.size(); i++) {
+                        PushOrder pushOrder = pushOrderService.querys(i, 2, query.getId()).get(0);
+                        System.out.println("pushOrder:" + pushOrder);
+                        //获取空闲司机
+                        List<Driver> list = driverService.queryIdleDriver(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();//计算占比转成整数(下标截取)
+                            lastIndex = lastIndex == 0 ? list.size() : lastIndex;
+                            list = list.subList(0, lastIndex);//获取空闲司机中占比数据
+                            for (Driver driver : list) {//开始进行推送
+                                //查询是否在限制推单范围内
+                                boolean bo = false;
+                                for (Integer integer : integers) {
+                                    if (integer.compareTo(driver.getId()) == 0) {
+                                        bo = true;
+                                        break;
+                                    }
+                                }
+                                if (bo) {
+                                    continue;
+                                }
+                                pushUtil.pushOrderState(2, driver.getId(), orderTaxi.getId(), 2, orderTaxi.getState(), pushOrder.getPushTime());
+                            }
+                        }
+                        Thread.sleep(pushOrder.getPushTime() * 1000);//设置等待时间
+                        OrderTaxi orderTaxi1 = OrderTaxiServiceImpl.this.selectById(orderTaxi.getId());
+                        Integer state = orderTaxi1.getState();
+                        if (state != 1) {
+                            break;
+                        }
+                        if (i == querys.size() && state == 1) {
+                            pushUtil.pushEndPush(1, orderTaxi.getUserId(), orderTaxi.getId(), 2);
+                            orderIds.remove(orderTaxi.getId());
+                        }
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }).start();
+    }
 }

--
Gitblit v1.7.1