|
@@ -18,7 +18,11 @@
|
|
|
package org.dromara.maxkey.persistence.service;
|
|
|
|
|
|
import java.sql.Types;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
|
import org.dromara.maxkey.entity.Organizations;
|
|
@@ -27,13 +31,17 @@ import org.dromara.maxkey.provision.ProvisionAction;
|
|
|
import org.dromara.maxkey.provision.ProvisionService;
|
|
|
import org.dromara.maxkey.provision.ProvisionTopic;
|
|
|
import org.dromara.mybatis.jpa.JpaService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
|
|
|
@Repository
|
|
|
public class OrganizationsService extends JpaService<Organizations>{
|
|
|
-
|
|
|
+ static final Logger _logger = LoggerFactory.getLogger(OrganizationsService.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
ProvisionService provisionService;
|
|
|
|
|
@@ -91,6 +99,73 @@ public class OrganizationsService extends JpaService<Organizations>{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public void reorgNamePath(String instId) {
|
|
|
+ _logger.debug("instId {}", instId);
|
|
|
+ if(StringUtils.isBlank(instId)) {
|
|
|
+ instId = "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, Organizations> reorgOrgMap = new HashMap<>();
|
|
|
+ List<Organizations> orgList = find(" where instid ='" + instId + "'");
|
|
|
+ List<Organizations> originOrgList = new ArrayList<>();
|
|
|
+ Organizations rootOrg = null;
|
|
|
+ for (Organizations org : orgList) {
|
|
|
+ reorgOrgMap.put(org.getId(), org);
|
|
|
+ if (isRootOrg(org)) {
|
|
|
+ rootOrg = org;
|
|
|
+ }
|
|
|
+ Organizations cloneOrg = new Organizations();
|
|
|
+ BeanUtils.copyProperties(org, cloneOrg);
|
|
|
+ originOrgList.add(cloneOrg);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ reorg(reorgOrgMap, orgList, rootOrg);
|
|
|
+ _logger.debug("reorged .");
|
|
|
+ long reorgCount = 0;
|
|
|
+ for (Organizations originOrg : originOrgList) {
|
|
|
+ Organizations reorgOrg = reorgOrgMap.get( originOrg.getId());
|
|
|
+ _logger.trace("reorged Organization {}" ,reorgOrg);
|
|
|
+ if(originOrg.getNamePath()== null || !originOrg.getNamePath().equals(reorgOrg.getNamePath())) {
|
|
|
+ _logger.debug("update reorgCount {} , Organization {}" ,++reorgCount,reorgOrg);
|
|
|
+ getMapper().updateNamePath(reorgOrg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _logger.debug("reorg finished .");
|
|
|
+ } catch (Exception e) {
|
|
|
+ _logger.error("reorgNamePath Exception ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isRootOrg(Organizations rootOrg){
|
|
|
+ if(rootOrg.getParentId() == null
|
|
|
+ || rootOrg.getParentId().equalsIgnoreCase("-1")
|
|
|
+ || rootOrg.getParentId().equalsIgnoreCase("0")
|
|
|
+ || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getId())
|
|
|
+ || rootOrg.getParentId().equalsIgnoreCase(rootOrg.getInstId())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ void reorg(HashMap<String, Organizations> orgMap, List<Organizations> orgList,Organizations rootOrg) {
|
|
|
+ if (isRootOrg(rootOrg)) {
|
|
|
+ rootOrg.setCodePath("/" + rootOrg.getId()+"/");
|
|
|
+ rootOrg.setNamePath("/" + rootOrg.getOrgName()+"/");
|
|
|
+ } else {
|
|
|
+ Organizations parent = orgMap.get(rootOrg.getParentId());
|
|
|
+ rootOrg.setCodePath(parent.getCodePath() + rootOrg.getId()+ "/");
|
|
|
+ rootOrg.setNamePath(parent.getNamePath() + rootOrg.getOrgName()+ "/");
|
|
|
+ }
|
|
|
+ rootOrg.setReorgNamePath(true);
|
|
|
+
|
|
|
+ for (Organizations org : orgList) {
|
|
|
+ if (org.isReorgNamePath())
|
|
|
+ continue;
|
|
|
+ if (org.getParentId().equalsIgnoreCase(rootOrg.getId())) {
|
|
|
+ reorg(orgMap, orgList, org);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 根据数据格式返回数据
|
|
|
*
|