From b4e7bb990df01dffc48e8adcbcf0d254978e7253 Mon Sep 17 00:00:00 2001 From: zz Date: Tue, 15 Mar 2022 14:46:56 +0800 Subject: [PATCH] stop invalid order --- .../pp/controller/ChargingController.java | 29 ++++++++++++++----- .../xhpc/pp/controller/PileController.java | 2 +- .../com/xhpc/pp/logic/OrderDataLogic.java | 10 ++++++- 3 files changed, 32 insertions(+), 9 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 41d48016..e44dd3bc 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 @@ -207,7 +207,7 @@ public class ChargingController { refreshBalanceMsg = refreshBalanceMsg.concat(CRCCalculator.calcCrc(refreshBalanceMsg)); ClientHandler handler = getHandler(pileNo); R r; - if (handler != null) { //todo 余额下发重试机制 + if (handler != null && handler.isOpen()) { //todo 余额下发重试机制 if (!handler.isOpen()) { log.error("[{}]({}) connection lost", handler.getName(), pileNo); removeHandler(pileNo); @@ -235,6 +235,11 @@ public class ChargingController { String pileNo = startChargingData.getPileNo(); ClientHandler handler = ChargingPileServer.getHandler(pileNo); if (handler == null) { + try { + handler.closeConnection(); + } catch (Exception e) { + log.error("invalid conn [{}]", handler.getName()); + } return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); } else if (!handler.isOpen()) { log.error("[{}]({}) connection lost", handler.getName(), pileNo); @@ -290,7 +295,11 @@ public class ChargingController { ClientHandler handler = ChargingPileServer.getHandler(pileNo); if (handler == null) { -// ChargingPileServer.removeHandler(pileNo); + try { + handler.closeConnection(); + } catch (Exception e) { + log.error("invalid conn [{}]", handler.getName()); + } return R.fail("充电桩没有连接到上次注册的服务器,请稍后再试一次"); } try { @@ -321,7 +330,7 @@ public class ChargingController { String pileNo = orderNo.substring(0, 14); ClientHandler handler = ChargingPileServer.getHandler(pileNo); - if (handler != null) { + if (handler != null && handler.isOpen()) { try { String connectorId = pileNo.substring(0, 16); String gunkey = "gun:".concat(connectorId); @@ -333,16 +342,22 @@ public class ChargingController { removeHandler(pileNo); } else { String orderkey = REDIS.getCacheMapValue(gunkey, "orderkey"); - Integer sts = REDIS.getCacheMapValue(orderkey, "sts"); - if (orderkey != null && orderNo.equals(orderkey.substring(6)) && (sts == null)) { +// Integer sts = REDIS.getCacheMapValue(orderkey, "sts"); + if (orderkey != null && orderNo.equals(orderkey.substring(6))) {// && (sts == null)) { handler.sendClientBinary(msg); log.error("invalid orderNo [{}], stop msg sent to pile |{}|", pileNo, HexUtils.toHex(msg)); - REDIS.setCacheMapValue(orderkey, "sts", 1); +// REDIS.setCacheMapValue(orderkey, "sts", 1); } } } catch (IOException e) { - log.error("send message failed. " + e.getMessage(), e); + try { + handler.closeConnection(); + } catch (Exception e1) { + log.error("invalid conn [{}]", handler.getName()); + } } + } else if (handler != null) { + handler.closeConnection(); } } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java index b6ccee03..96319ea3 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/controller/PileController.java @@ -69,7 +69,7 @@ public class PileController { ClientHandler handler = getHandler(pileNo); R r; - if (handler != null) { + if (handler != null && handler.isOpen()) { if (!handler.isOpen()) { log.error("send message failed. [{}]({}) connection lost", handler.getName(), pileNo); removeHandler(pileNo); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/OrderDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/OrderDataLogic.java index c041c25c..fdcd18a3 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/OrderDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/OrderDataLogic.java @@ -6,6 +6,7 @@ import com.xhpc.common.api.PileOrderService; import com.xhpc.common.core.domain.R; import com.xhpc.common.data.redis.CacheOrderData; import com.xhpc.common.data.up.OrderData; +import com.xhpc.pp.controller.ChargingController; import com.xhpc.pp.tx.ServiceParameter; import com.xhpc.pp.tx.ServiceResult; import com.xhpc.pp.tx.logic.ServiceLogic; @@ -33,6 +34,8 @@ public class OrderDataLogic implements ServiceLogic { @Autowired private PileOrderService pileOrderService; + @Autowired + private ChargingController chargingController; @Override public ServiceResult service(ServiceParameter sp) throws Exception { @@ -76,8 +79,13 @@ public class OrderDataLogic implements ServiceLogic { final R r = pileOrderService.pileEndOrder(orderNo); if (r.getCode() == 200) return new ServiceResult(HexUtils.toBytes(resultStr), ServiceResult.OK); - else + else { + String msg = r.getMsg(); + if (msg != null && msg.contains("无效订单")) { + chargingController.stopInvalidOrder(pileNo); + } return new ServiceResult(ServiceResult.FAIL); + } } private CacheOrderData translate(OrderData orderData) throws InvocationTargetException, IllegalAccessException, InstantiationException {