From 8bfdaf54996b96e2fcdc9025dd3af7bb4d14662a Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Wed, 15 Feb 2023 11:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=9F=A5=E8=AF=A2=20?= =?UTF-8?q?=E6=88=90=E5=91=98=E7=9A=84accountId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/ding/task/EmployeeBatchGetTask.java | 64 +++++++++++++--------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java index c015747..9eb8877 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/EmployeeBatchGetTask.java +++ b/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 dingEmployeeInfoSaveRecordList = new ArrayList<>(); if (allOrganizationEmployeePositionList.size() <= GROUP_SIZE) { - List employeeCodes = allOrganizationEmployeePositionList.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); - GenericResult> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); - List employeeAccountIdDTOList = listGenericResult.getData(); - Map employeeCodeAccountIdMap = employeeAccountIdDTOList.stream() - .collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); - - List 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> split = Lists.partition(allOrganizationEmployeePositionList, GROUP_SIZE); + for (List segment : split) { + assemblerAccountId(segment, dingEmployeeInfoSaveRecordList); + } } // 批量保存用户信息 - saveBatch(allOrganizationEmployeePositionList); + saveBatch(dingEmployeeInfoSaveRecordList); } } + } + + private void assemblerAccountId(List segment, List dingEmployeeInfoSaveRecordList) { + List employeeCodes = segment.stream().map(OrganizationEmployeePosition::getEmployeeCode).distinct().collect(Collectors.toList()); + GenericResult> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); + List employeeAccountIdDTOList = listGenericResult.getData(); + Map employeeCodeAccountIdMap = employeeAccountIdDTOList.stream() + .collect(Collectors.toMap(EmployeeAccountIdDTO::getEmployeeCode, EmployeeAccountIdDTO::getAccountId)); + + List dingEmployeeInfos = buildDingEmployeeInfoRecordList(segment); + + dingEmployeeInfos = dingEmployeeInfos.stream().map(r -> { + r.setAccountId(employeeCodeAccountIdMap.get(r.getEmployeeCode())); + return r; + }).collect(Collectors.toList()); + dingEmployeeInfoSaveRecordList.addAll(dingEmployeeInfos); } private List buildDingEmployeeInfoRecordList(List allOrganizationEmployeePositionList) { @@ -137,16 +149,14 @@ public class EmployeeBatchGetTask { return saveRecordList; } - private void saveBatch(List allOrganizationEmployeePositionList) { -// // 批量保存 -// if (saveRecordList.size() <= GROUP_SIZE) { -// iDingOrganizationService.saveBatch(saveRecordList); -// } else { -// List> split = Lists.partition(saveRecordList, GROUP_SIZE); -// for (List segment : split) { -// iDingOrganizationService.saveBatch(segment); -// } -// } - + private void saveBatch(List dingEmployeeInfoSaveRecordList) { + if (dingEmployeeInfoSaveRecordList.size() <= GROUP_SIZE) { + iDingEmployeeInfoService.saveBatch(dingEmployeeInfoSaveRecordList); + } else { + List> split = Lists.partition(dingEmployeeInfoSaveRecordList, GROUP_SIZE); + for (List segment : split) { + iDingEmployeeInfoService.saveBatch(segment); + } + } } }