From f25075576d93b318367667ca3820ac7318f49434 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Mon, 25 Sep 2023 13:59:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8D=89=E7=A8=BF=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/organization/OrganizationTest.java | 150 ++++++++++++++++++++- .../projectCollection/ProjectCollectionTest.java | 2 +- 2 files changed, 148 insertions(+), 4 deletions(-) diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java index 478f66b..9201518 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java @@ -1,21 +1,32 @@ package com.ningdatech.pmapi.organization; +import cn.hutool.core.collection.CollUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.collect.Lists; import com.ningdatech.basic.model.GenericResult; import com.ningdatech.pmapi.AppTests; +import com.ningdatech.pmapi.ding.model.DingOrgInfoTreeDTO; import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask; import com.ningdatech.pmapi.ding.task.GovBusinessStripsTask; import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; +import com.ningdatech.pmapi.organization.model.entity.DingOrganization; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; import com.ningdatech.zwdd.client.ZwddClient; -import com.ningdatech.zwdd.model.dto.DingInfoByMobileDTO; -import com.ningdatech.zwdd.model.dto.EmployeeInfoDTO; +import com.ningdatech.zwdd.model.dto.*; +import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.*; +import java.util.stream.Collectors; + /** * @author liuxinxin * @date 2023/2/9 下午3:54 */ - +@Slf4j class OrganizationTest extends AppTests { @Autowired @@ -30,6 +41,11 @@ class OrganizationTest extends AppTests { @Autowired private ZwddClient zwddClient; + @Autowired + private IDingOrganizationService organizationService; + + private static final Integer GROUP_SIZE = 100; + @Test public void testBatchGetOrganization() { organizationBatchGetTask.batchGetOrganizationTask(); @@ -54,4 +70,132 @@ class OrganizationTest extends AppTests { System.out.println("---"); } + @Test + public void test2() { + // 获取顶级组织code + GenericResult scopesV2Result = zwddClient.getScopesV2(); + DingScopesV2DTO scopesV2 = scopesV2Result.getData(); + + if (Objects.nonNull(scopesV2)) { + List currentAllOrganizationList = organizationService.list(); + + // 顶级组织code + List deptVisibleScopes = scopesV2.getDeptVisibleScopes(); + log.info("顶级组织code: size = " + deptVisibleScopes.size() + "列表:" + JSONObject.toJSONString(deptVisibleScopes)); + // 获取顶级节点信息 + GenericResult> listGenericResult = zwddClient.listOrganizationsByCodes(deptVisibleScopes); + log.info("listGenericResult: {}" + JSON.toJSONString(listGenericResult)); + List dingOrgInfoDtos = listGenericResult.getData(); + for (String orgCode : deptVisibleScopes) { + List treeDTOList = new ArrayList<>(); + + DingOrgInfoTreeDTO childDingOrgInfoTreeDTO = new DingOrgInfoTreeDTO(); + //设置节点详情 + if (dingOrgInfoDtos != null && !dingOrgInfoDtos.isEmpty()) { + for (DingOrgInfoDTO orgInfo : dingOrgInfoDtos) { + if (orgInfo.getOrganizationCode().equals(orgCode)) { + childDingOrgInfoTreeDTO.setDingOrgInfoDTO(orgInfo); + } + } + } + childDingOrgInfoTreeDTO.setCode(orgCode); + childDingOrgInfoTreeDTO.setChildCodes(new ArrayList<>()); + getDingOrgChild(childDingOrgInfoTreeDTO); + treeDTOList.add(childDingOrgInfoTreeDTO); + if (CollectionUtils.isNotEmpty(treeDTOList)) { + List saveRecordList = new ArrayList<>(); + buildSaveRecordList(treeDTOList, saveRecordList,currentAllOrganizationList); + // 批量保存 + if (saveRecordList.size() <= GROUP_SIZE) { + organizationService.saveOrUpdateBatch(saveRecordList); + } else { + List> split = Lists.partition(saveRecordList, GROUP_SIZE); + for (List segment : split) { + organizationService.saveOrUpdateBatch(segment); + } + } + } + log.info("----拉取浙政钉组织结构结束---,顶级code:" + orgCode); + } + } + } + + private void getDingOrgChild(DingOrgInfoTreeDTO parentDingOrgInfoTreeDTO) { + String parentOrgCode = parentDingOrgInfoTreeDTO.getCode(); + DingOrgInfoDTO orgInfoDTO = parentDingOrgInfoTreeDTO.getDingOrgInfoDTO(); + boolean leaf = orgInfoDTO.getLeaf(); + if (!leaf) { + int currentPage = 1; + int pageSize = 100; + GenericResult pageSubOrganizationCodeDTOGenericResult = zwddClient.pageSubOrganizationCodes(currentPage++, pageSize, parentOrgCode); + PageSubOrganizationCodeDTO pageSubOrganizationCodeDTO = pageSubOrganizationCodeDTOGenericResult.getData(); + + if (CollUtil.isNotEmpty(pageSubOrganizationCodeDTO.getSubOrganizationCodeList())) { + List subOrganizationCodeList = new ArrayList<>(pageSubOrganizationCodeDTO.getSubOrganizationCodeList()); + Long totalSize = pageSubOrganizationCodeDTO.getTotalSize(); + + while (totalSize > (long) currentPage * pageSize) { + GenericResult subPageSubOrganizationCodeDTOGenericResult = zwddClient + .pageSubOrganizationCodes(currentPage++, pageSize, parentOrgCode); + PageSubOrganizationCodeDTO subOrganizationCodeDTO = subPageSubOrganizationCodeDTOGenericResult.getData(); + if (CollectionUtils.isNotEmpty(subOrganizationCodeDTO.getSubOrganizationCodeList())) { + subOrganizationCodeList.addAll(subOrganizationCodeDTO.getSubOrganizationCodeList()); + } + } + + if (CollectionUtils.isNotEmpty(subOrganizationCodeList)) { + GenericResult> listGenericResult = zwddClient + .listOrganizationsByCodes(subOrganizationCodeList); + List dingOrgInfoDtos = listGenericResult.getData(); + List dingOrgInfoTreeDTOList = dingOrgInfoDtos.stream().map(r -> { + DingOrgInfoTreeDTO dingOrgInfoTreeDTO = new DingOrgInfoTreeDTO(); + dingOrgInfoTreeDTO.setCode(r.getOrganizationCode()); + dingOrgInfoTreeDTO.setDingOrgInfoDTO(r); + dingOrgInfoTreeDTO.setChildCodes(new ArrayList<>()); + getDingOrgChild(dingOrgInfoTreeDTO); + return dingOrgInfoTreeDTO; + }).collect(Collectors.toList()); + parentDingOrgInfoTreeDTO.setChildCodes(dingOrgInfoTreeDTOList); + } + } + } + } + + private void buildSaveRecordList(List treeDTOList, List saveRecordList, + List oldList) { + Set set = new HashSet(); + Map map = oldList.stream() + .filter(o -> set.add(o.getOrganizationCode())) + .collect(Collectors.toMap(DingOrganization::getOrganizationCode,o -> o)); + if (CollectionUtils.isEmpty(treeDTOList)) { + return; + } + for (DingOrgInfoTreeDTO dingOrgInfoTreeDTO : treeDTOList) { + DingOrganization saveRecord = new DingOrganization(); + DingOrgInfoDTO dingOrgInfoDTO = dingOrgInfoTreeDTO.getDingOrgInfoDTO(); + List childCodes = dingOrgInfoTreeDTO.getChildCodes(); + if(map.containsKey(dingOrgInfoDTO.getOrganizationCode())) { + DingOrganization organization = map.get(dingOrgInfoDTO.getOrganizationCode()); + saveRecord.setId(organization.getId()); + if (CollectionUtils.isNotEmpty(childCodes)) { + buildSaveRecordList(childCodes, saveRecordList,oldList); + } + continue; + } + + saveRecord.setDisplayOrder(dingOrgInfoDTO.getDisplayOrder()); +// saveRecord.setEnabled("1"); + saveRecord.setParentCode(dingOrgInfoDTO.getParentCode()); + saveRecord.setTypeCode(dingOrgInfoDTO.getTypeCode()); + saveRecord.setTypeName(dingOrgInfoDTO.getTypeName()); + saveRecord.setOrganizationCode(dingOrgInfoDTO.getOrganizationCode()); +// saveRecord.setSubCount((long) dingOrgInfoTreeDTO.getChildCodes().size()); + saveRecord.setOrganizationName(dingOrgInfoDTO.getOrganizationName()); + saveRecord.setDivisionCode(dingOrgInfoDTO.getDivisionCode()); + saveRecordList.add(saveRecord); + if (CollectionUtils.isNotEmpty(childCodes)) { + buildSaveRecordList(childCodes, saveRecordList,oldList); + } + } + } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollectionTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollectionTest.java index 5c9c5ed..a9e5bab 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollectionTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/projectCollection/ProjectCollectionTest.java @@ -75,7 +75,7 @@ public class ProjectCollectionTest extends AppTests { @Test public void test(){ - List baseProjIds = Lists.newArrayList("33110000020210100193"); + List baseProjIds = Lists.newArrayList("null00020220100001"); for(String baseProjId : baseProjIds){ GovBizProjectBaseinfo baseinfo = baseinfoService.getOne(Wrappers.lambdaQuery(GovBizProjectBaseinfo.class) .eq(GovBizProjectBaseinfo::getBaseProjId, baseProjId)