From f17933a034b526eaec27c7bfe6759b1579bc1216 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 18 四月 2025 13:51:24 +0800 Subject: [PATCH] 修改bug --- DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java | 38 ++++++++++++++++++++++---------------- 1 files changed, 22 insertions(+), 16 deletions(-) diff --git a/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java b/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java index 726234e..9263e89 100644 --- a/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java +++ b/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java @@ -12,6 +12,8 @@ import com.stylefeng.guns.modular.system.model.OrderPosition; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; @@ -27,6 +29,8 @@ import java.io.FileInputStream; import java.io.InputStreamReader; import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; import java.util.*; /** @@ -34,6 +38,8 @@ */ @Component public class PushUtil { + + private Logger log = LoggerFactory.getLogger(PushUtil.class); @Autowired private RestTemplate internalRestTemplate; @@ -94,10 +100,10 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ - System.err.println(jsonObject1.getString("msg")); + log.error(jsonObject1.getString("msg")); } } @@ -128,10 +134,10 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ - System.err.println(jsonObject1.getString("msg")); + log.error(jsonObject1.getString("msg")); } } @@ -278,7 +284,7 @@ //计算预计距离和剩余时间 String value = redisUtil.getValue("DRIVER" + String.valueOf(driverId)); if(null == value || "".equals(value)){ - System.err.println("司机没有上传位置信息"); +// System.err.println("司机没有上传位置信息"); return; } @@ -303,8 +309,8 @@ System.err.println("查询距离出错了"); return; }else{ - d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); - t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; + d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); + t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; } map.put("reservationMileage", d);//当前位置距离预约点的剩余里程 map.put("reservationTime", t);//当前位置距离预约点的剩余分钟 @@ -325,8 +331,8 @@ if(null == distance){ System.err.println("查询距离出错了"); }else{ - d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); - t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; + d = new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).toString(); + t = new BigDecimal(distance.get("duration")).divide(new BigDecimal(60), new MathContext(2, RoundingMode.HALF_EVEN)).setScale(2, BigDecimal.ROUND_HALF_EVEN).intValue() + ""; } map.put("laveMileage", d);//距离终点剩余未服务的里程数 map.put("laveTime", t);//距离终端剩余未服务的预计时间 @@ -357,10 +363,10 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ - System.err.println(jsonObject1.getString("msg")); + log.error(jsonObject1.getString("msg")); } } @@ -388,7 +394,7 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ System.err.println(jsonObject1.getString("msg")); @@ -427,10 +433,10 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ - System.err.println(jsonObject1.getString("msg")); + log.error(jsonObject1.getString("msg")); } } @@ -464,10 +470,10 @@ 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); + String s = internalRestTemplate.postForObject("http://message-push/netty/sendMsgToClient",requestEntity , String.class); JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); if(jsonObject1.getIntValue("code") != 200){ - System.err.println(jsonObject1.getString("msg")); + log.error(jsonObject1.getString("msg")); } } -- Gitblit v1.7.1