|
@@ -1,12 +1,15 @@
|
|
|
package com.mooctest.crowd.site.anticorruption.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.mooctest.crowd.domain.domainobject.Role;
|
|
|
import com.mooctest.crowd.domain.domainobject.User;
|
|
|
+import com.mooctest.crowd.domain.exception.UserNotExistException;
|
|
|
import com.mooctest.crowd.domain.factory.UserFactory;
|
|
|
import com.mooctest.crowd.domain.repository.UserRepo;
|
|
|
import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
|
|
|
import com.mooctest.crowd.site.anticorruption.impl.data.UserInfo;
|
|
|
import com.mooctest.crowd.site.util.EncryptionUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
@@ -16,7 +19,9 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -24,6 +29,7 @@ import java.util.Map;
|
|
|
* @Email: 171256175@qq.com
|
|
|
* @date 2019-08-08 23:40
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
public class UserAntiCorruptionImpl implements UserAntiCorruption {
|
|
|
@Autowired
|
|
@@ -56,4 +62,27 @@ public class UserAntiCorruptionImpl implements UserAntiCorruption {
|
|
|
user.setPassword(userInfo.getPassword());
|
|
|
return user;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public User getUserInfo(Long userId) {
|
|
|
+ UserInfo userInfo = restTemplate.getForEntity(userServiceUrl+"/api/user/"+userId, UserInfo.class).getBody();
|
|
|
+ if (userInfo == null)
|
|
|
+ throw new UserNotExistException();
|
|
|
+ log.info("userInfo: " + userInfo.toString());
|
|
|
+ try{
|
|
|
+ //将用户中心的用户中心的用户数据对本系统内同步
|
|
|
+ User newUser = userInfo.toUser();
|
|
|
+ User oldUser = userRepo.getByID(userId);
|
|
|
+ newUser.setRoleList(oldUser.getRoleList());
|
|
|
+ newUser.setGender(oldUser.getGender());
|
|
|
+ userRepo.saveUser(newUser);
|
|
|
+ }catch (UserNotExistException e){ //本站不存在该用户,是未同步信息的新用户,初始化角色
|
|
|
+ User user = userInfo.toUser();
|
|
|
+ List<Role> roles = new ArrayList<>();
|
|
|
+ roles.add(userRepo.getRole("generalUser"));
|
|
|
+ user.setRoleList(roles);
|
|
|
+ userRepo.saveUser(user);
|
|
|
+ }
|
|
|
+ return userRepo.getByID(userId);
|
|
|
+ }
|
|
|
}
|