diff --git a/zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java b/zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java index 61f1d2be..4f201cff 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java @@ -3,13 +3,17 @@ package com.zc.business.controller; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcSwitch; +import com.zc.business.domain.Device; import com.zc.business.enums.UniversalEnum; import com.zc.business.service.DcSwitchService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.tomcat.util.Diagnostics; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -105,4 +109,12 @@ public class DcSwitchController extends BaseController { // 批量修改 dcSwitchService.updateBatchByNetWorkStatus(collect); } + //设备处理建议 + @PostMapping("/deviceDiagnostics") + public AjaxResult deviceDiagnostics(@RequestBody Device device) throws Exception { + if (device==null||device.getDeviceIp()==null){ + return AjaxResult.error("参数错误"); + } + return dcSwitchService.deviceDiagnostics(device); + } } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java index 7b59135e..de5b45b5 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java @@ -1,8 +1,10 @@ package com.zc.business.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcSwitch; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -16,4 +18,15 @@ public interface DcSwitchMapper extends BaseMapper { List getSwitchList(DcSwitch dcSwitch); int updateBatchByNetWorkStatus(List list); + + //查询交换机ip存在的设备id + List getSwitchIPDeviceId(); + //根据设备ip查询设备id + List getDcDeviceId(String deviceIp); + //依据交换机ip查询交换机名称 + List getSwitchName(String switchIp); + //根据交换机ip查询对应的桩号 + DcSwitch getStakeMark(String switchIp); + //根据桩号查询设备箱的物联id + DcDevice getIotDeviceIdAndIp(String stakeMark); } diff --git a/zc-business/src/main/java/com/zc/business/service/DcSwitchService.java b/zc-business/src/main/java/com/zc/business/service/DcSwitchService.java index 5fb43223..31c653fe 100644 --- a/zc-business/src/main/java/com/zc/business/service/DcSwitchService.java +++ b/zc-business/src/main/java/com/zc/business/service/DcSwitchService.java @@ -1,8 +1,12 @@ package com.zc.business.service; +import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcSwitch; +import com.zc.business.domain.Device; +import java.io.IOException; +import java.net.UnknownHostException; import java.util.List; /** @@ -34,4 +38,8 @@ public interface DcSwitchService { * @return */ int updateBatchByNetWorkStatus(List list); + + //设备诊断 + + AjaxResult deviceDiagnostics(Device device) throws Exception; } 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 a34d4b05..1d7244fe 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,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 i return dcSwitchMapper.updateBatchByNetWorkStatus(list); } + private void recursionFn(List list, DcSwitch t) { // 得到子节点列表 List childList = getChildList(list, t); @@ -163,4 +179,73 @@ public class DcSwitchServiceImpl extends ServiceImpl i private boolean hasChild(List 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 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 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 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("未诊断出设备异常"); + } + + } diff --git a/zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml b/zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml index caac9b35..897b37bc 100644 --- a/zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml @@ -44,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + update dc_switch @@ -66,5 +67,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{item.switchId} - + + + + +