Bläddra i källkod

ref:联调问题处理

liusw 7 år sedan
förälder
incheckning
4d9246c295

+ 1 - 1
sso-server/src/main/java/com/uas/sso/controller/PersonalRegisterController.java

@@ -151,7 +151,7 @@ public class PersonalRegisterController extends BaseController {
         st.setData(JSON.toJSONString(userAccount));
         SSOHelper.setSSOCookie(request, response, st, true);
 
-        syncSsoService.sendUserLoginStateToSso(0L, user.getUserUU(), response, null);
+        syncSsoService.sendUserLoginStateToSso(0L, userAccount.getUserUU(), response, null);
 
         ModelMap data = new ModelMap();
         data.addAttribute("data", userAccount)

+ 3 - 1
sso-server/src/main/java/com/uas/sso/controller/UserspaceRegisterController.java

@@ -196,7 +196,9 @@ public class UserspaceRegisterController extends BaseController {
         ModelMap info = new ModelMap();
         info.addAttribute("enname", userspace.getSpaceName());
         info.addAttribute("enuu", userspace.getSpaceUU());
-        sendEmail("templateForSendMailAfterRegister", admin.getEmail(), info);
+        if (!StringUtils.isEmpty(admin.getEmail())) {
+            sendEmail("templateForSendMailAfterRegister", admin.getEmail(), info);
+        }
         sendSms("templateForSendSmsAfterRegister", admin.getMobile(), userspace.getSpaceName(), userspace.getSpaceUU());
 
         // 添加日志

+ 1 - 1
sso-server/src/main/java/com/uas/sso/service/impl/LoginServiceImpl.java

@@ -325,7 +325,7 @@ public class LoginServiceImpl implements LoginService {
         SSOToken st = new SSOToken(request, userAccount.getMobile());
         st.setData(JSON.toJSONString(userAccount));
         SSOHelper.setSSOCookie(request, response, st, true);
-        syncSsoService.sendUserLoginStateToSso(spaceUU, userUU, response, loginParam.getMaxage());
+        syncSsoService.sendUserLoginStateToSso(userAccount.getSpaceUU(), userAccount.getUserUU(), response, loginParam.getMaxage());
         LOGGER.info("用户({})登录成功,时间:{}", userUU, userRecord.getLastLoginTime());
         return loginByUser(userAccount, loginParam);
     }

+ 23 - 0
sso-server/src/main/java/com/uas/sso/sync/entity/SsoServiceUser.java

@@ -2,6 +2,7 @@ package com.uas.sso.sync.entity;
 
 import com.uas.sso.entity.UserQuestion;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -154,4 +155,26 @@ public class SsoServiceUser {
     public void setUserEncrypted(List<SsoServiceUserQuestion> userEncrypted) {
         this.userEncrypted = userEncrypted;
     }
+
+    /**
+     * 账号服务实体映射到账户中心
+     * @param ssoServiceUser
+     * @return
+     */
+    public SyncUser mappingUserInfo(SsoServiceUser ssoServiceUser, SyncUser syncUser) {
+        syncUser.setUserUU(Long.valueOf(ssoServiceUser.getUu()));
+        syncUser.setVipName(ssoServiceUser.getName());
+        syncUser.setMobile(ssoServiceUser.getMobile());
+        syncUser.setEmail(ssoServiceUser.getEmail());
+        syncUser.setWxUnionid(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());
+        syncUser.setPassword(ssoServiceUser.getPassword());
+        syncUser.setEmailValidCode(ssoServiceUser.getEmail() == null || ssoServiceUser.getEmail().equals("") ? (short) 0 : (short) 2);
+        syncUser.setIdentityValidCode((short) 0);
+        syncUser.setMobileValidCode((short) 2);
+        syncUser.setPasswordLevel((short) 2);
+        return syncUser;
+    }
 }

+ 22 - 5
sso-server/src/main/java/com/uas/sso/sync/entity/SsoServiceUserspace.java

@@ -1,5 +1,6 @@
 package com.uas.sso.sync.entity;
 
+import java.sql.Timestamp;
 import java.util.List;
 
 /**
@@ -21,7 +22,7 @@ public class SsoServiceUserspace {
     /**
      * 企业营业执照号
      */
-    private String bussinessCode;
+    private String businessCode;
 
     /**
      * 企业注册时间
@@ -59,12 +60,12 @@ public class SsoServiceUserspace {
         this.name = name;
     }
 
-    public String getBussinessCode() {
-        return bussinessCode;
+    public String getBusinessCode() {
+        return businessCode;
     }
 
-    public void setBussinessCode(String bussinessCode) {
-        this.bussinessCode = bussinessCode;
+    public void setBusinessCode(String businessCode) {
+        this.businessCode = businessCode;
     }
 
     public String getRegTime() {
@@ -98,4 +99,20 @@ public class SsoServiceUserspace {
     public void setUserUu(List<Integer> userUu) {
         this.userUu = userUu;
     }
+
+    /**
+     * 账号服务实体映射到账户中心
+     * @param ssoServiceUserspace
+     * @return
+     */
+    public SyncUserspace mappingUserspaceInfo(SyncUserspace syncUserspace, SsoServiceUserspace ssoServiceUserspace) {
+        syncUserspace.setSpaceUU(Long.valueOf(ssoServiceUserspace.getEnuu()));
+        syncUserspace.setSpaceName(ssoServiceUserspace.getName());
+        syncUserspace.setBusinessCode(ssoServiceUserspace.getBusinessCode());
+        syncUserspace.setRegisterDate(Timestamp.valueOf(ssoServiceUserspace.getRegTime()));
+        syncUserspace.setAdminUU(Long.valueOf(ssoServiceUserspace.getAdminuu()));
+        syncUserspace.setFromApp(ssoServiceUserspace.getSource());
+        syncUserspace.setValidCode((short) 0);
+        return syncUserspace;
+    }
 }

+ 20 - 1
sso-server/src/main/java/com/uas/sso/sync/entity/SyncUser.java

@@ -1,6 +1,7 @@
 package com.uas.sso.sync.entity;
 
 import com.uas.sso.entity.UserQuestion;
+import com.uas.sso.entity.UserView;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
 
 import javax.persistence.*;
@@ -226,7 +227,7 @@ public class SyncUser implements Serializable {
     /**
      * 密保问题
      */
-    @OneToMany(cascade = {CascadeType.REMOVE})
+    @OneToMany(cascade = {CascadeType.ALL}, fetch=FetchType.EAGER)
     @JoinColumn(name = "useruu", nullable = false)
     private List<SyncUserQuestion> questions;
 
@@ -497,4 +498,22 @@ public class SyncUser implements Serializable {
     public void setQuestions(List<SyncUserQuestion> questions) {
         this.questions = questions;
     }
+
+    public UserView toView() {
+        UserView userView = new UserView();
+        userView.setUserUU(this.getUserUU());
+        userView.setVipName(this.getVipName());
+        userView.setMobile(this.getMobile());
+        userView.setMobileArea(this.getMobileArea());
+        userView.setMobileValidCode(this.getMobileValidCode());
+        userView.setEmail(this.getEmail());
+        userView.setEmailValidCode(this.getEmailValidCode());
+        userView.setRealName(this.getRealName());
+        userView.setIdCard(this.getIdCard());
+        userView.setIdentityValidCode(this.getIdentityValidCode());
+        userView.setLock(this.getLock());
+        userView.setImId(this.getImId());
+        userView.setPassword(this.getPassword());
+        return userView;
+    }
 }

+ 67 - 0
sso-server/src/main/java/com/uas/sso/sync/entity/SyncUserspace.java

@@ -1,7 +1,11 @@
 package com.uas.sso.sync.entity;
 
+import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.sso.entity.App;
 import com.uas.sso.entity.Relation;
 import com.uas.sso.entity.User;
+import com.uas.sso.entity.UserSpaceView;
+import org.codehaus.jackson.annotate.JsonIgnore;
 import org.hibernate.annotations.Cache;
 import org.hibernate.annotations.CacheConcurrencyStrategy;
 
@@ -10,6 +14,7 @@ import java.sql.Timestamp;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * 企业实体
@@ -64,6 +69,13 @@ public class SyncUserspace {
     @Column(name = "adminuu")
     private Long adminUU;
 
+    /**
+     * 管理员
+     */
+    @ManyToOne
+    @JoinColumn(name = "adminuu", insertable=false, updatable=false)
+    private SyncUser admin;
+
     /**
      * 营业执照号
      */
@@ -242,6 +254,25 @@ public class SyncUserspace {
             inverseJoinColumns = {@JoinColumn(name="user_uu", referencedColumnName="useruu")})
     private List<SyncUser> users;
 
+    /**
+     * 企业开通的应用
+     */
+    @ManyToMany(fetch = FetchType.LAZY)
+    @JoinTable(name = "sso$app_userspace",
+            joinColumns = {@JoinColumn(name="space_uu", referencedColumnName="spaceuu")},
+            inverseJoinColumns = {@JoinColumn(name="app_uid", referencedColumnName="uid_")})
+    private List<App> apps;
+
+    @JsonIgnore
+    @JSONField(serialize = false)
+    public List<App> getApps() {
+        return apps;
+    }
+
+    public void setApps(List<App> apps) {
+        this.apps = apps;
+    }
+
     public Long getSpaceUU() {
         return spaceUU;
     }
@@ -525,4 +556,40 @@ public class SyncUserspace {
     public void setUsers(List<SyncUser> users) {
         this.users = users;
     }
+
+    public SyncUser getAdmin() {
+        return admin;
+    }
+
+    public void setAdmin(SyncUser admin) {
+        this.admin = admin;
+    }
+
+    /**
+     * 将企业信息变成视图
+     * @return
+     */
+    public UserSpaceView toView() {
+        UserSpaceView userSpaceView = new UserSpaceView();
+        userSpaceView.setSpaceUU(this.getSpaceUU());
+        userSpaceView.setSpaceName(this.getSpaceName());
+        userSpaceView.setCorporation(this.getCorporation());
+        userSpaceView.setRegisterDate(Optional.ofNullable(registerDate).map(Timestamp::getTime).orElse(null));
+        userSpaceView.setAdmin(this.getAdmin().toView());
+        userSpaceView.setAdminUU(this.getAdminUU());
+        userSpaceView.setBusinessCode(this.getBusinessCode());
+        userSpaceView.setBusinessCodeImage(this.getBusinessCodeImage());
+        userSpaceView.setRegAddress(this.getRegAddress());
+        userSpaceView.setValidCode(this.getValidCode());
+        userSpaceView.setLogoImage(this.getLogoImage());
+        userSpaceView.setTelephone(this.getTelephone());
+        userSpaceView.setProfession(this.getProfession());
+        userSpaceView.setTags(this.getTags());
+        userSpaceView.setInviteSpaceUU(this.getInviteSpaceUU());
+        userSpaceView.setInviteUserUU(this.getInviteUserUU());
+        userSpaceView.setSource(this.getSource());
+        userSpaceView.setArea(this.getArea());
+        userSpaceView.setAccessSecret(this.getAccessSecret());
+        return userSpaceView;
+    }
 }

+ 1 - 1
sso-server/src/main/java/com/uas/sso/sync/service/SyncUserspaceService.java

@@ -41,7 +41,7 @@ public interface SyncUserspaceService {
      * @param ssoServiceUserspace
      * @param isUpdate
      */
-    void syncUserspace(SsoServiceUserspace ssoServiceUserspace, boolean isUpdate);
+    void syncUserspace(SsoServiceUserspace ssoServiceUserspace, boolean isUpdate) throws Exception;
 
     /**
      * 发送企业信息到账号服务

+ 7 - 2
sso-server/src/main/java/com/uas/sso/sync/service/impl/SyncSsoServiceImpl.java

@@ -75,9 +75,12 @@ public class SyncSsoServiceImpl implements SyncSsoService {
 
     @Override
     public void sendUserLoginStateToSso(Long spaceUU, Long userUU, HttpServletResponse response, Integer maxAge) {
-        if (spaceUU == null || userUU == null) {
+        if (userUU == null) {
             throw new RuntimeException("用户信息不能为空");
         }
+        if (spaceUU == null) {
+            spaceUU = 0L;
+        }
         AccountCenterLoginState accountCenterLoginState = new AccountCenterLoginState();
         accountCenterLoginState.setEnuu(spaceUU.intValue());
         accountCenterLoginState.setUu(userUU.intValue());
@@ -88,7 +91,9 @@ public class SyncSsoServiceImpl implements SyncSsoService {
         Cookie tokenCookie = new Cookie("token", token);
         tokenCookie.setPath("/");
         tokenCookie.setDomain(SSOConfig.getInstance().getCookieDomain());
-        tokenCookie.setMaxAge(maxAge);
+        if (maxAge != null) {
+            tokenCookie.setMaxAge(maxAge);
+        }
         response.addCookie(tokenCookie);
         try {
             rabbitSendService.sendMessage("CTS", userUU + "", AppIdConstant.ACCOUNT_SERVICE, MqBizTypeConstant.CTS_LOGIN, userUU + "", JSON.toJSONString(accountCenterLoginState));

+ 59 - 40
sso-server/src/main/java/com/uas/sso/sync/service/impl/SyncUserServiceImpl.java

@@ -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());
+                    }
+                }
+            });
+        }
     }
 }

+ 78 - 20
sso-server/src/main/java/com/uas/sso/sync/service/impl/SyncUserspaceServiceImpl.java

@@ -1,10 +1,18 @@
 package com.uas.sso.sync.service.impl;
 
-import com.uas.sso.entity.PageInfo;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.sso.common.util.HttpUtil;
+import com.uas.sso.entity.*;
+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.SyncUserspaceDao;
 import com.uas.sso.sync.entity.*;
 import com.uas.sso.sync.service.SyncSsoService;
+import com.uas.sso.sync.service.SyncUserService;
 import com.uas.sso.sync.service.SyncUserspaceService;
 import com.uas.sso.util.CollectionUtils;
 import com.usoft.mq.utils.RabbitSendService;
@@ -17,13 +25,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;
 
 /**
  * 企业业务接口实现类
@@ -37,6 +47,9 @@ public class SyncUserspaceServiceImpl implements SyncUserspaceService {
     @Autowired
     private SyncUserspaceDao syncUserspaceDao;
 
+    @Autowired
+    private SyncUserService syncUserService;
+
     @Autowired
     private SyncSsoService syncSsoService;
 
@@ -46,7 +59,13 @@ public class SyncUserspaceServiceImpl implements SyncUserspaceService {
     @Autowired
     private RabbitSendService rabbitSendService;
 
-    private final static Logger LOGGER = LoggerFactory.getLogger(SyncUserspaceServiceImpl.class);
+    @Autowired
+    private AppService appService;
+
+    @Autowired
+    private ExecutorService executorService;
+
+    private SyncBufferedLogger syncLogger = LoggerManager.getLogger(SyncBufferedLogger.class);
 
     @Override
     public Page<SyncUserspace> getSyncUserSpacePageInfo(int pageSize, int pageNumber, Long timestamp) {
@@ -87,22 +106,40 @@ public class SyncUserspaceServiceImpl implements SyncUserspaceService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void syncUserspace(SsoServiceUserspace ssoServiceUserspace, boolean isUpdate) {
+    public void syncUserspace(SsoServiceUserspace ssoServiceUserspace, boolean isUpdate) throws Exception {
         // 查询企业信息
         SyncUserspace syncUserspace = syncUserspaceDao.findOne(Long.valueOf(ssoServiceUserspace.getEnuu()));
-        syncUserspace = mappingUserspaceInfo(syncUserspace, ssoServiceUserspace);
+        if(syncUserspace == null) {
+            syncUserspace = new SyncUserspace();
+        }
+        syncUserspace = ssoServiceUserspace.mappingUserspaceInfo(syncUserspace, ssoServiceUserspace);
+
         List<Integer> userUu = ssoServiceUserspace.getUserUu();
         if (!CollectionUtils.isEmpty(userUu)) {
             syncUserspace.setUsers(null);
         }
+
+        List<SyncUser> syncUsers = new ArrayList<>();
+        SyncUser adminUser = null;
         for (Integer uu : userUu) {
             SyncUser syncUser = syncUserDao.findOne(Long.valueOf(uu));
             if (syncUser == null) {
-                throw new RuntimeException("uu:" + uu + ",账户中心不存在该用户");
+                syncUser = new SyncUser();
+                SsoServiceUser ssoServiceUser = syncSsoService.getSsoServiceUser(uu);
+                syncUser = ssoServiceUser.mappingUserInfo(ssoServiceUser, syncUser);
+                syncUser = syncUserDao.save(syncUser);
+            }
+            if (uu.equals(ssoServiceUserspace.getAdminuu())) {
+                adminUser = syncUser;
             }
-            syncUserspace.getUsers().add(syncUser);
+            syncUsers.add(syncUser);
         }
-        syncUserspaceDao.save(syncUserspace);
+        List<App> apps = appService.findDefaultUseApp();
+        syncUserspace.setApps(apps);
+        syncUserspace.setUsers(syncUsers);
+        syncUserspace.setAdmin(adminUser);
+        syncUserspace = syncUserspaceDao.save(syncUserspace);
+        syncUserSpaceInfo(syncUserspace, apps);
     }
 
     /**
@@ -122,18 +159,39 @@ public class SyncUserspaceServiceImpl implements SyncUserspaceService {
     }
 
     /**
-     * 账号服务实体映射到账户中心
-     * @param ssoServiceUserspace
-     * @return
+     * 企业信息同步
      */
-    private SyncUserspace mappingUserspaceInfo(SyncUserspace syncUserspace, SsoServiceUserspace ssoServiceUserspace) {
-        syncUserspace.setSpaceUU(Long.valueOf(ssoServiceUserspace.getEnuu()));
-        syncUserspace.setSpaceName(ssoServiceUserspace.getName());
-        syncUserspace.setBusinessCode(ssoServiceUserspace.getBussinessCode());
-        syncUserspace.setRegisterDate(Timestamp.valueOf(ssoServiceUserspace.getRegTime()));
-        syncUserspace.setAdminUU(Long.valueOf(ssoServiceUserspace.getAdminuu()));
-        syncUserspace.setFromApp(ssoServiceUserspace.getSource());
-        syncUserspace.setValidCode((short) 0);
-        return syncUserspace;
+    private void syncUserSpaceInfo(SyncUserspace syncUserspace, List<App> apps) {
+        UserSpaceView userSpaceView = syncUserspace.toView();
+        final UserView admin = userSpaceView.getAdmin();
+        userSpaceView.setAdminUU(userSpaceView.getAdmin().getUserUU());
+        userSpaceView.setAdmin(null);
+        JSONObject formData = JSON.parseObject(JSON.toJSONString(userSpaceView));
+        formData.putAll(JSON.parseObject(JSON.toJSONString(admin)));
+        String msg = "账号服务数据同步";
+        for (final App app : apps) {
+            executorService.execute(new Runnable() {
+                @Override
+                public void run() {
+                    String url = app.getBackSpaceUrl();
+                    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());
+                    }
+                }
+            });
+        }
     }
+
 }

+ 0 - 11
sso-server/src/main/resources/config/application-dev.properties

@@ -31,14 +31,3 @@ zk.url=zookeeper://10.10.100.11:2181
 sync.cts.secret.key = uu7gz6baXzcVYnIdz6gQLQEZ61GQncghrdtYgiMd
 sync.stc.secret.key = J5jL6X5hdc6FpzOYhxPIzqXfFvmE6D8JWYRCBW7kjK4=
 sso.service.url = https://ssorest.uuzcc.cn
-
-#RabbitMq ÅäÖÃ
-spring.rabbitmq.virtual-host=account
-spring.rabbitmq.host=rabbitmq.uuzcc.cn
-spring.rabbitmq.port=5672
-spring.rabbitmq.username=account_platform
-spring.rabbitmq.password=platform8888
-spring.rabbitmq.publisher-confirms=true
-spring.rabbitmq.publisher-returns=true
-spring.rabbitmq.listener.simple.acknowledge-mode=manual
-spring.rabbitmq.requested-heartbeat=30

+ 11 - 0
sso-server/src/main/resources/config/application-ptest.properties

@@ -31,3 +31,14 @@ zk.url=zookeeper://10.10.100.11:2181
 sync.cts.secret.key = uu7gz6baXzcVYnIdz6gQLQEZ61GQncghrdtYgiMd
 sync.stc.secret.key = J5jL6X5hdc6FpzOYhxPIzqXfFvmE6D8JWYRCBW7kjK4=
 sso.service.url = https://ssorest.uuzcc.cn
+
+#RabbitMq ÅäÖÃ
+spring.rabbitmq.virtual-host=account
+spring.rabbitmq.host=rabbitmq.uuzcc.cn
+spring.rabbitmq.port=5672
+spring.rabbitmq.username=account_platform
+spring.rabbitmq.password=platform8888
+spring.rabbitmq.publisher-confirms=true
+spring.rabbitmq.publisher-returns=true
+spring.rabbitmq.listener.simple.acknowledge-mode=manual
+spring.rabbitmq.requested-heartbeat=30