Browse Source

优化诊断功能ip冲突问题

develop
wangsixiang 1 week ago
parent
commit
f29b87208f
  1. 6
      zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java
  2. 3
      zc-business/src/main/java/com/zc/business/mapper/DcSwitchMapper.java
  3. 3
      zc-business/src/main/java/com/zc/business/service/DcSwitchService.java
  4. 8
      zc-business/src/main/java/com/zc/business/service/impl/DcSwitchServiceImpl.java
  5. 4
      zc-business/src/main/resources/mapper/business/DcSwitchMapper.xml

6
zc-business/src/main/java/com/zc/business/controller/DcSwitchController.java

@ -2,6 +2,8 @@ package com.zc.business.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcDeviceOfflineRecord;
import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
import com.zc.business.enums.UniversalEnum;
@ -111,8 +113,8 @@ public class DcSwitchController extends BaseController {
}
//设备处理建议
@PostMapping("/deviceDiagnostics")
public AjaxResult deviceDiagnostics(@RequestBody Device device) throws Exception {
if (device==null||device.getDeviceIp()==null){
public AjaxResult deviceDiagnostics(@RequestBody DcDeviceOfflineRecord device) throws Exception {
if (device==null||device.getDeviceIp()==null||device.getDeviceType()==null){
return AjaxResult.error("参数错误");
}
return dcSwitchService.deviceDiagnostics(device);

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

@ -2,6 +2,7 @@ package com.zc.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcDeviceOfflineRecord;
import com.zc.business.domain.DcSwitch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -22,7 +23,7 @@ public interface DcSwitchMapper extends BaseMapper<DcSwitch> {
//查询交换机ip存在的设备id
List<DcSwitch> getSwitchIPDeviceId();
//根据设备ip查询设备id
List<DcDevice> getDcDeviceId(String deviceIp);
List<DcDeviceOfflineRecord> getDcDeviceId(@Param("deviceIp") String deviceIp,@Param("deviceType") String deviceType);
//依据交换机ip查询交换机名称
List<DcSwitch> getSwitchName(String switchIp);
//根据交换机ip查询对应的桩号

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

@ -2,6 +2,7 @@ package com.zc.business.service;
import com.ruoyi.common.core.domain.AjaxResult;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcDeviceOfflineRecord;
import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
@ -41,5 +42,5 @@ public interface DcSwitchService {
//设备诊断
AjaxResult deviceDiagnostics(Device device) throws Exception;
AjaxResult deviceDiagnostics(DcDeviceOfflineRecord device) throws Exception;
}

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

@ -9,6 +9,7 @@ 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.DcDeviceOfflineRecord;
import com.zc.business.domain.DcSwitch;
import com.zc.business.domain.Device;
import com.zc.business.enums.UniversalEnum;
@ -176,8 +177,9 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i
@Override
public AjaxResult deviceDiagnostics(Device device) throws Exception {
public AjaxResult deviceDiagnostics(DcDeviceOfflineRecord device) throws Exception {
String deviceIp = device.getDeviceIp();
String deviceType = device.getDeviceType();
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
String cacheObject = redisCache.getCacheObject(DEVICEDIAGNOSTICS+deviceIp);//获取缓存是否存在诊断结果
if (StringUtils.isNotBlank(cacheObject)){ //存在即返回
@ -191,13 +193,13 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i
redisCache.setCacheObject(DEVICEDIAGNOSTICS+deviceIp,"设备网关网络异常",2, TimeUnit.MINUTES);
return AjaxResult.success("设备网关网络异常");
}
List<DcDevice> dcDeviceId = dcSwitchMapper.getDcDeviceId(deviceIp);//查询设备id
List<DcDeviceOfflineRecord> dcDeviceId = dcSwitchMapper.getDcDeviceId(deviceIp,deviceType);//查询设备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){
for (DcDeviceOfflineRecord dcDeviceValue:dcDeviceId){
dcDevice.setId(dcDeviceValue.getId());//存入设备id
}
}

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

@ -70,8 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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 id="getDcDeviceId" resultType="com.zc.business.domain.DcDeviceOfflineRecord">
select id from dc_device where device_ip=#{deviceIp} and device_type=#{deviceType}
</select>
<select id="getSwitchName" resultType="com.zc.business.domain.DcSwitch">
select switch_name from dc_switch where switch_ip=#{switchIp}

Loading…
Cancel
Save