提交 5619441f authored 作者: YunaiV's avatar YunaiV

完善 AdminUserServiceImpl 单元测试

上级 6474fba9
package cn.iocoder.yudao.framework.datapermission.core.util;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder;
import lombok.SneakyThrows;
/**
* 数据权限 Util
*
* @author 芋道源码
*/
public class DataPermissionUtils {
private static DataPermission DATA_PERMISSION_DISABLE;
@DataPermission(enable = false)
@SneakyThrows
private static DataPermission getDisableDataPermissionDisable() {
if (DATA_PERMISSION_DISABLE == null) {
DATA_PERMISSION_DISABLE = DataPermissionUtils.class
.getDeclaredMethod("getDisableDataPermissionDisable")
.getAnnotation(DataPermission.class);
}
return DATA_PERMISSION_DISABLE;
}
/**
* 忽略数据权限,执行对应的逻辑
*
* @param runnable 逻辑
*/
public static void executeIgnore(Runnable runnable) {
DataPermission dataPermission = getDisableDataPermissionDisable();
DataPermissionContextHolder.add(dataPermission);
try {
// 执行 runnable
runnable.run();
} finally {
DataPermissionContextHolder.remove();
}
}
}
package cn.iocoder.yudao.framework.datapermission.core.utils;
import cn.iocoder.yudao.framework.datapermission.core.aop.DataPermissionContextHolder;
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class DataPermissionUtilsTest {
@Test
public void testExecuteIgnore() {
DataPermissionUtils.executeIgnore(() -> assertFalse(DataPermissionContextHolder.get().enable()));
}
}
......@@ -220,7 +220,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
} else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.POST.getType())) {
postApi.validPostList(options);
} else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER.getType())) {
adminUserApi.validUsers(options);
adminUserApi.validUserList(options);
} else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.USER_GROUP.getType())) {
userGroupService.validUserGroups(options);
} else if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.SCRIPT.getType())) {
......@@ -288,7 +288,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
}
private Set<Long> calculateTaskCandidateUsersByDeptMember(BpmTaskAssignRuleDO rule) {
List<AdminUserRespDTO> users = adminUserApi.getUsersByDeptIds(rule.getOptions()).getCheckedData();
List<AdminUserRespDTO> users = adminUserApi.getUserListByDeptIds(rule.getOptions()).getCheckedData();
return convertSet(users, AdminUserRespDTO::getId);
}
......@@ -298,7 +298,7 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService {
}
private Set<Long> calculateTaskCandidateUsersByPost(BpmTaskAssignRuleDO rule) {
List<AdminUserRespDTO> users = adminUserApi.getUsersByPostIds(rule.getOptions()).getCheckedData();
List<AdminUserRespDTO> users = adminUserApi.getUserListByPostIds(rule.getOptions()).getCheckedData();
return convertSet(users, AdminUserRespDTO::getId);
}
......
......@@ -87,7 +87,7 @@ public class BpmTaskAssignRuleServiceImplTest extends BaseDbUnitTest {
// mock 方法
List<AdminUserRespDTO> users = CollectionUtils.convertList(asSet(11L, 22L),
id -> new AdminUserRespDTO().setId(id));
when(adminUserApi.getUsersByDeptIds(eq(rule.getOptions()))).thenReturn(success(users));
when(adminUserApi.getUserListByDeptIds(eq(rule.getOptions()))).thenReturn(success(users));
mockGetUserMap(asSet(11L, 22L));
// 调用
......@@ -121,7 +121,7 @@ public class BpmTaskAssignRuleServiceImplTest extends BaseDbUnitTest {
// mock 方法
List<AdminUserRespDTO> users = CollectionUtils.convertList(asSet(11L, 22L),
id -> new AdminUserRespDTO().setId(id));
when(adminUserApi.getUsersByPostIds(eq(rule.getOptions()))).thenReturn(success(users));
when(adminUserApi.getUserListByPostIds(eq(rule.getOptions()))).thenReturn(success(users));
mockGetUserMap(asSet(11L, 22L));
// 调用
......
......@@ -30,17 +30,17 @@ public interface AdminUserApi {
@GetMapping(PREFIX + "/list")
@ApiOperation("通过用户 ID 查询用户们")
@ApiImplicitParam(name = "ids", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
CommonResult<List<AdminUserRespDTO>> getUsers(@RequestParam("ids") Collection<Long> ids);
CommonResult<List<AdminUserRespDTO>> getUserList(@RequestParam("ids") Collection<Long> ids);
@GetMapping(PREFIX + "/list-by-dept-id")
@ApiOperation("获得指定部门的用户数组")
@ApiImplicitParam(name = "deptIds", value = "部门编号数组", example = "1,2", required = true, allowMultiple = true)
CommonResult<List<AdminUserRespDTO>> getUsersByDeptIds(@RequestParam("deptIds") Collection<Long> deptIds);
CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(@RequestParam("deptIds") Collection<Long> deptIds);
@GetMapping(PREFIX + "/list-by-post-id")
@ApiOperation("获得指定岗位的用户数组")
@ApiImplicitParam(name = "postIds", value = "岗位编号数组", example = "2,3", required = true, allowMultiple = true)
CommonResult<List<AdminUserRespDTO>> getUsersByPostIds(@RequestParam("postIds") Collection<Long> postIds);
CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(@RequestParam("postIds") Collection<Long> postIds);
/**
* 获得用户 Map
......@@ -49,12 +49,12 @@ public interface AdminUserApi {
* @return 用户 Map
*/
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
return CollectionUtils.convertMap(getUsers(ids).getCheckedData(), AdminUserRespDTO::getId);
return CollectionUtils.convertMap(getUserList(ids).getCheckedData(), AdminUserRespDTO::getId);
}
@GetMapping(PREFIX + "/valid")
@ApiOperation("校验用户们是否有效")
@ApiImplicitParam(name = "ids", value = "用户编号数组", example = "3,5", required = true)
CommonResult<Boolean> validUsers(@RequestParam("ids") Set<Long> ids);
CommonResult<Boolean> validUserList(@RequestParam("ids") Set<Long> ids);
}
......@@ -33,26 +33,26 @@ public class AdminUserApiImpl implements AdminUserApi {
}
@Override
public CommonResult<List<AdminUserRespDTO>> getUsers(Collection<Long> ids) {
List<AdminUserDO> users = userService.getUsers(ids);
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) {
List<AdminUserDO> users = userService.getUserList(ids);
return success(UserConvert.INSTANCE.convertList4(users));
}
@Override
public CommonResult<List<AdminUserRespDTO>> getUsersByDeptIds(Collection<Long> deptIds) {
List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds);
public CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(Collection<Long> deptIds) {
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
return success(UserConvert.INSTANCE.convertList4(users));
}
@Override
public CommonResult<List<AdminUserRespDTO>> getUsersByPostIds(Collection<Long> postIds) {
List<AdminUserDO> users = userService.getUsersByPostIds(postIds);
public CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(Collection<Long> postIds) {
List<AdminUserDO> users = userService.getUserListByPostIds(postIds);
return success(UserConvert.INSTANCE.convertList4(users));
}
@Override
public CommonResult<Boolean> validUsers(Set<Long> ids) {
userService.validUsers(ids);
public CommonResult<Boolean> validUserList(Set<Long> ids) {
userService.validateUserList(ids);
return success(true);
}
......
......@@ -111,9 +111,9 @@ public class UserController {
@GetMapping("/list-all-simple")
@ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项")
public CommonResult<List<UserSimpleRespVO>> getSimpleUsers() {
// 获用户列表,只要开启状态的
List<AdminUserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus());
public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
// 获用户列表,只要开启状态的
List<AdminUserDO> list = userService.getUserListByStatus(CommonStatusEnum.ENABLE.getStatus());
// 排序后,返回给前端
return success(UserConvert.INSTANCE.convertList04(list));
}
......@@ -122,7 +122,7 @@ public class UserController {
@ApiOperation("获得用户详情")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('system:user:query')")
public CommonResult<UserRespVO> getInfo(@RequestParam("id") Long id) {
public CommonResult<UserRespVO> getUser(@RequestParam("id") Long id) {
return success(UserConvert.INSTANCE.convert(userService.getUser(id)));
}
......@@ -130,10 +130,10 @@ public class UserController {
@ApiOperation("导出用户")
@PreAuthorize("@ss.hasPermission('system:user:export')")
@OperateLog(type = EXPORT)
public void exportUsers(@Validated UserExportReqVO reqVO,
HttpServletResponse response) throws IOException {
public void exportUserList(@Validated UserExportReqVO reqVO,
HttpServletResponse response) throws IOException {
// 获得用户列表
List<AdminUserDO> users = userService.getUsers(reqVO);
List<AdminUserDO> users = userService.getUserList(reqVO);
// 获得拼接需要的数据
Collection<Long> deptIds = convertList(users, AdminUserDO::getDeptId);
......@@ -183,7 +183,7 @@ public class UserController {
public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class);
return success(userService.importUsers(list, updateSupport));
return success(userService.importUserList(list, updateSupport));
}
}
......@@ -6,7 +6,6 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserExportReqVO;
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
......@@ -16,15 +15,15 @@ import java.util.List;
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
default AdminUserDO selectByUsername(String username) {
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getUsername, username));
return selectOne(AdminUserDO::getUsername, username);
}
default AdminUserDO selectByEmail(String email) {
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getEmail, email));
return selectOne(AdminUserDO::getEmail, email);
}
default AdminUserDO selectByMobile(String mobile) {
return selectOne(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getMobile, mobile));
return selectOne(AdminUserDO::getMobile, mobile);
}
default PageResult<AdminUserDO> selectPage(UserPageReqVO reqVO, Collection<Long> deptIds) {
......@@ -50,10 +49,6 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getNickname, nickname));
}
default List<AdminUserDO> selectListByUsername(String username) {
return selectList(new LambdaQueryWrapperX<AdminUserDO>().like(AdminUserDO::getUsername, username));
}
default List<AdminUserDO> selectListByStatus(Integer status) {
return selectList(AdminUserDO::getStatus, status);
}
......
......@@ -49,7 +49,7 @@ public class OperateLogServiceImpl implements OperateLogService {
// 处理基于用户昵称的查询
Collection<Long> userIds = null;
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
if (CollUtil.isEmpty(userIds)) {
return PageResult.empty();
}
......@@ -63,7 +63,7 @@ public class OperateLogServiceImpl implements OperateLogService {
// 处理基于用户昵称的查询
Collection<Long> userIds = null;
if (StrUtil.isNotEmpty(reqVO.getUserNickname())) {
userIds = convertSet(userService.getUsersByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
userIds = convertSet(userService.getUserListByNickname(reqVO.getUserNickname()), AdminUserDO::getId);
if (CollUtil.isEmpty(userIds)) {
return Collections.emptyList();
}
......
......@@ -127,7 +127,7 @@ public interface AdminUserService {
* @param deptIds 部门数组
* @return 用户数组
*/
List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds);
List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds);
/**
* 获得指定岗位的用户数组
......@@ -135,7 +135,7 @@ public interface AdminUserService {
* @param postIds 岗位数组
* @return 用户数组
*/
List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds);
List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds);
/**
* 获得用户列表
......@@ -143,7 +143,7 @@ public interface AdminUserService {
* @param ids 用户编号数组
* @return 用户列表
*/
List<AdminUserDO> getUsers(Collection<Long> ids);
List<AdminUserDO> getUserList(Collection<Long> ids);
/**
* 校验用户们是否有效。如下情况,视为无效:
......@@ -152,7 +152,7 @@ public interface AdminUserService {
*
* @param ids 用户编号数组
*/
void validUsers(Set<Long> ids);
void validateUserList(Collection<Long> ids);
/**
* 获得用户 Map
......@@ -164,7 +164,7 @@ public interface AdminUserService {
if (CollUtil.isEmpty(ids)) {
return new HashMap<>();
}
return CollectionUtils.convertMap(getUsers(ids), AdminUserDO::getId);
return CollectionUtils.convertMap(getUserList(ids), AdminUserDO::getId);
}
/**
......@@ -173,7 +173,7 @@ public interface AdminUserService {
* @param reqVO 列表请求
* @return 用户列表
*/
List<AdminUserDO> getUsers(UserExportReqVO reqVO);
List<AdminUserDO> getUserList(UserExportReqVO reqVO);
/**
* 获得用户列表,基于昵称模糊匹配
......@@ -181,15 +181,7 @@ public interface AdminUserService {
* @param nickname 昵称
* @return 用户列表
*/
List<AdminUserDO> getUsersByNickname(String nickname);
/**
* 获得用户列表,基于用户账号模糊匹配
*
* @param username 用户账号
* @return 用户列表
*/
List<AdminUserDO> getUsersByUsername(String username);
List<AdminUserDO> getUserListByNickname(String nickname);
/**
* 批量导入用户
......@@ -198,7 +190,7 @@ public interface AdminUserService {
* @param isUpdateSupport 是否支持更新
* @return 导入结果
*/
UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
/**
* 获得指定状态的用户们
......@@ -206,7 +198,7 @@ public interface AdminUserService {
* @param status 状态
* @return 用户们
*/
List<AdminUserDO> getUsersByStatus(Integer status);
List<AdminUserDO> getUserListByStatus(Integer status);
/**
* 判断密码是否匹配
......
......@@ -64,7 +64,7 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest {
o.setNickname("wang");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
});
when(userService.getUsersByNickname("wang")).thenReturn(Collections.singletonList(user));
when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user));
Long userId = user.getId();
// 构造操作日志
......@@ -112,7 +112,7 @@ public class OperateLogServiceImplTest extends BaseDbUnitTest {
o.setNickname("wang");
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
});
when(userService.getUsersByNickname("wang")).thenReturn(Collections.singletonList(user));
when(userService.getUserListByNickname("wang")).thenReturn(Collections.singletonList(user));
Long userId = user.getId();
// 构造操作日志
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论