Browse Source

获取上级条线单位

master
niohe·erbao 1 year ago
parent
commit
a722853e81
5 changed files with 136 additions and 5 deletions
  1. +6
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java
  2. +22
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/organization/helper/GovBusinessStripHelper.java
  3. +70
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/organization/helper/impl/GovBusinessStripHelperImpl.java
  4. +15
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java
  5. +23
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java

+ 6
- 0
pmapi/src/main/java/com/ningdatech/pmapi/organization/entity/GovBusinessStrip.java View File

@@ -32,7 +32,13 @@ public class GovBusinessStrip implements Serializable {

private Long updateBy;

/**
* 条线code
*/
private String businessStripCode;

/**
* 条线名称
*/
private String businessStripName;
}

+ 22
- 0
pmapi/src/main/java/com/ningdatech/pmapi/organization/helper/GovBusinessStripHelper.java View File

@@ -0,0 +1,22 @@
package com.ningdatech.pmapi.organization.helper;

import com.ningdatech.pmapi.organization.model.entity.DingOrganization;

import java.util.List;

/**
* @author liuxinxin
* @date 2023/3/8 下午3:23
*/

public interface GovBusinessStripHelper {

/**
* 获取上级条线单位
*
* @param organizationCode
* @return
*/
List<DingOrganization> getSupGovBusinessStrip(String organizationCode);

}

+ 70
- 0
pmapi/src/main/java/com/ningdatech/pmapi/organization/helper/impl/GovBusinessStripHelperImpl.java View File

@@ -0,0 +1,70 @@
package com.ningdatech.pmapi.organization.helper.impl;

import com.ningdatech.pmapi.organization.helper.GovBusinessStripHelper;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.ningdatech.pmapi.organization.service.IDingOrganizationService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;

/**
* @author liuxinxin
* @date 2023/3/8 下午3:34
*/

@Component
@RequiredArgsConstructor
public class GovBusinessStripHelperImpl implements GovBusinessStripHelper {

private final IDingOrganizationService organizationService;

@Override
public List<DingOrganization> getSupGovBusinessStrip(String organizationCode) {
List<DingOrganization> supGovBusinessStripList = new ArrayList<>();

DingOrganization dingOrganization = organizationService.getByOrgCode(organizationCode);
if (Objects.isNull(dingOrganization)) {
return null;
}
String businessStripCodes = dingOrganization.getBusinessStripCodes();
if (StringUtils.isNotBlank(businessStripCodes)) {
String[] businessStripCodeList = businessStripCodes.split("|");
for (String businessStripCode : businessStripCodeList) {
DingOrganization supGovBusinessStrip = getSupGovBusinessStrip(dingOrganization.getOrganizationCode(), businessStripCode);
if (Objects.nonNull(supGovBusinessStrip)) {
supGovBusinessStripList.add(supGovBusinessStrip);
}
}
}
return supGovBusinessStripList;
}

private DingOrganization getSupGovBusinessStrip(String organizationCode, String businessStripCode) {
String tempParentOrgCode = organizationCode;

HashSet<String> tempParentOrgCodeSet = new HashSet<>();
while (true) {
if (StringUtils.isBlank(tempParentOrgCode)) {
return null;
}
// 防止脏数据导致死循环
if (!tempParentOrgCodeSet.add(tempParentOrgCode)) {
return null;
}
DingOrganization parentOrganization = organizationService.getParentOrganization(tempParentOrgCode);
if (Objects.isNull(parentOrganization)) {
return null;
}
String businessStripCodes = parentOrganization.getBusinessStripCodes();
if (StringUtils.isNotBlank(businessStripCode) && businessStripCodes.contains(businessStripCode)) {
return parentOrganization;
}
tempParentOrgCode = parentOrganization.getParentCode();
}
}
}

+ 15
- 2
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/IDingOrganizationService.java View File

@@ -1,11 +1,11 @@
package com.ningdatech.pmapi.organization.service;

import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;

/**
* <p>
* 服务类
* 服务类
* </p>
*
* @author Lierbao
@@ -13,4 +13,17 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IDingOrganizationService extends IService<DingOrganization> {

/**
* 根据组织code查询组织信息
* @param orgCode
* @return
*/
DingOrganization getByOrgCode(String orgCode);

/**
* 根据组织code查询父组织信息
* @param orgCode
* @return
*/
DingOrganization getParentOrganization(String orgCode);
}

+ 23
- 3
pmapi/src/main/java/com/ningdatech/pmapi/organization/service/impl/DingOrganizationServiceImpl.java View File

@@ -1,14 +1,16 @@
package com.ningdatech.pmapi.organization.service.impl;

import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.organization.mapper.DingOrganizationMapper;
import com.ningdatech.pmapi.organization.model.entity.DingOrganization;
import com.ningdatech.pmapi.organization.service.IDingOrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
* <p>
* 服务实现类
* 服务实现类
* </p>
*
* @author Lierbao
@@ -17,4 +19,22 @@ import org.springframework.stereotype.Service;
@Service
public class DingOrganizationServiceImpl extends ServiceImpl<DingOrganizationMapper, DingOrganization> implements IDingOrganizationService {

@Override
public DingOrganization getByOrgCode(String orgCode) {
if (StringUtils.isBlank(orgCode)) {
return null;
}
return this.getOne(Wrappers.lambdaQuery(DingOrganization.class)
.eq(DingOrganization::getOrganizationCode, orgCode));
}

@Override
public DingOrganization getParentOrganization(String orgCode) {
DingOrganization dingOrganization = getByOrgCode(orgCode);
if (dingOrganization == null) {
return null;
}
String parentCode = dingOrganization.getParentCode();
return getByOrgCode(parentCode);
}
}

Loading…
Cancel
Save