Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
mengff 3 weeks ago
parent
commit
e417cf6e30
  1. 12
      zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java
  2. 13
      zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java
  3. 8
      zc-business/src/main/java/com/zc/business/service/DcSwitchService.java
  4. 85
      zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java
  5. 17
      zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

12
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.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcSwitch; import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.DcSwitchService; import com.zc.business.service.DcSwitchService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.util.Diagnostics;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -105,4 +109,12 @@ public class DcSwitchController extends BaseController {
// 批量修改 // 批量修改
dcSwitchService.updateBatchByNetWorkStatus(collect); 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);
}
} }

13
zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java

@ -1,8 +1,10 @@
package com.zc.business.mapper; package com.zc.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcSwitch; import com.zc.business.domain.DcSwitch;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -16,4 +18,15 @@ public interface DcSwitchMapper extends BaseMapper<DcSwitch> {
List<DcSwitch> getSwitchList(DcSwitch dcSwitch); List<DcSwitch> getSwitchList(DcSwitch dcSwitch);
int updateBatchByNetWorkStatus(List<DcSwitch> list); int updateBatchByNetWorkStatus(List<DcSwitch> list);
//查询交换机ip存在的设备id
List<DcSwitch> getSwitchIPDeviceId();
//根据设备ip查询设备id
List<DcDevice> getDcDeviceId(String deviceIp);
//依据交换机ip查询交换机名称
List<DcSwitch> getSwitchName(String switchIp);
//根据交换机ip查询对应的桩号
DcSwitch getStakeMark(String switchIp);
//根据桩号查询设备箱的物联id
DcDevice getIotDeviceIdAndIp(String stakeMark);
} }

8
zc-business/src/main/java/com/zc/business/service/DcSwitchService.java

@ -1,8 +1,12 @@
package com.zc.business.service; package com.zc.business.service;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcSwitch; import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.List; import java.util.List;
/** /**
@ -34,4 +38,8 @@ public interface DcSwitchService {
* @return * @return
*/ */
int updateBatchByNetWorkStatus(List<DcSwitch> list); int updateBatchByNetWorkStatus(List<DcSwitch> list);
//设备诊断
AjaxResult deviceDiagnostics(Device device) throws Exception;
} }

85
zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java

@ -1,21 +1,36 @@
package com.zc.business.service.impl; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.zc.business.constant.RedisKeyConstants; import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.controller.DcDeviceController;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcSwitch; import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.mapper.DcSwitchMapper; import com.zc.business.mapper.DcSwitchMapper;
import com.zc.business.service.DcSwitchService; import com.zc.business.service.DcSwitchService;
import com.zc.business.service.IDcDeviceService;
import javafx.scene.control.TableView;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -131,6 +146,7 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i
return dcSwitchMapper.updateBatchByNetWorkStatus(list); return dcSwitchMapper.updateBatchByNetWorkStatus(list);
} }
private void recursionFn(List<DcSwitch> list, DcSwitch t) { private void recursionFn(List<DcSwitch> list, DcSwitch t) {
// 得到子节点列表 // 得到子节点列表
List<DcSwitch> childList = getChildList(list, 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) { private boolean hasChild(List<DcSwitch> list, DcSwitch t) {
return getChildList(list, t).size() > UniversalEnum.ZERO.getNumber(); 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("未诊断出设备异常");
}
} }

17
zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

@ -44,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where> </where>
</select> </select>
<update id="updateBatchByNetWorkStatus" parameterType="List"> <update id="updateBatchByNetWorkStatus" parameterType="List">
update dc_switch update dc_switch
<trim prefix="set" suffixOverrides=","> <trim prefix="set" suffixOverrides=",">
@ -66,5 +67,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.switchId} #{item.switchId}
</foreach> </foreach>
</update> </update>
<select id="getSwitchIPDeviceId" resultType="com.zc.business.domain.DcSwitch">
select switch_ip,device_list from dc_switch where switch_ip!='' and device_list !=''
</select>
<select id="getDcDeviceId" resultType="com.zc.business.domain.DcDevice">
select id from dc_device where device_ip=#{deviceIp}
</select>
<select id="getSwitchName" resultType="com.zc.business.domain.DcSwitch">
select switch_name from dc_switch where switch_ip=#{switchIp}
</select>
<select id="getStakeMark" resultType="com.zc.business.domain.DcSwitch">
select stake_mark from dc_switch where switch_ip=#{switchIp}
</select>
<select id="getIotDeviceIdAndIp" resultType="com.zc.business.domain.DcDevice">
select iot_device_id,device_ip from dc_device where LOWER(stake_mark) = LOWER(#{stakeMark}) and device_type=13
</select>
</mapper> </mapper>

Loading…
Cancel
Save