充电桩状态字段处理逻辑完善

This commit is contained in:
ZZ 2021-08-23 15:17:13 +08:00
parent 0b2de8b5a4
commit 19c5590271
3 changed files with 13 additions and 6 deletions

View File

@ -203,13 +203,16 @@ public class ChargingController {
String pileNo = startChargingData.getPileNo(); String pileNo = startChargingData.getPileNo();
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo); ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); if (clientHandler == null) {
ChargingPileServer.removeHandler(pileNo);
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
}
try { try {
String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId()); String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId());
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey); Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
String gunstatus = (String) cacheGun.get("status"); String gunstatus = (String) cacheGun.get("status");
if (!"空闲".equals(gunstatus)) { if (!"空闲".equals(gunstatus)) {
return R.fail("充电桩不在空闲正常状态,稍后再试"); return R.fail("充电桩不在空闲正常状态,稍后再试");
} }
if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应");
String skey = gunkey.concat(".seqhex"); 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) { public R nativeStopCharging(@PathVariable("pileNo") String pileNo, @PathVariable("gunId") String gunId, @PathVariable("version") String version) {
ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo); ClientHandler clientHandler = ChargingPileServer.getHandler(pileNo);
if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); if (clientHandler == null) {
ChargingPileServer.removeHandler(pileNo);
return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次");
}
try { try {
String gunkey = "gun:".concat(pileNo).concat(gunId); String gunkey = "gun:".concat(pileNo).concat(gunId);
if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应"); if (CacheDataUtils.hori(gunkey)) return R.fail("等待上一条指令响应");

View File

@ -48,8 +48,9 @@ public class RegisterLogic implements ServiceLogic {
cachePile.put("status", REGISTERED); cachePile.put("status", REGISTERED);
String localIPAndPort = getLocalIPAndPort(); String localIPAndPort = getLocalIPAndPort();
cachePile.put("svcSrv", localIPAndPort); cachePile.put("svcSrv", localIPAndPort);
REDIS.setCacheMap("pile:".concat(pileNo), cachePile);
int gunNum = Integer.parseInt(req.get("gunNum").toString()); 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++) { for (int gunN = 1; gunN <= gunNum; gunN++) {
String gunId = String.format("%02d", gunN); String gunId = String.format("%02d", gunN);
String gunkey = "gun:".concat(pileNo.concat(gunId)); String gunkey = "gun:".concat(pileNo.concat(gunId));

View File

@ -91,10 +91,10 @@ public class ChargingPileServer {
Map<String, Object> cachePile = REDIS.getCacheMap(pkey); Map<String, Object> cachePile = REDIS.getCacheMap(pkey);
cachePile.put("status", DISCONNECTED); cachePile.put("status", DISCONNECTED);
REDIS.setCacheMap(pkey, cachePile); 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)); String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i));
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey); Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
if (cacheGun != null && !cacheGun.isEmpty()) { if (!cacheGun.isEmpty()) {
cacheGun.put("status", DISCONNECTED); cacheGun.put("status", DISCONNECTED);
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
} }