From 73d0e67213508c883700cf2e0cdcb9707e18e988 Mon Sep 17 00:00:00 2001 From: ZZ Date: Fri, 20 Aug 2021 14:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E6=98=AF=E7=AE=80=E5=8D=95=E6=8B=92?= =?UTF-8?q?=E7=BB=9D=E6=AF=94=E8=BE=83=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xhpc/pp/controller/ChargingController.java | 12 ++++++------ .../xhpc/pp/server/ChargingPileBinaryHandler.java | 6 ++++-- .../com/xhpc/pp/utils/security/CacheDataUtils.java | 4 ++-- 3 files changed, 12 insertions(+), 10 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 4e3320a9..07e4958f 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 @@ -173,11 +173,11 @@ public class ChargingController { } @PostMapping("native/charging/balance/refresh") - public R nativeRefreshBalance(@Validated @RequestBody StartChargingData refreshBalanceData) throws InterruptedException { + public R nativeRefreshBalance(@Validated @RequestBody StartChargingData refreshBalanceData) { String pileNo = refreshBalanceData.getPileNo(); String gunkey = "gun:".concat(pileNo).concat(refreshBalanceData.getGunId()); - if (CacheDataUtils.hori(gunkey)) Thread.sleep(500L);// return R.fail("等待上一条指令响应"); + if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); String skey = gunkey.concat(".seqhex"); String seq = seqHex(skey); String refreshBalanceMsg = "6817".concat(seq).concat("0042").concat(pileNo) @@ -212,7 +212,7 @@ public class ChargingController { if (!"空闲".equals(gunstatus)) { return R.fail("充电桩不在空闲正常状态,稍后再试"); } - if (CacheDataUtils.hori(gunkey)) Thread.sleep(500L); //return R.fail("等待上一条指令响应"); + if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); String skey = gunkey.concat(".seqhex"); String seq = seqHex(skey); byte[] msg = translateStart(startChargingData, seq); @@ -232,7 +232,7 @@ public class ChargingController { cacheGun.put("orderkey", orderkey); REDIS.setCacheMap(gunkey, cacheGun); return R.ok("指令已下发至充电桩"); - } catch (IOException | InterruptedException e) { + } catch (IOException e) { log.error("send message failed. " + e.getMessage(), e); return R.fail(e.getMessage()); } @@ -245,7 +245,7 @@ public class ChargingController { if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); try { String gunkey = "gun:".concat(pileNo).concat(gunId); - if (CacheDataUtils.hori(gunkey)) Thread.sleep(500L);//return R.fail("等待上一条指令响应"); + if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); String skey = gunkey.concat(".seqhex"); String seq = seqHex(skey); byte[] msg = translateStop(pileNo, gunId, version, seq); @@ -253,7 +253,7 @@ public class ChargingController { Map cacheGun = REDIS.getCacheMap(gunkey); REDIS.setCacheMap(gunkey, cacheGun); return R.ok("指令已下发至充电桩"); - } catch (IOException | InterruptedException e) { + } catch (IOException e) { log.error("send message failed. " + e.getMessage(), e); return R.fail(e.getMessage()); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java index 8003662e..c2c25730 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileBinaryHandler.java @@ -106,8 +106,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { if (result.getBinary() != null) { String gunId = (String) req.get("gunId"); if (gunId != null) { - String gunkey = "gun:".concat(pileNo).concat(gunId); - hori2(gunkey); + hori2(pileNo, gunId); } log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary())); handler.sendClientBinary(result.getBinary()); @@ -123,6 +122,9 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler { REDIS.setCacheMap(pilekey, cachePile); log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin); handler.sendClientBinary(HexUtils.toBytes(timebin)); + if (gunId != null) { + hori2(pileNo, gunId); + } cachePile.put("tcfg", true); REDIS.setCacheMap(pilekey, cachePile); } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/CacheDataUtils.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/CacheDataUtils.java index c9184bec..1ba85013 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/CacheDataUtils.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/utils/security/CacheDataUtils.java @@ -40,9 +40,9 @@ public class CacheDataUtils { return tarobj; } - public static void hori2(String gunkey) { + public static void hori2(String pileNo, String gunId) { - String hori = gunkey.concat(".hori"); + String hori = "gun:".concat(pileNo).concat(gunId).concat(".hori"); REDIS.setCacheObject(hori, "protection film", 300L, TimeUnit.MILLISECONDS); }