|
@@ -1046,12 +1046,16 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
}
|
|
|
|
|
|
watch.start("orgInfoAddSync");
|
|
|
- orgInfoAddSync();
|
|
|
+ List<AuthOrgInfo> updateOrgInfos = orgInfoAddSync();
|
|
|
watch.stop();
|
|
|
|
|
|
watch.start("Set path And ReInitTrees");
|
|
|
- List<String> updateOrgCodes = setAddPathAndUpId();
|
|
|
- orgTreeService.updateTreeByCode(updateOrgCodes, false);
|
|
|
+ List<String> updateOrgCodesInTrees = setAddPathAndUpId(updateOrgInfos);
|
|
|
+ List<String> delCode = orgAddOriginalService.getDelCodes();
|
|
|
+ //需要删除的机构code也加入
|
|
|
+ //如果同一个机构code是先删除后新增的机构,id也变了也需要从树结构中移除
|
|
|
+ updateOrgCodesInTrees.addAll(delCode);
|
|
|
+ orgTreeService.updateTreeByCode(updateOrgCodesInTrees, false);
|
|
|
watch.stop();
|
|
|
|
|
|
watch.start("onOrgSyncEnd");
|
|
@@ -1071,21 +1075,20 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- private List<String> setAddPathAndUpId() {
|
|
|
- List<String> addOrgCodes = orgAddOriginalService.getCodes();
|
|
|
+ private List<String> setAddPathAndUpId(List<AuthOrgInfo> updateOrgInfos) {
|
|
|
+ Set<String> addOrgCodes = updateOrgInfos.stream().map(AuthOrgInfo::getCode).collect(Collectors.toSet());
|
|
|
//获取新增或修改的机构
|
|
|
- List<AuthOrgInfo> addOrgInfos = authOrgInfoService.getOrgByCodes(addOrgCodes);
|
|
|
- List<String> upOrgInfoCodes = addOrgInfos.stream()
|
|
|
+ List<String> upOrgInfoCodes = updateOrgInfos.stream()
|
|
|
.map(AuthOrgInfo::getUpGovCode)
|
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
- //查询增量同步机构在已存在机构中的上级机构
|
|
|
+ //查询增量同步机构中的上级机构,且是已存在机构表中的机构
|
|
|
List<String> collect = upOrgInfoCodes.stream().filter(e -> !addOrgCodes.contains(e)).collect(Collectors.toList());
|
|
|
List<AuthOrgInfo> upOrgInfos = authOrgInfoService.getOrgByCodes(collect);
|
|
|
//设置path和upGovId
|
|
|
Map<String, AuthOrgInfo> upOrgMap = upOrgInfos.stream()
|
|
|
.collect(Collectors.toMap(AuthOrgInfo::getCode, e -> e, (old, last) -> last));
|
|
|
- Map<String, List<AuthOrgInfo>> addOrgGroup = addOrgInfos.stream()
|
|
|
+ Map<String, List<AuthOrgInfo>> addOrgGroup = updateOrgInfos.stream()
|
|
|
.collect(Collectors.groupingBy(AuthOrgInfo::getUpGovCode));
|
|
|
Set<String> upOrgCodes = upOrgMap.keySet();
|
|
|
Deque<String> deque = new LinkedList<>(upOrgCodes);
|
|
@@ -1110,28 +1113,26 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ //经过这次循环之后所有需要修改机构树的节点code都被添加到upOrgCodes
|
|
|
+
|
|
|
//批量更新机构path和upGovId、upGovName
|
|
|
- authOrgInfoService.batchUpdatePathUpGovId(addOrgInfos);
|
|
|
+ authOrgInfoService.batchUpdatePathUpGovId(updateOrgInfos);
|
|
|
|
|
|
- //过滤被删除的机构code
|
|
|
- Set<String> addOrgCodeSet = addOrgInfos.stream().map(AuthOrgInfo::getCode).collect(Collectors.toSet());
|
|
|
- List<String> delOrgCodes = addOrgCodes.stream().filter(e -> !addOrgCodeSet.contains(e)).distinct().collect(Collectors.toList());
|
|
|
//返回所有需要修改树节点信息的机构code
|
|
|
- //这里只添加能串树节点的机构code和删除的机构code
|
|
|
- List<String> list = new ArrayList<>(upOrgCodes);
|
|
|
- list.addAll(delOrgCodes);
|
|
|
- return list;
|
|
|
+ //这里只添加能串联起树节点的机构code
|
|
|
+ return new ArrayList<>(upOrgCodes);
|
|
|
}
|
|
|
|
|
|
- private void orgInfoAddSync() {
|
|
|
+ private List<AuthOrgInfo> orgInfoAddSync() {
|
|
|
int currentPage = 0;
|
|
|
Searchable searchable = Searchable.newSearchable();
|
|
|
searchable.addSort(Sort.Direction.ASC, "orgUpdateTime");
|
|
|
+ List<AuthOrgInfo> list = new ArrayList<>();
|
|
|
do {
|
|
|
searchable.setPage(currentPage, 1000);
|
|
|
Page<AuthOrgAddOriginal> page = orgAddOriginalService.pageSearch(searchable);
|
|
|
if(page.isEmpty()) {
|
|
|
- return;
|
|
|
+ break;
|
|
|
}
|
|
|
List<AuthOrgAddOriginal> content = page.getContent();
|
|
|
List<AuthOrgInfo> orgInfoList = content.stream().map(item -> {
|
|
@@ -1147,10 +1148,11 @@ public class SubSyncBusinessImpl implements ISubSyncBusiness {
|
|
|
return authOrgInfo;
|
|
|
}
|
|
|
}).collect(Collectors.toList());
|
|
|
- authOrgInfoService.batchSaveByOrgCode(orgInfoList);
|
|
|
+ List<AuthOrgInfo> updateOrgInfos = authOrgInfoService.batchSaveByOrgCode(orgInfoList);
|
|
|
+ list.addAll(updateOrgInfos);
|
|
|
++currentPage;
|
|
|
}while (true);
|
|
|
-
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
private Integer getOrgInfoAddFromRemote(Integer pageSize, Date syncStartTime, List<Header> headers) {
|