From d52037b84cd6689b1cc03b47a5cd43fcb6b7342f Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期二, 26 九月 2023 21:23:51 +0800
Subject: [PATCH] 贝博粮情解析1
---
igds-core/src/main/java/com/ld/igds/common/impl/CoreDeviceServiceImpl.java | 111 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 84 insertions(+), 27 deletions(-)
diff --git a/igds-core/src/main/java/com/ld/igds/common/impl/CoreDeviceServiceImpl.java b/igds-core/src/main/java/com/ld/igds/common/impl/CoreDeviceServiceImpl.java
index f96082f..11d32fb 100644
--- a/igds-core/src/main/java/com/ld/igds/common/impl/CoreDeviceServiceImpl.java
+++ b/igds-core/src/main/java/com/ld/igds/common/impl/CoreDeviceServiceImpl.java
@@ -1,15 +1,16 @@
package com.ld.igds.common.impl;
import java.util.*;
-import java.util.stream.Collectors;
import com.ld.igds.common.CoreDeviceService;
import com.ld.igds.common.dto.DepotSerData;
import com.ld.igds.common.mapper.DeviceMapper;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.DeviceStatus;
-
import com.ld.igds.constant.DeviceType;
+
+import com.ld.igds.io.request.ExeDevice;
+import com.ld.igds.models.Depot;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@@ -32,37 +33,63 @@
private DeviceMapper deviceMapper;
- @Override
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
public void setCacheAllDevice(List<Device> listAll, String companyId) {
- // 棣栧厛鎸夌収鍒嗘満鍒嗙粍锛岀劧鍚庡瓨鏇存柊缂撳瓨銆�
- Map<String, List<Device>> map = listAll.stream().collect(Collectors.groupingBy(Device::getSerId));
- if (null == map || map.isEmpty()) {
- log.error("瀛楀吀淇℃伅锛氭墍鏈夎澶囨寜鐓у垎鏈哄垎缁勪繚瀛樼紦瀛樺け璐ワ紝娌℃湁鍒嗙粍鎴愬姛=={}", companyId);
- return;
- }
+ if (null == listAll || listAll.isEmpty()) return;
- for (String serId : map.keySet()) {
- updateCacheDeviceBySerId(map.get(serId), companyId, serId);
- }
+ //鎸夌収鍒嗘満鍒嗙被
+ Map<String, List<Device>> mapSer = new HashMap<>();
- this.setCacheDepotDeviceSer(listAll, companyId);
- }
+ //浠撳簱-璁惧-鍒嗘満瀵硅薄鍒嗙被
+ Map<String, DepotSerData> mapDepot = new HashMap<>();
- @SuppressWarnings({"unchecked", "rawtypes"})
- private void setCacheDepotDeviceSer(List<Device> listAll, String companyId) {
- // 澶勭悊浠撳簱涓庡垎鏈虹殑鍏崇郴缂撳瓨
- Map<String, DepotSerData> tempMap = new HashMap<>();
- String key;
- for (Device item : listAll) {
- key = companyId + "-" + item.getDepotId() + "-" + item.getSerId();
- if (tempMap.get(key) == null) {
- tempMap.put(key, new DepotSerData(companyId, item.getDepotId(), item.getSerId()));
+
+ //鎶婅澶囨寜鐓у垎鏈鸿繘琛屽垎缁勶紝鍚屼簨鍚ц澶囨坊鍔犲埌缂撳瓨鍒楄〃涓�
+ String deviceKey, depotDataKey;
+ for (Device device : listAll) {
+
+ //灏佽浠撳簱-璁惧-鍒嗘満瀵硅薄鍏崇郴
+ depotDataKey = companyId + "-" + device.getDepotId() + "-" + device.getSerId();
+ if (mapDepot.get(depotDataKey) == null) {
+ mapDepot.put(depotDataKey, new DepotSerData(companyId, device.getDepotId(), device.getSerId()));
}
+
+
+ //鍗曚釜璁惧杩涜缂撳瓨
+ deviceKey = RedisConst.buildKey(companyId, RedisConst.KEY_DEVICE, device.getId());
+ redisUtil.set(deviceKey, device);
+
+ //鎸夌収鍒嗘満鍒嗙被
+ if (null == mapSer.get(device.getSerId())) mapSer.put(device.getSerId(), new ArrayList<Device>());
+ mapSer.get(device.getSerId()).add(device);
+
}
- redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_SER_LIST), new ArrayList(tempMap.values()));
+ //浠ュ垎鏈轰负鍗曚綅缂撳瓨璁惧
+ for (String serId : mapSer.keySet()) {
+ updateCacheDeviceBySerId(mapSer.get(serId), companyId, serId);
+ }
+
+
+ redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_SER_LIST), new ArrayList(mapDepot.values()));
}
+
+
+// private void setCacheDepotDeviceSer(List<Device> listAll, String companyId) {
+// // 澶勭悊浠撳簱涓庡垎鏈虹殑鍏崇郴缂撳瓨
+// Map<String, DepotSerData> tempMap = new HashMap<>();
+// String key;
+// for (Device item : listAll) {
+// key = companyId + "-" + item.getDepotId() + "-" + item.getSerId();
+// if (tempMap.get(key) == null) {
+// tempMap.put(key, new DepotSerData(companyId, item.getDepotId(), item.getSerId()));
+// }
+// }
+//
+// redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_SER_LIST), new ArrayList(tempMap.values()));
+// }
@Override
public void updateCacheDeviceBySerId(List<Device> listBySer, String companyId, String serId) {
@@ -85,6 +112,36 @@
return null;
}
return list;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Set<String> getCacheDeviceSerByDepotId(String companyId, String depotId) {
+ String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEVICE_LIST);
+
+ Set<String> keys = redisUtil.keys(patten);
+ if (null == keys) return null;
+
+ List<Device> list = new ArrayList<>();
+ for (String key : keys) {
+ list.addAll((List<Device>) redisUtil.get(key));
+ }
+ if (list.isEmpty()) {
+ return null;
+ }
+ Set<String> result = new HashSet<>();
+ for (Device device : list) {
+ if(depotId.equals(device.getDepotId())){
+ result.add(device.getSerId());
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public Device getCacheDeviceById(String companyId, String id) {
+ String key = RedisConst.buildDeviceKey(companyId, RedisConst.KEY_DEVICE, id);
+ return (Device) redisUtil.get(key);
}
@Override
@@ -173,7 +230,7 @@
}
log.debug("瑙f瀽璁惧鐘舵��--涓婚�氶亾={}---鍏宠仈閫氶亾={}--瑙f瀽鍚庣姸鎬�={}", curDevice.getPassCode(), curDevice.getLink(), curDevice.getStatus());
}
-
+
// 鏇存柊缂撳瓨
this.updateCacheDeviceBySerId(listCache, companyId, serId);
}
@@ -279,7 +336,7 @@
}
@Override
- public List<Device> getDeviceByTimId(String companyId,String timId){
- return deviceMapper.queryByTimId(companyId,timId);
+ public List<Device> getDeviceByTimId(String companyId, String timId) {
+ return deviceMapper.queryByTimId(companyId, timId);
}
}
--
Gitblit v1.9.3