diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java index 356c8c0..516cf06 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java @@ -84,6 +84,11 @@ public class DingInfoPullController { organizationBatchGetTask.batchGetOrganizationTask(); } + @GetMapping("/organization/{orgCode}") + public void organizationGetSubs(@PathVariable String orgCode) { + organizationBatchGetTask.organizationGetSubs(orgCode); + } + @GetMapping("/employeeByRegionCode/{regionCode}") public void employeeBatchGetByRegionCode(@PathVariable String regionCode) { employeeBatchGetTask.batchGetEmployeeTaskByRegionCode(regionCode); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java index f183d2f..5b1ddb3 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.ningdatech.basic.model.GenericResult; +import com.ningdatech.pmapi.common.constant.BizConst; import com.ningdatech.pmapi.ding.model.DingOrgInfoTreeDTO; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingOrganizationService; @@ -21,6 +22,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -103,6 +105,49 @@ public class OrganizationBatchGetTask { } } + /** + * 更新 其 子单位 + * @param orgCode + */ + public void organizationGetSubs(String orgCode) { + log.info("----拉取浙政钉组织子单位开始---,顶级code:" + orgCode); + DingOrganization topOrg = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) + .eq(DingOrganization::getOrganizationCode, orgCode) + .last(BizConst.LIMIT_1)); + // 顶级组织code + List topOrgCodes = Lists.newArrayList(orgCode); + GenericResult> listGenericResult = zwddClient.listOrganizationsByCodes(topOrgCodes); + log.info("listGenericResult: {}" + JSON.toJSONString(listGenericResult)); + List dingOrgInfoDtos = listGenericResult.getData(); + + for(DingOrgInfoDTO dingOrgInfo : dingOrgInfoDtos){ + DingOrganization old = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) + .eq(DingOrganization::getOrganizationCode, dingOrgInfo.getOrganizationCode()) + .last(BizConst.LIMIT_1)); + if(Objects.nonNull(old)){ + log.info("该单位已经存在 :{}",old.getOrganizationName()); + continue; + } + + DingOrganization organization = new DingOrganization(); + organization.setOrganizationCode(dingOrgInfo.getOrganizationCode()); + organization.setOrganizationName(dingOrgInfo.getOrganizationName()); + //和顶级单位一个区域 + organization.setDivisionCode(topOrg.getDivisionCode()); + organization.setParentCode(dingOrgInfo.getParentCode()); + organization.setTypeName(dingOrgInfo.getTypeName()); + organization.setAddress(dingOrgInfo.getAddress()); + organization.setBusinessStripCodes(dingOrgInfo.getBusinessStripCodes()); + organization.setDisplayOrder(dingOrgInfo.getDisplayOrder()); + organization.setGmtCreate(LocalDateTime.now()); + organization.setInstitutionLevelCode(dingOrgInfo.getInstitutionLevelCode()); + organization.setParentName(dingOrgInfo.getParentName()); + iDingOrganizationService.save(organization); + } + + log.info("----拉取浙政钉组织子单位结束---,顶级code:" + orgCode); + } + private void buildSaveRecordList(List treeDTOList, List saveRecordList) { if (CollectionUtils.isEmpty(treeDTOList)) { return;