From 119fd1b872b88e8c4c62b206028b38ef0a963eae Mon Sep 17 00:00:00 2001 From: ZZ Date: Mon, 9 Aug 2021 16:49:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96,=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xhpc/pp/controller/ChargingController.java | 3 +-- .../com/xhpc/pp/logic/RateModelRequestLogic.java | 2 +- .../com/xhpc/pp/logic/RateModelValidateLogic.java | 13 ++++++++----- .../java/com/xhpc/pp/utils/security/HexUtils.java | 7 ------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java index 529521c5..605f9d38 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/ChargingController.java @@ -28,7 +28,6 @@ import static com.xhpc.common.data.redis.SeqUtil.seqHex; import static com.xhpc.pp.logic.RegisterLogic.REGISTERED; import static com.xhpc.pp.server.ChargingPileServer.*; import static com.xhpc.pp.utils.security.HexUtils.toHexInt; -import static com.xhpc.pp.utils.security.HexUtils.toHexIntX; @RestController public class ChargingController { @@ -74,7 +73,7 @@ public class ChargingController { CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString())); String rateModel = RateModelRequestLogic.translate(cacheRateModel); String rateModelMsg = "680E0000000A".concat(pileNo) - .concat(toHexIntX(Math.toIntExact(stationRateModelId))) + .concat(String.format("%04X", stationRateModelId)) .concat(rateModel) .concat(ServiceResult.HEX_OK); rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel)); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java index 8c4f9942..d142f793 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelRequestLogic.java @@ -43,7 +43,7 @@ public class RateModelRequestLogic implements ServiceLogic { CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(rateModelId.toString())); String rateModel = translate(cacheRateModel); String resultStr = "680E0000000A".concat(pileNo) - .concat(HexUtils.toHexIntX(Math.toIntExact(rateModelId))) + .concat(String.format("%04X", rateModelId)) .concat(rateModel) .concat(ServiceResult.HEX_OK); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java index f751ee70..e61253b0 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RateModelValidateLogic.java @@ -1,5 +1,6 @@ package com.xhpc.pp.logic; +import com.xhpc.common.api.dto.ChargingStationDto; import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.logic.ServiceLogic; @@ -25,16 +26,18 @@ public class RateModelValidateLogic implements ServiceLogic { Map req = sp.getParameters(); String pileNo = (String) req.get("pileNo"); - String rateModelId = (String) req.get("rateModelId"); - Map cachePile = REDIS.getCacheMap(pileNo); + String rateModelIdStr = (String) req.get("rateModelId"); + Map cachePile = REDIS.getCacheMap("pile:".concat(pileNo)); String resultCode = ServiceResult.OK; String hexCode = ServiceResult.HEX_OK; - Integer rateModelIdCache = cachePile.get("rateModelId"); - if (rateModelIdCache != Integer.parseInt(rateModelId, 16)) { + ChargingStationDto cacheStation = REDIS.getCacheObject("station:".concat(cachePile.get("stationId").toString())); + Long csRateModelId = cacheStation.getRateModelId(); + int rateModelId = Integer.parseInt(rateModelIdStr, 16); + if (csRateModelId.intValue() != rateModelId) { hexCode = ServiceResult.HEX_FAIL; resultCode = ServiceResult.FAIL; } - String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04d", rateModelIdCache)).concat(hexCode); + String resultStr = "680E00000006".concat(pileNo).concat(String.format("%04X", csRateModelId)).concat(hexCode); resultStr = resultStr.concat(CRCCalculator.calcCrc(resultStr)); return new ServiceResult(HexUtils.toBytes(resultStr), resultCode); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/HexUtils.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/HexUtils.java index 4d8f6572..983b5b8c 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/HexUtils.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/HexUtils.java @@ -16,11 +16,6 @@ public class HexUtils { return toHex(toIntBytes(String.format("%08d", dec), 8)); } - public static String toHexIntX(Integer dec) { - - return toHex(Objects.requireNonNull(toBytes(String.format("%04X", dec)))); - } - public static int reverseHexInt(String hex) { byte[] data = toBytes(reverseHex(hex)); @@ -185,8 +180,6 @@ public class HexUtils { public static void main(String[] args) { - System.out.println(toHexIntX(0xffff)); - System.out.println(toHexIntX(65535)); System.out.println(Integer.parseInt("FFFF", 16)); byte[] data1 = toBytes(reverseHex("FC080000")); System.out.println(toInteger(data1, 0, 4));