liupeng 5 jaren geleden
bovenliggende
commit
fdb5164e25

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

@@ -40,6 +40,7 @@ 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)) {
+			System.out.println(depart);
 			if (id.equals(depart.getParentId())) {
 				map.put(depart.getName(), depart.getId());
 			}

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

@@ -16,6 +16,7 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.stereotype.Service;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
 @Service
@@ -53,8 +54,7 @@ public class SapOrgService extends BaseService {
 		return (SapOrg) findObject("SapOrgMapper.selectOne", sapOrg);
 	}
 
-	private String saveOrUpdateSapOrg(String parentId, String sapCode, String sapName, String level)
-			throws Exception {
+	private String saveOrUpdateSapOrg(String parentId, String sapCode, String sapName, String level) throws Exception {
 		SapOrg sapOrg = selectOne(parentId, sapCode, level);
 		if (sapOrg != null) {
 			sapOrg.setSapName(sapName);
@@ -119,39 +119,43 @@ public class SapOrgService extends BaseService {
 		}
 		return sapUsers;
 	}
-	
+
 	public void updateAllWxDepartId() throws Exception {
-		Map<String, Long> map = Maps.newHashMap();
 		List<SapOrg> firstOrgs = findListByParentId("0");
+		List<SapOrg> allOrgs = Lists.newArrayList();
 		for (SapOrg firstOrg : firstOrgs) {
-			map.put(firstOrg.getId(),
-					WXCpDepartUtil.createOrUpdate(firstOrg.getWxDepartId(), 1L, firstOrg.getSapName()));
+			firstOrg.setWxDepartId(WXCpDepartUtil.createOrUpdate(firstOrg.getWxDepartId(), 1L, firstOrg.getSapName()));
+			allOrgs.add(firstOrg);
 			List<SapOrg> sencodOrgs = findListByParentId(firstOrg.getParentId());
 			for (SapOrg sencodOrg : sencodOrgs) {
-				map.put(firstOrg.getId(), WXCpDepartUtil.createOrUpdate(sencodOrg.getWxDepartId(),
+				sencodOrg.setWxDepartId(WXCpDepartUtil.createOrUpdate(sencodOrg.getWxDepartId(),
 						firstOrg.getWxDepartId(), sencodOrg.getSapName()));
+				allOrgs.add(sencodOrg);
 				List<SapOrg> thirdOrgs = findListByParentId(sencodOrg.getParentId());
 				for (SapOrg thirdOrg : thirdOrgs) {
-					map.put(firstOrg.getId(), WXCpDepartUtil.createOrUpdate(thirdOrg.getWxDepartId(),
+					thirdOrg.setWxDepartId(WXCpDepartUtil.createOrUpdate(thirdOrg.getWxDepartId(),
 							sencodOrg.getWxDepartId(), thirdOrg.getSapName()));
+					allOrgs.add(thirdOrg);
 					List<SapOrg> fourthOrgs = findListByParentId(thirdOrg.getParentId());
 					for (SapOrg fourthOrg : fourthOrgs) {
-						map.put(firstOrg.getId(), WXCpDepartUtil.createOrUpdate(fourthOrg.getWxDepartId(),
+						fourthOrg.setWxDepartId(WXCpDepartUtil.createOrUpdate(fourthOrg.getWxDepartId(),
 								thirdOrg.getWxDepartId(), fourthOrg.getSapName()));
+						allOrgs.add(fourthOrg);
 					}
 				}
 			}
 		}
-		List<SapOrg> orgs = findListByParentId(null);
-		for(SapOrg org : orgs) {
-			org.setWxDepartId(map.get(org.getId()));
+		
+		for(SapOrg org : allOrgs) {
 			updateWxDepartId(org);
 		}
+		
 	}
 
 	@SuppressWarnings("unchecked")
 	public List<SapOrg> findListByParentId(String parentId) throws Exception {
-		return (List<SapOrg>) findList("SapOrgMapper.findListByParentId", parentId);
+		SapOrg org = SapOrg.builder().parentId(parentId).build();
+		return (List<SapOrg>) findList("SapOrgMapper.findListByParentId", org);
 	}
 
 	public void updateWxDepartId(SapOrg org) throws Exception {