From 84c95a273b0bd8d22d5e14e2a1f88eda1367d8c4 Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Wed, 15 Feb 2023 10:47:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?UserInfo=20=E8=A1=A5=E5=85=85accountId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java index 7eac278..21c009d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/entity/UserInfo.java @@ -76,4 +76,7 @@ public class UserInfo implements Serializable { @ApiModelProperty("身份证号") private String idCard; + @ApiModelProperty("浙政钉accountId") + private Long accountId; + } From 5c2148aa2c5b450425423f3e1a8ea592e15240a1 Mon Sep 17 00:00:00 2001 From: liuxinxin Date: Wed, 15 Feb 2023 10:58:12 +0800 Subject: [PATCH 2/2] batch Task --- .../pmapi/ding/task/EmployeeBatchGetTask.java | 292 +++++++++++---------- .../model/entity/DingEmployeeInfo.java | 10 +- 2 files changed, 156 insertions(+), 146 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 ea96239..c015747 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,144 +1,152 @@ -//package com.ningdatech.pmapi.ding.task; -// -//import cn.hutool.core.collection.CollUtil; -//import com.ningdatech.basic.model.GenericResult; -//import com.ningdatech.pmapi.organization.entity.DingEmployeeInfo; -//import com.ningdatech.pmapi.organization.entity.DingOrganization; -//import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; -//import com.ningdatech.pmapi.organization.service.IDingOrganizationService; -//import com.ningdatech.zwdd.client.ZwddClient; -//import com.ningdatech.zwdd.model.Page; -//import com.ningdatech.zwdd.model.dto.EmployeeAccountIdDTO; -//import com.ningdatech.zwdd.model.query.PageOrganizationEmployeePositionsQuery; -//import com.ningdatech.zwdd.model.response.OrganizationEmployeePosition; -//import com.ningdatech.zwdd.model.response.OrganizationEmployeePosition.GovEmployeePosition; -//import org.springframework.beans.BeanUtils; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Component; -//import org.springframework.transaction.annotation.Transactional; -// -//import java.util.ArrayList; -//import java.util.List; -//import java.util.stream.Collectors; -// -///** -// * @author liuxinxin -// * @date 2023/2/10 上午9:52 -// */ -// -//@Component -//public class EmployeeBatchGetTask { -// -// private final static Integer PAGE_SIZE = 20; -// -// private final static Integer GROUP_SIZE = 100; -// -// @Autowired -// private ZwddClient zwddClient; -// -// @Autowired -// private IDingOrganizationService iDingOrganizationService; -// -// @Autowired -// private IDingEmployeeInfoService iDingEmployeeInfoService; -// -// @Transactional(rollbackFor = Exception.class) -// public void batchGetEmployeeTask() { -// -// // 获取所有的组织列表用户获取组织下的 用户信息 -// List dingOrganizationList = iDingOrganizationService.list(); -// if (CollUtil.isNotEmpty(dingOrganizationList)) { -// for (DingOrganization dingOrganization : dingOrganizationList) { -// List allOrganizationEmployeePositionList = new ArrayList<>(); -// String organizationCode = dingOrganization.getOrganizationCode(); -// PageOrganizationEmployeePositionsQuery query = new PageOrganizationEmployeePositionsQuery(); -// query.setEmployeeStatus("A"); -// query.setOrganizationCode(organizationCode); -// query.setReturnTotalSize(true); -//// query.setTenantId(GovDingProperties.tenantId); -// int pageNo = 1; -// query.setPageNo(pageNo); -// query.setPageSize(PAGE_SIZE); -// -// // 查询组织下 用户信息 -// GenericResult> firstPageGenericResult = zwddClient.pageOrganizationEmployeePositions(query); -// Page data = firstPageGenericResult.getData(); -// if (CollUtil.isNotEmpty(data.getData())) { -// -// allOrganizationEmployeePositionList.addAll(data.getData()); -// } -// Long totalSize = data.getTotalSize(); -// if (totalSize > PAGE_SIZE) { -// int maxPageNo = (int) Math.ceil(totalSize / PAGE_SIZE); -// for (pageNo = 2; pageNo <= maxPageNo; pageNo++) { -// query.setPageNo(maxPageNo); -// GenericResult> pageGenericResult = zwddClient.pageOrganizationEmployeePositions(query); -// if (CollUtil.isNotEmpty(pageGenericResult.getData().getData())) { -// allOrganizationEmployeePositionList.addAll(pageGenericResult.getData().getData()); -// } -// } -// } -// -// List dingEmployeeInfoList = new ArrayList<>(); -// if (allOrganizationEmployeePositionList.size() <= GROUP_SIZE) { -// List employeeCodes = allOrganizationEmployeePositionList.stream().map(OrganizationEmployeePosition::getEmployeeCode).collect(Collectors.toList()); -// GenericResult> listGenericResult = zwddClient.listEmployeeAccountIds(employeeCodes); -//// List employeeAccountIdDTOList = listGenericResult.getData(); -// } else { -//// iDingEmployeeInfoService.saveBatch(); -// } -// // 批量保存用户信息 -// saveBatch(allOrganizationEmployeePositionList); +package com.ningdatech.pmapi.ding.task; + +import cn.hutool.core.collection.CollUtil; +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.client.ZwddClient; +import com.ningdatech.zwdd.model.Page; +import com.ningdatech.zwdd.model.dto.EmployeeAccountIdDTO; +import com.ningdatech.zwdd.model.query.PageOrganizationEmployeePositionsQuery; +import com.ningdatech.zwdd.model.response.OrganizationEmployeePosition; +import com.ningdatech.zwdd.model.response.OrganizationEmployeePosition.GovEmployeePosition; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author liuxinxin + * @date 2023/2/10 上午9:52 + */ + +@Component +public class EmployeeBatchGetTask { + + private final static Integer PAGE_SIZE = 20; + + private final static Integer GROUP_SIZE = 100; + + @Autowired + private ZwddClient zwddClient; + + @Autowired + private IDingOrganizationService iDingOrganizationService; + + @Autowired + private IDingEmployeeInfoService iDingEmployeeInfoService; + + @Transactional(rollbackFor = Exception.class) + public void batchGetEmployeeTask() { + + // 获取所有的组织列表用户获取组织下的 用户信息 + List dingOrganizationList = iDingOrganizationService.list(); + if (CollUtil.isNotEmpty(dingOrganizationList)) { + for (DingOrganization dingOrganization : dingOrganizationList) { + List allOrganizationEmployeePositionList = new ArrayList<>(); + String organizationCode = dingOrganization.getOrganizationCode(); + PageOrganizationEmployeePositionsQuery query = new PageOrganizationEmployeePositionsQuery(); + query.setEmployeeStatus("A"); + query.setOrganizationCode(organizationCode); + query.setReturnTotalSize(true); +// query.setTenantId(GovDingProperties.tenantId); + int pageNo = 1; + query.setPageNo(pageNo); + query.setPageSize(PAGE_SIZE); + + // 查询组织下 用户信息 + GenericResult> firstPageGenericResult = zwddClient.pageOrganizationEmployeePositions(query); + Page data = firstPageGenericResult.getData(); + if (CollUtil.isNotEmpty(data.getData())) { + + allOrganizationEmployeePositionList.addAll(data.getData()); + } + Long totalSize = data.getTotalSize(); + if (totalSize > PAGE_SIZE) { + int maxPageNo = (int) Math.ceil(totalSize / PAGE_SIZE); + for (pageNo = 2; pageNo <= maxPageNo; pageNo++) { + query.setPageNo(maxPageNo); + GenericResult> pageGenericResult = zwddClient.pageOrganizationEmployeePositions(query); + if (CollUtil.isNotEmpty(pageGenericResult.getData().getData())) { + allOrganizationEmployeePositionList.addAll(pageGenericResult.getData().getData()); + } + } + } + + // 批量查询 成员的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); + } else { +// iDingEmployeeInfoService.saveBatch(); + } + // 批量保存用户信息 + saveBatch(allOrganizationEmployeePositionList); + } + } + + + } + + private List buildDingEmployeeInfoRecordList(List allOrganizationEmployeePositionList) { + List saveRecordList = new ArrayList<>(); + for (OrganizationEmployeePosition organizationEmployeePosition : allOrganizationEmployeePositionList) { + List govEmployeePositions = organizationEmployeePosition.getGovEmployeePositions(); + if (CollUtil.isNotEmpty(govEmployeePositions)) { + List segmentSaveRecordList = new ArrayList<>(); + for (GovEmployeePosition govEmployeePosition : govEmployeePositions) { + DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); + BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); + dingEmployeeInfo.setMainJob(govEmployeePosition.getMainJob()); + dingEmployeeInfo.setEmpPosUnitCode(govEmployeePosition.getEmpPosUnitCode()); + dingEmployeeInfo.setEmpPosEmployeeRoleCode(govEmployeePosition.getEmpPosEmployeeRoleCode()); + dingEmployeeInfo.setEmpPosInnerInstitutionCode(govEmployeePosition.getEmpPosInnerInstitutionCode()); + dingEmployeeInfo.setEmployeeCode(govEmployeePosition.getEmployeeCode()); + dingEmployeeInfo.setJobAttributesCode(govEmployeePosition.getJobAttributesCode()); + dingEmployeeInfo.setOrganizationCode(govEmployeePosition.getOrganizationCode()); + dingEmployeeInfo.setEmpPosVirtualOrganizationCode(govEmployeePosition.getEmpPosVirtualOrganizationCode()); + dingEmployeeInfo.setEmpStatus(govEmployeePosition.getStatus()); + segmentSaveRecordList.add(dingEmployeeInfo); + } + saveRecordList.addAll(segmentSaveRecordList); + } else { + DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); + BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); + saveRecordList.add(dingEmployeeInfo); + } + } + 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 List buildDingEmployeeInfoRecord(List allOrganizationEmployeePositionList) { -// List saveRecordList = new ArrayList<>(); -// for (OrganizationEmployeePosition organizationEmployeePosition : allOrganizationEmployeePositionList) { -// List govEmployeePositions = organizationEmployeePosition.getGovEmployeePositions(); -// if (CollUtil.isNotEmpty(govEmployeePositions)) { -// List segmentSaveRecordList = new ArrayList<>(); -// for (GovEmployeePosition govEmployeePosition : govEmployeePositions) { -// DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); -// BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); -// dingEmployeeInfo.setMainJob(govEmployeePosition.getMainJob()); -// dingEmployeeInfo.setEmpPosUnitCode(govEmployeePosition.getEmpPosUnitCode()); -// dingEmployeeInfo.setEmpPosEmployeeRoleCode(govEmployeePosition.getEmpPosEmployeeRoleCode()); -// dingEmployeeInfo.setEmpPosInnerInstitutionCode(govEmployeePosition.getEmpPosInnerInstitutionCode()); -// dingEmployeeInfo.setEmployeeCode(govEmployeePosition.getEmployeeCode()); -// dingEmployeeInfo.setJobAttributesCode(govEmployeePosition.getJobAttributesCode()); -// dingEmployeeInfo.setOrganizationCode(govEmployeePosition.getOrganizationCode()); -// dingEmployeeInfo.setEmpPosVirtualOrganizationCode(govEmployeePosition.getEmpPosVirtualOrganizationCode()); -// dingEmployeeInfo.setEmpStatus(govEmployeePosition.getStatus()); -// segmentSaveRecordList.add(dingEmployeeInfo); -// } -// saveRecordList.addAll(segmentSaveRecordList); -// } else { -// DingEmployeeInfo dingEmployeeInfo = new DingEmployeeInfo(); -// BeanUtils.copyProperties(organizationEmployeePosition, dingEmployeeInfo); -// saveRecordList.add(dingEmployeeInfo); -// } -// -// -// } -// return null; -// } -// -// 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); -//// } -//// } -// -// } -//} + + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingEmployeeInfo.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingEmployeeInfo.java index a0e52ad..5513659 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingEmployeeInfo.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/model/entity/DingEmployeeInfo.java @@ -1,15 +1,15 @@ package com.ningdatech.pmapi.organization.model.entity; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.time.LocalDateTime; import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.io.Serializable; +import java.time.LocalDateTime; + /** *

- * + * *

* * @author Lierbao @@ -68,4 +68,6 @@ public class DingEmployeeInfo implements Serializable { private String empStatus; + private Long accountId; + }