From acef56864eb9678b3fc239184ce9093739319dbe Mon Sep 17 00:00:00 2001 From: Lemon Date: Mon, 14 Aug 2023 11:41:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=20=E6=A1=A9=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=95=B0=E6=8D=AE=20=E6=95=85=E9=9A=9C=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jsowell/common/constant/CacheConstants.java | 5 +++++ .../netty/handler/UploadRealTimeMonitorHandler.java | 13 +++++++++++++ .../service/impl/PileConnectorInfoServiceImpl.java | 12 ++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java index 31b621df0..3166e05ca 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -143,6 +143,11 @@ public class CacheConstants { */ public static final String AUTHORIZER_REFRESH_TOKEN = "authorizer_refresh_token:"; + /** + * 桩硬件故障 + */ + public static final String PILE_HARDWARE_FAULT = "pile_hardware_fault:"; + /** * 充电桩sn生成 key */ diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java index ea85d9d70..fa4211dd9 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/handler/UploadRealTimeMonitorHandler.java @@ -3,9 +3,11 @@ package com.jsowell.netty.handler; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.google.common.collect.Lists; +import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.core.domain.ykc.RealTimeMonitorData; import com.jsowell.common.core.domain.ykc.YKCDataProtocol; import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.enums.ykc.OrderStatusEnum; import com.jsowell.common.enums.ykc.YKCPileFaultReasonEnum; import com.jsowell.common.util.BytesUtil; @@ -25,6 +27,7 @@ import org.springframework.stereotype.Component; import java.util.Date; import java.util.Map; import java.util.Objects; +import java.util.concurrent.TimeUnit; /** * 获取桩上传的实时监测数据 @@ -59,6 +62,9 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler { @Autowired private IThirdPartyStationRelationService thirdPartyStationRelationService; + @Autowired + private RedisCache redisCache; + @Override public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) { log.info("[===获取桩上传的实时监测数据===] param:{}, channel:{}", JSONObject.toJSONString(ykcDataProtocol), channel.toString()); @@ -248,6 +254,13 @@ public class UploadRealTimeMonitorHandler extends AbstractHandler { // 公共方法修改状态 pileBasicInfoService.updateStatus(BytesUtil.bcd2Str(ykcDataProtocol.getFrameType()), pileSn, connectorCode, connectorStatus, putGunType); + // 01表示故障 + if (StringUtils.equals(connectorStatus, "01")) { + // 故障原因存入缓存 + String redisKey = CacheConstants.PILE_HARDWARE_FAULT + pileSn + connectorCode; + redisCache.setCacheObject(redisKey, faultReason, 5, TimeUnit.MINUTES); + } + // 03表示充电中 if (StringUtils.equals(connectorStatus, "03")) { // 充电时保存实时数据到redis diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java index f37426b93..09a79d041 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileConnectorInfoServiceImpl.java @@ -474,12 +474,16 @@ public class PileConnectorInfoServiceImpl implements IPileConnectorInfoService { BigDecimal instantPowerTemp = outputVoltage.multiply(outputCurrent); BigDecimal instantPower = instantPowerTemp.divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP); pileConnectorInfoVO.setInstantPower(instantPower); - // 如果故障,添加故障原因 - if (!StringUtils.equals("无", realTimeMonitorData.getHardwareFault())) { - pileConnectorInfoVO.setFaultReason(realTimeMonitorData.getHardwareFault()); - } + log.info("枪口实时数据:{}", JSONObject.toJSONString(pileConnectorInfoVO)); } + // 查缓存是否故障 + String redisKey = CacheConstants.PILE_HARDWARE_FAULT + pileConnectorInfoVO.getPileConnectorCode(); + String faultReason = redisCache.getCacheObject(redisKey); + // 如果不为空,set 数据 + if (StringUtils.isNotBlank(faultReason)) { + pileConnectorInfoVO.setFaultReason(faultReason); + } if (checkPileOffLine(pileConnectorInfoVO.getPileSn())) { // 最后收到消息的时间在1分钟前,则返回给前端枪口离线