浏览代码

fix:学校同步机构父id重复

caozixuan 3 年之前
父节点
当前提交
be8812d5cf

+ 18 - 17
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -342,9 +342,10 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         if (sysPrivileges.size() == 0) {
             throw ExceptionResultEnum.ERROR.exception("默认学校权限不存在");
         }
-        Map<Long, Long> map = new HashMap<>();
-        List<SysPrivilege> newList = new ArrayList<>();
         for (Long newSchoolId : targetSchoolIdSet) {
+            // 一个学校一个学校的权限加 如果放在外面的话必须在map的key中关联进学校主键
+            Map<Long, Long> map = new HashMap<>();
+            List<SysPrivilege> newList = new ArrayList<>();
             BasicSchool basicSchool = basicSchoolService.getById(newSchoolId);
             if (Objects.isNull(basicSchool)) {
                 throw ExceptionResultEnum.ERROR.exception("未找到学校信息");
@@ -359,24 +360,24 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
                 cell.setEnable(basicSchool.getEnable());
                 newList.add(cell);
             }
-        }
-        for (SysPrivilege sysPrivilege : newList) {
-            if (Objects.nonNull(sysPrivilege.getParentId())) {
-                sysPrivilege.setParentId(map.get(sysPrivilege.getParentId()));
-            }
-            String relateId = sysPrivilege.getRelated();
-            if (StringUtils.isNotBlank(relateId)) {
-                String[] relateIds = relateId.split(",");
-                List<String> newRelateIds = new ArrayList<>();
-                for (String id : relateIds) {
-                    Long lid = Long.valueOf(id.trim());
-                    newRelateIds.add(String.valueOf(map.get(lid)));
+            for (SysPrivilege sysPrivilege : newList) {
+                if (Objects.nonNull(sysPrivilege.getParentId())) {
+                    sysPrivilege.setParentId(map.get(sysPrivilege.getParentId()));
+                }
+                String relateId = sysPrivilege.getRelated();
+                if (StringUtils.isNotBlank(relateId)) {
+                    String[] relateIds = relateId.split(",");
+                    List<String> newRelateIds = new ArrayList<>();
+                    for (String id : relateIds) {
+                        Long lid = Long.valueOf(id.trim());
+                        newRelateIds.add(String.valueOf(map.get(lid)));
+                    }
+                    String newRelateId = String.join(",", newRelateIds);
+                    sysPrivilege.setRelated(newRelateId);
                 }
-                String newRelateId = String.join(",", newRelateIds);
-                sysPrivilege.setRelated(newRelateId);
             }
+            sysPrivilegeService.saveBatch(newList);
         }
-        sysPrivilegeService.saveBatch(newList);
     }
 
     /**