summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortanghao <admin@LAPTOP-QCSKVLI9>2021-05-21 19:44:23 +0800
committertanghao <admin@LAPTOP-QCSKVLI9>2021-05-21 19:44:23 +0800
commit80a1dea75294459cac018c38edc1e0f8ae060934 (patch)
treeb60ea21863c6e507e09a6ba117d2af3eed9b5e24 /src
parent00022eb894615f65339b836123c74aebcae1503d (diff)
fix: 去重snmp凭证数据
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/nis/service/impl/AssetAssetServiceImpl.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/com/nis/service/impl/AssetAssetServiceImpl.java b/src/main/java/com/nis/service/impl/AssetAssetServiceImpl.java
index 2a6dc82..9bcdc67 100644
--- a/src/main/java/com/nis/service/impl/AssetAssetServiceImpl.java
+++ b/src/main/java/com/nis/service/impl/AssetAssetServiceImpl.java
@@ -1,6 +1,7 @@
package com.nis.service.impl;
import cn.hutool.core.lang.UUID;
+import cn.hutool.core.lang.hash.MurmurHash;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
@@ -109,6 +110,8 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
Map<Integer,SnmpCredential> assetIdAndSnmpCredential = new HashMap<Integer,SnmpCredential>();
List<SnmpCredential> snmpCredentials = new ArrayList<SnmpCredential>();
+
+ Map<String,SnmpCredential> snmpCredentialDistinctMap = new HashMap<String,SnmpCredential>();
//snmp凭证表添加数据信息
for(Account account : accounts) {
if(account.getProtocol().equals("SNMP")) {
@@ -133,8 +136,15 @@ public class AssetAssetServiceImpl extends ServiceImpl<AssetAssetDao, AssetAsset
snmpCredential.setType((Integer)map.get("version"));
snmpCredential.setPort(account.getPort());
snmpCredential.setConfig(JSON.toJSONString(config));
- snmpCredentials.add(snmpCredential);
- assetIdAndSnmpCredential.put(account.getAssetId(), snmpCredential);
+ String hash = String.valueOf(Math.abs(MurmurHash.hash64(snmpCredential.getConfig()+snmpCredential.getType()+snmpCredential.getPort())));
+ 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 {
String params = (String) account.getParams();
Map<String,Object> map = (Map<String, Object>) JSON.parse(params);