mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-29 18:48:13 +08:00
refactor(系统设置): 用户管理批量操作接口返回值简化
This commit is contained in:
parent
5b2831bb64
commit
5c9cacf508
@ -2,11 +2,8 @@ package io.metersphere.system.dto.response;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserBatchProcessResponse {
|
public class UserBatchProcessResponse {
|
||||||
private long totalCount;
|
private long totalCount;
|
||||||
private long successCount;
|
private long successCount;
|
||||||
private List<String> processedIds;
|
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,6 @@ public class GlobalUserRoleRelationService extends BaseUserRoleRelationService {
|
|||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getUserIds().size());
|
||||||
response.setSuccessCount(saveList.size());
|
response.setSuccessCount(saveList.size());
|
||||||
response.setProcessedIds(saveList.stream().map(UserRoleRelation::getUserId).collect(Collectors.toList()));
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,7 +211,6 @@ public class UserService {
|
|||||||
updateUser.setUpdateUser(operator);
|
updateUser.setUpdateUser(operator);
|
||||||
updateUser.setUpdateTime(System.currentTimeMillis());
|
updateUser.setUpdateTime(System.currentTimeMillis());
|
||||||
response.setSuccessCount(userMapper.updateByExampleSelective(updateUser, userExample));
|
response.setSuccessCount(userMapper.updateByExampleSelective(updateUser, userExample));
|
||||||
response.setProcessedIds(request.getUserIds());
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +292,6 @@ public class UserService {
|
|||||||
//更新删除标志位
|
//更新删除标志位
|
||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
||||||
response.setTotalCount(userIdList.size());
|
response.setTotalCount(userIdList.size());
|
||||||
response.setProcessedIds(userIdList);
|
|
||||||
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
response.setSuccessCount(this.deleteUserByList(userIdList, operator));
|
||||||
//删除用户角色关系
|
//删除用户角色关系
|
||||||
userRoleRelationService.deleteByUserIdList(userIdList);
|
userRoleRelationService.deleteByUserIdList(userIdList);
|
||||||
@ -455,7 +453,6 @@ public class UserService {
|
|||||||
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
UserBatchProcessResponse response = new UserBatchProcessResponse();
|
||||||
response.setTotalCount(request.getUserIds().size());
|
response.setTotalCount(request.getUserIds().size());
|
||||||
response.setSuccessCount(request.getUserIds().size());
|
response.setSuccessCount(request.getUserIds().size());
|
||||||
response.setProcessedIds(request.getUserIds());
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,7 +611,8 @@ public class UserControllerTests extends BaseTest {
|
|||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
UserBatchProcessResponse.class
|
UserBatchProcessResponse.class
|
||||||
);
|
);
|
||||||
List<User> userList = userService.selectByIdList(response.getProcessedIds());
|
Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), 1);
|
||||||
|
List<User> userList = userService.selectByIdList(Collections.singletonList(userId));
|
||||||
for (User checkUser : userList) {
|
for (User checkUser : userList) {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
||||||
@ -628,7 +629,14 @@ public class UserControllerTests extends BaseTest {
|
|||||||
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
this.requestPostAndReturn(userRequestUtils.URL_USER_RESET_PASSWORD, request),
|
||||||
UserBatchProcessResponse.class
|
UserBatchProcessResponse.class
|
||||||
);
|
);
|
||||||
List<User> userList = userService.selectByIdList(response.getProcessedIds());
|
UserExample example = new UserExample();
|
||||||
|
example.createCriteria().andIdNotEqualTo("admin");
|
||||||
|
long count = userMapper.countByExample(example);
|
||||||
|
Assertions.assertEquals(response.getTotalCount(), response.getSuccessCount(), count);
|
||||||
|
|
||||||
|
example.clear();
|
||||||
|
example.createCriteria().andIdNotEqualTo("admin");
|
||||||
|
List<User> userList = userMapper.selectByExample(example);
|
||||||
for (User checkUser : userList) {
|
for (User checkUser : userList) {
|
||||||
UserExample userExample = new UserExample();
|
UserExample userExample = new UserExample();
|
||||||
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
userExample.createCriteria().andIdEqualTo(checkUser.getId()).andPasswordEqualTo(CodingUtil.md5(checkUser.getEmail()));
|
||||||
@ -731,12 +739,8 @@ public class UserControllerTests extends BaseTest {
|
|||||||
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample example = new UserExample();
|
User user = userMapper.selectByPrimaryKey(deleteUser.getId());
|
||||||
example.createCriteria().andIdIn(response.getProcessedIds());
|
Assertions.assertTrue(user.getDeleted());
|
||||||
List<User> userList = userMapper.selectByExample(example);
|
|
||||||
for (User user : userList) {
|
|
||||||
Assertions.assertTrue(user.getDeleted());
|
|
||||||
}
|
|
||||||
USER_LIST.remove(deleteUser);
|
USER_LIST.remove(deleteUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -746,11 +750,10 @@ public class UserControllerTests extends BaseTest {
|
|||||||
request.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
request.setUserIds(USER_LIST.stream().map(UserCreateInfo::getId).collect(Collectors.toList()));
|
||||||
request.setSkipIds(Collections.singletonList("admin"));
|
request.setSkipIds(Collections.singletonList("admin"));
|
||||||
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), UserBatchProcessResponse.class);
|
UserBatchProcessResponse response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responsePost(userRequestUtils.URL_USER_DELETE, request), UserBatchProcessResponse.class);
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount());
|
Assertions.assertEquals(request.getUserIds().size(), response.getTotalCount(), response.getSuccessCount());
|
||||||
Assertions.assertEquals(request.getUserIds().size(), response.getSuccessCount());
|
|
||||||
//检查数据库
|
//检查数据库
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
example.createCriteria().andIdIn(response.getProcessedIds());
|
example.createCriteria().andIdIn(request.getUserIds());
|
||||||
List<User> userList = userMapper.selectByExample(example);
|
List<User> userList = userMapper.selectByExample(example);
|
||||||
for (User user : userList) {
|
for (User user : userList) {
|
||||||
Assertions.assertTrue(user.getDeleted());
|
Assertions.assertTrue(user.getDeleted());
|
||||||
@ -759,7 +762,7 @@ public class UserControllerTests extends BaseTest {
|
|||||||
//记录已经删除了的用户,用于反例
|
//记录已经删除了的用户,用于反例
|
||||||
DELETED_USER_ID_LIST.clear();
|
DELETED_USER_ID_LIST.clear();
|
||||||
USER_LIST.clear();
|
USER_LIST.clear();
|
||||||
DELETED_USER_ID_LIST.addAll(response.getProcessedIds());
|
DELETED_USER_ID_LIST.addAll(request.getUserIds());
|
||||||
//检查删除了的用户,可以用其邮箱继续注册
|
//检查删除了的用户,可以用其邮箱继续注册
|
||||||
this.testAddSuccess();
|
this.testAddSuccess();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user