|
|
@@ -1,15 +1,22 @@
|
|
|
package com.uas.sso.sync.service.impl;
|
|
|
|
|
|
import com.alibaba.dubbo.common.utils.CollectionUtils;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.uas.sso.common.util.HttpUtil;
|
|
|
+import com.uas.sso.entity.App;
|
|
|
import com.uas.sso.entity.PageInfo;
|
|
|
+import com.uas.sso.entity.SyncLog;
|
|
|
+import com.uas.sso.logging.LoggerManager;
|
|
|
+import com.uas.sso.logging.SyncBufferedLogger;
|
|
|
+import com.uas.sso.service.AppService;
|
|
|
+import com.uas.sso.support.SyncFail;
|
|
|
import com.uas.sso.sync.dao.SyncUserDao;
|
|
|
import com.uas.sso.sync.dao.SyncUserQuestionDao;
|
|
|
import com.uas.sso.sync.entity.*;
|
|
|
import com.uas.sso.sync.service.SyncSsoService;
|
|
|
import com.uas.sso.sync.service.SyncUserService;
|
|
|
import com.usoft.mq.utils.RabbitSendService;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
@@ -17,14 +24,15 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import javax.persistence.criteria.Root;
|
|
|
-import java.sql.Timestamp;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
/**
|
|
|
* 用户业务接口实现类
|
|
|
@@ -47,7 +55,13 @@ public class SyncUserServiceImpl implements SyncUserService {
|
|
|
@Autowired
|
|
|
private RabbitSendService rabbitSendService;
|
|
|
|
|
|
- private final static Logger LOGGER = LoggerFactory.getLogger(SyncUserServiceImpl.class);
|
|
|
+ @Autowired
|
|
|
+ private AppService appService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExecutorService executorService;
|
|
|
+
|
|
|
+ private SyncBufferedLogger syncLogger = LoggerManager.getLogger(SyncBufferedLogger.class);
|
|
|
|
|
|
@Override
|
|
|
public Page<SyncUser> getSyncUserPageInfo(int pageSize, int pageNumber, Long timestamp) {
|
|
|
@@ -95,10 +109,6 @@ public class SyncUserServiceImpl implements SyncUserService {
|
|
|
public void syncUser(SsoServiceUser ssoServiceUser, boolean isUpdate) {
|
|
|
// 同步用户基本信息
|
|
|
syncUserInfo(ssoServiceUser, isUpdate);
|
|
|
- // 同步用户密保问题
|
|
|
- syncUserQuestion(ssoServiceUser, isUpdate);
|
|
|
- // 同步到其他应用
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -123,17 +133,11 @@ public class SyncUserServiceImpl implements SyncUserService {
|
|
|
* @param isUpdate
|
|
|
*/
|
|
|
private void syncUserInfo(SsoServiceUser ssoServiceUser, boolean isUpdate) {
|
|
|
- SyncUser syncUser = mappingUserInfo(ssoServiceUser);
|
|
|
- syncUserDao.save(syncUser);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步密保问题
|
|
|
- * @param ssoServiceUser
|
|
|
- * @param isUpdate
|
|
|
- */
|
|
|
- private void syncUserQuestion(SsoServiceUser ssoServiceUser, boolean isUpdate) {
|
|
|
- // 查询用户信息
|
|
|
+ SyncUser syncUser = syncUserDao.findOne(Long.valueOf(ssoServiceUser.getUu()));
|
|
|
+ if(syncUser == null) {
|
|
|
+ syncUser = new SyncUser();
|
|
|
+ }
|
|
|
+ syncUser = ssoServiceUser.mappingUserInfo(ssoServiceUser, syncUser);
|
|
|
List<SsoServiceUserQuestion> ssoServiceUserQuestion = ssoServiceUser.getUserEncrypted();
|
|
|
if (!CollectionUtils.isEmpty(ssoServiceUserQuestion)) {
|
|
|
List<SyncUserQuestion> syncUserQuestions = new ArrayList<>();
|
|
|
@@ -142,33 +146,48 @@ public class SyncUserServiceImpl implements SyncUserService {
|
|
|
syncUserQuestion.setAnswer(question.getAnswer());
|
|
|
syncUserQuestion.setQuestion(question.getQuestion());
|
|
|
syncUserQuestion.setSort(Integer.valueOf(question.getSort()).toString());
|
|
|
- syncUserQuestion.setUserUU(Long.valueOf(question.getUu()));
|
|
|
+ syncUserQuestion.setUserUU((long) question.getUu());
|
|
|
syncUserQuestions.add(syncUserQuestion);
|
|
|
}
|
|
|
- syncUserQuestionDao.save(syncUserQuestions);
|
|
|
+ syncUser.setQuestions(syncUserQuestions);
|
|
|
}
|
|
|
+ syncUser = syncUserDao.save(syncUser);
|
|
|
+ syncUserInfo(syncUser);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 账号服务实体映射到账户中心
|
|
|
- * @param ssoServiceUser
|
|
|
- * @return
|
|
|
+ * 同步信息到指定应用
|
|
|
*/
|
|
|
- private SyncUser mappingUserInfo(SsoServiceUser ssoServiceUser) {
|
|
|
- SyncUser syncUser = new SyncUser();
|
|
|
- syncUser.setUserUU(Long.valueOf(ssoServiceUser.getUu()));
|
|
|
- syncUser.setVipName(ssoServiceUser.getName() == null ? "" : ssoServiceUser.getName());
|
|
|
- syncUser.setMobile(ssoServiceUser.getMobile() == null ? "" : ssoServiceUser.getMobile());
|
|
|
- syncUser.setEmail(ssoServiceUser.getEmail() == null ? "" : ssoServiceUser.getEmail());
|
|
|
- syncUser.setWxUnionid(ssoServiceUser.getWxUnionid() == null ? "" : ssoServiceUser.getWxUnionid());
|
|
|
- syncUser.setRegisterDate(ssoServiceUser.getRegTime() == null ? new Timestamp(System.currentTimeMillis()) : Timestamp.valueOf(ssoServiceUser.getRegTime()));
|
|
|
- syncUser.setSalt(Long.valueOf(ssoServiceUser.getUu()).toString());
|
|
|
- syncUser.setFromApp(ssoServiceUser.getSource() == null ? "" : ssoServiceUser.getSource());
|
|
|
- syncUser.setPassword(ssoServiceUser.getPassword() == null ? "" : ssoServiceUser.getPassword());
|
|
|
- syncUser.setEmailValidCode((short) 0);
|
|
|
- syncUser.setIdentityValidCode((short) 0);
|
|
|
- syncUser.setMobileValidCode((short) 0);
|
|
|
- syncUser.setPasswordLevel((short) 2);
|
|
|
- return syncUser;
|
|
|
+ private void syncUserInfo(final SyncUser user) {
|
|
|
+ List<App> apps = appService.findDefaultUseApp();
|
|
|
+ JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
|
|
|
+ formData.put("password", user.getPassword());
|
|
|
+ boolean hasQuestion = !org.springframework.util.CollectionUtils.isEmpty(user.getQuestions());
|
|
|
+ formData.put("hasQuestion", hasQuestion);
|
|
|
+
|
|
|
+ String msg = "用户信息同步";
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|