组织同步逻辑修改
This commit is contained in:
+64
-33
@@ -200,7 +200,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
return new ServiceException("调用OA接口查询公司信息失败");
|
return new ServiceException("调用OA接口查询公司信息失败");
|
||||||
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
||||||
// 处理数据
|
// 处理数据
|
||||||
OrgSyncCount syncCount = handleCompany(list);
|
OrgSyncCount syncCount = handleCompany(list, false);
|
||||||
notHandleList.addAll(syncCount.getNotHandledList());
|
notHandleList.addAll(syncCount.getNotHandledList());
|
||||||
});
|
});
|
||||||
// 3. 未处理的数据
|
// 3. 未处理的数据
|
||||||
@@ -217,7 +217,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
* @param startTime 查询开始时间
|
* @param startTime 查询开始时间
|
||||||
*/
|
*/
|
||||||
private void syncDept(Date startTime) {
|
private void syncDept(Date startTime) {
|
||||||
String subCompanyIds = getSubCompanyIds();
|
String subCompanyIds = getOaSubCompanyIds(false);
|
||||||
if (StringUtils.isEmpty(subCompanyIds)) {
|
if (StringUtils.isEmpty(subCompanyIds)) {
|
||||||
ComposeLogUtil.getLastLog().warn("未查询到子公司查询参数");
|
ComposeLogUtil.getLastLog().warn("未查询到子公司查询参数");
|
||||||
return;
|
return;
|
||||||
@@ -232,7 +232,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
return new ServiceException("调用OA接口查询部门信息失败");
|
return new ServiceException("调用OA接口查询部门信息失败");
|
||||||
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
}, 10000, ComposeLogUtil.getLastLog()::info).accept(list -> {
|
||||||
// 处理数据
|
// 处理数据
|
||||||
OrgSyncCount syncCount = handleDept(list);
|
OrgSyncCount syncCount = handleDept(list, false);
|
||||||
notHandleList.addAll(syncCount.getNotHandledList());
|
notHandleList.addAll(syncCount.getNotHandledList());
|
||||||
});
|
});
|
||||||
// 3. 未处理的数据
|
// 3. 未处理的数据
|
||||||
@@ -338,7 +338,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
List<OACompanyResponse> oaCompanies = responseData.getDataList() == null
|
List<OACompanyResponse> oaCompanies = responseData.getDataList() == null
|
||||||
? Collections.emptyList() : responseData.getDataList();
|
? Collections.emptyList() : responseData.getDataList();
|
||||||
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
||||||
OrgSyncCount syncCount = handleCompany(oaCompanies);
|
OrgSyncCount syncCount = handleCompany(oaCompanies, true);
|
||||||
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
||||||
ComposeLogUtil.getLastLog().warn("同步公司,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
ComposeLogUtil.getLastLog().warn("同步公司,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
||||||
}
|
}
|
||||||
@@ -363,9 +363,9 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
private OaOrgSyncPageVO syncDepartmentFromOaPage(int current, int size) {
|
private OaOrgSyncPageVO syncDepartmentFromOaPage(int current, int size) {
|
||||||
int pageNo = current < 1 ? 1 : current;
|
int pageNo = current < 1 ? 1 : current;
|
||||||
int pageSize = size < 1 ? 20 : Math.min(size, 200);
|
int pageSize = size < 1 ? 20 : Math.min(size, 200);
|
||||||
String subCompanyIds = getSubCompanyIds();
|
String subCompanyIds = getOaSubCompanyIds(true);
|
||||||
if (StringUtils.isEmpty(subCompanyIds)) {
|
if (StringUtils.isEmpty(subCompanyIds)) {
|
||||||
ComposeLogUtil.getLastLog().warn("未查询到子公司查询参数,跳过部门同步");
|
ComposeLogUtil.getLastLog().warn("未查询到已同步的OA公司,跳过部门同步");
|
||||||
OaOrgSyncPageVO emptyPageVO = buildOrgSyncPageVO("department", pageNo, pageSize, 0L, 0, OrgSyncCount.empty());
|
OaOrgSyncPageVO emptyPageVO = buildOrgSyncPageVO("department", pageNo, pageSize, 0L, 0, OrgSyncCount.empty());
|
||||||
emptyPageVO.setFinished(true);
|
emptyPageVO.setFinished(true);
|
||||||
return emptyPageVO;
|
return emptyPageVO;
|
||||||
@@ -382,7 +382,7 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
List<OADepartmentResponse> oaDepartments = responseData.getDataList() == null
|
List<OADepartmentResponse> oaDepartments = responseData.getDataList() == null
|
||||||
? Collections.emptyList() : responseData.getDataList();
|
? Collections.emptyList() : responseData.getDataList();
|
||||||
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
long totalSize = responseData.getTotalSize() == null ? 0L : responseData.getTotalSize();
|
||||||
OrgSyncCount syncCount = handleDept(oaDepartments);
|
OrgSyncCount syncCount = handleDept(oaDepartments, true);
|
||||||
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
if (CollectionUtil.isNotEmpty(syncCount.getNotHandledList())) {
|
||||||
ComposeLogUtil.getLastLog().warn("同步部门,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
ComposeLogUtil.getLastLog().warn("同步部门,本页未处理数据:{}", JSON.toJSONString(syncCount.getNotHandledList()));
|
||||||
}
|
}
|
||||||
@@ -477,19 +477,20 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理oa公司
|
* 处理oa公司
|
||||||
* @param oaCompanies
|
* @param oaCompanies OA公司列表
|
||||||
|
* @param syncAll true=自动同步时不过滤字典白名单;false=仅同步配置的公司名称
|
||||||
* @return 同步统计
|
* @return 同步统计
|
||||||
*/
|
*/
|
||||||
private OrgSyncCount handleCompany(List<OACompanyResponse> oaCompanies) {
|
private OrgSyncCount handleCompany(List<OACompanyResponse> oaCompanies, boolean syncAll) {
|
||||||
if (CollectionUtil.isEmpty(oaCompanies)) {
|
if (CollectionUtil.isEmpty(oaCompanies)) {
|
||||||
return OrgSyncCount.empty();
|
return OrgSyncCount.empty();
|
||||||
}
|
}
|
||||||
// 获取需要的公司名称
|
// 获取需要的公司名称
|
||||||
Set<String> companyNames = getCompanyNames();
|
Set<String> companyNames = syncAll ? Collections.emptySet() : getCompanyNames();
|
||||||
// 转换数据
|
// 转换数据
|
||||||
List<Dept> allParam = oaCompanies.stream()
|
List<Dept> allParam = oaCompanies.stream()
|
||||||
// 筛选只要需要的公司
|
// 非全量同步时,筛选只要配置的公司
|
||||||
.filter(company -> companyNames.contains(company.getSubcompanyname()))
|
.filter(company -> syncAll || companyNames.contains(company.getSubcompanyname()))
|
||||||
.map(deptConvert::company2dept)
|
.map(deptConvert::company2dept)
|
||||||
.toList();
|
.toList();
|
||||||
int filteredSkipCount = oaCompanies.size() - allParam.size();
|
int filteredSkipCount = oaCompanies.size() - allParam.size();
|
||||||
@@ -509,10 +510,11 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理oa部门
|
* 处理oa部门
|
||||||
* @param oaDepts
|
* @param oaDepts OA部门列表
|
||||||
|
* @param syncAll true=自动同步时不过滤根公司部门白名单;false=沿用原过滤规则
|
||||||
* @return 同步统计
|
* @return 同步统计
|
||||||
*/
|
*/
|
||||||
private OrgSyncCount handleDept(List<OADepartmentResponse> oaDepts) {
|
private OrgSyncCount handleDept(List<OADepartmentResponse> oaDepts, boolean syncAll) {
|
||||||
if (CollectionUtil.isEmpty(oaDepts)) {
|
if (CollectionUtil.isEmpty(oaDepts)) {
|
||||||
return OrgSyncCount.empty();
|
return OrgSyncCount.empty();
|
||||||
}
|
}
|
||||||
@@ -520,15 +522,18 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
Map<String, Long> companyDeptMap = getAllCompanyDeptMap();
|
Map<String, Long> companyDeptMap = getAllCompanyDeptMap();
|
||||||
// 根公司id
|
// 根公司id
|
||||||
String rootCompanyId = getRootCompanyId();
|
String rootCompanyId = getRootCompanyId();
|
||||||
if (rootCompanyId == null) {
|
if (!syncAll && rootCompanyId == null) {
|
||||||
return new OrgSyncCount(0, oaDepts.size(), Collections.emptyList());
|
return new OrgSyncCount(0, oaDepts.size(), Collections.emptyList());
|
||||||
}
|
}
|
||||||
// 根公司下要同步的部门名称
|
// 根公司下要同步的部门名称
|
||||||
Set<String> rootCompanyDeptNames = getRootCompanyDeptNames();
|
Set<String> rootCompanyDeptNames = syncAll ? Collections.emptySet() : getRootCompanyDeptNames();
|
||||||
// 转换数据
|
// 转换数据
|
||||||
List<Dept> allParam = oaDepts.stream()
|
List<Dept> allParam = oaDepts.stream()
|
||||||
// 部门的公司不是根公司,或者部门名称在根公司下需要同步的部门列表中,且是根部门
|
// 全量同步时不过滤;否则:部门的公司不是根公司,或者部门名称在根公司下需要同步的部门列表中,且是根部门
|
||||||
.filter(oaDept -> !rootCompanyId.equals(oaDept.getSubcompanyid1()) || (OAConstant.ROOT_COMPANY_ID.equals(oaDept.getSupdepid()) && rootCompanyDeptNames.contains(oaDept.getDepartmentname())))
|
.filter(oaDept -> syncAll
|
||||||
|
|| rootCompanyId == null
|
||||||
|
|| !rootCompanyId.equals(oaDept.getSubcompanyid1())
|
||||||
|
|| (OAConstant.ROOT_COMPANY_ID.equals(oaDept.getSupdepid()) && rootCompanyDeptNames.contains(oaDept.getDepartmentname())))
|
||||||
.map(dept -> deptConvert.dept2dept(dept, companyDeptMap))
|
.map(dept -> deptConvert.dept2dept(dept, companyDeptMap))
|
||||||
.toList();
|
.toList();
|
||||||
int filteredSkipCount = oaDepts.size() - allParam.size();
|
int filteredSkipCount = oaDepts.size() - allParam.size();
|
||||||
@@ -551,6 +556,8 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
).stream()
|
).stream()
|
||||||
.filter(dept -> StringUtils.isNotEmpty(dept.getDeptCode()))
|
.filter(dept -> StringUtils.isNotEmpty(dept.getDeptCode()))
|
||||||
.collect(Collectors.toMap(Dept::getDeptCode, Dept::getId, (a, b) -> b));
|
.collect(Collectors.toMap(Dept::getDeptCode, Dept::getId, (a, b) -> b));
|
||||||
|
// 公司编码也放入 map,根部门挂到公司时才能解析父级
|
||||||
|
companyDeptMap.forEach(deptMap::putIfAbsent);
|
||||||
// 处理部门
|
// 处理部门
|
||||||
List<Dept> notHandledList = this.handleDept(allParam, deptMap, DeptCategory.DEPT);
|
List<Dept> notHandledList = this.handleDept(allParam, deptMap, DeptCategory.DEPT);
|
||||||
int syncedCount = allParam.size() - notHandledList.size();
|
int syncedCount = allParam.size() - notHandledList.size();
|
||||||
@@ -657,24 +664,48 @@ public class OASyncServiceImpl implements IOASyncService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取oa查询参数,子公司id参数
|
* 获取 OA 部门查询使用的子公司 id
|
||||||
* @return
|
*
|
||||||
|
* @param syncAll true=取已同步的全部 OA 公司;false=仅取字典配置的公司
|
||||||
|
* @return 逗号分隔的 OA 公司 id
|
||||||
*/
|
*/
|
||||||
private String getSubCompanyIds() {
|
private String getOaSubCompanyIds(boolean syncAll) {
|
||||||
Set<String> companyNames = this.getCompanyNames();
|
List<Dept> companyList;
|
||||||
if (companyNames.isEmpty()) {
|
if (syncAll) {
|
||||||
|
companyList = deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||||
|
.eq(Dept::getDeptCategory, DeptCategory.COMPANY.getCode())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Set<String> companyNames = this.getCompanyNames();
|
||||||
|
if (companyNames.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
companyList = deptService.list(Wrappers.<Dept>lambdaQuery()
|
||||||
|
.in(Dept::getDeptName, companyNames)
|
||||||
|
.eq(Dept::getDeptCategory, DeptCategory.COMPANY.getCode())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return companyList.stream()
|
||||||
|
.map(this::resolveOaCompanyId)
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析本地公司对应的 OA 公司 id
|
||||||
|
*/
|
||||||
|
private String resolveOaCompanyId(Dept dept) {
|
||||||
|
if (dept == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return deptService.list(Wrappers.<Dept>lambdaQuery()
|
if (StringUtils.isNotBlank(dept.getOaId())) {
|
||||||
// 根据名称查询公司
|
return dept.getOaId();
|
||||||
.in(Dept::getDeptName, companyNames)
|
}
|
||||||
.eq(Dept::getDeptCategory, DeptCategory.COMPANY.getCode())
|
if (StringUtils.isNotBlank(dept.getDeptCode()) && dept.getDeptCode().startsWith(OAConvertConstant.COMPANY_OA_PREFIX)) {
|
||||||
).stream()
|
return dept.getDeptCode().replace(OAConvertConstant.COMPANY_OA_PREFIX, "");
|
||||||
// 只要部门编码不为空,且包含了oa公司前缀的
|
}
|
||||||
.filter(dept -> StringUtils.isNotBlank(dept.getDeptCode()) && dept.getDeptCode().contains(OAConvertConstant.COMPANY_OA_PREFIX))
|
return null;
|
||||||
// 去掉oa公司前缀
|
|
||||||
.map(dept -> dept.getDeptCode().replace(OAConvertConstant.COMPANY_OA_PREFIX, ""))
|
|
||||||
.collect(Collectors.joining(","));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user