MaxKey il y a 1 an
Parent
commit
f3035baa6b

+ 8 - 6
maxkey-persistence/src/main/java/org/dromara/maxkey/persistence/service/OrganizationsService.java

@@ -57,6 +57,7 @@ public class OrganizationsService  extends JpaService<Organizations>{
 		return (OrganizationsMapper)super.getMapper();
 	}
 	
+	 @Override
 	 public boolean insert(Organizations organization) {
 	     if(super.insert(organization)){
 	    	 provisionService.send(
@@ -66,6 +67,7 @@ public class OrganizationsService  extends JpaService<Organizations>{
          return false;
 	 }
 	 
+	 @Override
 	 public boolean update(Organizations organization) {
 	     if(super.update(organization)){
 	    	 provisionService.send(
@@ -77,7 +79,7 @@ public class OrganizationsService  extends JpaService<Organizations>{
  
 	 public void saveOrUpdate(Organizations organization) {
 		 Organizations loadOrg =findOne(" id = ? and instid = ?", 
-					new Object[] { organization.getId().toString(), organization.getInstId() },
+					new Object[] { organization.getId(), organization.getInstId() },
               new int[] { Types.VARCHAR, Types.VARCHAR });
 		 if( loadOrg == null) {
 				insert(organization);
@@ -90,6 +92,7 @@ public class OrganizationsService  extends JpaService<Organizations>{
 		 return getMapper().queryOrgs(organization);
 	 }
 	 
+	 @Override
 	 public boolean delete(Organizations organization) {
 	     if(super.delete(organization)){
 	    	 provisionService.send(
@@ -137,14 +140,13 @@ public class OrganizationsService  extends JpaService<Organizations>{
 	}
 	
 	public static boolean isRootOrg(Organizations rootOrg){
-		if(rootOrg.getParentId() == null 
+		return (
+				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;
+				|| rootOrg.getParentId().equalsIgnoreCase(rootOrg.getInstId())
+				);
 	}
 
 	void reorg(HashMap<String, Organizations> orgMap, List<Organizations> orgList,Organizations rootOrg) {

+ 2 - 2
maxkey-synchronizers/maxkey-synchronizer-reorgdept/src/main/java/org/dromara/maxkey/synchronizer/reorg/ReorgDeptSynchronizerService.java

@@ -19,7 +19,7 @@ package org.dromara.maxkey.synchronizer.reorg;
 
 import org.dromara.maxkey.entity.Synchronizers;
 import org.dromara.maxkey.synchronizer.ISynchronizerService;
-import org.dromara.maxkey.synchronizer.workweixin.service.ReorgDeptService;
+import org.dromara.maxkey.synchronizer.reorg.service.ReorgDeptService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,7 +27,7 @@ import org.springframework.stereotype.Service;
 
 @Service
 public class ReorgDeptSynchronizerService implements ISynchronizerService {
-    final static Logger _logger = LoggerFactory.getLogger(ReorgDeptSynchronizerService.class);
+	static final Logger _logger = LoggerFactory.getLogger(ReorgDeptSynchronizerService.class);
     Synchronizers synchronizer;
 
     @Autowired

+ 36 - 0
maxkey-synchronizers/maxkey-synchronizer-reorgdept/src/main/java/org/dromara/maxkey/synchronizer/reorg/service/ReorgDeptService.java

@@ -0,0 +1,36 @@
+/*
+ * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.dromara.maxkey.synchronizer.reorg.service;
+
+import org.dromara.maxkey.synchronizer.AbstractSynchronizerService;
+import org.dromara.maxkey.synchronizer.ISynchronizerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ReorgDeptService extends AbstractSynchronizerService implements ISynchronizerService{
+	static final Logger _logger = LoggerFactory.getLogger(ReorgDeptService.class);
+
+	public void sync() {
+		_logger.info("Sync Organizations ...");
+		organizationsService.reorgNamePath(this.synchronizer.getInstId());
+			
+	}
+
+}

+ 0 - 103
maxkey-synchronizers/maxkey-synchronizer-reorgdept/src/main/java/org/dromara/maxkey/synchronizer/workweixin/service/ReorgDeptService.java

@@ -1,103 +0,0 @@
-/*
- * Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- 
-
-package org.dromara.maxkey.synchronizer.workweixin.service;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.dromara.maxkey.constants.ConstsStatus;
-import org.dromara.maxkey.entity.Organizations;
-import org.dromara.maxkey.synchronizer.AbstractSynchronizerService;
-import org.dromara.maxkey.synchronizer.ISynchronizerService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-@Service
-public class ReorgDeptService extends AbstractSynchronizerService implements ISynchronizerService{
-	final static Logger _logger = LoggerFactory.getLogger(ReorgDeptService.class);
-
-	String rootParentOrgId = "-1";
-
-	public void sync() {
-		_logger.info("Sync Organizations ...");
-
-		try {
-			long responseCount =0;
-			HashMap<String,Organizations>orgCastMap =new HashMap<String,Organizations>();
-			Organizations queryOrganization =new Organizations();
-			queryOrganization.setInstId(this.synchronizer.getInstId());
-			List<Organizations> listOrg = organizationsService.query(queryOrganization);
-
-			buildNamePath(orgCastMap,listOrg);
-			
-			for(Organizations org :listOrg) {
-				_logger.info("Dept "+(++responseCount)+" : " + org);
-				org.setStatus(ConstsStatus.ACTIVE);
-				organizationsService.update(org);
-			}
-			
-			
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		
-	}
-	
-
-	
-	/**
-	 * Reorganization name path & code path	
-	 * @param orgCastMap
-	 * @param listOrgCast
-	 */
-	public void buildNamePath(HashMap<String,Organizations>orgMap,
-			List<Organizations> listOrg) {
-			Organizations tempOrg = null;
-		//root org
-		for(int i=0;i<listOrg.size();i++) {
-			if(listOrg.get(i).getParentId().equals(rootParentOrgId)){
-				tempOrg = listOrg.get(i); 
-				tempOrg.setReorgNamePath(true);
-				tempOrg.setNamePath("/"+tempOrg.getOrgName());
-				tempOrg.setCodePath("/"+tempOrg.getId());
-				tempOrg.setParentId("-1");
-				tempOrg.setParentName("");
-				orgMap.put(tempOrg.getId(), tempOrg);
-	        }
-		}
-		
- 	   	do {
- 	   		for(int i=0;i<listOrg.size();i++) {
- 	   			if(!listOrg.get(i).isReorgNamePath()) {
- 	   				Organizations parentOrg = orgMap.get(listOrg.get(i).getParentId());
-	 	   			tempOrg = listOrg.get(i); 
-	 	   			if(!tempOrg.isReorgNamePath() && parentOrg != null){
-	 	   				tempOrg.setReorgNamePath(true);
-	 	   				tempOrg.setParentName(parentOrg.getOrgName());
-	 	   				tempOrg.setCodePath(parentOrg.getCodePath()+"/"+tempOrg.getId());
-	 	   				tempOrg.setNamePath(parentOrg.getNamePath()+"/"+tempOrg.getOrgName());
-	 	   				orgMap.put(tempOrg.getId(), tempOrg);
-						_logger.info("reorg : " + tempOrg);
-	 	   			}
- 	   			}
- 	   		}
- 	   	}while(listOrg.size()>listOrg.size());
-	}
-
-}