CZT
2023-10-11 f169fcb00f7bf8c15bb1d461cd3710ebaf8106e8
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();
@@ -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);
   }
}