diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index 2d5d665e..f2adef3e 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -2,6 +2,7 @@ package com.chint.application.out; import com.chint.application.commands.OrderCreateCommand; +import com.chint.application.services.login.strategy.PailaLoginStrategy; import com.chint.domain.aggregates.user.User; import com.chint.domain.exceptions.OrderException; import com.chint.domain.service.SystemDomainService; @@ -16,6 +17,7 @@ import com.chint.infrastructure.util.Digest; import com.chint.infrastructure.util.Result; import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest; import com.chint.interfaces.rest.ly.LYUserRequest; +import com.chint.interfaces.rest.ly.dto.login.LoginParam; import com.chint.interfaces.rest.user.UserHttpRequest; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -43,6 +45,9 @@ public class LoginController { @Autowired private SystemDomainService systemDomainService; + @Autowired + private PailaLoginStrategy pailaLoginStrategy; + @ApiOperation("财务共享登录") @Transactional @GetMapping("/login") @@ -98,9 +103,11 @@ public class LoginController { @ApiOperation("商旅平台单点") @Transactional @PostMapping("/login/sso") - public Result loginSSO(){ - UserLoginParam userLoginParam = new UserLoginParam(); - userLoginParam.setSfno("170717012"); + public Result loginSSO(@RequestBody UserLoginParam userLoginParam){ + + String employeeNo = pailaLoginStrategy.login(userLoginParam.getCode()); + + userLoginParam.setSfno(employeeNo); UserLoginResult userLoginResult = authenticateService .authenticateEmployeeNo(userLoginParam); diff --git a/src/main/java/com/chint/application/services/login/LocalLoginStrategy.java b/src/main/java/com/chint/application/services/login/LocalLoginStrategy.java index a77d5507..2ec2ea02 100644 --- a/src/main/java/com/chint/application/services/login/LocalLoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/LocalLoginStrategy.java @@ -15,7 +15,7 @@ public class LocalLoginStrategy implements LoginStrategy { } @Override - public User getUserInfo(String accessToken) { + public String getUserInfo(String accessToken) { return null; } } diff --git a/src/main/java/com/chint/application/services/login/LoginStrategy.java b/src/main/java/com/chint/application/services/login/LoginStrategy.java index 1f47fdd5..c7855ea4 100644 --- a/src/main/java/com/chint/application/services/login/LoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/LoginStrategy.java @@ -20,14 +20,14 @@ import java.util.regex.Pattern; public interface LoginStrategy { Logger log = LoggerFactory.getLogger("UserService"); - default User login(String code) { + default String login(String code) { Optional accessToken = getAccessToken(code); return getUserInfo(accessToken.orElseThrow(()-> new AuthException("Failed to obtain access token"))); } Optional getAccessToken(String code); - User getUserInfo(String accessToken); + String getUserInfo(String accessToken); static Optional getAccessTokenMethod(HttpRequestBase request, String tokenName) { String responseBody = null; diff --git a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java index 40e39eee..0b883e87 100644 --- a/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java +++ b/src/main/java/com/chint/application/services/login/strategy/PailaLoginStrategy.java @@ -3,8 +3,7 @@ package com.chint.application.services.login.strategy; import com.alibaba.fastjson.JSON; import com.chint.application.dtos.UserDTO; import com.chint.application.services.login.LoginStrategy; -import com.chint.domain.aggregates.user.User; -import com.chint.domain.exceptions.AuthException; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.factoriy.user.UserFactory; import com.chint.domain.repository.UserRepository; import com.chint.interfaces.rest.user.UserHttpRequest; @@ -71,7 +70,7 @@ public class PailaLoginStrategy implements LoginStrategy { } @Override - public User getUserInfo(String accessToken) { + public String getUserInfo(String accessToken) { List userInfoParams = Collections.singletonList( @@ -89,18 +88,10 @@ public class PailaLoginStrategy implements LoginStrategy { log.error(e.getMessage()); } UserDTO userDTO = JSON.parseObject(userInfoResBody, UserDTO.class); - User user; - if (userDTO != null) { - user = userRepository.findByUserEmployeeNo(userDTO.getUid()); - if (user == null) { - user = userFactory.create(userDTO.getUid()); - userHttpRequest.loadUserInfo(user); - userRepository.save(user); - } - } else { - throw new AuthException(NOT_FOUND); + if (userDTO == null) { + throw new NotFoundException(NOT_FOUND); } - return user; + return userDTO.getUid(); } private HttpGet getRequest(String path, List parameters) { diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java index 283f19d2..89da197c 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -41,7 +41,7 @@ public class AuthenticateServiceImpl implements AuthenticateService { @Override public UserLoginResult authenticateEmployeeNo(UserLoginParam userLoginParam) { User user = userRepository.findByUserEmployeeNo(userLoginParam.getSfno()); - if (user != null) { + if (user != null) { // 部分数据需要通过查询外部的http来获取 BaseContext.setCurrentUser(user); user.setCompanyCode(userLoginParam.getCompanyCode()); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index f880cb16..05d230ab 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -121,7 +121,7 @@ class RouteApplicationTests { // @Test void ssoLogin(){ - User login = pailaLoginStrategy.login("OC-5909-zRqrWjZGNThNXJiAV1kA7dPXTojGzVxK3nE"); + String login = pailaLoginStrategy.login("OC-5909-zRqrWjZGNThNXJiAV1kA7dPXTojGzVxK3nE"); System.out.println(login); } }