liupeng пре 5 година
родитељ
комит
dceec61f22

+ 2 - 2
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/GetAllUserDataUtil.java

@@ -13,9 +13,9 @@ import me.chanjar.weixin.cp.bean.WxCpUser;
 public class GetAllUserDataUtil {
 
 	public static void main(String[] args) throws WxErrorException {
-		List<WxCpUser> users = WXCpUserUtil.listByDepartment(17L);
+		List<WxCpUser> users = WXCpUserUtil.listByDepartment(158L);
 		for (WxCpUser user : users) {
-			System.out.println(user.getUserId());
+			System.out.println(user);
 		}
 	}
 }

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

@@ -1,92 +1,94 @@
-package org.fouram.core.plugin.weixin.cp.util;
-
-import static org.fouram.core.plugin.weixin.cp.core.WXCpBase.departService;
-
-import java.util.List;
-import java.util.Map;
-
-import org.fouram.core.util.Tools;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.bean.WxCpDepart;
-
-/**
- * 企业微信科室工具类
- * 
- * @author Liup
- */
-public class WXCpDepartUtil {
-	
-	public static void main(String[] args) throws WxErrorException {
-		System.out.println(getChildDepartMap(1L));
-		System.out.println(getChildDeparts(1L));
-	}
-	
-	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())) {
-				departs.add(depart);
-			}
-		}
-		return departs;
-	}
-
-	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())) {
-				map.put(depart.getName(), depart.getId());
-			}
-		}
-		return map;
-	}
-
-	public static Long create(String subCompany, String depatment) throws WxErrorException {
-		Long subCompanyId = create(1L, subCompany);
-		if (Tools.isEmpty(depatment)) {
-			return subCompanyId;
-		}
-		return create(subCompanyId, depatment);
-	}
-
-	public static Long create(String firstOrg, String secondOrg, String thirdOrg, String fourthOrg)
-			throws WxErrorException {
-		Long firstOrgId = create(1L, firstOrg);
-		if (Tools.isEmpty(secondOrg)) {
-			return firstOrgId;
-		}
-		Long secondOrgId = create(firstOrgId, secondOrg);
-		if (Tools.isEmpty(thirdOrg)) {
-			return secondOrgId;
-		}
-		Long thirdOrgId = create(secondOrgId, thirdOrg);
-		if (Tools.isEmpty(fourthOrg)) {
-			return thirdOrgId;
-		}
-		return create(thirdOrgId, fourthOrg);
-	}
-
-	private static Long create(Long parentId, String depatment) throws WxErrorException {
-		Map<String, Long> map = getChildDepartMap(parentId);
-		Long depatmentId = map.get(depatment);
-		if (depatmentId == null) {
-			WxCpDepart depart = new WxCpDepart();
-			depart.setName(depatment);
-			depart.setParentId(parentId);
-			depatmentId = departService.create(depart);
-		}
-		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);
-	}
-}
+package org.fouram.core.plugin.weixin.cp.util;
+
+import static org.fouram.core.plugin.weixin.cp.core.WXCpBase.departService;
+
+import java.util.List;
+import java.util.Map;
+
+import org.fouram.core.util.Tools;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+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) {
+			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())) {
+				departs.add(depart);
+			}
+		}
+		return departs;
+	}
+
+	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())) {
+				map.put(depart.getName(), depart.getId());
+			}
+		}
+		return map;
+	}
+
+	public static Long create(String subCompany, String depatment) throws WxErrorException {
+		Long subCompanyId = create(1L, subCompany);
+		if (Tools.isEmpty(depatment)) {
+			return subCompanyId;
+		}
+		return create(subCompanyId, depatment);
+	}
+
+	public static Long create(String firstOrg, String secondOrg, String thirdOrg, String fourthOrg)
+			throws WxErrorException {
+		Long firstOrgId = create(1L, firstOrg);
+		if (Tools.isEmpty(secondOrg)) {
+			return firstOrgId;
+		}
+		Long secondOrgId = create(firstOrgId, secondOrg);
+		if (Tools.isEmpty(thirdOrg)) {
+			return secondOrgId;
+		}
+		Long thirdOrgId = create(secondOrgId, thirdOrg);
+		if (Tools.isEmpty(fourthOrg)) {
+			return thirdOrgId;
+		}
+		return create(thirdOrgId, fourthOrg);
+	}
+
+	private static Long create(Long parentId, String depatment) throws WxErrorException {
+		Map<String, Long> map = getChildDepartMap(parentId);
+		Long depatmentId = map.get(depatment);
+		if (depatmentId == null) {
+			WxCpDepart depart = new WxCpDepart();
+			depart.setName(depatment);
+			depart.setParentId(parentId);
+			depatmentId = departService.create(depart);
+		}
+		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);
+	}
+}

+ 154 - 151
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/WXCpUserUtil.java

@@ -1,151 +1,154 @@
-package org.fouram.core.plugin.weixin.cp.util;
-
-import static org.fouram.core.plugin.weixin.cp.core.WXCpBase.userService;
-
-import java.util.List;
-
-import org.fouram.core.util.Tools;
-
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.bean.Gender;
-import me.chanjar.weixin.cp.bean.WxCpUser;
-import me.chanjar.weixin.cp.bean.WxCpUser.ExternalAttribute;
-
-/**
- * 企业微信用户工具类
- * 
- * @author Liup
- */
-public class WXCpUserUtil {
-
-	public static String createOrUpdate(String userId, String name, String[] subCompanyList, String[] departmentList,
-			String position, String mobile, String gender, String email) {
-		WxCpUser user = getById(userId);
-		try {
-			if (user == null) {
-				user = getUser(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
-				userService.create(user);
-			} else {
-				user = getUser(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
-				userService.update(user);
-			}
-			return "SUCCESS";
-		} catch (WxErrorException e) {
-			return e.getMessage();
-		}
-	}
-
-	public static String createOrUpdate(String userId, String name, String[] firstOrgList, String[] secondOrgList,
-			String[] thirdOrgList, String[] fourthOrgList, String position, String mobile, String gender,
-			String email) {
-		WxCpUser user = getById(userId);
-		try {
-			if (user == null) {
-				user = getUser(userId, name, firstOrgList, secondOrgList, thirdOrgList, fourthOrgList, position, mobile,
-						gender, email);
-				userService.create(user);
-			} else {
-				user = getUser(userId, name, firstOrgList, secondOrgList, thirdOrgList, fourthOrgList, position, mobile,
-						gender, email);
-				userService.update(user);
-			}
-			return "SUCCESS";
-		} catch (WxErrorException e) {
-			return e.getMessage();
-		}
-	}
-
-	private static WxCpUser getUser(String userId, String name, String[] firstOrgList, String[] secondOrgList,
-			String[] thirdOrgList, String[] fourthOrgList, String position, String mobile, String gender, String email)
-			throws WxErrorException {
-		WxCpUser user = new WxCpUser();
-		if (Tools.notEmpty(userId)) {
-			user.setUserId(userId);
-		}
-		if (Tools.notEmpty(name)) {
-			user.setName(name);
-		}
-		Long[] departIds = new Long[firstOrgList.length];
-		for (int i = 0; i < firstOrgList.length; i++) {
-			departIds[i] = WXCpDepartUtil.create(firstOrgList[i], secondOrgList[i], thirdOrgList[i],
-					fourthOrgList[i]);
-		}
-		user.setDepartIds(departIds);
-		if (Tools.notEmpty(position)) {
-			user.setPosition(position);
-		}
-		if (Tools.notEmpty(mobile)) {
-			user.setMobile(mobile);
-		}
-		if (Tools.notEmpty(gender)) {
-			user.setGender(Gender.MALE.getGenderName().equals(gender) ? Gender.MALE : Gender.FEMALE);
-		}
-		if (Tools.notEmpty(email)) {
-			user.setEmail(email);
-		}
-		user.setToInvite(false);
-		ExternalAttribute attribute = ExternalAttribute.builder().name("所属公司").type(0).value(firstOrgList[0]).build();
-		user.addExternalAttr(attribute);
-		return user;
-	}
-
-	public static void updateUser(WxCpUser user) throws WxErrorException {
-		userService.update(user);
-	}
-
-	private static WxCpUser getUser(String userId, String name, String[] subCompanyList, String[] departmentList,
-			String position, String mobile, String gender, String email) throws WxErrorException {
-		WxCpUser user = new WxCpUser();
-		if (Tools.notEmpty(userId)) {
-			user.setUserId(userId);
-		}
-		if (Tools.notEmpty(name)) {
-			user.setName(name);
-		}
-		Long[] departIds = new Long[subCompanyList.length];
-		for (int i = 0; i < subCompanyList.length; i++) {
-			departIds[i] = WXCpDepartUtil.create(subCompanyList[i], departmentList[i]);
-		}
-		user.setDepartIds(departIds);
-		if (Tools.notEmpty(position)) {
-			user.setPosition(position);
-		}
-		if (Tools.notEmpty(mobile)) {
-			user.setMobile(mobile);
-		}
-		if (Tools.notEmpty(gender)) {
-			user.setGender(Gender.MALE.getGenderName().equals(gender) ? Gender.MALE : Gender.FEMALE);
-		}
-		if (Tools.notEmpty(email)) {
-			user.setEmail(email);
-		}
-		user.setToInvite(false);
-		ExternalAttribute attribute = ExternalAttribute.builder().name("所属公司").type(0).value(subCompanyList[0]).build();
-		user.addExternalAttr(attribute);
-		return user;
-	}
-
-	public static WxCpUser getById(String userId) {
-		try {
-			return userService.getById(userId);
-		} catch (WxErrorException e) {
-			return null;
-		}
-	}
-
-	public static void delete(String userId) {
-		try {
-			userService.delete(userId);
-		} catch (WxErrorException e) {
-		}
-	}
-
-	public static List<WxCpUser> listByDepartment(Long departId) throws WxErrorException {
-		return userService.listByDepartment(departId, true, 0);
-	}
-
-	public static void main(String[] args) {
-		createOrUpdate("yangbin", "杨斌", new String[] { "华人时代" }, new String[] { "管理层" }, "", "", "男",
-				"13671179900@jiinfo.cn");
-	}
-}
+package org.fouram.core.plugin.weixin.cp.util;
+
+import static org.fouram.core.plugin.weixin.cp.core.WXCpBase.userService;
+
+import java.util.List;
+
+import org.fouram.core.util.Tools;
+
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.bean.Gender;
+import me.chanjar.weixin.cp.bean.WxCpUser;
+import me.chanjar.weixin.cp.bean.WxCpUser.ExternalAttribute;
+
+/**
+ * 企业微信用户工具类
+ * 
+ * @author Liup
+ */
+public class WXCpUserUtil {
+
+	public static String createOrUpdate(String userId, String name, String[] subCompanyList, String[] departmentList,
+			String position, String mobile, String gender, String email) {
+		WxCpUser user = getById(userId);
+		try {
+			if (user == null) {
+				user = getUser(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
+				userService.create(user);
+			} else {
+				user = getUser(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
+				userService.update(user);
+			}
+			return "SUCCESS";
+		} catch (WxErrorException e) {
+			return e.getMessage();
+		}
+	}
+
+	public static String createOrUpdate(String userId, String name, String[] firstOrgList, String[] secondOrgList,
+			String[] thirdOrgList, String[] fourthOrgList, String position, String mobile, String gender,
+			String email, String telephone) {
+		WxCpUser user = getById(userId);
+		try {
+			if (user == null) {
+				user = getUser(userId, name, firstOrgList, secondOrgList, thirdOrgList, fourthOrgList, position, mobile,
+						gender, email, telephone);
+				userService.create(user);
+			} else {
+				user = getUser(userId, name, firstOrgList, secondOrgList, thirdOrgList, fourthOrgList, position, mobile,
+						gender, email, telephone);
+				userService.update(user);
+			}
+			return "SUCCESS";
+		} catch (WxErrorException e) {
+			return e.getMessage();
+		}
+	}
+
+	private static WxCpUser getUser(String userId, String name, String[] firstOrgList, String[] secondOrgList,
+			String[] thirdOrgList, String[] fourthOrgList, String position, String mobile, String gender, String email, String telephone)
+			throws WxErrorException {
+		WxCpUser user = new WxCpUser();
+		if (Tools.notEmpty(userId)) {
+			user.setUserId(userId);
+		}
+		if (Tools.notEmpty(name)) {
+			user.setName(name);
+		}
+		Long[] departIds = new Long[firstOrgList.length];
+		for (int i = 0; i < firstOrgList.length; i++) {
+			departIds[i] = WXCpDepartUtil.create(firstOrgList[i], secondOrgList[i], thirdOrgList[i],
+					fourthOrgList[i]);
+		}
+		user.setDepartIds(departIds);
+		if (Tools.notEmpty(position)) {
+			user.setPosition(position);
+		}
+		if (Tools.notEmpty(mobile)) {
+			user.setMobile(mobile);
+		}
+		if (Tools.notEmpty(gender)) {
+			user.setGender(Gender.MALE.getGenderName().equals(gender) ? Gender.MALE : Gender.FEMALE);
+		}
+		if (Tools.notEmpty(email)) {
+			user.setEmail(email);
+		}
+		if (Tools.notEmpty(telephone)) {
+			user.setTelephone(telephone);
+		}
+		user.setToInvite(false);
+		ExternalAttribute attribute = ExternalAttribute.builder().name("所属公司").type(0).value(firstOrgList[0]).build();
+		user.addExternalAttr(attribute);
+		return user;
+	}
+
+	public static void updateUser(WxCpUser user) throws WxErrorException {
+		userService.update(user);
+	}
+
+	private static WxCpUser getUser(String userId, String name, String[] subCompanyList, String[] departmentList,
+			String position, String mobile, String gender, String email) throws WxErrorException {
+		WxCpUser user = new WxCpUser();
+		if (Tools.notEmpty(userId)) {
+			user.setUserId(userId);
+		}
+		if (Tools.notEmpty(name)) {
+			user.setName(name);
+		}
+		Long[] departIds = new Long[subCompanyList.length];
+		for (int i = 0; i < subCompanyList.length; i++) {
+			departIds[i] = WXCpDepartUtil.create(subCompanyList[i], departmentList[i]);
+		}
+		user.setDepartIds(departIds);
+		if (Tools.notEmpty(position)) {
+			user.setPosition(position);
+		}
+		if (Tools.notEmpty(mobile)) {
+			user.setMobile(mobile);
+		}
+		if (Tools.notEmpty(gender)) {
+			user.setGender(Gender.MALE.getGenderName().equals(gender) ? Gender.MALE : Gender.FEMALE);
+		}
+		if (Tools.notEmpty(email)) {
+			user.setEmail(email);
+		}
+		user.setToInvite(false);
+		ExternalAttribute attribute = ExternalAttribute.builder().name("所属公司").type(0).value(subCompanyList[0]).build();
+		user.addExternalAttr(attribute);
+		return user;
+	}
+
+	public static WxCpUser getById(String userId) {
+		try {
+			return userService.getById(userId);
+		} catch (WxErrorException e) {
+			return null;
+		}
+	}
+
+	public static void delete(String userId) {
+		try {
+			userService.delete(userId);
+		} catch (WxErrorException e) {
+		}
+	}
+
+	public static List<WxCpUser> listByDepartment(Long departId) throws WxErrorException {
+		return userService.listByDepartment(departId, true, 0);
+	}
+
+	public static void main(String[] args) {
+		createOrUpdate("yangbin", "杨斌", new String[] { "华人时代" }, new String[] { "管理层" }, "", "", "男",
+				"13671179900@jiinfo.cn");
+	}
+}