|
|
@ -1,19 +1,20 @@ |
|
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.zc.business.constant.RedisKeyConstants; |
|
|
|
import com.zc.business.domain.DcDevice; |
|
|
|
import com.zc.business.domain.DcSwitch; |
|
|
|
import com.zc.business.mapper.DcDeviceMapper; |
|
|
|
import com.zc.business.mapper.DcSwitchMapper; |
|
|
|
import com.zc.business.service.DcSwitchService; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import java.util.concurrent.Executors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -29,14 +30,14 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
private DcSwitchMapper dcSwitchMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private DcDeviceMapper dcDeviceMapper; |
|
|
|
private RedisCache redisCache; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询交换机 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<DcSwitch> getSwitchList(DcSwitch dcSwitch) { |
|
|
|
return dcSwitchMapper.getSwitchList(dcSwitch); |
|
|
|
return getDeviceListBySwitch(dcSwitchMapper.getSwitchList(dcSwitch)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -48,7 +49,12 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
List<String> devices = Arrays.stream(deviceList.split(",")).collect(Collectors.toList()); |
|
|
|
return dcDeviceMapper.selectBatchIds(devices); |
|
|
|
List<DcDevice> dcDevices = new ArrayList<>(); |
|
|
|
devices.forEach(device -> { |
|
|
|
DcDevice cacheMapValue = redisCache.getCacheMapValue(RedisKeyConstants.DC_DEVICE_ID,device); |
|
|
|
dcDevices.add(cacheMapValue); |
|
|
|
}); |
|
|
|
return dcDevices; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -58,7 +64,8 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<DcSwitch> getSwitchListAll() { |
|
|
|
List<DcSwitch> dcSwitches = dcSwitchMapper.getSwitchList(new DcSwitch()); |
|
|
|
List<DcSwitch> deviceListBySwitch = dcSwitchMapper.getSwitchList(new DcSwitch()); |
|
|
|
List<DcSwitch> dcSwitches = getDeviceListBySwitch(deviceListBySwitch); |
|
|
|
List<DcSwitch> returnList = new ArrayList<>(); |
|
|
|
List<Integer> tempList = new ArrayList<>(); |
|
|
|
for (DcSwitch switche : dcSwitches) { |
|
|
@ -77,6 +84,52 @@ public class DcSwitchServiceImpl extends ServiceImpl<DcSwitchMapper, DcSwitch> i |
|
|
|
return returnList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 处置交换机数据-获取设备数据 |
|
|
|
* @param list |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<DcSwitch> getDeviceListBySwitch(List<DcSwitch> list) { |
|
|
|
ExecutorService executor = Executors.newFixedThreadPool(100); |
|
|
|
CountDownLatch latch = new CountDownLatch(list.size()); |
|
|
|
list.forEach(dcSwitch -> { |
|
|
|
executor.execute(() ->{ |
|
|
|
try { |
|
|
|
if (StringUtils.isNotEmpty(dcSwitch.getDeviceList())) { |
|
|
|
// 说明是设备交换机
|
|
|
|
List<DcDevice> deviceList = getDeviceList(dcSwitch.getDeviceList()); |
|
|
|
if (deviceList.size() > 0) { |
|
|
|
Map<String, List<DcDevice>> collect = deviceList.stream().collect(Collectors.groupingBy(DcDevice::getDeviceType)); |
|
|
|
dcSwitch.setDcDeviceList(collect); |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
}finally { |
|
|
|
latch.countDown(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
try { |
|
|
|
latch.await(); // 等待所有线程执行完毕
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
} finally { |
|
|
|
executor.shutdown(); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 批量修改网络状态 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int updateBatchByNetWorkStatus(List<DcSwitch> list) { |
|
|
|
return dcSwitchMapper.updateBatchByNetWorkStatus(list); |
|
|
|
} |
|
|
|
|
|
|
|
private void recursionFn(List<DcSwitch> list, DcSwitch t) { |
|
|
|
// 得到子节点列表
|
|
|
|
List<DcSwitch> childList = getChildList(list, t); |
|
|
|