diff --git a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java index 4cea706..3e1ed7f 100644 --- a/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java +++ b/ningda-generator/src/main/java/com/ningdatech/generator/config/GeneratorCodeKingbaseConfig.java @@ -56,7 +56,7 @@ public class GeneratorCodeKingbaseConfig { } public static void main(String[] args) { - generate("WendyYang", "projectlib", PATH_YYD, "nd_project_application"); + generate("Lierbao", "organization", PATH_LXX, "ding_organization"); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/GovDingProperties.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/GovDingProperties.java index 34ccd97..a107a7a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/GovDingProperties.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/GovDingProperties.java @@ -44,15 +44,15 @@ public class GovDingProperties { GovDingProperties.appAuthsecret = appAuthsecret; } - @Value("${ding.app-sso-auth-key}") - public void setAppSsoAuthKey(String appSsoAuthkey) { - GovDingProperties.appSsoAuthkey = appSsoAuthkey; - } - - @Value("${ding.app-sso-auth-secret}") - public void setAppSsoAuthsecret(String appSsoAuthsecret) { - GovDingProperties.appSsoAuthsecret = appSsoAuthsecret; - } +// @Value("${ding.app-sso-auth-key}") +// public void setAppSsoAuthKey(String appSsoAuthkey) { +// GovDingProperties.appSsoAuthkey = appSsoAuthkey; +// } +// +// @Value("${ding.app-sso-auth-secret}") +// public void setAppSsoAuthsecret(String appSsoAuthsecret) { +// GovDingProperties.appSsoAuthsecret = appSsoAuthsecret; +// } @Value("${ding.tenantId}") public void setTenantId(Long tenantId) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/model/DingOrgInfoTreeDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/model/DingOrgInfoTreeDTO.java new file mode 100644 index 0000000..7040ce1 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/model/DingOrgInfoTreeDTO.java @@ -0,0 +1,29 @@ +package com.ningdatech.pmapi.ding.model; + +import com.ningdatech.zwdd.model.dto.DingOrgInfoDTO; +import lombok.Data; + +import java.util.List; + +/** + * @author liuxinxin + * @date 2022/8/24 上午11:06 + * 钉钉组织结构树状结构 + */ +@Data +public class DingOrgInfoTreeDTO { + + /** + * 钉钉code码 + */ + private String code; + + /** + * 组织信息 + */ + private DingOrgInfoDTO dingOrgInfoDTO; + /** + * 子节点code + */ + private List childCodes; +} 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 new file mode 100644 index 0000000..3888c2c --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/task/OrganizationBatchGetTask.java @@ -0,0 +1,167 @@ +package com.ningdatech.pmapi.ding.task; + +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.ding.model.DingOrgInfoTreeDTO; +import com.ningdatech.pmapi.organization.entity.DingOrganization; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.ningdatech.zwdd.client.ZwddAuthClient; +import com.ningdatech.zwdd.client.ZwddClient; +import com.ningdatech.zwdd.model.dto.DingOrgInfoDTO; +import com.ningdatech.zwdd.model.dto.DingScopesV2DTO; +import com.ningdatech.zwdd.model.dto.PageSubOrganizationCodeDTO; +import lombok.extern.slf4j.Slf4j; +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.Objects; +import java.util.stream.Collectors; + +/** + * @author liuxinxin + * @date 2023/2/7 上午10:15 + */ + +@Slf4j +@Component +public class OrganizationBatchGetTask { + + @Autowired + private ZwddClient zwddClient; + + @Autowired + private ZwddAuthClient zwddAuthClient; + + private static final Integer GROUP_SIZE = 100; + + @Autowired + private IDingOrganizationService iDingOrganizationService; + + /** + * 获取浙政钉组织架构 + */ + @Transactional(rollbackFor = Exception.class) + public void OrganizationBatchGetTask() { +// List allList = iDingOrganizationService.list(); +// List currentAllOrganizationCodeList = allList.stream().map(DingOrganization::getOrganizationCode).collect(Collectors.toList()); + // 全量删除 + // iDingOrganizationService.remove(Wrappers.lambdaQuery(DingOrganization.class).isNotNull(DingOrganization::getId)); + // 获取顶级组织code + GenericResult scopesV2Result = zwddClient.getScopesV2(); + DingScopesV2DTO scopesV2 = scopesV2Result.getData(); + + if (Objects.nonNull(scopesV2)) { + // 顶级组织code + List deptVisibleScopes = scopesV2.getDeptVisibleScopes(); + log.info("顶级组织code: size = " + deptVisibleScopes.size() + "列表:" + JSONObject.toJSONString(deptVisibleScopes)); + // 获取顶级节点信息 + GenericResult> listGenericResult = zwddClient.listOrganizationsByCodes(deptVisibleScopes); + List dingOrgInfoDtos = listGenericResult.getData(); + for (String orgCode : deptVisibleScopes) { +// if (currentAllOrganizationCodeList.contains(orgCode)) { +// log.info("已存在组织架构---{}", orgCode); +// continue; +// } + 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); + + // 批量保存 + if (saveRecordList.size() <= GROUP_SIZE) { + iDingOrganizationService.saveBatch(saveRecordList); + } else { + List> split = Lists.partition(saveRecordList, GROUP_SIZE); + for (List segment : split) { + iDingOrganizationService.saveBatch(segment); + } + } + } + log.info("----拉取浙政钉组织结构结束---,顶级code:" + orgCode); + } + } + } + + private void buildSaveRecordList(List treeDTOList, List saveRecordList) { + if (CollectionUtils.isEmpty(treeDTOList)) { + return; + } + for (DingOrgInfoTreeDTO dingOrgInfoTreeDTO : treeDTOList) { + DingOrganization saveRecord = new DingOrganization(); + DingOrgInfoDTO dingOrgInfoDTO = dingOrgInfoTreeDTO.getDingOrgInfoDTO(); + List childCodes = dingOrgInfoTreeDTO.getChildCodes(); + saveRecord.setDisplayOrder(dingOrgInfoDTO.getDisplayOrder()); +// saveRecord.setEnabled("1"); + saveRecord.setParentCode(dingOrgInfoDTO.getParentCode()); + saveRecord.setOrganizationCode(dingOrgInfoDTO.getOrganizationCode()); +// saveRecord.setSubCount((long) dingOrgInfoTreeDTO.getChildCodes().size()); + saveRecord.setOrganizationName(dingOrgInfoDTO.getOrganizationName()); + saveRecordList.add(saveRecord); + if (CollectionUtils.isNotEmpty(childCodes)) { + buildSaveRecordList(childCodes, saveRecordList); + } + } + + } + + 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(); + + 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); + } + + } + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/DingOrganizationController.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/DingOrganizationController.java new file mode 100644 index 0000000..c86682d --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/DingOrganizationController.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.organization.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; + +import org.springframework.stereotype.Controller; + +/** + *

+ * 前端控制器 + *

+ * + * @author Lierbao + * @since 2023-02-09 + */ +@Controller +@RequestMapping("/pmapi.organization/ding-organization") +public class DingOrganizationController { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/OrganizationProcdefController.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/OrganizationProcdefController.java index 92e7e96..2ed8f47 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/OrganizationProcdefController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/controller/OrganizationProcdefController.java @@ -40,9 +40,9 @@ public class OrganizationProcdefController { } @ApiOperation(value = "单位流程配置详情", notes = "单位流程配置详情") - @GetMapping("/detail/{procdefId}") - public OrgProcdefVo detail(@PathVariable String procdefId) { - WflowOrgModelHistorys lastVersionModel = orgProcessModelService.getLastVersionModel(procdefId); + @GetMapping("/detail/{processDefId}") + public OrgProcdefVo detail(@PathVariable String processDefId) { + WflowOrgModelHistorys lastVersionModel = orgProcessModelService.getLastVersionModel(processDefId); OrgProcdefVo vo = new OrgProcdefVo(); BeanUtils.copyProperties(lastVersionModel, vo); return vo; @@ -55,16 +55,16 @@ public class OrganizationProcdefController { } @ApiOperation(value = "单位流程配置启用", notes = "单位流程配置启用") - @PutMapping("/enable/{procdefId}") - public String enableProcess(@PathVariable String procdefId) { - orgProcessModelService.enableProcess(procdefId,Boolean.FALSE); + @PutMapping("/enable/{processDefId}") + public String enableProcess(@PathVariable String processDefId) { + orgProcessModelService.enableProcess(processDefId,Boolean.FALSE); return "启用成功"; } @ApiOperation(value = "单位流程配置禁用", notes = "单位流程配置禁用") - @PutMapping("/disable/{procdefId}") - public String disableProcess(@PathVariable String procdefId) { - orgProcessModelService.enableProcess(procdefId,Boolean.TRUE); + @PutMapping("/disable/{processDefId}") + public String disableProcess(@PathVariable String processDefId) { + orgProcessModelService.enableProcess(processDefId,Boolean.TRUE); return "禁用成功"; } @@ -75,8 +75,8 @@ public class OrganizationProcdefController { } @ApiOperation(value = "单位流程配置删除", notes = "单位流程配置删除") - @PostMapping("/delete/{procdefId}") - public Boolean delete(@PathVariable String procdefId) { - return orgProcessModelService.delProcess(procdefId); + @PostMapping("/delete/{processDefId}") + public Boolean delete(@PathVariable String processDefId) { + return orgProcessModelService.delProcess(processDefId); } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/DingOrganization.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/DingOrganization.java new file mode 100644 index 0000000..25296fd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/DingOrganization.java @@ -0,0 +1,55 @@ +package com.ningdatech.pmapi.organization.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * + *

+ * + * @author Lierbao + * @since 2023-02-09 + */ +@TableName("ding_organization") +@ApiModel(value = "DingOrganization对象", description = "") +@Data +public class DingOrganization implements Serializable { + + private static final long serialVersionUID = 1L; + + private Long id; + + private String institutionLevelCode; + + private String address; + + private String organizationName; + + private Long displayOrder; + + private Long typeName; + + private Integer leaf; + + private LocalDateTime gmtCreate; + + private String typeCode; + + private String divisionCode; + + private String parentName; + + private String parentCode; + + private String organizationCode; + + private String businessStripCodes; + + private String status; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.java new file mode 100644 index 0000000..b3fee77 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.organization.mapper; + +import com.ningdatech.pmapi.organization.entity.DingOrganization; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author Lierbao + * @since 2023-02-09 + */ +public interface DingOrganizationMapper extends BaseMapper { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.xml b/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.xml new file mode 100644 index 0000000..e3e5708 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/mapper/DingOrganizationMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java new file mode 100644 index 0000000..b1b5ce3 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java @@ -0,0 +1,16 @@ +package com.ningdatech.pmapi.organization.service; + +import com.ningdatech.pmapi.organization.entity.DingOrganization; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author Lierbao + * @since 2023-02-09 + */ +public interface IDingOrganizationService extends IService { + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java new file mode 100644 index 0000000..4c154cb --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java @@ -0,0 +1,20 @@ +package com.ningdatech.pmapi.organization.service.impl; + +import com.ningdatech.pmapi.organization.entity.DingOrganization; +import com.ningdatech.pmapi.organization.mapper.DingOrganizationMapper; +import com.ningdatech.pmapi.organization.service.IDingOrganizationService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author Lierbao + * @since 2023-02-09 + */ +@Service +public class DingOrganizationServiceImpl extends ServiceImpl implements IDingOrganizationService { + +} diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index 96fe00f..7727198 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -158,12 +158,9 @@ sa-token: #专有钉钉 ding: #扫码 - app-auth-key: file-manage_dingoa-zte2LbiAfIj - app-auth-secret: H794aFZf271QbfUr50pbBpBTlXSrWIP71q9RTR34 - #扫码 - app-sso-auth-key: fgdn_wjlzjkxt_hz - app-sso-auth-secret: dafe1e6f7d424032acb81f5c2a797a1f - #免登/获取信息 + app-auth-key: expert-base_dingoa-c5nnefYVnie + app-auth-secret: nm8qtST8uK431HYrjr7srcE23sT4889QgMcYFM3L + # #免登/获取信息 app-key: file-manage-4Mjx9358wuxjyYFjY3 app-secret: hE41938wqyQ5LOpc1QDRA9e7gb5YugoClWD3nY4O #专有钉钉在开发管理工作台,右键查看网页源码realmId: '31141',浙政钉固定196729 diff --git a/pmapi/src/main/resources/integration/zwdd-dev.yml b/pmapi/src/main/resources/integration/zwdd-dev.yml new file mode 100644 index 0000000..0073994 --- /dev/null +++ b/pmapi/src/main/resources/integration/zwdd-dev.yml @@ -0,0 +1,11 @@ +#专有钉钉 +ding: + #扫码 + app-auth-key: expert-base_dingoa-c5nnefYVnie + app-auth-secret: nm8qtST8uK431HYrjr7srcE23sT4889QgMcYFM3L + # #免登/获取信息 + app-key: file-manage-4Mjx9358wuxjyYFjY3 + app-secret: hE41938wqyQ5LOpc1QDRA9e7gb5YugoClWD3nY4O + #专有钉钉在开发管理工作台,右键查看网页源码realmId: '31141',浙政钉固定196729 + tenantId: 31141 + domain: openplatform.dg-work.cn \ No newline at end of file diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java new file mode 100644 index 0000000..1f08428 --- /dev/null +++ b/pmapi/src/test/java/com/ningdatech/pmapi/organization/OrganizationTest.java @@ -0,0 +1,30 @@ +package com.ningdatech.pmapi.organization; + +import com.ningdatech.pmapi.AppTests; +import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; +import com.ningdatech.zwdd.client.ZwddAuthClient; +import com.ningdatech.zwdd.client.ZwddClient; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author liuxinxin + * @date 2023/2/9 下午3:54 + */ + +public class OrganizationTest extends AppTests { + + @Autowired + private ZwddClient zwddClient; + + @Autowired + private ZwddAuthClient zwddAuthClient; + + @Autowired + private OrganizationBatchGetTask organizationBatchGetTask; + + public void testBatchGetOrganization() { + + + } + +}