|
|
@ -1,21 +1,36 @@ |
|
|
|
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; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils; |
|
|
|
import com.zc.business.constant.RedisKeyConstants; |
|
|
|
import com.zc.business.controller.DcDeviceController; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.domain.DcSwitch; |
|
|
|
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; |
|
|
@ -131,6 +146,7 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
return dcSwitchMapper.updateBatchByNetWorkStatus(list); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void recursionFn(List<DcSwitch> list, DcSwitch t) { |
|
|
|
// 得到子节点列表
|
|
|
|
List<DcSwitch> childList = getChildList(list, t); |
|
|
@ -163,4 +179,73 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
private boolean hasChild(List<DcSwitch> list, DcSwitch t) { |
|
|
|
return getChildList(list, t).size() > UniversalEnum.ZERO.getNumber(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult deviceDiagnostics(Device device) throws Exception { |
|
|
|
String deviceIp = device.getDeviceIp(); |
|
|
|
String[] parts = deviceIp.split("\\."); |
|
|
|
parts[3] = "254"; |
|
|
|
String newDeviceIp = String.join(".", parts);//设备网关
|
|
|
|
InetAddress deviceGateway = InetAddress.getByName(newDeviceIp); |
|
|
|
if (!deviceGateway.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { |
|
|
|
return AjaxResult.success("设备网关网络异常"); |
|
|
|
} |
|
|
|
List<DcDevice> dcDeviceId = dcSwitchMapper.getDcDeviceId(deviceIp);//查询设备id
|
|
|
|
DcDevice dcDevice = new DcDevice();//存放设备id
|
|
|
|
if (dcDeviceId.size()>1){ |
|
|
|
return AjaxResult.success("设备IP存在冲突,请联系技术人员"); |
|
|
|
}else { |
|
|
|
for (DcDevice dcDeviceValue:dcDeviceId){ |
|
|
|
dcDevice.setId(dcDeviceValue.getId());//存入设备id
|
|
|
|
} |
|
|
|
} |
|
|
|
Long deviceId = dcDevice.getId(); |
|
|
|
String deviceIdString = String.valueOf(deviceId); |
|
|
|
List<DcSwitch> switchIPDeviceId = dcSwitchMapper.getSwitchIPDeviceId();//交换机ip设备id
|
|
|
|
String switchIp = switchIPDeviceId.stream() |
|
|
|
.filter(dcSwitch -> dcSwitch.getDeviceList().contains(deviceIdString)) |
|
|
|
.findFirst().map(DcSwitch::getSwitchIp).orElse(null); |
|
|
|
if (StringUtils.isBlank(switchIp)){ //switchIp为空不存在交换机ip
|
|
|
|
return AjaxResult.success("未查询到相关的二层交换机,请联系技术人员配置"); |
|
|
|
} |
|
|
|
List<DcSwitch> switchList = dcSwitchMapper.getSwitchName(switchIp); |
|
|
|
if (switchList.size()!=1){ |
|
|
|
return AjaxResult.success("二层交换机IP存在冲突,请联系技术人员"); |
|
|
|
}else { |
|
|
|
for (DcSwitch switchListValue:switchList) { |
|
|
|
InetAddress newSwitchIp = InetAddress.getByName(switchIp); |
|
|
|
if (!newSwitchIp.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { |
|
|
|
return AjaxResult.success("设备二层交换机"+switchListValue.getSwitchName()+"网络异常"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
InetAddress newDeviceIpCurrent = InetAddress.getByName(deviceIp);//传入的当前设备ip
|
|
|
|
if (!newDeviceIpCurrent.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { |
|
|
|
return AjaxResult.success("当前设备ip"+deviceIp+"网络异常"); |
|
|
|
} |
|
|
|
DcSwitch stakeMark = dcSwitchMapper.getStakeMark(switchIp);//交换机桩号
|
|
|
|
DcDevice iotDevice = dcSwitchMapper.getIotDeviceIdAndIp(stakeMark.getStakeMark());//拿出设备箱的物联id和ip
|
|
|
|
String iotDeviceIp = iotDevice.getDeviceIp();//设备箱ip
|
|
|
|
InetAddress newIotDeviceIp = InetAddress.getByName(iotDeviceIp);//传入关联的设备箱的ip
|
|
|
|
if (!newIotDeviceIp.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber())) { |
|
|
|
return AjaxResult.success("设备箱已离线"); |
|
|
|
} |
|
|
|
DcDeviceController dcDeviceController = SpringUtils.getBean(DcDeviceController.class); |
|
|
|
AjaxResult deviceLatestProperty = dcDeviceController.getDeviceLatestProperty(iotDevice.getIotDeviceId(), "1ac"); |
|
|
|
if (deviceLatestProperty==null||deviceLatestProperty.get("data")==null){ |
|
|
|
return AjaxResult.success("设备箱未上传数据"); |
|
|
|
} |
|
|
|
JSONObject data = (JSONObject) deviceLatestProperty.get("data"); |
|
|
|
JSONObject dataValue = (JSONObject) data.get("value"); |
|
|
|
String voltageStr = dataValue.get("ac_out_voltage_1").toString(); |
|
|
|
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){ |
|
|
|
return AjaxResult.success("设备电路异常"); |
|
|
|
} |
|
|
|
return AjaxResult.success("未诊断出设备异常"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|