From 2a1b7fa6fbcd922a0afce8a0e8134a82417a3cbc Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 21 八月 2025 00:24:06 +0800
Subject: [PATCH] 修改bug

---
 DispatchQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java |  122 ++++++++++++++++++++++++----------------
 1 files changed, 73 insertions(+), 49 deletions(-)

diff --git a/DispatchQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java b/DispatchQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
index adfc9c1..e52094b 100644
--- a/DispatchQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
+++ b/DispatchQYTTravel/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;
@@ -8,6 +11,7 @@
 import com.stylefeng.guns.modular.system.service.IOrderCrossCityService;
 import com.stylefeng.guns.modular.system.service.IOrderPrivateCarService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
@@ -24,6 +28,9 @@
  */
 @Component
 public class PushUtil {
+
+    @Value("${qyt.socket_uri}")
+    private String socket_uri;
 
     @Autowired
     private RestTemplate internalRestTemplate;
@@ -66,19 +73,23 @@
         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);
+        params.put("bussinessType", "dache");
+        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"));
+            }
         }
     }
 
@@ -101,19 +112,23 @@
         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);
+        params.put("bussinessType", "dache");
+        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"));
+            }
         }
     }
 
@@ -258,10 +273,6 @@
 
         msg.put("data", map);
 
-        //调用推送
-        HttpHeaders headers = new HttpHeaders();
-        // 以表单的方式提交
-        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
         //将请求头部和参数合成一个请求
         String value1 = redisUtil.getValue(orderId + "_" + orderType);
         if(ToolUtil.isEmpty(value1)){
@@ -269,15 +280,24 @@
             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.getString("id"));
+        params.put("type", jsonObject.getString("type"));
+        params.put("bussinessType", "dache");
+        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"));
+            }
         }
     }
 
@@ -295,19 +315,23 @@
         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);
+        params.put("bussinessType", "dache");
+        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