From ec40bfde744995797a5e82f0f8943dd0d660653c Mon Sep 17 00:00:00 2001 From: ZZ Date: Mon, 23 Aug 2021 11:53:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9E=AA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pp/controller/ChargingController.java | 43 +++++++++---------- .../com/xhpc/pp/logic/RealtimeDataLogic.java | 4 +- .../java/com/xhpc/pp/logic/RegisterLogic.java | 4 +- .../pp/server/ChargingPileEventHandler.java | 4 +- .../xhpc/pp/server/ChargingPileServer.java | 2 +- 5 files changed, 28 insertions(+), 29 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 07e4958f..90bd9bab 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 @@ -23,7 +23,9 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.io.IOException; +import java.util.Arrays; import java.util.Calendar; +import java.util.List; import java.util.Map; import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT; @@ -39,6 +41,7 @@ public class ChargingController { @Autowired private PowerPileService powerPileService; + private static List etable = Arrays.asList((new String[]{"离线", "故障"}).clone()); @PostMapping("test/pile/charging/order") public R test(@Validated @RequestBody StartChargingData startChargingData) { @@ -98,27 +101,23 @@ public class ChargingController { Long pileRateModelId = (Long) cachePile.get("rateModelId"); cachePile.put("rateModelId", pileRateModelId); if (!stationRateModelId.equals(pileRateModelId)) { - if (cachePile.get("status").toString().equals(REGISTERED)) { - CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString())); - String rateModel = RateModelRequestLogic.translate(cacheRateModel); - String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId()); - String skey = gunkey.concat(".seqhex"); - String seq = seqHex(skey); - String rateModelMsg = "680E".concat(seq).concat("0058").concat(pileNo) - .concat(String.format("%04X", stationRateModelId)) - .concat(rateModel); - rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel)); - String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg); - JSONObject responseJson = (JSONObject) JSON.parse(response); - assert responseJson != null; - int code = responseJson.getInteger("code"); - if (code != 200) { - r = R.fail(code, responseJson.getString("msg")); - } else { - r = R.fail(responseJson.get("data"), responseJson.getString("msg")); - } + CacheRateModel cacheRateModel = REDIS.getCacheObject("rateModel:".concat(stationRateModelId.toString())); + String rateModel = RateModelRequestLogic.translate(cacheRateModel); + String gunkey = "gun:".concat(pileNo).concat(startChargingData.getGunId()); + String skey = gunkey.concat(".seqhex"); + String seq = seqHex(skey); + String rateModelMsg = "680E".concat(seq).concat("0058").concat(pileNo) + .concat(String.format("%04X", stationRateModelId)) + .concat(rateModel); + rateModelMsg = rateModelMsg.concat(CRCCalculator.calcCrc(rateModel)); + String response = HttpUtils.post(fmt(svcSrv).concat("/native/pile/".concat(pileNo).concat("/rateModel")), rateModelMsg); + JSONObject responseJson = (JSONObject) JSON.parse(response); + assert responseJson != null; + int code = responseJson.getInteger("code"); + if (code != 200) { + r = R.fail(code, responseJson.getString("msg")); } else { - r = R.fail("充电桩离线,费率模型未更新或下发"); + r = R.fail(responseJson.get("data"), responseJson.getString("msg")); } } else { JSONObject json = (JSONObject) JSON.toJSON(startChargingData); @@ -135,8 +134,8 @@ public class ChargingController { return R.fail("充电桩未注册"); } String status = cachePile.get("status").toString(); - if (!REGISTERED.equals(status)) { - return R.fail("充电桩离线"); + if (etable.contains(status)) { + return R.fail("充电桩无法响应,状态:".concat(status)); } return R.ok(); } 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 4cef6e2a..bc13b110 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 @@ -36,7 +36,7 @@ public class RealtimeDataLogic implements ServiceLogic { private static Logger log = LoggerFactory.getLogger(RealtimeDataLogic.class); - public static final String[] stable = {"离线", "故障", "空闲", "充电"}; + public static final String[] stable = {"离线", "故障", "空闲", "充电中"}; public static final String[] pvgstable = {"否", "是", "未知"}; private static final String[] hftable = {"急停按钮动作故障", "无可用整流模块", "出风口温度过高", "交流防雷故障", "交直流模块DC20通信中断", "绝缘检测模块FC08通信中断", "电度表通信中断", "读卡器通信中断", "RC10通信中断", "风扇调速板故障", "直流熔断器故障", "高压接触器故障", "门打开"}; @@ -77,7 +77,7 @@ public class RealtimeDataLogic implements ServiceLogic { String stationTermStatusKey = "stationTerminalStatus:".concat(cachePile.get("stationId").toString()); String statusOrSOC; Integer socInt = Integer.parseInt(soc, 16); - if (statusplain.equals("充电")) { + if (statusplain.equals("充电中")) { statusOrSOC = socInt.toString(); } else { statusOrSOC = statusplain; 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 856f3e1b..cf6c96af 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 @@ -22,8 +22,8 @@ import static com.xhpc.pp.server.ChargingPileServer.REDIS; @Component("RegisterLogic") public class RegisterLogic implements ServiceLogic { - public static final String DISCONNECTED = "Disconnected"; - public static final String REGISTERED = "Registered"; + public static final String DISCONNECTED = "离线"; + public static final String REGISTERED = "已注册"; private static Logger log = LoggerFactory.getLogger(RegisterLogic.class); @Override diff --git a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileEventHandler.java b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileEventHandler.java index 2dfc2447..a45a38d0 100644 --- a/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileEventHandler.java +++ b/xhpc-modules/xhpc-power-pile/src/main/java/com/xhpc/pp/server/ChargingPileEventHandler.java @@ -1,6 +1,5 @@ package com.xhpc.pp.server; -import com.xhpc.pp.logic.RegisterLogic; import org.quickserver.net.server.ClientEventHandler; import org.quickserver.net.server.ClientHandler; import org.slf4j.Logger; @@ -10,6 +9,7 @@ import org.springframework.stereotype.Component; import java.util.Map; +import static com.xhpc.pp.logic.RegisterLogic.DISCONNECTED; import static com.xhpc.pp.server.ChargingPileServer.REDIS; @Lazy(false) @@ -46,7 +46,7 @@ public class ChargingPileEventHandler implements ClientEventHandler { ChargingPileServer.removeHandler(pileNo); String pkey = "pile:".concat(pileNo); Map cachePile = REDIS.getCacheMap(pkey); - cachePile.put("status", RegisterLogic.DISCONNECTED); + cachePile.put("status", DISCONNECTED); REDIS.setCacheMap(pkey, cachePile); handler.closeConnection(); log.info("-> ({}) - [{}] <- {}", pileNo, handler.getName(), handler.getSocket().getRemoteSocketAddress().toString()); 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 c7f77483..2fab2346 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 @@ -95,7 +95,7 @@ public class ChargingPileServer { String gunkey = "gun:".concat(pileNo).concat(String.format("%02d", i)); Map cacheGun = REDIS.getCacheMap(gunkey); if (cacheGun != null) { - cacheGun.put("status", "离线"); + cacheGun.put("status", DISCONNECTED); REDIS.setCacheMap(gunkey, cacheGun); } }