From 19c55902710e9e2a5a3c682700d501c2434eb512 Mon Sep 17 00:00:00 2001 From: ZZ Date: Mon, 23 Aug 2021 15:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=A1=A9=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xhpc/pp/controller/ChargingController.java | 12 +++++++++--- .../main/java/com/xhpc/pp/logic/RegisterLogic.java | 3 ++- .../java/com/xhpc/pp/server/ChargingPileServer.java | 4 ++-- 3 files changed, 13 insertions(+), 6 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 90bd9bab..cbf3bb9c 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 @@ -203,13 +203,16 @@ public class ChargingController { String pileNo = startChargingData.getPileNo(); ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo); - if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); + if (clientHandler == null) { + ChargingPileServer.removeHandler(pileNo); + return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); + } try { String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId()); Map cacheGun = REDIS.getCacheMap(gunkey); String gunstatus = (String) cacheGun.get("status"); if (!"空闲".equals(gunstatus)) { - return R.fail("充电桩不在空闲正常状态,稍后再试"); + return R.fail("充电桩不在空闲或正常状态,稍后再试"); } if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); String skey = gunkey.concat(".seqhex"); @@ -241,7 +244,10 @@ public class ChargingController { public R nativeStopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("gunId") String gunId, @PathVariable("version") String version) { ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo); - if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); + if (clientHandler == null) { + ChargingPileServer.removeHandler(pileNo); + return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); + } try { String gunkey = "gun:".concat(pileNo).concat(gunId); if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java index cf6c96af..1ca61561 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RegisterLogic.java @@ -48,8 +48,9 @@ public class RegisterLogic implements ServiceLogic { cachePile.put("status", REGISTERED); String localIPAndPort = getLocalIPAndPort(); cachePile.put("svcSrv", localIPAndPort); - REDIS.setCacheMap("pile:".concat(pileNo), cachePile); int gunNum = Integer.parseInt(req.get("gunNum").toString()); + cachePile.put("gunNum", gunNum); + REDIS.setCacheMap("pile:".concat(pileNo), cachePile); for (int gunN = 1; gunN <= gunNum; gunN++) { String gunId = String.format("%02d", gunN); String gunkey = "gun:".concat(pileNo.concat(gunId)); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileServer.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileServer.java index e31ea524..6a8d4b3d 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileServer.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileServer.java @@ -91,10 +91,10 @@ public class ChargingPileServer { Map cachePile = REDIS.getCacheMap(pkey); cachePile.put("status", DISCONNECTED); REDIS.setCacheMap(pkey, cachePile); - for (int i = 1; i <= 10; i++) { + for (int i = 1; i <= (int) cachePile.get("gunNum"); i++) { String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i)); Map cacheGun = REDIS.getCacheMap(gunkey); - if (cacheGun != null && !cacheGun.isEmpty()) { + if (!cacheGun.isEmpty()) { cacheGun.put("status", DISCONNECTED); REDIS.setCacheMap(gunkey, cacheGun); }