@@ -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"); | |||
} | |||
} |
@@ -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) { | |||
@@ -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<DingOrgInfoTreeDTO> childCodes; | |||
} |
@@ -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<DingOrganization> allList = iDingOrganizationService.list(); | |||
// List<String> currentAllOrganizationCodeList = allList.stream().map(DingOrganization::getOrganizationCode).collect(Collectors.toList()); | |||
// 全量删除 | |||
// iDingOrganizationService.remove(Wrappers.lambdaQuery(DingOrganization.class).isNotNull(DingOrganization::getId)); | |||
// 获取顶级组织code | |||
GenericResult<DingScopesV2DTO> scopesV2Result = zwddClient.getScopesV2(); | |||
DingScopesV2DTO scopesV2 = scopesV2Result.getData(); | |||
if (Objects.nonNull(scopesV2)) { | |||
// 顶级组织code | |||
List<String> deptVisibleScopes = scopesV2.getDeptVisibleScopes(); | |||
log.info("顶级组织code: size = " + deptVisibleScopes.size() + "列表:" + JSONObject.toJSONString(deptVisibleScopes)); | |||
// 获取顶级节点信息 | |||
GenericResult<List<DingOrgInfoDTO>> listGenericResult = zwddClient.listOrganizationsByCodes(deptVisibleScopes); | |||
List<DingOrgInfoDTO> dingOrgInfoDtos = listGenericResult.getData(); | |||
for (String orgCode : deptVisibleScopes) { | |||
// if (currentAllOrganizationCodeList.contains(orgCode)) { | |||
// log.info("已存在组织架构---{}", orgCode); | |||
// continue; | |||
// } | |||
List<DingOrgInfoTreeDTO> 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<DingOrganization> saveRecordList = new ArrayList<>(); | |||
buildSaveRecordList(treeDTOList, saveRecordList); | |||
// 批量保存 | |||
if (saveRecordList.size() <= GROUP_SIZE) { | |||
iDingOrganizationService.saveBatch(saveRecordList); | |||
} else { | |||
List<List<DingOrganization>> split = Lists.partition(saveRecordList, GROUP_SIZE); | |||
for (List<DingOrganization> segment : split) { | |||
iDingOrganizationService.saveBatch(segment); | |||
} | |||
} | |||
} | |||
log.info("----拉取浙政钉组织结构结束---,顶级code:" + orgCode); | |||
} | |||
} | |||
} | |||
private void buildSaveRecordList(List<DingOrgInfoTreeDTO> treeDTOList, List<DingOrganization> saveRecordList) { | |||
if (CollectionUtils.isEmpty(treeDTOList)) { | |||
return; | |||
} | |||
for (DingOrgInfoTreeDTO dingOrgInfoTreeDTO : treeDTOList) { | |||
DingOrganization saveRecord = new DingOrganization(); | |||
DingOrgInfoDTO dingOrgInfoDTO = dingOrgInfoTreeDTO.getDingOrgInfoDTO(); | |||
List<DingOrgInfoTreeDTO> 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<PageSubOrganizationCodeDTO> pageSubOrganizationCodeDTOGenericResult = zwddClient.pageSubOrganizationCodes(currentPage++, pageSize, parentOrgCode); | |||
PageSubOrganizationCodeDTO pageSubOrganizationCodeDTO = pageSubOrganizationCodeDTOGenericResult.getData(); | |||
List<String> subOrganizationCodeList = new ArrayList<>(pageSubOrganizationCodeDTO.getSubOrganizationCodeList()); | |||
Long totalSize = pageSubOrganizationCodeDTO.getTotalSize(); | |||
while (totalSize > (long) currentPage * pageSize) { | |||
GenericResult<PageSubOrganizationCodeDTO> subPageSubOrganizationCodeDTOGenericResult = zwddClient | |||
.pageSubOrganizationCodes(currentPage++, pageSize, parentOrgCode); | |||
PageSubOrganizationCodeDTO subOrganizationCodeDTO = subPageSubOrganizationCodeDTOGenericResult.getData(); | |||
if (CollectionUtils.isNotEmpty(subOrganizationCodeDTO.getSubOrganizationCodeList())) { | |||
subOrganizationCodeList.addAll(subOrganizationCodeDTO.getSubOrganizationCodeList()); | |||
} | |||
} | |||
if (CollectionUtils.isNotEmpty(subOrganizationCodeList)) { | |||
GenericResult<List<DingOrgInfoDTO>> listGenericResult = zwddClient | |||
.listOrganizationsByCodes(subOrganizationCodeList); | |||
List<DingOrgInfoDTO> dingOrgInfoDtos = listGenericResult.getData(); | |||
List<DingOrgInfoTreeDTO> 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); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package com.ningdatech.pmapi.organization.controller; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.stereotype.Controller; | |||
/** | |||
* <p> | |||
* 前端控制器 | |||
* </p> | |||
* | |||
* @author Lierbao | |||
* @since 2023-02-09 | |||
*/ | |||
@Controller | |||
@RequestMapping("/pmapi.organization/ding-organization") | |||
public class DingOrganizationController { | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; | |||
/** | |||
* <p> | |||
* | |||
* </p> | |||
* | |||
* @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; | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.ningdatech.pmapi.organization.mapper; | |||
import com.ningdatech.pmapi.organization.entity.DingOrganization; | |||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||
/** | |||
* <p> | |||
* Mapper 接口 | |||
* </p> | |||
* | |||
* @author Lierbao | |||
* @since 2023-02-09 | |||
*/ | |||
public interface DingOrganizationMapper extends BaseMapper<DingOrganization> { | |||
} |
@@ -0,0 +1,5 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
<mapper namespace="com.ningdatech.pmapi.organization.mapper.DingOrganizationMapper"> | |||
</mapper> |
@@ -0,0 +1,16 @@ | |||
package com.ningdatech.pmapi.organization.service; | |||
import com.ningdatech.pmapi.organization.entity.DingOrganization; | |||
import com.baomidou.mybatisplus.extension.service.IService; | |||
/** | |||
* <p> | |||
* 服务类 | |||
* </p> | |||
* | |||
* @author Lierbao | |||
* @since 2023-02-09 | |||
*/ | |||
public interface IDingOrganizationService extends IService<DingOrganization> { | |||
} |
@@ -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; | |||
/** | |||
* <p> | |||
* 服务实现类 | |||
* </p> | |||
* | |||
* @author Lierbao | |||
* @since 2023-02-09 | |||
*/ | |||
@Service | |||
public class DingOrganizationServiceImpl extends ServiceImpl<DingOrganizationMapper, DingOrganization> implements IDingOrganizationService { | |||
} |
@@ -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 | |||
@@ -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 |
@@ -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() { | |||
} | |||
} |