From 19877b00f0aa9eb273d3ba988e356e6b55554f3f Mon Sep 17 00:00:00 2001 From: attiya <2413103649@qq.com> Date: Wed, 3 Sep 2025 17:40:46 +0800 Subject: [PATCH] =?UTF-8?q?sw=E5=80=BC=E8=A7=A3=E6=9E=90bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cdzy/common/model/ResGPSDto.java | 2 -- .../ebikereport/component/ReoprtHandler.java | 12 +++++------ .../cdzy/ebikereport/utils/BinaryUtil.java | 21 +++++++++---------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ebike-common/src/main/java/com/cdzy/common/model/ResGPSDto.java b/ebike-common/src/main/java/com/cdzy/common/model/ResGPSDto.java index 834d33cb..472aa31e 100644 --- a/ebike-common/src/main/java/com/cdzy/common/model/ResGPSDto.java +++ b/ebike-common/src/main/java/com/cdzy/common/model/ResGPSDto.java @@ -2,8 +2,6 @@ package com.cdzy.common.model; import lombok.Data; -import java.time.LocalDateTime; - /** * @author attiya * @since 2025-03-20 diff --git a/ebike-report/src/main/java/com/cdzy/ebikereport/component/ReoprtHandler.java b/ebike-report/src/main/java/com/cdzy/ebikereport/component/ReoprtHandler.java index 7fd00d2b..26429da4 100644 --- a/ebike-report/src/main/java/com/cdzy/ebikereport/component/ReoprtHandler.java +++ b/ebike-report/src/main/java/com/cdzy/ebikereport/component/ReoprtHandler.java @@ -13,8 +13,6 @@ import jakarta.annotation.Resource; import org.springframework.data.geo.Point; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; - /** * @author attiya @@ -46,7 +44,9 @@ public class ReoprtHandler { public void gpsMsgHandler(JSONObject param, String deviceId) { Integer number = param.getInteger("sw"); - String binary = BinaryUtil.to28BitBinary(number); + String binary = BinaryUtil.to32BitBinary(number); + //修复高低bug + binary = new StringBuilder(binary).reverse().toString(); char helmet = binary.charAt(BitSwitch.IS_HELMET_EXIT); char acc = binary.charAt(BitSwitch.ACC_ON); char wheelLocked = binary.charAt(BitSwitch.IS_WHEEL_LOCKED); @@ -55,7 +55,7 @@ public class ReoprtHandler { char isWheelSpin = binary.charAt(BitSwitch.IS_WHEEL_SPIN); char isMoving = binary.charAt(BitSwitch.IS_MOVING); ResGPSDto resGpsDto = param.toJavaObject(ResGPSDto.class); - if (resGpsDto.getSoc() > 0 && resGpsDto.getSoc() < 20){ + if (resGpsDto.getSoc() > 0 && resGpsDto.getSoc() < 20) { maintenanceFeignClient.changeBattery(deviceId); } resGpsDto.setEcuSn(deviceId); @@ -68,10 +68,10 @@ public class ReoprtHandler { resGpsDto.setIsMoving(isMoving); redisUtil.set(deviceId, resGpsDto); double[] doubles = CoordinateUtil.WGS84ToGCJ02(resGpsDto.getLongitude(), resGpsDto.getLatitude()); - redisUtil.addLocation(new Point(doubles[0], doubles[1]),deviceId); + redisUtil.addLocation(new Point(doubles[0], doubles[1]), deviceId); boolean outOfChina = CoordinateUtil.outOfChina(doubles[0], doubles[1]); if (!outOfChina) { - EbikeTracking ebikeTracking = new EbikeTracking(deviceId,doubles[1], doubles[0]); + EbikeTracking ebikeTracking = new EbikeTracking(deviceId, doubles[1], doubles[0]); operateFeignClient.saveEbikeTracking(ebikeTracking); } } diff --git a/ebike-report/src/main/java/com/cdzy/ebikereport/utils/BinaryUtil.java b/ebike-report/src/main/java/com/cdzy/ebikereport/utils/BinaryUtil.java index cd471cd2..9dd21faf 100644 --- a/ebike-report/src/main/java/com/cdzy/ebikereport/utils/BinaryUtil.java +++ b/ebike-report/src/main/java/com/cdzy/ebikereport/utils/BinaryUtil.java @@ -6,19 +6,18 @@ package com.cdzy.ebikereport.utils; */ public class BinaryUtil { /** - * 将整数转换为28位二进制字符串,高位补零 - * @param number 输入数字(范围0 ~ 2^28-1) - * @return 28位二进制字符串 - * @throws IllegalArgumentException 输入超出范围时抛出异常 + * 将整数转换为32位二进制字符串 + * @param number 输入数字 + * @return 32位二进制字符串 */ - public static String to28BitBinary(int number) { - // 验证范围:0 ≤ number ≤ 268,435,455 (即2^28 -1) - if (number < 0 || number > 0x1FFFFFFF) { - throw new IllegalArgumentException("输入数值超出28位无符号范围: " + number); + public static String to32BitBinary(int number) { + String binaryStr = Integer.toBinaryString(number); + + // 补零到32位 + if (binaryStr.length() < 32) { + return "0".repeat(32 - binaryStr.length()) + binaryStr; } - // 转换为二进制并补零至28位 - String binaryStr = Integer.toBinaryString(number); - return "0".repeat(29 - binaryStr.length()) + binaryStr; + return binaryStr; } }