From 3163a383bb58507ac7b0bb56ac20dc26aa1a8e5a Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 25 六月 2025 15:05:05 +0800
Subject: [PATCH] 更新司机端中台接口

---
 DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java |  222 ++++++++++++++++++++++++++++++-------------------------
 1 files changed, 121 insertions(+), 101 deletions(-)

diff --git a/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java b/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
index b0cea43..a7e58bf 100644
--- a/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
+++ b/DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
@@ -1,5 +1,8 @@
 package com.stylefeng.guns.modular.system.util;
 
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.stylefeng.guns.core.util.ToolUtil;
@@ -13,12 +16,8 @@
 import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
 import java.math.BigDecimal;
@@ -46,29 +45,31 @@
 
     @Autowired
     private IOrderPrivateCarService orderPrivateCarService;
-
+    
     @Autowired
     private IOrderCrossCityService orderCrossCityService;
     
     @Autowired
     private RedisTemplate redisTemplate;
-
+    
     @Autowired
     private IOrderLogisticsService orderLogisticsService;
-
+    
     private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器
-
-
-
+    
+    private final String socket_uri = "http://172.21.35.142:6000";
+    
+    
     /**
      * 推送订单状态
-     * @param type          1=用户,2=司机
-     * @param uid           对象id
-     * @param orderId       订单id
-     * @param orderType     订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城,6=包车)
-     * @param state         订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中)
+     *
+     * @param type      1=用户,2=司机
+     * @param uid       对象id
+     * @param orderId   订单id
+     * @param orderType 订单类型(1=专车,2=出租车,3=城际,4=小件物流-同城,5=小件物流-跨城,6=包车)
+     * @param state     订单状态(1=待接单,2=待出发,3=待到达预约地点,4=待乘客上车,5=服务中,6=完成服务,7=待支付,8=待评价,9=已完成,10=已取消,11=改派中)
      */
-    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state){
+    public void pushOrderState(Integer type, Integer uid, Integer orderId, Integer orderType, Integer state) {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("code", 200);
         jsonObject.put("msg", "SUCCESS");
@@ -78,22 +79,26 @@
         map.put("orderType", orderType);
         map.put("state", state);
         jsonObject.put("data", map);
-
+        
         //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
         //将请求头部和参数合成一个请求
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", jsonObject.toJSONString());
-        params.add("id", String.valueOf(uid));
-        params.add("type", String.valueOf(type));
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", jsonObject.toJSONString());
+        params.put("id", uid);
+        params.put("type", type);
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
+        
     }
 
 
@@ -113,22 +118,24 @@
         map.put("orderId", orderId);
         map.put("orderType", orderType);
         jsonObject.put("data", map);
-
+    
         //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
         //将请求头部和参数合成一个请求
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", jsonObject.toJSONString());
-        params.add("id", String.valueOf(uid));
-        params.add("type", type.toString());
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        System.out.println("result:"+s);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", jsonObject.toJSONString());
+        params.put("id", uid);
+        params.put("type", type);
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
     }
 
@@ -336,31 +343,35 @@
                 map.put("laveMileage", d);//距离终点剩余未服务的里程数
                 map.put("laveTime", t);//距离终端剩余未服务的预计时间
             }
-
+    
         }
-
+    
         msg.put("data", map);
-
-        //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
-        //将请求头部和参数合成一个请求
+    
         String value1 = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType);
-        if(ToolUtil.isEmpty(value1)){
+        if (ToolUtil.isEmpty(value1)) {
             this.removeTask(orderId, orderType);
             return;
         }
         JSONObject jsonObject = JSON.parseObject(value1);
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", msg.toJSONString());
-        params.add("id", jsonObject.getString("id"));
-        params.add("type", jsonObject.getString("type"));
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+    
+        //调用推送
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
+        //将请求头部和参数合成一个请求
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", msg.toJSONString());
+        params.put("id", jsonObject.getIntValue("id"));
+        params.put("type", jsonObject.getIntValue("type"));
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
     }
 
@@ -371,27 +382,30 @@
      * @param id
      * @param type
      */
-    public void pushOffline(Integer id, Integer type){
+    public void pushOffline(Integer id, Integer type) {
         JSONObject msg = new JSONObject();
         msg.put("code", 200);
         msg.put("msg", "SUCCESS");
         msg.put("method", "OFFLINE");
         msg.put("data", new Object());
-
+    
         //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
         //将请求头部和参数合成一个请求
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", msg.toJSONString());
-        params.add("id", id.toString());
-        params.add("type", type.toString());
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", msg.toJSONString());
+        params.put("id", id);
+        params.put("type", type);
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
     }
 
@@ -416,21 +430,24 @@
         map.put("orderType", orderType);
         map.put("state", state);
         jsonObject.put("data", map);
-
+    
         //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
         //将请求头部和参数合成一个请求
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", jsonObject.toJSONString());
-        params.add("id", String.valueOf(uid));
-        params.add("type", String.valueOf(type));
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", jsonObject.toJSONString());
+        params.put("id", uid);
+        params.put("type", type);
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
     }
 
@@ -453,21 +470,24 @@
         map.put("orderType", orderType);
         map.put("money", money);
         jsonObject.put("data", map);
-
+    
         //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+        HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient");
+        post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
         //将请求头部和参数合成一个请求
-        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
-        params.add("msg", jsonObject.toJSONString());
-        params.add("id", String.valueOf(uid));
-        params.add("type", String.valueOf(type));
-        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers);
-        String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class);
-        JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class);
-        if(jsonObject1.getIntValue("code") != 200){
-            System.err.println(jsonObject1.getString("msg"));
+        Map<String, Object> params = new HashMap<>();
+        params.put("msg", jsonObject.toJSONString());
+        params.put("id", uid);
+        params.put("type", type);
+        post.form(params);
+        HttpResponse execute = post.execute();
+        if (200 != execute.getStatus()) {
+            System.err.println("推送异常");
+        } else {
+            JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class);
+            if (jsonObject1.getIntValue("code") != 200) {
+                System.err.println(jsonObject1.getString("msg"));
+            }
         }
     }
 

--
Gitblit v1.7.1