|
|
@@ -1,11 +1,13 @@ |
|
|
|
package com.ningdatech.pmapi.ding.task; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.ningdatech.basic.model.GenericResult; |
|
|
|
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; |
|
|
|
import com.ningdatech.pmapi.organization.model.entity.DingOrganization; |
|
|
|
import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; |
|
|
|
import com.ningdatech.pmapi.organization.service.IDingOrganizationService; |
|
|
|
import com.ningdatech.zwdd.ZwddIntegrationProperties; |
|
|
|
import com.ningdatech.zwdd.client.ZwddClient; |
|
|
|
import com.ningdatech.zwdd.model.Page; |
|
|
|
import com.ningdatech.zwdd.model.dto.EmployeeAccountIdDTO; |
|
|
@@ -43,6 +45,9 @@ public class EmployeeBatchGetTask { |
|
|
|
@Autowired |
|
|
|
private IDingEmployeeInfoService iDingEmployeeInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ZwddIntegrationProperties zwddIntegrationProperties; |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void batchGetEmployeeTask() { |
|
|
|
|
|
|
@@ -56,7 +61,7 @@ public class EmployeeBatchGetTask { |
|
|
|
query.setEmployeeStatus("A"); |
|
|
|
query.setOrganizationCode(organizationCode); |
|
|
|
query.setReturnTotalSize(true); |
|
|
|
// query.setTenantId(GovDingProperties.tenantId); |
|
|
|
query.setTenantId(zwddIntegrationProperties.getTenantId()); |
|
|
|
int pageNo = 1; |
|
|
|
query.setPageNo(pageNo); |
|
|
|
query.setPageSize(PAGE_SIZE); |
|
|
@@ -83,28 +88,35 @@ public class EmployeeBatchGetTask { |
|
|
|
// 批量查询 成员的accountId |
|
|
|
List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList = new ArrayList<>(); |
|
|
|
if (allOrganizationEmployeePositionList.size() <= GROUP_SIZE) { |
|
|
|
List<String> employeeCodes = allOrganizationEmployeePositionList.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); |
|
|
|
GenericResult<List<EmployeeAccountIdDTO>> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); |
|
|
|
List<EmployeeAccountIdDTO> employeeAccountIdDTOList = listGenericResult.getData(); |
|
|
|
Map<String, Long> employeeCodeAccountIdMap = employeeAccountIdDTOList.stream() |
|
|
|
.collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); |
|
|
|
|
|
|
|
List<DingEmployeeInfo> dingEmployeeInfos = buildDingEmployeeInfoRecordList(allOrganizationEmployeePositionList); |
|
|
|
|
|
|
|
dingEmployeeInfos = dingEmployeeInfos.stream().map(r -> { |
|
|
|
r.setAccountId(employeeCodeAccountIdMap.get(r.getEmployeeCode())); |
|
|
|
return r; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
dingEmployeeInfoSaveRecordList.addAll(dingEmployeeInfos); |
|
|
|
assemblerAccountId(allOrganizationEmployeePositionList, dingEmployeeInfoSaveRecordList); |
|
|
|
} else { |
|
|
|
// iDingEmployeeInfoService.saveBatch(); |
|
|
|
List<List<OrganizationEmployeePosition>> split = Lists.partition(allOrganizationEmployeePositionList, GROUP_SIZE); |
|
|
|
for (List<OrganizationEmployeePosition> segment : split) { |
|
|
|
assemblerAccountId(segment, dingEmployeeInfoSaveRecordList); |
|
|
|
} |
|
|
|
} |
|
|
|
// 批量保存用户信息 |
|
|
|
saveBatch(allOrganizationEmployeePositionList); |
|
|
|
saveBatch(dingEmployeeInfoSaveRecordList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void assemblerAccountId(List<OrganizationEmployeePosition> segment, List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList) { |
|
|
|
List<String> employeeCodes = segment.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); |
|
|
|
GenericResult<List<EmployeeAccountIdDTO>> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); |
|
|
|
List<EmployeeAccountIdDTO> employeeAccountIdDTOList = listGenericResult.getData(); |
|
|
|
Map<String, Long> employeeCodeAccountIdMap = employeeAccountIdDTOList.stream() |
|
|
|
.collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); |
|
|
|
|
|
|
|
List<DingEmployeeInfo> dingEmployeeInfos = buildDingEmployeeInfoRecordList(segment); |
|
|
|
|
|
|
|
dingEmployeeInfos = dingEmployeeInfos.stream().map(r -> { |
|
|
|
r.setAccountId(employeeCodeAccountIdMap.get(r.getEmployeeCode())); |
|
|
|
return r; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
dingEmployeeInfoSaveRecordList.addAll(dingEmployeeInfos); |
|
|
|
} |
|
|
|
|
|
|
|
private List<DingEmployeeInfo> buildDingEmployeeInfoRecordList(List<OrganizationEmployeePosition> allOrganizationEmployeePositionList) { |
|
|
@@ -137,16 +149,14 @@ public class EmployeeBatchGetTask { |
|
|
|
return saveRecordList; |
|
|
|
} |
|
|
|
|
|
|
|
private void saveBatch(List<OrganizationEmployeePosition> allOrganizationEmployeePositionList) { |
|
|
|
// // 批量保存 |
|
|
|
// if (saveRecordList.size() <= GROUP_SIZE) { |
|
|
|
// iDingOrganizationService.saveBatch(saveRecordList); |
|
|
|
// } else { |
|
|
|
// List<List<DingOrganization>> split = Lists.partition(saveRecordList, GROUP_SIZE); |
|
|
|
// for (List<DingOrganization> segment : split) { |
|
|
|
// iDingOrganizationService.saveBatch(segment); |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
private void saveBatch(List<DingEmployeeInfo> dingEmployeeInfoSaveRecordList) { |
|
|
|
if (dingEmployeeInfoSaveRecordList.size() <= GROUP_SIZE) { |
|
|
|
iDingEmployeeInfoService.saveBatch(dingEmployeeInfoSaveRecordList); |
|
|
|
} else { |
|
|
|
List<List<DingEmployeeInfo>> split = Lists.partition(dingEmployeeInfoSaveRecordList, GROUP_SIZE); |
|
|
|
for (List<DingEmployeeInfo> segment : split) { |
|
|
|
iDingEmployeeInfoService.saveBatch(segment); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |