소스 검색

Merge remote-tracking branch 'origin/master'

tags/24080901
WendyYang 1 년 전
부모
커밋
4c5bbff522
1개의 변경된 파일37개의 추가작업 그리고 27개의 파일을 삭제
  1. +37
    -27
      pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java

+ 37
- 27
pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java 파일 보기

@@ -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);
}
}
}
}

불러오는 중...
취소
저장