Showing
1 changed file
with
12 additions
and
6 deletions
... | ... | @@ -14,20 +14,23 @@ import org.thingsboard.server.common.data.id.UserId; |
14 | 14 | import org.thingsboard.server.common.data.security.UserCredentials; |
15 | 15 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
17 | +import org.thingsboard.server.common.data.yunteng.dto.UserDetailsDTO; | |
17 | 18 | import org.thingsboard.server.common.data.yunteng.dto.YtThirdUserDTO; |
18 | 19 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
19 | 20 | import org.thingsboard.server.common.data.yunteng.enums.ThirdPlatformEnum; |
21 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | |
20 | 22 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
21 | 23 | import org.thingsboard.server.controller.BaseController; |
22 | 24 | import org.thingsboard.server.dao.yunteng.entities.YtThirdUserEntity; |
23 | 25 | import org.thingsboard.server.dao.yunteng.service.YtThirdPlatformService; |
26 | +import org.thingsboard.server.dao.yunteng.service.YtUserService; | |
24 | 27 | import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; |
25 | 28 | import org.thingsboard.server.service.security.auth.yunteng.YtLoginResponse; |
26 | -import org.thingsboard.server.service.security.model.JwtTokenPair; | |
27 | 29 | import org.thingsboard.server.service.security.model.SecurityUser; |
28 | 30 | import org.thingsboard.server.service.security.model.UserPrincipal; |
29 | 31 | import org.thingsboard.server.service.security.model.token.JwtTokenFactory; |
30 | 32 | |
33 | +import java.util.List; | |
31 | 34 | import java.util.UUID; |
32 | 35 | |
33 | 36 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
... | ... | @@ -44,6 +47,7 @@ public class YtThirdPlatformController extends BaseController { |
44 | 47 | private final JwtTokenFactory tokenFactory; |
45 | 48 | private final RefreshTokenRepository refreshTokenRepository; |
46 | 49 | private final YtThirdPlatformService thirdService; |
50 | + private final YtUserService ytUserService; | |
47 | 51 | |
48 | 52 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
49 | 53 | @ApiOperation("分页") |
... | ... | @@ -66,14 +70,14 @@ public class YtThirdPlatformController extends BaseController { |
66 | 70 | public YtLoginResponse saveOrUpdateAlarmProfile( |
67 | 71 | @Validated @RequestBody YtThirdUserDTO dto) throws ThingsboardException { |
68 | 72 | UserDTO userDto = thirdService.bindUser(dto); |
69 | - return buildJwtToken(userDto,dto.getThirdUserId()); | |
73 | + return buildJwtToken(userDto, dto.getThirdUserId()); | |
70 | 74 | } |
71 | 75 | |
72 | 76 | @DeleteMapping |
73 | 77 | @ApiOperation("解绑") |
74 | 78 | public boolean deleteAlarmProfile(@Validated(DeleteGroup.class) @RequestBody YtThirdUserDTO dto) |
75 | 79 | throws ThingsboardException { |
76 | - return thirdService.unbindUser(getCurrentUser().getCurrentTenantId(), dto.getAppUserId(),dto.getThirdUserId()); | |
80 | + return thirdService.unbindUser(getCurrentUser().getCurrentTenantId(), dto.getAppUserId(), dto.getThirdUserId()); | |
77 | 81 | } |
78 | 82 | |
79 | 83 | @GetMapping("login/{loginCode}") |
... | ... | @@ -82,19 +86,21 @@ public class YtThirdPlatformController extends BaseController { |
82 | 86 | throws ThingsboardException { |
83 | 87 | String thirdUserId = thirdService.thirdLogin(loginCode); |
84 | 88 | UserDTO userDto = thirdService.login(thirdUserId); |
85 | - if(userDto == null){ | |
89 | + if (userDto == null) { | |
86 | 90 | return new YtLoginResponse().setThirdUserId(thirdUserId); |
87 | 91 | } |
88 | - return buildJwtToken(userDto,thirdUserId); | |
92 | + return buildJwtToken(userDto, thirdUserId); | |
89 | 93 | } |
90 | 94 | |
91 | 95 | @NotNull |
92 | - private YtLoginResponse buildJwtToken(UserDTO userDto,String thirdUserId) { | |
96 | + private YtLoginResponse buildJwtToken(UserDTO userDto, String thirdUserId) { | |
93 | 97 | String accessToken = ""; |
94 | 98 | String refreshToken = ""; |
95 | 99 | if (userDto != null && StringUtils.isNotEmpty(userDto.getTbUser())) { |
96 | 100 | UserId userId = new UserId(UUID.fromString(userDto.getTbUser())); |
97 | 101 | User user = userService.findUserById(null, userId); |
102 | + List<UserDetailsDTO> userDetailsDTOS = ytUserService.findUserDetailsByUsername(userDto.getUsername(),userDto.getTenantId()); | |
103 | + user.setUserDetailsDTO(userDetailsDTOS.get(0)); | |
98 | 104 | UserCredentials credentials = userService.findUserCredentialsByUserId(user.getTenantId(), userId); |
99 | 105 | String email = user.getEmail(); |
100 | 106 | int emailIndex = email.indexOf("@"); | ... | ... |