|
@@ -55,13 +55,13 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -55,13 +55,13 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
55
|
private final TenantMapper tenantMapper;
|
55
|
private final TenantMapper tenantMapper;
|
56
|
private final RoleMapper roleMapper;
|
56
|
private final RoleMapper roleMapper;
|
57
|
private final OrganizationMapper organizationMapper;
|
57
|
private final OrganizationMapper organizationMapper;
|
58
|
- private final UserOrganizationMappingMapper userOrganizationMappingMapper;
|
|
|
59
|
private final UserRoleMapper userRoleMapper;
|
58
|
private final UserRoleMapper userRoleMapper;
|
60
|
private final TenantRoleMapper tenantRoleMapper;
|
59
|
private final TenantRoleMapper tenantRoleMapper;
|
61
|
|
60
|
|
62
|
private final YtSmsService ytSmsService;
|
61
|
private final YtSmsService ytSmsService;
|
63
|
private final YtMessageTemplateService messageTemplateService;
|
62
|
private final YtMessageTemplateService messageTemplateService;
|
64
|
- private final YtOrganizationService groupService;
|
63
|
+ private final YtOrganizationService organizationService;
|
|
|
64
|
+ private final UserOrganizationMappingService userOrganizationMappingService;
|
65
|
|
65
|
|
66
|
public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s";
|
66
|
public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s";
|
67
|
private final PasswordEncoder passwordEncoder;
|
67
|
private final PasswordEncoder passwordEncoder;
|
|
@@ -75,8 +75,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -75,8 +75,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
75
|
@Override
|
75
|
@Override
|
76
|
@Transactional
|
76
|
@Transactional
|
77
|
public UserDTO saveAccount(
|
77
|
public UserDTO saveAccount(
|
78
|
- UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isPtSysadmin, String tenantId) {
|
|
|
79
|
- boolean isAdminOperate = isPtSysadmin;
|
78
|
+ UserDTO userDTO, boolean sendEmail, boolean sendMsg, boolean isTenantAdmin, String tenantId) {
|
|
|
79
|
+ boolean isTenantAdminOperate = isTenantAdmin;
|
80
|
if (sendMsg && StringUtils.isAllBlank(userDTO.getPhoneNumber())) {
|
80
|
if (sendMsg && StringUtils.isAllBlank(userDTO.getPhoneNumber())) {
|
81
|
throw new YtDataValidationException(
|
81
|
throw new YtDataValidationException(
|
82
|
"you must specify user phone number if you want send activate email to this user");
|
82
|
"you must specify user phone number if you want send activate email to this user");
|
|
@@ -91,43 +91,22 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -91,43 +91,22 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
91
|
if (StringUtils.isNotBlank(userDTO.getPassword())) {
|
91
|
if (StringUtils.isNotBlank(userDTO.getPassword())) {
|
92
|
user.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
92
|
user.setPassword(passwordEncoder.encode(userDTO.getPassword()));
|
93
|
}
|
93
|
}
|
94
|
- if (isAdminOperate) {
|
|
|
95
|
- // 添加的租户管理员
|
|
|
96
|
- if (StringUtils.isNotBlank(userDTO.getTenantId())) {
|
|
|
97
|
- user.setTenantId(userDTO.getTenantId());
|
|
|
98
|
- user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
|
|
|
99
|
- int tenantExist =
|
|
|
100
|
- tenantMapper.selectCount(
|
|
|
101
|
- new QueryWrapper<Tenant>().lambda().eq(Tenant::getTenantId, userDTO.getTenantId()));
|
|
|
102
|
- if (tenantExist == 0) {
|
|
|
103
|
- throw new YtDataValidationException("tenant must exist");
|
|
|
104
|
- }
|
|
|
105
|
- } else {
|
|
|
106
|
- // 添加的平台系统其他用户
|
|
|
107
|
- user.setLevel(FastIotConstants.LevelValue.IS_OTHER_ADMIN);
|
|
|
108
|
- user.setTenantId(tenantId);
|
|
|
109
|
- }
|
|
|
110
|
- userExist =
|
|
|
111
|
- baseMapper.selectCount(
|
|
|
112
|
- new QueryWrapper<User>()
|
|
|
113
|
- .lambda()
|
|
|
114
|
- .eq(User::getUsername, userDTO.getUsername())
|
|
|
115
|
- .eq(User::getTenantId, userDTO.getTenantId()))
|
|
|
116
|
- > 0;
|
|
|
117
|
- } else {
|
|
|
118
|
- user.setLevel(FastIotConstants.LevelValue.IS_NORMAL);
|
|
|
119
|
- user.setTenantId(tenantId);
|
|
|
120
|
- userExist =
|
|
|
121
|
- baseMapper.selectCount(
|
|
|
122
|
- new QueryWrapper<User>()
|
|
|
123
|
- .lambda()
|
|
|
124
|
- .eq(User::getUsername, userDTO.getUsername())
|
|
|
125
|
- .eq(User::getTenantId, tenantId))
|
|
|
126
|
- > 0;
|
|
|
127
|
- }
|
94
|
+ userExist =
|
|
|
95
|
+ baseMapper.selectCount(
|
|
|
96
|
+ new QueryWrapper<User>()
|
|
|
97
|
+ .lambda()
|
|
|
98
|
+ .eq(User::getUsername, userDTO.getUsername())
|
|
|
99
|
+ .eq(User::getTenantId, tenantId))
|
|
|
100
|
+ > 0;
|
128
|
if (userExist) {
|
101
|
if (userExist) {
|
129
|
throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
|
102
|
throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
|
130
|
} else {
|
103
|
} else {
|
|
|
104
|
+ user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
|
|
|
105
|
+ user.setTenantId(tenantId);
|
|
|
106
|
+ user.setLevel(
|
|
|
107
|
+ isTenantAdminOperate
|
|
|
108
|
+ ? FastIotConstants.LevelValue.IS_CUSTOMER_USER
|
|
|
109
|
+ : FastIotConstants.LevelValue.IS_PLATFORM_ADMIN);
|
131
|
baseMapper.insert(user);
|
110
|
baseMapper.insert(user);
|
132
|
for (String roleId : userDTO.getRoleIds()) {
|
111
|
for (String roleId : userDTO.getRoleIds()) {
|
133
|
// 添加用户角色信息
|
112
|
// 添加用户角色信息
|
|
@@ -137,7 +116,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -137,7 +116,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
137
|
userRoleMapper.insert(userRole);
|
116
|
userRoleMapper.insert(userRole);
|
138
|
}
|
117
|
}
|
139
|
// 绑定用户和组织的关系
|
118
|
// 绑定用户和组织的关系
|
140
|
- groupService.bindUserToOrganization(tenantId, user.getId(), userDTO.getOrganizationIds());
|
119
|
+ organizationService.bindUserToOrganization(tenantId, user.getId(), userDTO.getOrganizationIds());
|
141
|
user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN);
|
120
|
user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN);
|
142
|
return userDTO;
|
121
|
return userDTO;
|
143
|
}
|
122
|
}
|
|
@@ -145,10 +124,10 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -145,10 +124,10 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
145
|
|
124
|
|
146
|
@Override
|
125
|
@Override
|
147
|
public void validateUserNameAndPhoneNumberAndEmail(UserDTO userDTO) {
|
126
|
public void validateUserNameAndPhoneNumberAndEmail(UserDTO userDTO) {
|
148
|
- if(null == userDTO.getId()){
|
127
|
+ if (null == userDTO.getId()) {
|
149
|
User existUser =
|
128
|
User existUser =
|
150
|
- baseMapper.selectOne(
|
|
|
151
|
- new LambdaQueryWrapper<User>().eq(User::getUsername, userDTO.getUsername()));
|
129
|
+ baseMapper.selectOne(
|
|
|
130
|
+ new LambdaQueryWrapper<User>().eq(User::getUsername, userDTO.getUsername()));
|
152
|
if (null != existUser) {
|
131
|
if (null != existUser) {
|
153
|
throw new YtDataValidationException(ErrorMessage.USER_NAME_ALREADY_EXISTS.getMessage());
|
132
|
throw new YtDataValidationException(ErrorMessage.USER_NAME_ALREADY_EXISTS.getMessage());
|
154
|
}
|
133
|
}
|
|
@@ -171,7 +150,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -171,7 +150,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
171
|
|
150
|
|
172
|
@Override
|
151
|
@Override
|
173
|
public UserDTO findUserInfoById(String id) {
|
152
|
public UserDTO findUserInfoById(String id) {
|
174
|
- if(StringUtils.isEmpty(id)){
|
153
|
+ if (StringUtils.isEmpty(id)) {
|
175
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
154
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
176
|
}
|
155
|
}
|
177
|
return baseMapper.selectById(id).getDTO(UserDTO.class);
|
156
|
return baseMapper.selectById(id).getDTO(UserDTO.class);
|
|
@@ -264,6 +243,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -264,6 +243,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
264
|
}
|
243
|
}
|
265
|
baseMapper.updateById(user);
|
244
|
baseMapper.updateById(user);
|
266
|
deleteAndAddUserRole(user.getId(), Arrays.asList(userDTO.getRoleIds()));
|
245
|
deleteAndAddUserRole(user.getId(), Arrays.asList(userDTO.getRoleIds()));
|
|
|
246
|
+ userOrganizationMappingService.addOrUpdateUserOrganizationMapping(
|
|
|
247
|
+ user.getId(), Arrays.asList(userDTO.getOrganizationIds()), true);
|
267
|
user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN);
|
248
|
user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN);
|
268
|
return userDTO;
|
249
|
return userDTO;
|
269
|
}
|
250
|
}
|
|
@@ -282,7 +263,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -282,7 +263,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
282
|
if (StringUtils.isEmpty(roleType)) {
|
263
|
if (StringUtils.isEmpty(roleType)) {
|
283
|
roleType = RoleEnum.PLATFORM_ADMIN.name();
|
264
|
roleType = RoleEnum.PLATFORM_ADMIN.name();
|
284
|
userPage = baseMapper.getAdminUserPage(userIPage, tenantId, roleType);
|
265
|
userPage = baseMapper.getAdminUserPage(userIPage, tenantId, roleType);
|
285
|
- }else{
|
266
|
+ } else {
|
286
|
userPage = baseMapper.getTenantAdminPage(userIPage, tenantId);
|
267
|
userPage = baseMapper.getTenantAdminPage(userIPage, tenantId);
|
287
|
}
|
268
|
}
|
288
|
} else if (isPlatformAdmin) {
|
269
|
} else if (isPlatformAdmin) {
|
|
@@ -344,7 +325,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -344,7 +325,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
344
|
|
325
|
|
345
|
// 3. 解绑人员对应的group
|
326
|
// 3. 解绑人员对应的group
|
346
|
|
327
|
|
347
|
- groupService.unBindUserToOrganization(userIds);
|
328
|
+ organizationService.unBindUserToOrganization(userIds);
|
348
|
|
329
|
|
349
|
// 4. 删除人员
|
330
|
// 4. 删除人员
|
350
|
baseMapper.deleteBatchIds(userIds);
|
331
|
baseMapper.deleteBatchIds(userIds);
|
|
@@ -445,15 +426,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -445,15 +426,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
445
|
if (group == null || !group.getTenantId().equals(tenantId)) {
|
426
|
if (group == null || !group.getTenantId().equals(tenantId)) {
|
446
|
return Optional.empty();
|
427
|
return Optional.empty();
|
447
|
}
|
428
|
}
|
448
|
- Set<String> userIds =
|
|
|
449
|
- userOrganizationMappingMapper
|
|
|
450
|
- .selectList(
|
|
|
451
|
- new QueryWrapper<UserOrganizationMapping>()
|
|
|
452
|
- .lambda()
|
|
|
453
|
- .eq(UserOrganizationMapping::getOrganizationId, group))
|
|
|
454
|
- .stream()
|
|
|
455
|
- .map(UserOrganizationMapping::getUserId)
|
|
|
456
|
- .collect(Collectors.toSet());
|
429
|
+ List<String> userIds = userOrganizationMappingService.getUserIdsByOrganizationId(group.getId());
|
457
|
List<User> users = baseMapper.selectBatchIds(userIds);
|
430
|
List<User> users = baseMapper.selectBatchIds(userIds);
|
458
|
return Optional.ofNullable(ReflectUtils.sourceToTarget(users, UserDTO.class));
|
431
|
return Optional.ofNullable(ReflectUtils.sourceToTarget(users, UserDTO.class));
|
459
|
}
|
432
|
}
|
|
@@ -474,16 +447,9 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -474,16 +447,9 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
474
|
return roleIds.toArray(new String[roleIds.size()]);
|
447
|
return roleIds.toArray(new String[roleIds.size()]);
|
475
|
}
|
448
|
}
|
476
|
if (roleOrGroupReqDTO.isQueryOrganization()) {
|
449
|
if (roleOrGroupReqDTO.isQueryOrganization()) {
|
477
|
- List<String> roleIds =
|
|
|
478
|
- userOrganizationMappingMapper
|
|
|
479
|
- .selectList(
|
|
|
480
|
- new QueryWrapper<UserOrganizationMapping>()
|
|
|
481
|
- .lambda()
|
|
|
482
|
- .eq(UserOrganizationMapping::getUserId, userId))
|
|
|
483
|
- .stream()
|
|
|
484
|
- .map(UserOrganizationMapping::getOrganizationId)
|
|
|
485
|
- .collect(Collectors.toList());
|
|
|
486
|
- return roleIds.toArray(new String[roleIds.size()]);
|
450
|
+ List<String> organizationIds =
|
|
|
451
|
+ userOrganizationMappingService.getOrganizationIdsByUserId(userId);
|
|
|
452
|
+ return organizationIds.toArray(new String[organizationIds.size()]);
|
487
|
}
|
453
|
}
|
488
|
return null;
|
454
|
return null;
|
489
|
}
|
455
|
}
|
|
@@ -512,8 +478,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -512,8 +478,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
512
|
public User validateChangePasswordAccount(AccountReqDTO accountReqDTO) {
|
478
|
public User validateChangePasswordAccount(AccountReqDTO accountReqDTO) {
|
513
|
User user = baseMapper.selectById(accountReqDTO.getUserId());
|
479
|
User user = baseMapper.selectById(accountReqDTO.getUserId());
|
514
|
if (null == user
|
480
|
if (null == user
|
515
|
- || StringUtils.isEmpty(accountReqDTO.getPassword())
|
|
|
516
|
- || StringUtils.isEmpty(accountReqDTO.getResetPassword())) {
|
481
|
+ || StringUtils.isEmpty(accountReqDTO.getPassword())
|
|
|
482
|
+ || StringUtils.isEmpty(accountReqDTO.getResetPassword())) {
|
517
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
483
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
518
|
}
|
484
|
}
|
519
|
// 判断用户密码是否正确
|
485
|
// 判断用户密码是否正确
|
|
@@ -527,19 +493,21 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
|
@@ -527,19 +493,21 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
527
|
|
493
|
|
528
|
/**
|
494
|
/**
|
529
|
* 先删除用户与角色的关系,再添加新的关系
|
495
|
* 先删除用户与角色的关系,再添加新的关系
|
|
|
496
|
+ *
|
530
|
* @param userId 用户ID
|
497
|
* @param userId 用户ID
|
531
|
* @param roleIds 角色ID
|
498
|
* @param roleIds 角色ID
|
532
|
*/
|
499
|
*/
|
533
|
- private void deleteAndAddUserRole(String userId,List<String> roleIds){
|
|
|
534
|
- if(StringUtils.isAllEmpty(userId) || null == roleIds || roleIds.size()<1){
|
500
|
+ private void deleteAndAddUserRole(String userId, List<String> roleIds) {
|
|
|
501
|
+ if (StringUtils.isAllEmpty(userId) || null == roleIds || roleIds.size() < 1) {
|
535
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
502
|
throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
|
536
|
}
|
503
|
}
|
537
|
- //先删除用户与角色的关系,再添加用户与角色的关系
|
504
|
+ // 先删除用户与角色的关系,再添加用户与角色的关系
|
538
|
List<String> userIds = new ArrayList<>();
|
505
|
List<String> userIds = new ArrayList<>();
|
539
|
userIds.add(userId);
|
506
|
userIds.add(userId);
|
540
|
roleMapper.deleteRoleUserMappingByUserIds(userIds);
|
507
|
roleMapper.deleteRoleUserMappingByUserIds(userIds);
|
541
|
- roleIds.forEach(role ->{
|
|
|
542
|
- roleMapper.saveUserRoleMapping(userId,role);
|
|
|
543
|
- });
|
508
|
+ roleIds.forEach(
|
|
|
509
|
+ role -> {
|
|
|
510
|
+ roleMapper.saveUserRoleMapping(userId, role);
|
|
|
511
|
+ });
|
544
|
}
|
512
|
}
|
545
|
} |
513
|
} |