Commit 3478cd7ed7e40f2d0349369b7a6b92cf891ea9b7
1 parent
03235e57
fix: [DEFECT-799] ptAdmin allow manager tenant
Showing
7 changed files
with
188 additions
and
107 deletions
@@ -53,14 +53,15 @@ public class TkAdminController extends BaseController { | @@ -53,14 +53,15 @@ public class TkAdminController extends BaseController { | ||
53 | 53 | ||
54 | private final TkTenantService tkTenantService; | 54 | private final TkTenantService tkTenantService; |
55 | private final MenuService menuService; | 55 | private final MenuService menuService; |
56 | - private final TkUserService userService; | 56 | + private final TkUserService tkUserService; |
57 | private final TenantService tenantService; | 57 | private final TenantService tenantService; |
58 | private final InstallScripts installScripts; | 58 | private final InstallScripts installScripts; |
59 | private final UserService tbUserService; | 59 | private final UserService tbUserService; |
60 | 60 | ||
61 | @PostMapping("/tenant") | 61 | @PostMapping("/tenant") |
62 | @Deprecated | 62 | @Deprecated |
63 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:post'})") | 63 | + @PreAuthorize( |
64 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:post'})") | ||
64 | public ResponseEntity<TenantDTO> saveTenant(@RequestBody TenantReqDTO tenantReqDTO) { | 65 | public ResponseEntity<TenantDTO> saveTenant(@RequestBody TenantReqDTO tenantReqDTO) { |
65 | TenantDTO newTenant = tkTenantService.createNewTenant(tenantReqDTO); | 66 | TenantDTO newTenant = tkTenantService.createNewTenant(tenantReqDTO); |
66 | URI location = | 67 | URI location = |
@@ -92,7 +93,8 @@ public class TkAdminController extends BaseController { | @@ -92,7 +93,8 @@ public class TkAdminController extends BaseController { | ||
92 | } | 93 | } |
93 | 94 | ||
94 | @PutMapping("/tenant") | 95 | @PutMapping("/tenant") |
95 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:update'})") | 96 | + @PreAuthorize( |
97 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:update'})") | ||
96 | public TenantDTO updateTenant(@RequestBody TenantDTO tenantDTO) { | 98 | public TenantDTO updateTenant(@RequestBody TenantDTO tenantDTO) { |
97 | Assert.notNull(tenantDTO, "tenant cannot be null"); | 99 | Assert.notNull(tenantDTO, "tenant cannot be null"); |
98 | Assert.notNull(tenantDTO.getId(), "tenant id cannot be null when update"); | 100 | Assert.notNull(tenantDTO.getId(), "tenant id cannot be null when update"); |
@@ -106,7 +108,8 @@ public class TkAdminController extends BaseController { | @@ -106,7 +108,8 @@ public class TkAdminController extends BaseController { | ||
106 | } | 108 | } |
107 | 109 | ||
108 | @DeleteMapping("/tenant") | 110 | @DeleteMapping("/tenant") |
109 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:delete'})") | 111 | + @PreAuthorize( |
112 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:delete'})") | ||
110 | public void deleteTenant(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) | 113 | public void deleteTenant(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) |
111 | throws ThingsboardException { | 114 | throws ThingsboardException { |
112 | 115 | ||
@@ -130,20 +133,20 @@ public class TkAdminController extends BaseController { | @@ -130,20 +133,20 @@ public class TkAdminController extends BaseController { | ||
130 | } | 133 | } |
131 | 134 | ||
132 | @DeleteMapping("/user/deleteTenantAdmin") | 135 | @DeleteMapping("/user/deleteTenantAdmin") |
133 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:user:deleteTenantAdmin:delete'})") | 136 | + @PreAuthorize( |
137 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:user:deleteTenantAdmin:delete'})") | ||
134 | public ResponseEntity<Boolean> deleteTenantAdmin( | 138 | public ResponseEntity<Boolean> deleteTenantAdmin( |
135 | @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | 139 | @Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { |
136 | for (String strUserId : deleteDTO.getIds()) { | 140 | for (String strUserId : deleteDTO.getIds()) { |
137 | - UserDTO userDTO = userService.findUserInfoById(strUserId); | 141 | + UserDTO userDTO = tkUserService.findUserInfoById(strUserId); |
138 | if (null != userDTO && StringUtils.isNotBlank(userDTO.getTbUser())) { | 142 | if (null != userDTO && StringUtils.isNotBlank(userDTO.getTbUser())) { |
139 | - deleteTenantAdmin(userDTO.getTbUser()); | 143 | + deleteTenantAdmin(userDTO.getTbUser(), getCurrentUser().isPtAdmin()); |
140 | } | 144 | } |
141 | } | 145 | } |
146 | + boolean allowDelete = getCurrentUser().isPtSysadmin() || getCurrentUser().isPtAdmin(); | ||
142 | boolean result = | 147 | boolean result = |
143 | - userService.deleteUser( | ||
144 | - deleteDTO.getIds(), | ||
145 | - getCurrentUser().isPtSysadmin(), | ||
146 | - getCurrentUser().getCurrentTenantId()); | 148 | + tkUserService.deleteUser( |
149 | + deleteDTO.getIds(), allowDelete, getCurrentUser().getCurrentTenantId()); | ||
147 | return ResponseEntity.ok(result); | 150 | return ResponseEntity.ok(result); |
148 | } | 151 | } |
149 | 152 | ||
@@ -153,7 +156,8 @@ public class TkAdminController extends BaseController { | @@ -153,7 +156,8 @@ public class TkAdminController extends BaseController { | ||
153 | } | 156 | } |
154 | 157 | ||
155 | @PostMapping("/tenant/adminUser") | 158 | @PostMapping("/tenant/adminUser") |
156 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:adminUser:post'})") | 159 | + @PreAuthorize( |
160 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:adminUser:post'})") | ||
157 | public ResponseEntity<UserDTO> createTenantAdmin( | 161 | public ResponseEntity<UserDTO> createTenantAdmin( |
158 | @RequestParam(value = "sendEmail", required = false, defaultValue = "false") | 162 | @RequestParam(value = "sendEmail", required = false, defaultValue = "false") |
159 | boolean sendEmail, | 163 | boolean sendEmail, |
@@ -161,14 +165,14 @@ public class TkAdminController extends BaseController { | @@ -161,14 +165,14 @@ public class TkAdminController extends BaseController { | ||
161 | @RequestBody UserDTO userDTO) | 165 | @RequestBody UserDTO userDTO) |
162 | throws ThingsboardException { | 166 | throws ThingsboardException { |
163 | UserDTO newUserDTO = | 167 | UserDTO newUserDTO = |
164 | - userService.saveAccount( | 168 | + tkUserService.saveAccount( |
165 | userDTO, | 169 | userDTO, |
166 | sendEmail, | 170 | sendEmail, |
167 | sendMsg, | 171 | sendMsg, |
168 | getCurrentUser().isPtSysadmin(), | 172 | getCurrentUser().isPtSysadmin(), |
169 | getCurrentUser().getCurrentTenantId()); | 173 | getCurrentUser().getCurrentTenantId()); |
170 | Optional<UserDTO> optional = | 174 | Optional<UserDTO> optional = |
171 | - userService.getUser( | 175 | + tkUserService.getUser( |
172 | newUserDTO.getId(), | 176 | newUserDTO.getId(), |
173 | getCurrentUser().isPtSysadmin(), | 177 | getCurrentUser().isPtSysadmin(), |
174 | getCurrentUser().getCurrentTenantId()); | 178 | getCurrentUser().getCurrentTenantId()); |
@@ -190,7 +194,8 @@ public class TkAdminController extends BaseController { | @@ -190,7 +194,8 @@ public class TkAdminController extends BaseController { | ||
190 | getCurrentUser().getCurrentTenantId(), | 194 | getCurrentUser().getCurrentTenantId(), |
191 | getCurrentUser().getCurrentUserId(), | 195 | getCurrentUser().getCurrentUserId(), |
192 | getCurrentUser().isPtSysadmin(), | 196 | getCurrentUser().isPtSysadmin(), |
193 | - getCurrentUser().isPtTenantAdmin(),needButton)); | 197 | + getCurrentUser().isPtTenantAdmin(), |
198 | + needButton)); | ||
194 | } | 199 | } |
195 | 200 | ||
196 | @PutMapping("/menu/assign/{tenantId}") | 201 | @PutMapping("/menu/assign/{tenantId}") |
@@ -208,10 +213,15 @@ public class TkAdminController extends BaseController { | @@ -208,10 +213,15 @@ public class TkAdminController extends BaseController { | ||
208 | return tkTenantService.updateOrCreateTenant(tenantReqDTO); | 213 | return tkTenantService.updateOrCreateTenant(tenantReqDTO); |
209 | } | 214 | } |
210 | 215 | ||
211 | - private void deleteTenantAdmin(String strUserId) throws ThingsboardException { | 216 | + private void deleteTenantAdmin(String strUserId, boolean isPtAdmin) throws ThingsboardException { |
212 | try { | 217 | try { |
213 | UserId currentUserId = new UserId(toUUID(strUserId)); | 218 | UserId currentUserId = new UserId(toUUID(strUserId)); |
214 | - User user = checkUserId(currentUserId, Operation.DELETE); | 219 | + User user; |
220 | + if (isPtAdmin) { | ||
221 | + user = userService.findUserById(getCurrentUser().getTenantId(), currentUserId); | ||
222 | + } else { | ||
223 | + user = checkUserId(currentUserId, Operation.DELETE); | ||
224 | + } | ||
215 | List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), currentUserId); | 225 | List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), currentUserId); |
216 | tbUserService.deleteUser(getTenantId(), currentUserId); | 226 | tbUserService.deleteUser(getTenantId(), currentUserId); |
217 | logEntityAction( | 227 | logEntityAction( |
@@ -29,7 +29,7 @@ public class TkRoleController extends BaseController { | @@ -29,7 +29,7 @@ public class TkRoleController extends BaseController { | ||
29 | private final RoleService roleService; | 29 | private final RoleService roleService; |
30 | 30 | ||
31 | @GetMapping(params = {PAGE_SIZE, PAGE}) | 31 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
32 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN')") | 32 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN','TENANT_ADMIN')") |
33 | public YtPageData<RoleDTO> pageRole( | 33 | public YtPageData<RoleDTO> pageRole( |
34 | @RequestParam(PAGE_SIZE) int pageSize, | 34 | @RequestParam(PAGE_SIZE) int pageSize, |
35 | @RequestParam(PAGE) int page, | 35 | @RequestParam(PAGE) int page, |
@@ -46,13 +46,16 @@ public class TkRoleController extends BaseController { | @@ -46,13 +46,16 @@ public class TkRoleController extends BaseController { | ||
46 | if (status != null) { | 46 | if (status != null) { |
47 | queryMap.put("status", status == 1); | 47 | queryMap.put("status", status == 1); |
48 | } | 48 | } |
49 | + if (getCurrentUser().isPtAdmin()){ | ||
50 | + roleType = RoleEnum.TENANT_ADMIN; | ||
51 | + } | ||
49 | if(roleType !=null){ | 52 | if(roleType !=null){ |
50 | queryMap.put("roleType", roleType.name()); | 53 | queryMap.put("roleType", roleType.name()); |
51 | } | 54 | } |
52 | if (orderType != null) { | 55 | if (orderType != null) { |
53 | queryMap.put(ORDER_TYPE, orderType.name()); | 56 | queryMap.put(ORDER_TYPE, orderType.name()); |
54 | } | 57 | } |
55 | - return roleService.page(getCurrentUser().getCurrentTenantId(),queryMap); | 58 | + return roleService.page(getCurrentUser().getCurrentTenantId(), queryMap); |
56 | } | 59 | } |
57 | 60 | ||
58 | @DeleteMapping | 61 | @DeleteMapping |
@@ -37,7 +37,7 @@ public class TkTenantController extends AbstractUserAccount { | @@ -37,7 +37,7 @@ public class TkTenantController extends AbstractUserAccount { | ||
37 | } | 37 | } |
38 | 38 | ||
39 | @PostMapping("/reset_password/{userId}") | 39 | @PostMapping("/reset_password/{userId}") |
40 | - @PreAuthorize("hasAnyAuthority('SYS_ADMIN')") | 40 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") |
41 | public void resetPassword(@PathVariable("userId") String userId) throws ThingsboardException { | 41 | public void resetPassword(@PathVariable("userId") String userId) throws ThingsboardException { |
42 | //check is tenant account | 42 | //check is tenant account |
43 | UserDTO userDTO = userService.checkAccount(userId,2); | 43 | UserDTO userDTO = userService.checkAccount(userId,2); |
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
8 | import org.springframework.web.bind.annotation.RestController; | 8 | import org.springframework.web.bind.annotation.RestController; |
9 | import org.thingsboard.server.common.data.TenantProfile; | 9 | import org.thingsboard.server.common.data.TenantProfile; |
10 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 10 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | +import org.thingsboard.server.common.data.id.TenantId; | ||
11 | import org.thingsboard.server.common.data.page.PageData; | 12 | import org.thingsboard.server.common.data.page.PageData; |
12 | import org.thingsboard.server.common.data.page.PageLink; | 13 | import org.thingsboard.server.common.data.page.PageLink; |
13 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | 14 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
@@ -16,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | @@ -16,6 +17,7 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
16 | import org.thingsboard.server.controller.BaseController; | 17 | import org.thingsboard.server.controller.BaseController; |
17 | 18 | ||
18 | import java.util.List; | 19 | import java.util.List; |
20 | +import java.util.UUID; | ||
19 | 21 | ||
20 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | 22 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
21 | 23 | ||
@@ -24,7 +26,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | @@ -24,7 +26,7 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. | ||
24 | @RequiredArgsConstructor | 26 | @RequiredArgsConstructor |
25 | public class TkTenantProfilesController extends BaseController { | 27 | public class TkTenantProfilesController extends BaseController { |
26 | 28 | ||
27 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN'},{})") | 29 | + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{})") |
28 | @GetMapping( | 30 | @GetMapping( |
29 | name = "page", | 31 | name = "page", |
30 | params = {PAGE_SIZE, PAGE}) | 32 | params = {PAGE_SIZE, PAGE}) |
@@ -44,8 +46,12 @@ public class TkTenantProfilesController extends BaseController { | @@ -44,8 +46,12 @@ public class TkTenantProfilesController extends BaseController { | ||
44 | textSearch, | 46 | textSearch, |
45 | orderBy, | 47 | orderBy, |
46 | null == orderType ? OrderTypeEnum.DESC.name() : orderType.name()); | 48 | null == orderType ? OrderTypeEnum.DESC.name() : orderType.name()); |
49 | + TenantId tenantId = getTenantId(); | ||
50 | + if(getCurrentUser().isPtAdmin()){ | ||
51 | + tenantId = new TenantId(UUID.fromString(getCurrentUser().getCurrentTenantId())); | ||
52 | + } | ||
47 | PageData<TenantProfile> tenantProfilePageData = | 53 | PageData<TenantProfile> tenantProfilePageData = |
48 | - tenantProfileService.findTenantProfiles(getTenantId(), pageLink); | 54 | + tenantProfileService.findTenantProfiles(tenantId, pageLink); |
49 | List<TenantProfile> targetList = | 55 | List<TenantProfile> targetList = |
50 | ReflectUtils.sourceToTarget(tenantProfilePageData.getData(), TenantProfile.class); | 56 | ReflectUtils.sourceToTarget(tenantProfilePageData.getData(), TenantProfile.class); |
51 | return new YtPageData<>(targetList, tenantProfilePageData.getTotalElements()); | 57 | return new YtPageData<>(targetList, tenantProfilePageData.getTotalElements()); |
@@ -61,15 +61,19 @@ public class TkUserController extends AbstractUserAccount { | @@ -61,15 +61,19 @@ public class TkUserController extends AbstractUserAccount { | ||
61 | 61 | ||
62 | private final TkUserService userService; | 62 | private final TkUserService userService; |
63 | private final AccountProperties accountProperties; | 63 | private final AccountProperties accountProperties; |
64 | - public TkUserController(UserService tbUserService, ApplicationEventPublisher eventPublisher, | ||
65 | - SystemSecurityService systemSecurityService, | ||
66 | - BCryptPasswordEncoder passwordEncoder, | ||
67 | - TkUserService userService, | ||
68 | - AccountProperties accountProperties) { | ||
69 | - super(tbUserService,eventPublisher,systemSecurityService,passwordEncoder); | 64 | + |
65 | + public TkUserController( | ||
66 | + UserService tbUserService, | ||
67 | + ApplicationEventPublisher eventPublisher, | ||
68 | + SystemSecurityService systemSecurityService, | ||
69 | + BCryptPasswordEncoder passwordEncoder, | ||
70 | + TkUserService userService, | ||
71 | + AccountProperties accountProperties) { | ||
72 | + super(tbUserService, eventPublisher, systemSecurityService, passwordEncoder); | ||
70 | this.userService = userService; | 73 | this.userService = userService; |
71 | this.accountProperties = accountProperties; | 74 | this.accountProperties = accountProperties; |
72 | } | 75 | } |
76 | + | ||
73 | @GetMapping("{userId}") | 77 | @GetMapping("{userId}") |
74 | @PreAuthorize("@check.checkPermissions({},{'api:yt:user:get'})") | 78 | @PreAuthorize("@check.checkPermissions({},{'api:yt:user:get'})") |
75 | public ResponseEntity<UserDTO> getUser(@PathVariable("userId") String userId) | 79 | public ResponseEntity<UserDTO> getUser(@PathVariable("userId") String userId) |
@@ -93,11 +97,10 @@ public class TkUserController extends AbstractUserAccount { | @@ -93,11 +97,10 @@ public class TkUserController extends AbstractUserAccount { | ||
93 | @GetMapping( | 97 | @GetMapping( |
94 | path = "page", | 98 | path = "page", |
95 | params = {PAGE_SIZE, PAGE}) | 99 | params = {PAGE_SIZE, PAGE}) |
100 | + @ApiOperation(value = "获取用户分页数据") | ||
96 | public YtPageData<UserDTO> pageUser( | 101 | public YtPageData<UserDTO> pageUser( |
97 | @RequestParam(PAGE_SIZE) int pageSize, | 102 | @RequestParam(PAGE_SIZE) int pageSize, |
98 | @RequestParam(PAGE) int page, | 103 | @RequestParam(PAGE) int page, |
99 | - @RequestParam(value = "realName", required = false) String realName, | ||
100 | - @RequestParam(value = "username", required = false) String username, | ||
101 | @RequestParam(value = "tenantId", required = false) String tenantId, | 104 | @RequestParam(value = "tenantId", required = false) String tenantId, |
102 | @RequestParam(value = "organizationId", required = false) String organizationId, | 105 | @RequestParam(value = "organizationId", required = false) String organizationId, |
103 | @RequestParam(value = "roleType", required = false) RoleEnum roleType, | 106 | @RequestParam(value = "roleType", required = false) RoleEnum roleType, |
@@ -108,8 +111,6 @@ public class TkUserController extends AbstractUserAccount { | @@ -108,8 +111,6 @@ public class TkUserController extends AbstractUserAccount { | ||
108 | queryMap.put(PAGE_SIZE, pageSize); | 111 | queryMap.put(PAGE_SIZE, pageSize); |
109 | queryMap.put(PAGE, page); | 112 | queryMap.put(PAGE, page); |
110 | queryMap.put(ORDER_FILED, orderBy); | 113 | queryMap.put(ORDER_FILED, orderBy); |
111 | - queryMap.put("realName", realName); | ||
112 | - queryMap.put("username", username); | ||
113 | if (null != roleType && roleType.equals(RoleEnum.TENANT_ADMIN)) { | 114 | if (null != roleType && roleType.equals(RoleEnum.TENANT_ADMIN)) { |
114 | queryMap.put("roleType", roleType.name()); | 115 | queryMap.put("roleType", roleType.name()); |
115 | } else { | 116 | } else { |
@@ -127,6 +128,31 @@ public class TkUserController extends AbstractUserAccount { | @@ -127,6 +128,31 @@ public class TkUserController extends AbstractUserAccount { | ||
127 | queryMap, getCurrentUser().isPtSysadmin(), getCurrentUser().isTenantAdmin()); | 128 | queryMap, getCurrentUser().isPtSysadmin(), getCurrentUser().isTenantAdmin()); |
128 | } | 129 | } |
129 | 130 | ||
131 | + @PreAuthorize("hasAnyAuthority('SYS_ADMIN','PLATFORM_ADMIN')") | ||
132 | + @GetMapping( | ||
133 | + path = "/tenant/page", | ||
134 | + params = {PAGE_SIZE, PAGE}) | ||
135 | + @ApiOperation(value = "获取租户管理员分页数据") | ||
136 | + public YtPageData<UserDTO> tenantPage( | ||
137 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
138 | + @RequestParam(PAGE) int page, | ||
139 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
140 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType, | ||
141 | + @RequestParam(TENANT_ID) String tenantId) | ||
142 | + throws ThingsboardException { | ||
143 | + HashMap<String, Object> queryMap = new HashMap<>(); | ||
144 | + queryMap.put(PAGE_SIZE, pageSize); | ||
145 | + queryMap.put(PAGE, page); | ||
146 | + if (orderType != null) { | ||
147 | + queryMap.put(ORDER_TYPE, orderType.name()); | ||
148 | + } | ||
149 | + queryMap.put(ORDER_FILED, orderBy); | ||
150 | + if (StringUtils.isEmpty(tenantId)) { | ||
151 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | ||
152 | + } | ||
153 | + return userService.tenantPage(queryMap, tenantId); | ||
154 | + } | ||
155 | + | ||
130 | @PutMapping | 156 | @PutMapping |
131 | @ApiOperation(value = "修改用户信息") | 157 | @ApiOperation(value = "修改用户信息") |
132 | @PreAuthorize("@check.checkPermissions({},{'api:yt:user:update'})") | 158 | @PreAuthorize("@check.checkPermissions({},{'api:yt:user:update'})") |
@@ -138,12 +164,13 @@ public class TkUserController extends AbstractUserAccount { | @@ -138,12 +164,13 @@ public class TkUserController extends AbstractUserAccount { | ||
138 | 164 | ||
139 | @PutMapping("/center") | 165 | @PutMapping("/center") |
140 | @ApiOperation(value = "修改个人中心") | 166 | @ApiOperation(value = "修改个人中心") |
141 | - public UserInfoDTO updatePersonalCenter(@Validated(UpdateGroup.class) @RequestBody UserDTO userDTO) throws ThingsboardException { | 167 | + public UserInfoDTO updatePersonalCenter( |
168 | + @Validated(UpdateGroup.class) @RequestBody UserDTO userDTO) throws ThingsboardException { | ||
142 | userService.updatePersonalCenter(userDTO); | 169 | userService.updatePersonalCenter(userDTO); |
143 | return userService.me( | 170 | return userService.me( |
144 | - getCurrentUser().getCurrentUserId(), | ||
145 | - getCurrentUser().getCurrentTenantId(), | ||
146 | - getCurrentUser().getRoles()); | 171 | + getCurrentUser().getCurrentUserId(), |
172 | + getCurrentUser().getCurrentTenantId(), | ||
173 | + getCurrentUser().getRoles()); | ||
147 | } | 174 | } |
148 | 175 | ||
149 | @PostMapping | 176 | @PostMapping |
@@ -156,7 +183,7 @@ public class TkUserController extends AbstractUserAccount { | @@ -156,7 +183,7 @@ public class TkUserController extends AbstractUserAccount { | ||
156 | @Validated({AddGroup.class}) @RequestBody UserDTO userDTO) | 183 | @Validated({AddGroup.class}) @RequestBody UserDTO userDTO) |
157 | throws ThingsboardException { | 184 | throws ThingsboardException { |
158 | 185 | ||
159 | - //检查用户手机号、邮箱 | 186 | + // 检查用户手机号、邮箱 |
160 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); | 187 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); |
161 | // 如果当前用户是租户管理员,则代表创建的用户为CUSTOMER_USER,则需要调用TB,否则为本平台的管理员不需要调用TB | 188 | // 如果当前用户是租户管理员,则代表创建的用户为CUSTOMER_USER,则需要调用TB,否则为本平台的管理员不需要调用TB |
162 | boolean isTenantAdminOperator = getCurrentUser().isPtTenantAdmin(); | 189 | boolean isTenantAdminOperator = getCurrentUser().isPtTenantAdmin(); |
@@ -169,7 +196,7 @@ public class TkUserController extends AbstractUserAccount { | @@ -169,7 +196,7 @@ public class TkUserController extends AbstractUserAccount { | ||
169 | createTBUser( | 196 | createTBUser( |
170 | tbUser, userDTO, customer.getTenantId(), customer.getId(), Authority.CUSTOMER_USER); | 197 | tbUser, userDTO, customer.getTenantId(), customer.getId(), Authority.CUSTOMER_USER); |
171 | // 激活CUSTOMER_USER的管理员 | 198 | // 激活CUSTOMER_USER的管理员 |
172 | - activeTBUser(tbUser.getId(),userDTO.getPassword()); | 199 | + activeTBUser(tbUser.getId(), userDTO.getPassword(),null,false); |
173 | } | 200 | } |
174 | return ResponseEntity.ok( | 201 | return ResponseEntity.ok( |
175 | userService.saveAccount( | 202 | userService.saveAccount( |
@@ -180,8 +207,7 @@ public class TkUserController extends AbstractUserAccount { | @@ -180,8 +207,7 @@ public class TkUserController extends AbstractUserAccount { | ||
180 | getCurrentUser().getCurrentTenantId())); | 207 | getCurrentUser().getCurrentTenantId())); |
181 | } | 208 | } |
182 | 209 | ||
183 | - | ||
184 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN'},{'api:yt:user:saveTenantAdmin:post'})") | 210 | + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:user:saveTenantAdmin:post'})") |
185 | @PostMapping("save_tenant_admin") | 211 | @PostMapping("save_tenant_admin") |
186 | public UserDTO saveTenantAdmin(@Validated(AddGroup.class) @RequestBody UserDTO userDTO) | 212 | public UserDTO saveTenantAdmin(@Validated(AddGroup.class) @RequestBody UserDTO userDTO) |
187 | throws ThingsboardException { | 213 | throws ThingsboardException { |
@@ -190,7 +216,7 @@ public class TkUserController extends AbstractUserAccount { | @@ -190,7 +216,7 @@ public class TkUserController extends AbstractUserAccount { | ||
190 | } | 216 | } |
191 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); | 217 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); |
192 | userService.validateTenantRole(userDTO.getTenantId()); | 218 | userService.validateTenantRole(userDTO.getTenantId()); |
193 | - //租户角色不存在,会留存脏数据 | 219 | + // 租户角色不存在,会留存脏数据 |
194 | TenantId tenantId = TenantId.fromUUID(UUID.fromString(userDTO.getTenantId())); | 220 | TenantId tenantId = TenantId.fromUUID(UUID.fromString(userDTO.getTenantId())); |
195 | try { | 221 | try { |
196 | // 创建TB的租户管理员 | 222 | // 创建TB的租户管理员 |
@@ -200,14 +226,14 @@ public class TkUserController extends AbstractUserAccount { | @@ -200,14 +226,14 @@ public class TkUserController extends AbstractUserAccount { | ||
200 | if (null == userDTO.getId()) { | 226 | if (null == userDTO.getId()) { |
201 | tbUser = createTBUser(tbUser, userDTO, tenantId, customerId, Authority.TENANT_ADMIN); | 227 | tbUser = createTBUser(tbUser, userDTO, tenantId, customerId, Authority.TENANT_ADMIN); |
202 | // 激活租户管理员 | 228 | // 激活租户管理员 |
203 | - activeTBUser(tbUser.getId(),accountProperties.getDefaultPassword()); | 229 | + activeTBUser(tbUser.getId(), accountProperties.getDefaultPassword(),tbUser.getTenantId(),true); |
204 | } | 230 | } |
205 | } catch (Exception e) { | 231 | } catch (Exception e) { |
206 | throw handleException(e); | 232 | throw handleException(e); |
207 | } | 233 | } |
208 | 234 | ||
209 | return userService.saveTenantAdmin( | 235 | return userService.saveTenantAdmin( |
210 | - userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); | 236 | + userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); |
211 | } | 237 | } |
212 | 238 | ||
213 | @DeleteMapping | 239 | @DeleteMapping |
@@ -249,16 +275,16 @@ public class TkUserController extends AbstractUserAccount { | @@ -249,16 +275,16 @@ public class TkUserController extends AbstractUserAccount { | ||
249 | @GetMapping("/account_exist/{username}") | 275 | @GetMapping("/account_exist/{username}") |
250 | public ResponseResult<UserDTO> accountExist(@PathVariable String username) | 276 | public ResponseResult<UserDTO> accountExist(@PathVariable String username) |
251 | throws ThingsboardException { | 277 | throws ThingsboardException { |
252 | - return ResponseResult.success( | ||
253 | - userService.accountExist(username)); | 278 | + return ResponseResult.success(userService.accountExist(username)); |
254 | } | 279 | } |
255 | 280 | ||
256 | @ApiOperation(value = "判断电话是否重复") | 281 | @ApiOperation(value = "判断电话是否重复") |
257 | @GetMapping("/get_user/{phoneNumber}") | 282 | @GetMapping("/get_user/{phoneNumber}") |
258 | - public ResponseResult<UserDTO> findUserByPhoneNumber(@PathVariable String phoneNumber) throws ThingsboardException { | ||
259 | - return ResponseResult.success( | ||
260 | - userService.findUserByPhoneNumber(phoneNumber)); | 283 | + public ResponseResult<UserDTO> findUserByPhoneNumber(@PathVariable String phoneNumber) |
284 | + throws ThingsboardException { | ||
285 | + return ResponseResult.success(userService.findUserByPhoneNumber(phoneNumber)); | ||
261 | } | 286 | } |
287 | + | ||
262 | @PostMapping("/relation") | 288 | @PostMapping("/relation") |
263 | public String[] getUserRoleOrGroup( | 289 | public String[] getUserRoleOrGroup( |
264 | @Validated @RequestBody RoleOrOrganizationReqDTO roleOrGroupReqDTO) { | 290 | @Validated @RequestBody RoleOrOrganizationReqDTO roleOrGroupReqDTO) { |
@@ -269,16 +295,14 @@ public class TkUserController extends AbstractUserAccount { | @@ -269,16 +295,14 @@ public class TkUserController extends AbstractUserAccount { | ||
269 | @ApiOperation(value = "修改密码") | 295 | @ApiOperation(value = "修改密码") |
270 | public ResponseResult<Boolean> changePassword(@RequestBody AccountReqDTO accountReqDTO) | 296 | public ResponseResult<Boolean> changePassword(@RequestBody AccountReqDTO accountReqDTO) |
271 | throws ThingsboardException { | 297 | throws ThingsboardException { |
272 | - SysUserEntity user = | ||
273 | - userService.validateChangePasswordAccount(accountReqDTO); | 298 | + SysUserEntity user = userService.validateChangePasswordAccount(accountReqDTO); |
274 | String resetPassword = accountReqDTO.getResetPassword(); | 299 | String resetPassword = accountReqDTO.getResetPassword(); |
275 | if (!getCurrentUser().isPtAdmin()) { | 300 | if (!getCurrentUser().isPtAdmin()) { |
276 | - updatePassword(resetPassword,getCurrentUser()); | 301 | + updatePassword(resetPassword, getCurrentUser()); |
277 | } | 302 | } |
278 | return ResponseResult.success(userService.changePassword(user)); | 303 | return ResponseResult.success(userService.changePassword(user)); |
279 | } | 304 | } |
280 | 305 | ||
281 | - | ||
282 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})") | 306 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})") |
283 | @ApiOperation(value = "获取租户下对应组织的所有客户") | 307 | @ApiOperation(value = "获取租户下对应组织的所有客户") |
284 | @GetMapping("/customers/{organizationId}") | 308 | @GetMapping("/customers/{organizationId}") |
@@ -325,13 +349,17 @@ public class TkUserController extends AbstractUserAccount { | @@ -325,13 +349,17 @@ public class TkUserController extends AbstractUserAccount { | ||
325 | * @param userId 用户ID | 349 | * @param userId 用户ID |
326 | * @throws ThingsboardException tb运行异常 | 350 | * @throws ThingsboardException tb运行异常 |
327 | */ | 351 | */ |
328 | - private void activeTBUser(UserId userId,String password) throws ThingsboardException { | 352 | + private void activeTBUser(UserId userId, String password,TenantId tenantId ,boolean isPtAdmin) throws ThingsboardException { |
329 | try { | 353 | try { |
330 | // 1、获取UserCredentials 并获取activateToken | 354 | // 1、获取UserCredentials 并获取activateToken |
331 | - User user = checkUserId(userId, Operation.READ); | ||
332 | - SecurityUser authUser = getCurrentUser(); | 355 | + if(!isPtAdmin){ |
356 | + User user = checkUserId(userId, Operation.READ); | ||
357 | + userId = user.getId(); | ||
358 | + SecurityUser authUser = getCurrentUser(); | ||
359 | + tenantId = authUser.getTenantId(); | ||
360 | + } | ||
333 | UserCredentials userCredentials = | 361 | UserCredentials userCredentials = |
334 | - tbUserService.findUserCredentialsByUserId(authUser.getTenantId(), user.getId()); | 362 | + tbUserService.findUserCredentialsByUserId(tenantId, userId); |
335 | // 2、进行激活 | 363 | // 2、进行激活 |
336 | String encodedPassword = passwordEncoder.encode(password); | 364 | String encodedPassword = passwordEncoder.encode(password); |
337 | UserCredentials credentials = | 365 | UserCredentials credentials = |
@@ -362,7 +390,7 @@ public class TkUserController extends AbstractUserAccount { | @@ -362,7 +390,7 @@ public class TkUserController extends AbstractUserAccount { | ||
362 | tbUser.setAuthority(authority); | 390 | tbUser.setAuthority(authority); |
363 | tbUser.setTenantId(tenantId); | 391 | tbUser.setTenantId(tenantId); |
364 | tbUser.setCustomerId(customerId); | 392 | tbUser.setCustomerId(customerId); |
365 | - tbUser.setEmail(userDTO.getUsername() +"@"+ accountProperties.getEmailSuffix()); | 393 | + tbUser.setEmail(userDTO.getUsername() + "@" + accountProperties.getEmailSuffix()); |
366 | tbUser = tbUserService.saveUser(tbUser); | 394 | tbUser = tbUserService.saveUser(tbUser); |
367 | userDTO.setTbUser(tbUser.getId().getId().toString()); | 395 | userDTO.setTbUser(tbUser.getId().getId().toString()); |
368 | logEntityAction( | 396 | logEntityAction( |
@@ -60,21 +60,19 @@ import static org.thingsboard.server.common.data.yunteng.constant.ModelConstants | @@ -60,21 +60,19 @@ import static org.thingsboard.server.common.data.yunteng.constant.ModelConstants | ||
60 | public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserEntity> | 60 | public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserEntity> |
61 | implements TkUserService { | 61 | implements TkUserService { |
62 | 62 | ||
63 | + public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; | ||
63 | private final AdminSettingMapper adminSettingMapper; | 64 | private final AdminSettingMapper adminSettingMapper; |
64 | private final ObjectMapper mapper; | 65 | private final ObjectMapper mapper; |
65 | private final RoleMapper roleMapper; | 66 | private final RoleMapper roleMapper; |
66 | private final OrganizationMapper organizationMapper; | 67 | private final OrganizationMapper organizationMapper; |
67 | private final UserRoleMapper userRoleMapper; | 68 | private final UserRoleMapper userRoleMapper; |
68 | private final TenantRoleMapper tenantRoleMapper; | 69 | private final TenantRoleMapper tenantRoleMapper; |
69 | - | ||
70 | private final TkSmsService tkSmsService; | 70 | private final TkSmsService tkSmsService; |
71 | private final TkMessageTemplateService messageTemplateService; | 71 | private final TkMessageTemplateService messageTemplateService; |
72 | private final TkOrganizationService organizationService; | 72 | private final TkOrganizationService organizationService; |
73 | private final UserOrganizationMappingService userOrganizationMappingService; | 73 | private final UserOrganizationMappingService userOrganizationMappingService; |
74 | private final SceneLinkageService sceneLinkageService; | 74 | private final SceneLinkageService sceneLinkageService; |
75 | private final SceneLinkageMapper sceneLinkageMapper; | 75 | private final SceneLinkageMapper sceneLinkageMapper; |
76 | - | ||
77 | - public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; | ||
78 | private final PasswordEncoder passwordEncoder; | 76 | private final PasswordEncoder passwordEncoder; |
79 | 77 | ||
80 | private final CacheUtils cacheUtils; | 78 | private final CacheUtils cacheUtils; |
@@ -83,6 +81,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -83,6 +81,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
83 | private final AccountProperties accountProperties; | 81 | private final AccountProperties accountProperties; |
84 | 82 | ||
85 | private final TenantMapper tenantMapper; | 83 | private final TenantMapper tenantMapper; |
84 | + | ||
86 | @Override | 85 | @Override |
87 | public List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId) { | 86 | public List<UserDetailsDTO> findUserDetailsByUsername(String username, String tenantId) { |
88 | // 多个租户可能存在多个username相同的情况 | 87 | // 多个租户可能存在多个username相同的情况 |
@@ -146,7 +145,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -146,7 +145,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
146 | if (null == userDTO.getId()) { | 145 | if (null == userDTO.getId()) { |
147 | SysUserEntity existUser = | 146 | SysUserEntity existUser = |
148 | baseMapper.selectOne( | 147 | baseMapper.selectOne( |
149 | - new LambdaQueryWrapper<SysUserEntity>().eq(SysUserEntity::getUsername, userDTO.getUsername())); | 148 | + new LambdaQueryWrapper<SysUserEntity>() |
149 | + .eq(SysUserEntity::getUsername, userDTO.getUsername())); | ||
150 | if (null != existUser) { | 150 | if (null != existUser) { |
151 | throw new YtDataValidationException(ErrorMessage.USER_NAME_ALREADY_EXISTS.getMessage()); | 151 | throw new YtDataValidationException(ErrorMessage.USER_NAME_ALREADY_EXISTS.getMessage()); |
152 | } | 152 | } |
@@ -161,8 +161,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -161,8 +161,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
161 | throw new YtDataValidationException(ErrorMessage.PROVIDE_CORRECT_EMAIL.getMessage()); | 161 | throw new YtDataValidationException(ErrorMessage.PROVIDE_CORRECT_EMAIL.getMessage()); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | - if (StringUtils.isEmpty(userDTO.getEmail()) | ||
165 | - && StringUtils.isEmpty(userDTO.getPhoneNumber())) { | 164 | + if (StringUtils.isEmpty(userDTO.getEmail()) && StringUtils.isEmpty(userDTO.getPhoneNumber())) { |
166 | throw new YtDataValidationException(ErrorMessage.PHONE_NUMBER_OR_EMAIL_REQUIRED.getMessage()); | 165 | throw new YtDataValidationException(ErrorMessage.PHONE_NUMBER_OR_EMAIL_REQUIRED.getMessage()); |
167 | } | 166 | } |
168 | boolean needCheck = true; | 167 | boolean needCheck = true; |
@@ -201,7 +200,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -201,7 +200,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
201 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 200 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
202 | } | 201 | } |
203 | SysUserEntity user = baseMapper.selectById(id); | 202 | SysUserEntity user = baseMapper.selectById(id); |
204 | - return null !=user?user.getDTO(UserDTO.class):null; | 203 | + return null != user ? user.getDTO(UserDTO.class) : null; |
205 | } | 204 | } |
206 | 205 | ||
207 | @Override | 206 | @Override |
@@ -219,7 +218,9 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -219,7 +218,9 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
219 | adminSettingMapper.selectList( | 218 | adminSettingMapper.selectList( |
220 | new QueryWrapper<SysAdminSettingEntity>() | 219 | new QueryWrapper<SysAdminSettingEntity>() |
221 | .lambda() | 220 | .lambda() |
222 | - .eq(SysAdminSettingEntity::getKey, ModelConstants.AdminSettingConfigKey.GENERAL_SETTING)); | 221 | + .eq( |
222 | + SysAdminSettingEntity::getKey, | ||
223 | + ModelConstants.AdminSettingConfigKey.GENERAL_SETTING)); | ||
223 | SysAdminSettingEntity adminSetting = generalSetting.get(0); | 224 | SysAdminSettingEntity adminSetting = generalSetting.get(0); |
224 | JsonNode configNode = mapper.readTree(adminSetting.getConfigJson()); | 225 | JsonNode configNode = mapper.readTree(adminSetting.getConfigJson()); |
225 | String baseUrl = configNode.get(FastIotConstants.ConfigJSONKey.BASE_URL).asText(); | 226 | String baseUrl = configNode.get(FastIotConstants.ConfigJSONKey.BASE_URL).asText(); |
@@ -237,10 +238,17 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -237,10 +238,17 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
237 | userInfoDTO.setNeedSetPwd(false); | 238 | userInfoDTO.setNeedSetPwd(false); |
238 | } | 239 | } |
239 | AtomicReference<LocalDateTime> expireTime = new AtomicReference<>(user.getAccountExpireTime()); | 240 | AtomicReference<LocalDateTime> expireTime = new AtomicReference<>(user.getAccountExpireTime()); |
240 | - if(expireTime.get() == null){ | ||
241 | - SysTenantEntity tenant =tenantMapper.selectOne(new QueryWrapper<SysTenantEntity>().lambda().eq(SysTenantEntity::getTenantId,tenantId)); | ||
242 | - Optional.ofNullable(tenant).ifPresent(i -> { | ||
243 | - expireTime.set(i.getTenantExpireTime());}); | 241 | + if (expireTime.get() == null) { |
242 | + SysTenantEntity tenant = | ||
243 | + tenantMapper.selectOne( | ||
244 | + new QueryWrapper<SysTenantEntity>() | ||
245 | + .lambda() | ||
246 | + .eq(SysTenantEntity::getTenantId, tenantId)); | ||
247 | + Optional.ofNullable(tenant) | ||
248 | + .ifPresent( | ||
249 | + i -> { | ||
250 | + expireTime.set(i.getTenantExpireTime()); | ||
251 | + }); | ||
244 | } | 252 | } |
245 | userInfoDTO.setAccountExpireTime(expireTime.get()); | 253 | userInfoDTO.setAccountExpireTime(expireTime.get()); |
246 | userInfoDTO.setUserId(userId); | 254 | userInfoDTO.setUserId(userId); |
@@ -325,15 +333,10 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -325,15 +333,10 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
325 | queryMap.put("userIds", userIds); | 333 | queryMap.put("userIds", userIds); |
326 | } | 334 | } |
327 | if (isPtSysadmin) { | 335 | if (isPtSysadmin) { |
328 | - String roleType = (String) queryMap.get("roleType"); | ||
329 | - if (!StringUtils.isEmpty(roleType)) { | ||
330 | - userPage = baseMapper.getTenantAdminPage(userIPage, tenantId); | 336 | + if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) { |
337 | + userPage = new Page<>(); | ||
331 | } else { | 338 | } else { |
332 | - if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) { | ||
333 | - userPage = new Page<>(); | ||
334 | - } else { | ||
335 | - userPage = baseMapper.getUserPage(userIPage, queryMap); | ||
336 | - } | 339 | + userPage = baseMapper.getUserPage(userIPage, queryMap); |
337 | } | 340 | } |
338 | } else if (isTenantAdmin) { | 341 | } else if (isTenantAdmin) { |
339 | if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) { | 342 | if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) { |
@@ -356,6 +359,23 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -356,6 +359,23 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
356 | return getPageData(userPage, UserDTO.class); | 359 | return getPageData(userPage, UserDTO.class); |
357 | } | 360 | } |
358 | 361 | ||
362 | + @Override | ||
363 | + public YtPageData<UserDTO> tenantPage(Map<String, Object> queryMap, String tenantId) { | ||
364 | + IPage<SysUserEntity> userIPage = getPage(queryMap, "create_time", false); | ||
365 | + IPage<UserDTO> userPage = baseMapper.getTenantAdminPage(userIPage, tenantId); | ||
366 | + if (null != userPage) { | ||
367 | + userPage | ||
368 | + .getRecords() | ||
369 | + .forEach( | ||
370 | + record -> { | ||
371 | + fillUserStatus(record); | ||
372 | + record.setHasPassword(StringUtils.isNotBlank(record.getActivateToken())); | ||
373 | + record.setPassword(null); | ||
374 | + }); | ||
375 | + } | ||
376 | + return getPageData(userPage, UserDTO.class); | ||
377 | + } | ||
378 | + | ||
359 | private void fillUserStatus(UserDTO userDTO) { | 379 | private void fillUserStatus(UserDTO userDTO) { |
360 | userDTO.setUserStatusEnum(UserStatusEnum.NORMAL); | 380 | userDTO.setUserStatusEnum(UserStatusEnum.NORMAL); |
361 | if (!userDTO.isEnabled()) { | 381 | if (!userDTO.isEnabled()) { |
@@ -395,18 +415,16 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -395,18 +415,16 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
395 | baseMapper.deleteBatchIds(userIds); | 415 | baseMapper.deleteBatchIds(userIds); |
396 | 416 | ||
397 | // 5、删除场景联动 | 417 | // 5、删除场景联动 |
398 | - Wrapper filter = new QueryWrapper<TkSceneLinkageEntity>().lambda() | ||
399 | - .in(TkSceneLinkageEntity::getCreator,userIds); | ||
400 | - List<TkSceneLinkageEntity> sceneLinkages =sceneLinkageMapper.selectList(filter); | ||
401 | - if(sceneLinkages ==null || sceneLinkages.isEmpty()){ | 418 | + Wrapper filter = |
419 | + new QueryWrapper<TkSceneLinkageEntity>() | ||
420 | + .lambda() | ||
421 | + .in(TkSceneLinkageEntity::getCreator, userIds); | ||
422 | + List<TkSceneLinkageEntity> sceneLinkages = sceneLinkageMapper.selectList(filter); | ||
423 | + if (sceneLinkages == null || sceneLinkages.isEmpty()) { | ||
402 | return true; | 424 | return true; |
403 | } | 425 | } |
404 | - Set<String> sceneIds = sceneLinkages.stream() | ||
405 | - .map(i -> i.getId()) | ||
406 | - .collect(Collectors.toSet()); | ||
407 | - sceneLinkageService.deleteSceneLinkage(sceneIds, tenantId,null); | ||
408 | - | ||
409 | - | 426 | + Set<String> sceneIds = sceneLinkages.stream().map(i -> i.getId()).collect(Collectors.toSet()); |
427 | + sceneLinkageService.deleteSceneLinkage(sceneIds, tenantId, null); | ||
410 | 428 | ||
411 | return true; | 429 | return true; |
412 | } | 430 | } |
@@ -423,12 +441,14 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -423,12 +441,14 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
423 | user.setLevel(FastIotConstants.LevelValue.IS_TENANT_ADMIN); | 441 | user.setLevel(FastIotConstants.LevelValue.IS_TENANT_ADMIN); |
424 | List<SysUserEntity> users = | 442 | List<SysUserEntity> users = |
425 | baseMapper.selectList( | 443 | baseMapper.selectList( |
426 | - new QueryWrapper<SysUserEntity>().lambda().eq(SysUserEntity::getUsername, userDTO.getUsername())); | 444 | + new QueryWrapper<SysUserEntity>() |
445 | + .lambda() | ||
446 | + .eq(SysUserEntity::getUsername, userDTO.getUsername())); | ||
427 | if (!users.isEmpty()) { | 447 | if (!users.isEmpty()) { |
428 | throw new YtDataValidationException("用户已存在"); | 448 | throw new YtDataValidationException("用户已存在"); |
429 | } | 449 | } |
430 | baseMapper.insert(user); | 450 | baseMapper.insert(user); |
431 | - List<SysTenantRoleEntity> tenantRoleList =validateTenantRole(userDTO.getTenantId()) ; | 451 | + List<SysTenantRoleEntity> tenantRoleList = validateTenantRole(userDTO.getTenantId()); |
432 | for (SysTenantRoleEntity tenantRole : tenantRoleList) { | 452 | for (SysTenantRoleEntity tenantRole : tenantRoleList) { |
433 | roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); | 453 | roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); |
434 | } | 454 | } |
@@ -439,10 +459,10 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -439,10 +459,10 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
439 | @Override | 459 | @Override |
440 | public List<SysTenantRoleEntity> validateTenantRole(String tenantId) { | 460 | public List<SysTenantRoleEntity> validateTenantRole(String tenantId) { |
441 | List<SysTenantRoleEntity> tenantRoleList = | 461 | List<SysTenantRoleEntity> tenantRoleList = |
442 | - tenantRoleMapper.selectList( | ||
443 | - new QueryWrapper<SysTenantRoleEntity>() | ||
444 | - .lambda() | ||
445 | - .eq(SysTenantRoleEntity::getTenantId, tenantId)); | 462 | + tenantRoleMapper.selectList( |
463 | + new QueryWrapper<SysTenantRoleEntity>() | ||
464 | + .lambda() | ||
465 | + .eq(SysTenantRoleEntity::getTenantId, tenantId)); | ||
446 | // 保存用户与角色的映射信息 | 466 | // 保存用户与角色的映射信息 |
447 | if (null == tenantRoleList || tenantRoleList.size() == 0) { | 467 | if (null == tenantRoleList || tenantRoleList.size() == 0) { |
448 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | 468 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
@@ -493,20 +513,21 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -493,20 +513,21 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
493 | 513 | ||
494 | SysUserEntity user = | 514 | SysUserEntity user = |
495 | baseMapper.selectOne( | 515 | baseMapper.selectOne( |
496 | - new QueryWrapper<SysUserEntity>().lambda().eq(SysUserEntity::getPhoneNumber, phoneNumber)); | 516 | + new QueryWrapper<SysUserEntity>() |
517 | + .lambda() | ||
518 | + .eq(SysUserEntity::getPhoneNumber, phoneNumber)); | ||
497 | 519 | ||
498 | - if(StringUtils.isNotBlank(user.getTbUser())){ | 520 | + if (StringUtils.isNotBlank(user.getTbUser())) { |
499 | UserId userId = new UserId(UUID.fromString(user.getTbUser())); | 521 | UserId userId = new UserId(UUID.fromString(user.getTbUser())); |
500 | UserCredentials userCredentials = | 522 | UserCredentials userCredentials = |
501 | - tbUserService.findUserCredentialsByUserId(TenantId.SYS_TENANT_ID, userId); | 523 | + tbUserService.findUserCredentialsByUserId(TenantId.SYS_TENANT_ID, userId); |
502 | 524 | ||
503 | userCredentials.setPassword(passwordEncoder.encode(pwd)); | 525 | userCredentials.setPassword(passwordEncoder.encode(pwd)); |
504 | tbUserService.replaceUserCredentials( | 526 | tbUserService.replaceUserCredentials( |
505 | - TenantId.fromUUID(UUID.fromString(user.getTenantId())), userCredentials); | 527 | + TenantId.fromUUID(UUID.fromString(user.getTenantId())), userCredentials); |
506 | // eventPublisher.publishEvent(new UserAuthDataChangedEvent(userId)); | 528 | // eventPublisher.publishEvent(new UserAuthDataChangedEvent(userId)); |
507 | } | 529 | } |
508 | 530 | ||
509 | - | ||
510 | user.setPassword(pwd); | 531 | user.setPassword(pwd); |
511 | changePassword(user); | 532 | changePassword(user); |
512 | } | 533 | } |
@@ -517,7 +538,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -517,7 +538,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
517 | } | 538 | } |
518 | 539 | ||
519 | @Override | 540 | @Override |
520 | - public void sendRestPasswordMsg(String tenantId,SendResetPasswordEmailMsg msg) { | 541 | + public void sendRestPasswordMsg(String tenantId, SendResetPasswordEmailMsg msg) { |
521 | // 通过用户ID查询用户信息 | 542 | // 通过用户ID查询用户信息 |
522 | SysUserEntity user = baseMapper.selectById(msg.getUserId()); | 543 | SysUserEntity user = baseMapper.selectById(msg.getUserId()); |
523 | if (null == user) { | 544 | if (null == user) { |
@@ -534,7 +555,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -534,7 +555,8 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
534 | List<MessageTemplateDTO> templateDTOList = | 555 | List<MessageTemplateDTO> templateDTOList = |
535 | messageTemplateService.findMessageTemplate(messageTemplateDTO); | 556 | messageTemplateService.findMessageTemplate(messageTemplateDTO); |
536 | if (null == templateDTOList || templateDTOList.size() < 1) { | 557 | if (null == templateDTOList || templateDTOList.size() < 1) { |
537 | - throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS_SELF_NOTICE.getMessage()); | 558 | + throw new YtDataValidationException( |
559 | + ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS_SELF_NOTICE.getMessage()); | ||
538 | } | 560 | } |
539 | if (messageType.equalsIgnoreCase(MessageTypeEnum.PHONE_MESSAGE.name())) { | 561 | if (messageType.equalsIgnoreCase(MessageTypeEnum.PHONE_MESSAGE.name())) { |
540 | SmsReqDTO smsReqDTO = new SmsReqDTO(); | 562 | SmsReqDTO smsReqDTO = new SmsReqDTO(); |
@@ -569,15 +591,24 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -569,15 +591,24 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
569 | if (roleOrGroupReqDTO.isQueryRole()) { | 591 | if (roleOrGroupReqDTO.isQueryRole()) { |
570 | List<String> roleIds = | 592 | List<String> roleIds = |
571 | userRoleMapper | 593 | userRoleMapper |
572 | - .selectList(new QueryWrapper<SysUserRoleEntity>().lambda().eq(SysUserRoleEntity::getUserId, userId)) | 594 | + .selectList( |
595 | + new QueryWrapper<SysUserRoleEntity>() | ||
596 | + .lambda() | ||
597 | + .eq(SysUserRoleEntity::getUserId, userId)) | ||
573 | .stream() | 598 | .stream() |
574 | .map(SysUserRoleEntity::getRoleId) | 599 | .map(SysUserRoleEntity::getRoleId) |
575 | .collect(Collectors.toList()); | 600 | .collect(Collectors.toList()); |
576 | - List<String> enableRoles = roleMapper.selectList(new QueryWrapper<SysRoleEntity>().lambda() | ||
577 | - .eq(SysRoleEntity::isEnabled, true).in(SysRoleEntity::getId,roleIds)) | ||
578 | - .stream().map(m -> m.getId()) | 601 | + List<String> enableRoles = |
602 | + roleMapper | ||
603 | + .selectList( | ||
604 | + new QueryWrapper<SysRoleEntity>() | ||
605 | + .lambda() | ||
606 | + .eq(SysRoleEntity::isEnabled, true) | ||
607 | + .in(SysRoleEntity::getId, roleIds)) | ||
608 | + .stream() | ||
609 | + .map(m -> m.getId()) | ||
579 | .collect(Collectors.toList()); | 610 | .collect(Collectors.toList()); |
580 | - if(enableRoles.size() == 0){ | 611 | + if (enableRoles.size() == 0) { |
581 | return null; | 612 | return null; |
582 | } | 613 | } |
583 | return enableRoles.toArray(new String[enableRoles.size()]); | 614 | return enableRoles.toArray(new String[enableRoles.size()]); |
@@ -631,7 +662,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -631,7 +662,7 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
631 | } | 662 | } |
632 | if (isTenantAdmin) { | 663 | if (isTenantAdmin) { |
633 | List<String> userList = | 664 | List<String> userList = |
634 | - userOrganizationMappingService.getUserIdByOrganizationIds(tenantId,organizationId); | 665 | + userOrganizationMappingService.getUserIdByOrganizationIds(tenantId, organizationId); |
635 | if (null != userList && userList.size() > FastIotConstants.MagicNumber.ZERO) { | 666 | if (null != userList && userList.size() > FastIotConstants.MagicNumber.ZERO) { |
636 | return baseMapper.getMyCustomers(tenantId, EntityId.NULL_UUID.toString(), userList); | 667 | return baseMapper.getMyCustomers(tenantId, EntityId.NULL_UUID.toString(), userList); |
637 | } | 668 | } |
@@ -654,7 +685,9 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | @@ -654,7 +685,9 @@ public class SysUserServiceImpl extends AbstractBaseService<UserMapper, SysUserE | ||
654 | public UserDTO checkAccount(String userId, Integer level) { | 685 | public UserDTO checkAccount(String userId, Integer level) { |
655 | SysUserEntity user = | 686 | SysUserEntity user = |
656 | baseMapper.selectOne( | 687 | baseMapper.selectOne( |
657 | - new LambdaQueryWrapper<SysUserEntity>().eq(SysUserEntity::getId, userId).eq(SysUserEntity::getLevel, level)); | 688 | + new LambdaQueryWrapper<SysUserEntity>() |
689 | + .eq(SysUserEntity::getId, userId) | ||
690 | + .eq(SysUserEntity::getLevel, level)); | ||
658 | return null != user ? user.getDTO(UserDTO.class) : null; | 691 | return null != user ? user.getDTO(UserDTO.class) : null; |
659 | } | 692 | } |
660 | 693 |
@@ -34,6 +34,7 @@ public interface TkUserService { | @@ -34,6 +34,7 @@ public interface TkUserService { | ||
34 | Map<String, Object> queryMap, | 34 | Map<String, Object> queryMap, |
35 | boolean isPtSysadmin, | 35 | boolean isPtSysadmin, |
36 | boolean isTenantAdmin); | 36 | boolean isTenantAdmin); |
37 | + YtPageData<UserDTO> tenantPage(Map<String, Object> queryMap,String tenantId); | ||
37 | 38 | ||
38 | UserDTO updateUser(UserDTO userDTO, boolean isPtSysadmin, String tenantId); | 39 | UserDTO updateUser(UserDTO userDTO, boolean isPtSysadmin, String tenantId); |
39 | 40 |