|
@@ -19,15 +19,15 @@ import me.chanjar.weixin.cp.bean.WxCpUser.ExternalAttribute;
|
|
|
*/
|
|
|
public class WXCpUserUtil {
|
|
|
|
|
|
- public static String createOrUpdateForTest(String userId, String name, String[] subCompanyList, String[] departmentList,
|
|
|
- String position, String mobile, String gender, String email) {
|
|
|
- WxCpUser user = getById(userId);
|
|
|
+ public static String createOrUpdateForTest(String userId, String name, String[] subCompanyList,
|
|
|
+ String[] departmentList, String position, String mobile, String gender, String email) {
|
|
|
+ WxCpUser user = getByIdOrEmail(userId, email);
|
|
|
try {
|
|
|
if (user == null) {
|
|
|
user = getUserForTest(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
|
|
|
userService.create(user);
|
|
|
} else {
|
|
|
- user = getUserForTest(userId, name, subCompanyList, departmentList, position, mobile, gender, email);
|
|
|
+ user = getUserForTest(user.getUserId(), name, subCompanyList, departmentList, position, mobile, gender, email);
|
|
|
userService.update(user);
|
|
|
}
|
|
|
return WebConstants.SUCCESS;
|
|
@@ -39,14 +39,14 @@ public class WXCpUserUtil {
|
|
|
public static String createOrUpdate(String userId, String name, Long[] firstOrgWxDepartIdList,
|
|
|
Long[] secondOrgWxDepartIdList, Long[] thirdOrgWxDepartIdList, Long[] fourthOrgWxDepartIdList,
|
|
|
String position, String mobile, String gender, String email, String telephone, String firstOrgName) {
|
|
|
- WxCpUser user = getById(userId);
|
|
|
+ WxCpUser user = getByIdOrEmail(userId, email);
|
|
|
try {
|
|
|
if (user == null) {
|
|
|
user = getUser(userId, name, firstOrgWxDepartIdList, secondOrgWxDepartIdList, thirdOrgWxDepartIdList,
|
|
|
fourthOrgWxDepartIdList, position, mobile, gender, email, telephone, firstOrgName);
|
|
|
userService.create(user);
|
|
|
} else {
|
|
|
- user = getUser(userId, name, firstOrgWxDepartIdList, secondOrgWxDepartIdList, thirdOrgWxDepartIdList,
|
|
|
+ user = getUser(user.getUserId(), name, firstOrgWxDepartIdList, secondOrgWxDepartIdList, thirdOrgWxDepartIdList,
|
|
|
fourthOrgWxDepartIdList, position, mobile, gender, email, telephone, firstOrgName);
|
|
|
userService.update(user);
|
|
|
}
|
|
@@ -130,21 +130,25 @@ public class WXCpUserUtil {
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
- public static WxCpUser getById(String userId) {
|
|
|
+ public static WxCpUser getByIdOrEmail(String userId, String email) {
|
|
|
try {
|
|
|
- return userService.getById(userId);
|
|
|
+ WxCpUser user = userService.getById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ user = userService.getById(email);
|
|
|
+ }
|
|
|
+ return user;
|
|
|
} 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);
|
|
|
}
|