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); }