|
|
@@ -1,8 +1,10 @@
|
|
|
package cc.iotkit.system.service.impl;
|
|
|
|
|
|
+import cc.iotkit.common.constant.GlobalConstants;
|
|
|
import cc.iotkit.common.constant.UserConstants;
|
|
|
import cc.iotkit.common.enums.ErrCode;
|
|
|
import cc.iotkit.common.exception.BizException;
|
|
|
+import cc.iotkit.common.redis.utils.RedisUtils;
|
|
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
|
|
import cc.iotkit.common.utils.MapstructUtils;
|
|
|
import cc.iotkit.common.utils.SpringUtils;
|
|
|
@@ -23,9 +25,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -316,4 +316,38 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
}
|
|
|
return sysDepts;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void reCacheDept(String tenantId) {
|
|
|
+ List<SysDept> sysDepts = sysDeptData.findAllDeptsByTenant(tenantId);
|
|
|
+// List<SysDept> cacheDepts = new ArrayList<>();
|
|
|
+// if(CollectionUtil.isNotEmpty(sysDepts)){
|
|
|
+// cacheDepts = sysDepts.stream().filter(item->item.getTenantId().equals(tenantId)).collect(Collectors.toList());
|
|
|
+// }
|
|
|
+ Map<String,List<String>> deptChildMap = new HashMap<>();
|
|
|
+ if(CollectionUtil.isNotEmpty(sysDepts)){
|
|
|
+ String key = null;
|
|
|
+ String ancestors = null;
|
|
|
+ String[] splits = null;
|
|
|
+ for (SysDept sysDept:sysDepts){
|
|
|
+ ancestors= sysDept.getAncestors();
|
|
|
+ splits= ancestors.split(",");
|
|
|
+ for(String split:splits ){
|
|
|
+ key = GlobalConstants.DEPT_CHILD_PREFIX + sysDept.getTenantId() + ":" + String.valueOf(split);
|
|
|
+ List<String> children = deptChildMap.get(key);
|
|
|
+ if(CollectionUtil.isEmpty(children)){
|
|
|
+ children = new ArrayList<>();
|
|
|
+ children.add(String.valueOf(sysDept.getId()));
|
|
|
+ }else{
|
|
|
+ children.add(String.valueOf(sysDept.getId()));
|
|
|
+ }
|
|
|
+ deptChildMap.put(key,children);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //缓存到redis
|
|
|
+ for (Map.Entry<String, List<String>> itemMap: deptChildMap.entrySet()) {
|
|
|
+ RedisUtils.setCacheObject(itemMap.getKey(),String.join(",", itemMap.getValue()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|