liupeng 5 anos atrás
pai
commit
3462b23f2c

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

@@ -98,16 +98,25 @@ public class WXCpDepartUtil {
 		return depatmentId;
 	}
 	
-	public static Long createOrUpdate(Long parentId, String name) throws WxErrorException {
-		Map<String, Long> map = getChildDepartMap(parentId);
-		Long depatmentId = map.get(name);
-		if (depatmentId == null) {
+	public static Long createOrUpdate(Long id, Long parentId, String name) throws WxErrorException {
+		if(id == null) {
+			Map<String, Long> map = getChildDepartMap(parentId);
+			Long depatmentId = map.get(name);
+			if (depatmentId == null) {
+				WxCpDepart depart = new WxCpDepart();
+				depart.setName(name);
+				depart.setParentId(parentId);
+				depatmentId = departService.create(depart);
+			}
+			return depatmentId;
+		} else {
 			WxCpDepart depart = new WxCpDepart();
+			depart.setId(id);
 			depart.setName(name);
 			depart.setParentId(parentId);
-			depatmentId = departService.create(depart);
+			departService.update(depart);
+			return id;
 		}
-		return depatmentId;
 	}
 
 	public static List<WxCpDepart> getAllChildDeparts(Long id) throws WxErrorException {

+ 1 - 1
code/sapparent/sapservice/src/main/java/org/fouram/service/SapOrgService.java

@@ -156,7 +156,7 @@ public class SapOrgService extends BaseService {
 	}
 
 	private Long getWxDepartId(SapOrg org, Long parentId) throws WxErrorException {
-		return WXCpDepartUtil.createOrUpdate(parentId, org.getSapName());
+		return WXCpDepartUtil.createOrUpdate(org.getWxDepartId(), parentId, org.getSapName());
 	}
 
 	@SuppressWarnings("unchecked")