|
|
@@ -34,6 +34,7 @@ import javax.persistence.criteria.*;
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -60,6 +61,9 @@ public class UserServiceImpl implements UserService {
|
|
|
@Autowired
|
|
|
private AppService appService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExecutorService executorService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private UserQuestionService userQuestionService;
|
|
|
|
|
|
@@ -96,7 +100,7 @@ public class UserServiceImpl implements UserService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized User register(User user) {
|
|
|
+ public synchronized User register(User user, String appId) {
|
|
|
String noEncryPwd = user.getPassword();
|
|
|
// 校验手机号是否被注册
|
|
|
if (mobileHasRegistered(user.getMobile())) {
|
|
|
@@ -124,12 +128,14 @@ public class UserServiceImpl implements UserService {
|
|
|
user.setUserRecord(new UserRecord());
|
|
|
user.getUserRecord().setUser(user);
|
|
|
user.getUserRecord().setUserUU(user.getUserUU());
|
|
|
+ user.setFromApp(appId);
|
|
|
|
|
|
- userDao.save(user);
|
|
|
+ user = userDao.save(user);
|
|
|
userLogger.info(user, Type.UPDATE_REGISTER.getValue());
|
|
|
|
|
|
// 同步到各个应用
|
|
|
- return syncUserInfo(user.getUserUU(), noEncryPwd, "个人注册");
|
|
|
+ App app = appService.findOne(appId);
|
|
|
+ return syncUserInfo(user, noEncryPwd, "个人注册", app);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -152,7 +158,7 @@ public class UserServiceImpl implements UserService {
|
|
|
@Override
|
|
|
public User save(User user) {
|
|
|
user = userDao.save(user);
|
|
|
- return syncUserInfo(user, null, "修改用户信息");
|
|
|
+ return syncUserInfo(user, null, "修改用户信息", null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -309,13 +315,13 @@ public class UserServiceImpl implements UserService {
|
|
|
user.setMobileValidCode((short) Status.AUTHENTICATED.getCode());
|
|
|
|
|
|
// 保存用户信息
|
|
|
- userDao.save(user);
|
|
|
+ user = userDao.save(user);
|
|
|
|
|
|
// 保存日志
|
|
|
userLogger.info(user, Type.UPDATE_MOBILE.getValue());
|
|
|
|
|
|
// 同步到各个应用
|
|
|
- syncUserInfo(user.getUserUU(), null, "修改手机号");
|
|
|
+ syncUserInfo(user, null, "修改手机号", null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -331,13 +337,13 @@ public class UserServiceImpl implements UserService {
|
|
|
user.setEmailValidCode((short) Status.AUTHENTICATED.getCode());
|
|
|
|
|
|
// 保存用户信息
|
|
|
- userDao.save(user);
|
|
|
+ user = userDao.save(user);
|
|
|
|
|
|
// 保存日志
|
|
|
userLogger.info(user, Type.UPDATE_EMAIL.getValue());
|
|
|
|
|
|
// 同步信息到各应用
|
|
|
- syncUserInfo(user.getUserUU(), null, "修改邮箱");
|
|
|
+ syncUserInfo(user, null, "修改邮箱", null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -404,36 +410,34 @@ public class UserServiceImpl implements UserService {
|
|
|
* @param type 类型 (bind or unbind)
|
|
|
*/
|
|
|
private void syncRelation(final Long userUU, final Long spaceUU, final String type) {
|
|
|
- List<String> apps = appService.findUid();
|
|
|
-
|
|
|
- ExecuteUtils.execute(new ICallable<Void, String>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public Void call(String appId) {
|
|
|
- App tempApp = appService.findOne(appId);
|
|
|
- if (tempApp != null && StringUtils.isEmpty(tempApp.getUserControl())
|
|
|
- && !StringUtils.isEmpty(tempApp.getBackRelationUrl())) {
|
|
|
- String url = tempApp.getBackRelationUrl();
|
|
|
- ModelMap formData = new ModelMap();
|
|
|
- formData.put("userUU", userUU);
|
|
|
- formData.put("spaceUU", spaceUU);
|
|
|
- formData.put("type", type);
|
|
|
+ Userspace userspace = userspaceService.findOne(spaceUU);
|
|
|
+ List<App> apps = userspace.getApps();
|
|
|
+
|
|
|
+ final ModelMap formData = new ModelMap();
|
|
|
+ formData.put("userUU", userUU);
|
|
|
+ formData.put("spaceUU", spaceUU);
|
|
|
+ formData.put("type", type);
|
|
|
+
|
|
|
+ for (final App app : apps) {
|
|
|
+ executorService.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String url = app.getBackRelationUrl();
|
|
|
HttpUtil.ResponseWrap res = null;
|
|
|
try {
|
|
|
res = HttpUtil.doPost(url, formData, 10000);
|
|
|
if (!res.isSuccess()) {
|
|
|
- SyncLog syncLog = syncLogger.error(appId, "同步绑定信息失败", JSON.toJSONString(formData), res.getContent());
|
|
|
- SyncFail.add(syncLog.getId(), formData, url, appId);
|
|
|
+ SyncLog syncLog = syncLogger.error(app.getUid(), "同步绑定信息失败", JSON.toJSONString(formData), res.getContent());
|
|
|
+ SyncFail.add(syncLog.getId(), formData, url, app.getUid());
|
|
|
} else {
|
|
|
- syncLogger.info(appId, "同步绑定信息成功", JSON.toJSONString(formData));
|
|
|
+ syncLogger.info(app.getUid(), "同步绑定信息成功", JSON.toJSONString(formData));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- syncLogger.error(appId, "同步绑定信息失败", JSON.toJSONString(formData), e.getMessage());
|
|
|
+ syncLogger.error(app.getUid(), "同步绑定信息失败", JSON.toJSONString(formData), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
- }
|
|
|
- }, apps);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -488,7 +492,7 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
// 保存并添加日志
|
|
|
user = userDao.save(user);
|
|
|
- syncUserInfo(user, null, "修改密保");
|
|
|
+ syncUserInfo(user, null, "修改密保", null);
|
|
|
userLogger.info(user, Type.UPDATE_QUESTION.getValue(), JSON.toJSONString(user.getQuestions()));
|
|
|
}
|
|
|
|
|
|
@@ -511,7 +515,7 @@ public class UserServiceImpl implements UserService {
|
|
|
user.setPassword(getEncryPassword(Const.ENCRY_FORMAT, noEncryPwd, user.getSalt()));
|
|
|
user.setPasswordLevel(PasswordLevelUtils.checkPasswordLevel(noEncryPwd).getValue());
|
|
|
|
|
|
- user = syncUserInfo(user , noEncryPwd, "用户修改密码");
|
|
|
+ user = syncUserInfo(user , noEncryPwd, "用户修改密码", null);
|
|
|
|
|
|
return userDao.save(user);
|
|
|
}
|
|
|
@@ -595,7 +599,7 @@ public class UserServiceImpl implements UserService {
|
|
|
// 保存用户信息
|
|
|
oldUser = userDao.save(oldUser);
|
|
|
|
|
|
- oldUser = syncUserInfo(oldUser, null, "(接口调用)修改用户信息");
|
|
|
+ oldUser = syncUserInfo(oldUser, null, "(接口调用)修改用户信息", null);
|
|
|
return oldUser;
|
|
|
}
|
|
|
|
|
|
@@ -616,89 +620,95 @@ public class UserServiceImpl implements UserService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 同步用户信息到各个应用
|
|
|
- * @param userUU 用户uu号
|
|
|
- * @param noEncryPwd 未加密密码,用于同步im
|
|
|
- * @param msg 同步信息描述,用户区分同步类型
|
|
|
- */
|
|
|
- private User syncUserInfo(Long userUU, String noEncryPwd, String msg) {
|
|
|
- return syncUserInfo(findOne(userUU), noEncryPwd, msg);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 同步用户信息到各个应用
|
|
|
* @param user 用户信息
|
|
|
* @param noEncryPwd 未加密密码,用于同步im
|
|
|
* @param msg 同步信息描述,用户区分同步类型
|
|
|
*/
|
|
|
- private User syncUserInfo(User user, String noEncryPwd, final String msg) {
|
|
|
- List<String> apps = appService.findUid();
|
|
|
- final boolean hasQuestion = !CollectionUtils.isEmpty(user.getQuestions());
|
|
|
+ private User syncUserInfo(User user, String noEncryPwd, final String msg, App otherApp) {
|
|
|
+ List<App> apps = appService.findDefaultUseApp();
|
|
|
+ if (otherApp != null && !apps.contains(otherApp)) {
|
|
|
+ apps.add(otherApp);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- // 同步信息到im
|
|
|
+ // 其他应用可能会用到IMID,要先同步到im之后再同步到其他应用
|
|
|
String imId = syncUserToIm(user, noEncryPwd, msg);
|
|
|
user.setImId(imId);
|
|
|
user = userDao.save(user);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- final User finalUser = user;
|
|
|
- ExecuteUtils.execute(new ICallable<Void, String>() {
|
|
|
|
|
|
- @Override
|
|
|
- public Void call(String appId) {
|
|
|
- App tempApp = appService.findOne(appId);
|
|
|
- if (tempApp != null && StringUtils.isEmpty(tempApp.getUserControl())
|
|
|
- && !StringUtils.isEmpty(tempApp.getBackUserUrl()) && !"im".equals(appId)) {
|
|
|
- String url = tempApp.getBackUserUrl();
|
|
|
- JSONObject formData = JSON.parseObject(JSON.toJSONString(finalUser));
|
|
|
- formData.put("password", finalUser.getPassword());
|
|
|
- formData.put("hasQuestion", hasQuestion);
|
|
|
- HttpUtil.ResponseWrap res = null;
|
|
|
- try {
|
|
|
- res = HttpUtil.doPost(url, formData, 10000);
|
|
|
- if (!res.isSuccess()) {
|
|
|
- SyncLog syncLog = syncLogger.error(appId, msg + ",同步用户信息失败", JSON.toJSONString(formData), res.getContent());
|
|
|
- SyncFail.add(syncLog.getId(), formData, url, appId);
|
|
|
- } else {
|
|
|
- syncLogger.info(appId, msg + ",同步用户信息成功", JSON.toJSONString(formData));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- syncLogger.error(appId, msg + ",同步用户信息失败", JSON.toJSONString(formData), e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- }, apps);
|
|
|
+ // 封装同步其他应用数据并同步
|
|
|
+ boolean hasQuestion = !CollectionUtils.isEmpty(user.getQuestions());
|
|
|
+ JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
|
|
|
+ formData.put("password", user.getPassword());
|
|
|
+ formData.put("hasQuestion", hasQuestion);
|
|
|
+ syncUserInfo(formData, msg, apps);
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
private String syncUserToIm(User user, String noEncryPwd, String msg) throws Exception {
|
|
|
String appId = "im";
|
|
|
App app = appService.findOne(appId);
|
|
|
- if (!StringUtils.isEmpty(app.getBackUserUrl())) {
|
|
|
- String url = app.getBackUserUrl();
|
|
|
- HttpUtil.ResponseWrap res = null;
|
|
|
- ModelMap formData = new ModelMap();
|
|
|
- formData.put("dialectUID", user.getImId());
|
|
|
- formData.put("realName", StringUtils.isEmpty(user.getRealName()) ? user.getVipName() : user.getRealName());
|
|
|
- formData.put("password", noEncryPwd);
|
|
|
- formData.put("email", StringUtils.isEmpty(user.getEmail()) ? "0" : user.getEmail());
|
|
|
- formData.put("mobile", user.getMobile());
|
|
|
- res = HttpUtil.doPost(url, formData, 10000);
|
|
|
- if (!res.isSuccess()) {
|
|
|
+ if (StringUtils.isEmpty(app.getBackUserUrl())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装数据同步到im
|
|
|
+ String url = app.getBackUserUrl();
|
|
|
+ HttpUtil.ResponseWrap res = null;
|
|
|
+ ModelMap formData = new ModelMap();
|
|
|
+ formData.put("dialectUID", user.getImId());
|
|
|
+ formData.put("realName", StringUtils.isEmpty(user.getRealName()) ? user.getVipName() : user.getRealName());
|
|
|
+ formData.put("password", noEncryPwd);
|
|
|
+ formData.put("email", StringUtils.isEmpty(user.getEmail()) ? "0" : user.getEmail());
|
|
|
+ formData.put("mobile", user.getMobile());
|
|
|
+ res = HttpUtil.doPost(url, formData, 10000);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ syncLogger.error(appId, msg + ",同步用户信息失败", formData.toString(), res.getContent());
|
|
|
+ throw new Exception(res.getContent());
|
|
|
+ } else {
|
|
|
+ JSONObject obj = JSON.parseObject(res.getContent());
|
|
|
+ if (obj.getString("resultMsg") != null) {
|
|
|
syncLogger.error(appId, msg + ",同步用户信息失败", formData.toString(), res.getContent());
|
|
|
- throw new Exception(res.getContent());
|
|
|
- } else {
|
|
|
- JSONObject obj = JSON.parseObject(res.getContent());
|
|
|
- if (obj.getString("resultMsg") != null) {
|
|
|
- syncLogger.error(appId, msg + ",同步用户信息失败", formData.toString(), res.getContent());
|
|
|
- }
|
|
|
- syncLogger.info(appId, msg + ",同步用户信息成功", formData.toString(), res.getContent());
|
|
|
- return obj.getString("dialectUID");
|
|
|
}
|
|
|
+ syncLogger.info(appId, msg + ",同步用户信息成功", formData.toString(), res.getContent());
|
|
|
+ return obj.getString("dialectUID");
|
|
|
}
|
|
|
- return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步信息到指定应用
|
|
|
+ * @param formData 同步数据
|
|
|
+ * @param msg 同步信息
|
|
|
+ * @param apps 需要同步的应用
|
|
|
+ */
|
|
|
+ private void syncUserInfo(final Map<String, Object> formData, final String msg, List<App> apps) {
|
|
|
+ for (final App app : apps) {
|
|
|
+ executorService.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ String url = app.getBackUserUrl();
|
|
|
+ if (StringUtils.isEmpty(url)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ HttpUtil.ResponseWrap res;
|
|
|
+ try {
|
|
|
+ res = HttpUtil.doPost(url, formData, 10000);
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ SyncLog syncLog = syncLogger.error(app.getUid(), msg + ",同步用户信息失败", JSON.toJSONString(formData), res.getContent());
|
|
|
+ SyncFail.add(syncLog.getId(), formData, url, app.getUid());
|
|
|
+ } else {
|
|
|
+ syncLogger.info(app.getUid(), msg + ",同步用户信息成功", JSON.toJSONString(formData));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ syncLogger.error(app.getUid(), msg + ",同步用户信息失败", JSON.toJSONString(formData), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|