diff --git a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java index 2af0370b..a6524184 100644 --- a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java @@ -2066,6 +2066,9 @@ RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateB // warningData: WARNING_DATA(0, "warningData:"), + // deviceDiagnostics: + DEVICE_DIAGNOSTICS(0, "deviceDiagnostics:"), + // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet EXPORT_THE_TEMPLATE_CONTENT_TYPE(0, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:"), diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java index 1f24b6e8..469b2d7a 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java @@ -1,7 +1,5 @@ package com.zc.business.service.impl; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.AjaxResult; @@ -16,24 +14,19 @@ import com.zc.business.domain.Device; import com.zc.business.enums.UniversalEnum; import com.zc.business.mapper.DcSwitchMapper; import com.zc.business.service.DcSwitchService; -import com.zc.business.service.IDcDeviceService; -import javafx.scene.control.TableView; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.io.IOException; import java.math.BigDecimal; import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -51,6 +44,7 @@ public class DcSwitchServiceImpl extends ServiceImpl i @Resource private RedisCache redisCache; + private static final String DEVICEDIAGNOSTICS = UniversalEnum.DEVICE_DIAGNOSTICS.getValue();//redis事件缓存的key,设备诊断 /** * 查询交换机 */ @@ -184,16 +178,23 @@ public class DcSwitchServiceImpl extends ServiceImpl i @Override public AjaxResult deviceDiagnostics(Device device) throws Exception { String deviceIp = device.getDeviceIp(); + RedisCache redisCache = SpringUtils.getBean(RedisCache.class); + String cacheObject = redisCache.getCacheObject(DEVICEDIAGNOSTICS+deviceIp);//获取缓存是否存在诊断结果 + if (StringUtils.isNotBlank(cacheObject)){ //存在即返回 + return AjaxResult.success(cacheObject); + } String[] parts = deviceIp.split("\\."); parts[3] = "254"; String newDeviceIp = String.join(".", parts);//设备网关 InetAddress deviceGateway = InetAddress.getByName(newDeviceIp); if (!deviceGateway.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备网关网络异常",2, TimeUnit.MINUTES); return AjaxResult.success("设备网关网络异常"); } List dcDeviceId = dcSwitchMapper.getDcDeviceId(deviceIp);//查询设备id DcDevice dcDevice = new DcDevice();//存放设备id if (dcDeviceId.size()>1){ + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备IP存在冲突",2, TimeUnit.MINUTES); return AjaxResult.success("设备IP存在冲突"); }else { for (DcDevice dcDeviceValue:dcDeviceId){ @@ -207,33 +208,43 @@ public class DcSwitchServiceImpl extends ServiceImpl i .filter(dcSwitch -> dcSwitch.getDeviceList().contains(deviceIdString)) .findFirst().map(DcSwitch::getSwitchIp).orElse(null); if (StringUtils.isBlank(switchIp)){ //switchIp为空不存在交换机ip + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"未查询到相关的二层交换机",2, TimeUnit.MINUTES); return AjaxResult.success("未查询到相关的二层交换机"); } List switchList = dcSwitchMapper.getSwitchName(switchIp); if (switchList.size()!=1){ + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"二层交换机IP存在冲突",2, TimeUnit.MINUTES); return AjaxResult.success("二层交换机IP存在冲突"); }else { for (DcSwitch switchListValue:switchList) { InetAddress newSwitchIp = InetAddress.getByName(switchIp); if (!newSwitchIp.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备二层交换机"+switchListValue.getSwitchName()+"网络异常",2, TimeUnit.MINUTES); return AjaxResult.success("设备二层交换机"+switchListValue.getSwitchName()+"网络异常"); } } } InetAddress newDeviceIpCurrent = InetAddress.getByName(deviceIp);//传入的当前设备ip if (!newDeviceIpCurrent.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"当前设备ip"+deviceIp+"网络异常",2, TimeUnit.MINUTES); return AjaxResult.success("当前设备ip"+deviceIp+"网络异常"); } DcSwitch stakeMark = dcSwitchMapper.getStakeMark(switchIp);//交换机桩号 DcDevice iotDevice = dcSwitchMapper.getIotDeviceIdAndIp(stakeMark.getStakeMark());//拿出设备箱的物联id和ip + if (iotDevice==null){ + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"未查询出交换机该桩号下设备箱相关信息",2, TimeUnit.MINUTES); + return AjaxResult.success("未查询出交换机该桩号下设备箱相关信息"); + } String iotDeviceIp = iotDevice.getDeviceIp();//设备箱ip InetAddress newIotDeviceIp = InetAddress.getByName(iotDeviceIp);//传入关联的设备箱的ip if (!newIotDeviceIp.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备箱已离线",2, TimeUnit.MINUTES); return AjaxResult.success("设备箱已离线"); } DcDeviceController dcDeviceController = SpringUtils.getBean(DcDeviceController.class); AjaxResult deviceLatestProperty = dcDeviceController.getDeviceLatestProperty(iotDevice.getIotDeviceId(), "1ac"); if (deviceLatestProperty==null||deviceLatestProperty.get("data")==null){ + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备箱未上传数据",2, TimeUnit.MINUTES); return AjaxResult.success("设备箱未上传数据"); } JSONObject data = (JSONObject) deviceLatestProperty.get("data"); @@ -242,8 +253,10 @@ public class DcSwitchServiceImpl extends ServiceImpl i BigDecimal voltageBigDecimal = new BigDecimal(voltageStr); int ac_out_voltage_1 = voltageBigDecimal.setScale(0, BigDecimal.ROUND_DOWN).intValue(); //支路1,220V电压 截取整数部分,不进行四舍五入 if (ac_out_voltage_1==0){ + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备电路异常",2, TimeUnit.MINUTES); return AjaxResult.success("设备电路异常"); } + redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"未诊断出设备异常",2, TimeUnit.MINUTES); return AjaxResult.success("未诊断出设备异常"); }