From f169fcb00f7bf8c15bb1d461cd3710ebaf8106e8 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期三, 11 十月 2023 14:07:56 +0800
Subject: [PATCH] 优化液位计算

---
 igds-core/src/main/java/com/ld/igds/view/service/BuildingService.java |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/igds-core/src/main/java/com/ld/igds/view/service/BuildingService.java b/igds-core/src/main/java/com/ld/igds/view/service/BuildingService.java
index f3c0ec2..33a9b22 100644
--- a/igds-core/src/main/java/com/ld/igds/view/service/BuildingService.java
+++ b/igds-core/src/main/java/com/ld/igds/view/service/BuildingService.java
@@ -3,6 +3,8 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
+
 import org.apache.commons.lang3.StringUtils;
 import org.hibernate.Session;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -61,7 +63,7 @@
 			}
 			data.setCompanyId(ContextUtil.getCompanyId());
 			session.saveOrUpdate(data);
-			refreshCache(data.getCompanyId(), data.getDeptId());
+			refreshCache(data.getCompanyId());
 		} finally {
 			session.flush();
 			session.close();
@@ -101,7 +103,7 @@
 				}
 			}
 			
-			refreshCache(items.get(0).getCompanyId(), items.get(0).getDeptId());
+			refreshCache(items.get(0).getCompanyId());
 		} finally {
 			session.flush();
 			session.close();
@@ -110,7 +112,7 @@
 	}
 
 	@SuppressWarnings("unchecked")
-	public List<Building> getCacheBuilding(String companyId,String deptId) {
+	public List<Building> getCacheBuilding(String companyId, String deptId) {
 		if(StringUtils.isEmpty(companyId)){
 			companyId = ContextUtil.getCompanyId();
 		}
@@ -120,14 +122,15 @@
 		List<Building> result = (List<Building>) redisUtil.get(key);
 
 		if (null == result) {
-			refreshCache(companyId, deptId);
+			refreshCache(companyId);
 			
 			return null;
 		}
 
 		if(null == deptId) return result;
-		
-		return result;
+
+		return result.stream().filter(item -> item.getDeptId().equals(deptId))
+				.collect(Collectors.toList());
 	}
 
 	@SuppressWarnings("unchecked")
@@ -136,12 +139,10 @@
 			companyId = ContextUtil.getCompanyId();
 		}
 
-		String key = RedisConst.buildKey(companyId, RedisConst.KEY_BUILDING_LIST);
-
-		List<Building> result = (List<Building>) redisUtil.get(key);
+		List<Building> result = getCacheBuilding(companyId, deptId);
 
 		if (null == result) {
-			refreshCache(companyId, deptId);
+			refreshCache(companyId);
 
 			return null;
 		}
@@ -154,12 +155,11 @@
 	}
 	
 	
-	public void refreshCache(String companyId, String deptId) {
+	public void refreshCache(String companyId) {
 		Map<String, Object> parameter = new HashMap<String, Object>();
 		parameter.put("companyId", companyId);
-		parameter.put("deptId", deptId);
 		List<Building> list = this.loadData(parameter);
 		
-		redisUtil.set(RedisConst.buildKey(companyId, deptId, RedisConst.KEY_BUILDING_LIST),list);
+		redisUtil.set(RedisConst.buildKey(companyId, RedisConst.KEY_BUILDING_LIST),list);
 	}
 }

--
Gitblit v1.9.3