liupeng %!s(int64=5) %!d(string=hai) anos
pai
achega
32d687deb7

+ 23 - 9
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/WXCpDepartUtil.java

@@ -19,18 +19,18 @@ import me.chanjar.weixin.cp.bean.WxCpDepart;
  * @author Liup
  */
 public class WXCpDepartUtil {
-	
+
 	public static void main(String[] args) throws WxErrorException {
 		List<WxCpDepart> departs = getAllChildDeparts(1L);
-		for(WxCpDepart depart : departs) {
+		for (WxCpDepart depart : departs) {
 			System.out.println(depart);
 		}
 	}
-	
+
 	public static List<WxCpDepart> getChildDeparts(Long id) throws WxErrorException {
 		List<WxCpDepart> departs = Lists.newArrayList();
-		for(WxCpDepart depart : departService.list(id)) {
-			if(id.equals(depart.getParentId())) {
+		for (WxCpDepart depart : departService.list(id)) {
+			if (id.equals(depart.getParentId())) {
 				departs.add(depart);
 			}
 		}
@@ -39,8 +39,8 @@ public class WXCpDepartUtil {
 
 	public static Map<String, Long> getChildDepartMap(Long id) throws WxErrorException {
 		Map<String, Long> map = Maps.newHashMap();
-		for(WxCpDepart depart : departService.list(id)) {
-			if(id.equals(depart.getParentId())) {
+		for (WxCpDepart depart : departService.list(id)) {
+			if (id.equals(depart.getParentId())) {
 				map.put(depart.getName(), depart.getId());
 			}
 		}
@@ -72,6 +72,20 @@ public class WXCpDepartUtil {
 		return create(thirdOrgId, fourthOrg);
 	}
 
+	public static Long create(Long firstOrgId, Long secondOrgId, Long thirdOrgId, Long fourthOrgId)
+			throws WxErrorException {
+		if (secondOrgId == null) {
+			return firstOrgId;
+		}
+		if (thirdOrgId == null) {
+			return secondOrgId;
+		}
+		if (fourthOrgId == null) {
+			return thirdOrgId;
+		}
+		return fourthOrgId;
+	}
+
 	private static Long create(Long parentId, String depatment) throws WxErrorException {
 		Map<String, Long> map = getChildDepartMap(parentId);
 		Long depatmentId = map.get(depatment);
@@ -83,11 +97,11 @@ public class WXCpDepartUtil {
 		}
 		return depatmentId;
 	}
-	
+
 	public static List<WxCpDepart> getAllChildDeparts(Long id) throws WxErrorException {
 		return departService.list(id);
 	}
-	
+
 	public static void delete(Long id) throws WxErrorException {
 		departService.delete(id);
 	}