From fd9e21524500424dec4ea86225b3529533f3ff7f Mon Sep 17 00:00:00 2001 From: ZZ Date: Wed, 24 Nov 2021 13:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AE=A2=E5=8D=95=E5=90=AF/?= =?UTF-8?q?=E5=81=9C/=E5=BC=82=E5=B8=B8/=E6=8E=A8=E9=80=81=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NotificationStartChargeResultTask.java | 31 +++++++----- .../NotificationStopChargeResultTask.java | 10 ++-- .../com/xhpc/pp/logic/RealtimeDataLogic.java | 48 +++++++++++-------- .../pp/logic/RemoteStartReplyDataLogic.java | 7 +-- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStartChargeResultTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStartChargeResultTask.java index 5a04bbe0..37b8e12c 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStartChargeResultTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStartChargeResultTask.java @@ -28,33 +28,34 @@ public class NotificationStartChargeResultTask extends CoreDispatcher { @Autowired private AuthSecretTokenRepository authSecretTokenRepository; - - private Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class); + private final Logger logger = LoggerFactory.getLogger(NotificationStartChargeResultTask.class); /** * Judging the 3rd whether it has got the start charging task. */ - @Scheduled(fixedRate = 1000 * 20) + @Scheduled(fixedRate = 1000 * 3) public void run() throws IOException { //Getting the charge orders which from 3rd. Collection pushOrderKeys = REDIS.keys("pushOrder:*"); for (String pushOrderKey : pushOrderKeys) { Map pushOrder = REDIS.getCacheMap(pushOrderKey); - if (null != pushOrder) { + if ((Integer) pushOrder.get("startChargeSeqStat") > 1) { Integer startChargeNotificationStat = (Integer) pushOrder.get("startChargeNotificationStat"); if (null != startChargeNotificationStat && 1 != startChargeNotificationStat && startChargeNotificationStat <= 20) { String startChargeSeq = (String) pushOrder.get("internetSerialNumber"); String operatorId = startChargeSeq.substring(0, 9); - Optional authSecretToken = authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, SECRET_TOKEN_TYPE_OUT); + Optional authSecretToken = + authSecretTokenRepository.findByOperatorId3irdptyAndSecretTokenType(operatorId, + SECRET_TOKEN_TYPE_OUT); if (authSecretToken.isPresent()) { - NotificationStartChargeResultRequestData notificationStartChargeResultRequestData = new NotificationStartChargeResultRequestData(); + NotificationStartChargeResultRequestData notificationStartChargeResultRequestData = + new NotificationStartChargeResultRequestData(); notificationStartChargeResultRequestData.setStartTime((String) pushOrder.get("startTime")); notificationStartChargeResultRequestData.setStartChargeSeq(startChargeSeq); notificationStartChargeResultRequestData.setConnectorId((String) pushOrder.get("connectorID")); - REDIS.setCacheMapValue(pushOrderKey, "startChargeSeqStat", 2); - pushOrder.put("startChargeSeqStat", 2); - notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get("startChargeSeqStat")); + notificationStartChargeResultRequestData.setStartChargeSeqStat((Integer) pushOrder.get( + "startChargeSeqStat")); notify(notificationStartChargeResultRequestData, authSecretToken.get(), pushOrderKey.substring(10)); } } @@ -63,7 +64,8 @@ public class NotificationStartChargeResultTask extends CoreDispatcher { } //Notifying others platform. - public void notify(NotificationStartChargeResultRequestData notificationStartChargeResultRequestData, AuthSecretToken authSecretTokenOut, String orderNo) throws IOException { + public void notify(NotificationStartChargeResultRequestData notificationStartChargeResultRequestData, + AuthSecretToken authSecretTokenOut, String orderNo) throws IOException { String operatorIdEvcs = "MA6DFCTD5"; String data = JSONUtil.toJSONString(notificationStartChargeResultRequestData); @@ -73,22 +75,25 @@ public class NotificationStartChargeResultTask extends CoreDispatcher { String responseBody = ok(commonRequest, "/notification_start_charge_result", authSecretTokenOut); NotificationStartStopChargeResultResponse notificationStartStopChargeResultResponse = DTOJsonHelper.parseResponseData(responseBody, - NotificationStartStopChargeResultResponse.class, authSecretTokenOut); + NotificationStartStopChargeResultResponse.class, authSecretTokenOut); if (null != notificationStartStopChargeResultResponse) { //Ensuring that only when startChargeNotificationStat equals 1 won't be notified. if (notificationStartStopChargeResultResponse.getSuccStat() == 0) { REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", 1); } else { - Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat"); + Integer startChargeNotificationStat = REDIS.getCacheMapValue("pushOrder:".concat(orderNo), + "startChargeNotificationStat"); if (startChargeNotificationStat == 0) { startChargeNotificationStat = 2; } else { ++startChargeNotificationStat; } - REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", startChargeNotificationStat); + REDIS.setCacheMapValue("pushOrder:".concat(orderNo), "startChargeNotificationStat", + startChargeNotificationStat); throw new RuntimeException(String.format("push CD start charge order status [%s] failed: %s", notificationStartChargeResultRequestData.getStartChargeSeq(), responseBody)); } } } + } diff --git a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStopChargeResultTask.java b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStopChargeResultTask.java index 7ebcd838..dad5b675 100644 --- a/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStopChargeResultTask.java +++ b/evcs-modules/evcs-core/src/main/java/com/xhpc/evcs/notification/NotificationStopChargeResultTask.java @@ -50,8 +50,8 @@ public class NotificationStopChargeResultTask extends CoreDispatcher { String orderNo = pushOrderKey.substring(10); String orderkey = "order:".concat(orderNo); CacheOrderData orderData = REDIS.getCacheMapValue(orderkey, "orderData"); - if (orderData != null) { - Map pushOrder = REDIS.getCacheMap(pushOrderKey); + Map pushOrder = REDIS.getCacheMap(pushOrderKey); + if (orderData != null || (Integer) pushOrder.get("startChargeSeqStat") > 3) { Boolean isStopNotified = (Boolean) pushOrder.get("isStopNotified"); if (isStopNotified == null || !isStopNotified) { String internetSerialNumber = (String) pushOrder.get("internetSerialNumber"); @@ -63,11 +63,9 @@ public class NotificationStopChargeResultTask extends CoreDispatcher { ChargeResultRequest chargeResultRequest = new ChargeResultRequest(); chargeResultRequest.setStartChargeSeq(internetSerialNumber); //使用指定包装类封装数据 - chargeResultRequest.setConnectorID(orderData.getPileNo() + orderData.getGunId()); - int succStat = 0; - int failReason = 0; + chargeResultRequest.setConnectorID(orderkey.substring(0, 16)); chargeResultRequest.setStartChargeSeqStat(4); - chargeResultRequest.setSuccStat(succStat); + chargeResultRequest.setSuccStat(0); chargeResultRequest.setFailReason(3); //将其转换为json String jsonData = JSONUtil.toJSONString(chargeResultRequest); diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java index 5fe83129..fdc8fab0 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RealtimeDataLogic.java @@ -29,7 +29,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static cn.hutool.core.util.NumberUtil.isInteger; import static com.xhpc.common.data.redis.StaticBeanUtil.REDIS; import static com.xhpc.pp.server.ChargingPileServer.default_version; import static com.xhpc.pp.utils.HexUtils.reverseHexInt; @@ -191,48 +190,57 @@ public class RealtimeDataLogic implements ServiceLogic { R r = null; if (cacheRData == null) { r = pileOrderService.abnormalOrder(orderNo); + cacheOrder.put("abnormal", "1.1");//lord is null + log.error("abnormal.1 order[{}]", orderNo); } else { CacheOrderData lordAsOd = new CacheOrderData(cacheRData, (String) cacheOrder.get("orderstarttime"), (Integer) cacheOrder.get("startSoc"), (Integer) cacheOrder.get("stopSoc")); cacheOrder.put("orderData", lordAsOd); r = pileOrderService.pileEndOrder(orderNo); REDIS.setCacheMap(orderkey, cacheOrder); + cacheOrder.put("abnormal", "1.2");//lord as orderData + log.error("abnormal.1.2 order[{}]", orderNo); } if (r == null || r.getCode() != 200) { log.error("errorfreecnt r{}", JSONUtil.toJsonStr(r)); errorfreecnt = 1; } - cacheOrder.put("abnormal.1", "lord as order data"); - log.error("abnormal.1 order[{}]", orderNo); } cacheOrder.put("errorfreecnt", errorfreecnt); } REDIS.setCacheMap(orderkey, cacheOrder); } else { orderkey = (String) cacheGun.get("orderkey"); - if (orderkey != null) { - Integer idleCnt = (Integer) cacheGun.get("idleCnt"); + Integer idleCnt = (Integer) cacheGun.get("idleCnt"); + if (orderkey != null && statusInt != 3) { idleCnt = idleCnt == null ? 0 : idleCnt; idleCnt++; - if (idleCnt > 3) { - if (orderkey != null && orderkey.length() > 0) { + if (idleCnt >= 2) { + if (orderkey.length() > 0) { Map problematicOrder = REDIS.getCacheMap(orderkey); - Object orderData = problematicOrder.get("orderData"); - String status = (String) problematicOrder.get("status"); - if (!isInteger(status) && !status.equals("充电中") && orderData == null) { - String lorder = orderkey.replace("order:", ""); - pileOrderService.abnormalOrder(lorder); - log.error("abnormal.2 order[{}]", lorder); - cacheGun.put("orderkey", null); - idleCnt = 0; + CacheRealtimeData cacheRealtimeData = REDIS.getCacheObject(orderkey.concat(".lord")); + if (problematicOrder != null && cacheRealtimeData != null) { + Integer startSoc = (Integer) problematicOrder.get("startSoc"); + Integer endSoc = (Integer) problematicOrder.get("endSoc"); + problematicOrder.put("orderData", new CacheOrderData(cacheRealtimeData, + (String) problematicOrder.get("startTime"), + startSoc == null ? 0 : startSoc, endSoc == null ? 0 : endSoc)); + log.error("abnormal.2.1 order[{}]", orderNo); + cacheOrder.put("abnormal", "2.1"); + } else { + log.error("abnormal.2.2 order[{}]", orderNo); + cacheOrder.put("abnormal", "2.2");//not respond + REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 4); } -// } else { -// Collection cacheOrderKyes = REDIS.keys("order:".concat(terminalId).concat("*")); -// for (String cacheOrderKye : cacheOrderKyes) { //todo ??? -// -// } + orderNo = orderkey.replace("order:", ""); + pileOrderService.abnormalOrder(orderNo); + cacheGun.put("orderkey", null); + idleCnt = 0; + cacheGun.put("idleCnt", idleCnt); } } + } else { + idleCnt = 0; cacheGun.put("idleCnt", idleCnt); } } diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RemoteStartReplyDataLogic.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RemoteStartReplyDataLogic.java index d498405e..bcd896e2 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RemoteStartReplyDataLogic.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/logic/RemoteStartReplyDataLogic.java @@ -25,8 +25,8 @@ import static com.xhpc.pp.tx.ServiceResult.HEX_01; @Component("RemoteStartReplyDataLogic") public class RemoteStartReplyDataLogic implements ServiceLogic { - private static Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class); - private static Map frs; + private static final Logger log = LoggerFactory.getLogger(RemoteStartReplyDataLogic.class); + private static final Map frs; static { frs = new HashMap<>(); @@ -65,8 +65,9 @@ public class RemoteStartReplyDataLogic implements ServiceLogic { REDIS.setCacheMap(gunkey, cacheGun); REDIS.setCacheMap(orderkey, cacheOrder); pileOrderService.pileStartup(orderNo, 1, "启动充电成功"); + REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 2); } else { - + REDIS.setCacheMapValue(orderkey.replace("order:", "pushOrder:"), "startChargeSeqStat", 4); final String remark = frs.get(remoteStartReplyData.getFailReason()); pileOrderService.pileStartup(orderNo, 2, remark == null ? "未知错误" : remark); }