fix: 去重snmp凭证数据

This commit is contained in:
tanghao
2021-05-21 19:44:23 +08:00
parent 00022eb894
commit 80a1dea752

View File

@@ -1,6 +1,7 @@
package com.nis.service.impl; package com.nis.service.impl;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import cn.hutool.core.lang.hash.MurmurHash;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log; import cn.hutool.log.Log;
@@ -109,6 +110,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
Map<Integer,SnmpCredential> assetIdAndSnmpCredential = new HashMap<Integer,SnmpCredential>(); Map<Integer,SnmpCredential> assetIdAndSnmpCredential = new HashMap<Integer,SnmpCredential>();
List<SnmpCredential> snmpCredentials = new ArrayList<SnmpCredential>(); List<SnmpCredential> snmpCredentials = new ArrayList<SnmpCredential>();
Map<String,SnmpCredential> snmpCredentialDistinctMap = new HashMap<String,SnmpCredential>();
//snmp凭证表添加数据信息 //snmp凭证表添加数据信息
for(Account account : accounts) { for(Account account : accounts) {
if(account.getProtocol().equals("SNMP")) { if(account.getProtocol().equals("SNMP")) {
@@ -133,8 +136,15 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
snmpCredential.setType((Integer)map.get("version")); snmpCredential.setType((Integer)map.get("version"));
snmpCredential.setPort(account.getPort()); snmpCredential.setPort(account.getPort());
snmpCredential.setConfig(JSON.toJSONString(config)); snmpCredential.setConfig(JSON.toJSONString(config));
snmpCredentials.add(snmpCredential); String hash = String.valueOf(Math.abs(MurmurHash.hash64(snmpCredential.getConfig()+snmpCredential.getType()+snmpCredential.getPort())));
assetIdAndSnmpCredential.put(account.getAssetId(), snmpCredential); SnmpCredential snmpObject = snmpCredentialDistinctMap.get(hash);
if(ToolUtil.isEmpty(snmpObject)) {
snmpCredentialDistinctMap.put(hash, snmpCredential);
snmpCredentials.add(snmpCredential);
assetIdAndSnmpCredential.put(account.getAssetId(), snmpCredential);
}else {
assetIdAndSnmpCredential.put(account.getAssetId(), snmpObject);
}
}else { }else {
String params = (String) account.getParams(); String params = (String) account.getParams();
Map<String,Object> map = (Map<String, Object>) JSON.parse(params); Map<String,Object> map = (Map<String, Object>) JSON.parse(params);