还是简单拒绝比较好

This commit is contained in:
ZZ 2021-08-20 14:56:27 +08:00
parent 78d9a4ccc1
commit 73d0e67213
3 changed files with 12 additions and 10 deletions

View File

@ -173,11 +173,11 @@ public class ChargingController {
} }
@PostMapping("native/charging/balance/refresh") @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 pileNo = refreshBalanceData.getPileNo();
String gunkey = "gun:".concat(pileNo).concat(refreshBalanceData.getGunId()); 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 skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
String refreshBalanceMsg = "6817".concat(seq).concat("0042").concat(pileNo) String refreshBalanceMsg = "6817".concat(seq).concat("0042").concat(pileNo)
@ -212,7 +212,7 @@ public class ChargingController {
if (!"空闲".equals(gunstatus)) { if (!"空闲".equals(gunstatus)) {
return R.fail("充电桩不在空闲正常状态,稍后再试"); 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 skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
byte[] msg = translateStart(startChargingData, seq); byte[] msg = translateStart(startChargingData, seq);
@ -232,7 +232,7 @@ public class ChargingController {
cacheGun.put("orderkey", orderkey); cacheGun.put("orderkey", orderkey);
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
return R.ok("指令已下发至充电桩"); return R.ok("指令已下发至充电桩");
} catch (IOException | InterruptedException e) { } catch (IOException e) {
log.error("send message failed. " + e.getMessage(), e); log.error("send message failed. " + e.getMessage(), e);
return R.fail(e.getMessage()); return R.fail(e.getMessage());
} }
@ -245,7 +245,7 @@ public class ChargingController {
if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器"); if (clientHandler == null) return R.fail("充电桩没有连接到上次注册的服务器");
try { try {
String gunkey = "gun:".concat(pileNo).concat(gunId); 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 skey = gunkey.concat(".seqhex");
String seq = seqHex(skey); String seq = seqHex(skey);
byte[] msg = translateStop(pileNo, gunId, version, seq); byte[] msg = translateStop(pileNo, gunId, version, seq);
@ -253,7 +253,7 @@ public class ChargingController {
Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey); Map<String, Object> cacheGun = REDIS.getCacheMap(gunkey);
REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(gunkey, cacheGun);
return R.ok("指令已下发至充电桩"); return R.ok("指令已下发至充电桩");
} catch (IOException | InterruptedException e) { } catch (IOException e) {
log.error("send message failed. " + e.getMessage(), e); log.error("send message failed. " + e.getMessage(), e);
return R.fail(e.getMessage()); return R.fail(e.getMessage());
} }

View File

@ -106,8 +106,7 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
if (result.getBinary() != null) { if (result.getBinary() != null) {
String gunId = (String) req.get("gunId"); String gunId = (String) req.get("gunId");
if (gunId != null) { if (gunId != null) {
String gunkey = "gun:".concat(pileNo).concat(gunId); hori2(pileNo, gunId);
hori2(gunkey);
} }
log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary())); log.info("server send msg >>>> ({}) |{}|", pileNo, toHex(result.getBinary()));
handler.sendClientBinary(result.getBinary()); handler.sendClientBinary(result.getBinary());
@ -123,6 +122,9 @@ public class ChargingPileBinaryHandler implements ClientBinaryHandler {
REDIS.setCacheMap(pilekey, cachePile); REDIS.setCacheMap(pilekey, cachePile);
log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin); log.info("server send time config msg >>>> ({}) |{}|", pileNo, timebin);
handler.sendClientBinary(HexUtils.toBytes(timebin)); handler.sendClientBinary(HexUtils.toBytes(timebin));
if (gunId != null) {
hori2(pileNo, gunId);
}
cachePile.put("tcfg", true); cachePile.put("tcfg", true);
REDIS.setCacheMap(pilekey, cachePile); REDIS.setCacheMap(pilekey, cachePile);
} }

View File

@ -40,9 +40,9 @@ public class CacheDataUtils {
return tarobj; 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); REDIS.setCacheObject(hori, "protection film", 300L, TimeUnit.MILLISECONDS);
} }