|
@@ -199,10 +199,20 @@ public class UserServiceImpl implements IUserService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public PaginationData<UserListDTO> getUsersByWorkspaceId(long page, long pageSize, String workspaceId) {
|
|
|
|
|
|
|
+ public PaginationData<UserListDTO> getUsersByWorkspaceId(long page, long pageSize, String workspaceId,String username) {
|
|
|
|
|
+ LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq(UserEntity::getWorkspaceId, workspaceId);
|
|
|
|
|
+ queryWrapper.and(wrapper -> {
|
|
|
|
|
+ wrapper.eq(UserEntity::getUserType, UserTypeEnum.WEB.getVal());
|
|
|
|
|
+ wrapper.or().eq(UserEntity::getUserType, UserTypeEnum.PILOT.getVal());
|
|
|
|
|
+ });
|
|
|
|
|
+ if(username != null) {
|
|
|
|
|
+ queryWrapper.like(UserEntity::getUsername,username);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Page<UserEntity> userEntityPage = mapper.selectPage(
|
|
Page<UserEntity> userEntityPage = mapper.selectPage(
|
|
|
new Page<>(page, pageSize),
|
|
new Page<>(page, pageSize),
|
|
|
- new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getWorkspaceId, workspaceId));
|
|
|
|
|
|
|
+ queryWrapper);
|
|
|
|
|
|
|
|
List<UserListDTO> usersList = userEntityPage.getRecords()
|
|
List<UserListDTO> usersList = userEntityPage.getRecords()
|
|
|
.stream()
|
|
.stream()
|
|
@@ -382,7 +392,7 @@ public class UserServiceImpl implements IUserService {
|
|
|
userEntity = new UserEntity();
|
|
userEntity = new UserEntity();
|
|
|
userEntity.setUsername(username);
|
|
userEntity.setUsername(username);
|
|
|
userEntity.setUserId(UUID.randomUUID().toString());
|
|
userEntity.setUserId(UUID.randomUUID().toString());
|
|
|
- userEntity.setUserType(UserTypeEnum.SUPER_SYS.getVal());
|
|
|
|
|
|
|
+ userEntity.setUserType(UserTypeEnum.WEB.getVal());
|
|
|
userEntity.setPassword("");
|
|
userEntity.setPassword("");
|
|
|
userEntity.setWorkspaceId(workSpaceId);
|
|
userEntity.setWorkspaceId(workSpaceId);
|
|
|
userEntity.setMqttUsername(mqttPropertyConfiguration.mqttConnectOptions().getUserName());
|
|
userEntity.setMqttUsername(mqttPropertyConfiguration.mqttConnectOptions().getUserName());
|
|
@@ -432,6 +442,72 @@ public class UserServiceImpl implements IUserService {
|
|
|
return HttpResultResponse.success(userDTO);
|
|
return HttpResultResponse.success(userDTO);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResultResponse savePilotUser(String username, String password,String workspaceId) {
|
|
|
|
|
+
|
|
|
|
|
+ if(!StringUtils.hasText(username)) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("用户名不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!StringUtils.hasText(password)) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("密码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(!StringUtils.hasText(workspaceId)) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("工作空间不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ UserEntity userEntity = getUserByUsername(username);
|
|
|
|
|
+ if(userEntity != null) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("用户已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Optional<WorkspaceDTO> workspace = workspaceService.getWorkspaceByWorkspaceId(workspaceId);
|
|
|
|
|
+ if(workspace.isEmpty()) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("工作空间不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ //密码加密
|
|
|
|
|
+ String salt = DesUtil.genSalt();
|
|
|
|
|
+ String encryptPsw = DesUtil.getEncryptData(password,salt);
|
|
|
|
|
+
|
|
|
|
|
+ long curTime = System.currentTimeMillis();
|
|
|
|
|
+ userEntity = UserEntity.builder().
|
|
|
|
|
+ userId(UUID.randomUUID().toString())
|
|
|
|
|
+ .username(username)
|
|
|
|
|
+ .password(encryptPsw)
|
|
|
|
|
+ .workspaceId(workspaceId)
|
|
|
|
|
+ .userType(UserTypeEnum.PILOT.getVal())
|
|
|
|
|
+ .mqttUsername(mqttPropertyConfiguration.mqttConnectOptions().getUserName())
|
|
|
|
|
+ .mqttPassword(String.valueOf(mqttPropertyConfiguration.mqttConnectOptions().getPassword()))
|
|
|
|
|
+ .createTime(curTime)
|
|
|
|
|
+ .updateTime(curTime)
|
|
|
|
|
+ .salt(salt)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ int cnt = mapper.insert(userEntity);
|
|
|
|
|
+ return cnt > 0 ? HttpResultResponse.success():HttpResultResponse.error("添加失败");
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResultResponse getPwd(String username) {
|
|
|
|
|
+ UserEntity userEntity = getUserByUsername(username);
|
|
|
|
|
+ if (userEntity == null) {
|
|
|
|
|
+ return new HttpResultResponse()
|
|
|
|
|
+ .setCode(HttpStatus.BAD_REQUEST.value())
|
|
|
|
|
+ .setMessage("用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ String decryptPwd = DesUtil.getDecryptData(userEntity.getPassword(),userEntity.getSalt());
|
|
|
|
|
+ return new HttpResultResponse().success(decryptPwd);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private UserEntity getApiUser(String clientId) {
|
|
private UserEntity getApiUser(String clientId) {
|
|
|
return mapper.selectOne(new QueryWrapper<UserEntity>()
|
|
return mapper.selectOne(new QueryWrapper<UserEntity>()
|
|
|
.eq("client_id", clientId)
|
|
.eq("client_id", clientId)
|