mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 20:28:44 +08:00 
			
		
		
		
	完善 AdminUserServiceImpl 单元测试
This commit is contained in:
		@@ -9,7 +9,6 @@ import org.springframework.stereotype.Service;
 | 
			
		||||
import javax.annotation.Resource;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Admin 用户 API 实现类
 | 
			
		||||
@@ -29,26 +28,26 @@ public class AdminUserApiImpl implements AdminUserApi {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserRespDTO> getUsers(Collection<Long> ids) {
 | 
			
		||||
        List<AdminUserDO> users = userService.getUsers(ids);
 | 
			
		||||
    public List<AdminUserRespDTO> getUserList(Collection<Long> ids) {
 | 
			
		||||
        List<AdminUserDO> users = userService.getUserList(ids);
 | 
			
		||||
        return UserConvert.INSTANCE.convertList4(users);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserRespDTO> getUsersByDeptIds(Collection<Long> deptIds) {
 | 
			
		||||
        List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds);
 | 
			
		||||
    public List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds) {
 | 
			
		||||
        List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
 | 
			
		||||
        return UserConvert.INSTANCE.convertList4(users);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserRespDTO> getUsersByPostIds(Collection<Long> postIds) {
 | 
			
		||||
        List<AdminUserDO> users = userService.getUsersByPostIds(postIds);
 | 
			
		||||
        List<AdminUserDO> users = userService.getUserListByPostIds(postIds);
 | 
			
		||||
        return UserConvert.INSTANCE.convertList4(users);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void validUsers(Set<Long> ids) {
 | 
			
		||||
        userService.validUsers(ids);
 | 
			
		||||
    public void validateUserList(Collection<Long> ids) {
 | 
			
		||||
        userService.validateUserList(ids);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -111,9 +111,9 @@ public class UserController {
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/list-all-simple")
 | 
			
		||||
    @ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项")
 | 
			
		||||
    public CommonResult<List<UserSimpleRespVO>> getSimpleUsers() {
 | 
			
		||||
    public CommonResult<List<UserSimpleRespVO>> getSimpleUserList() {
 | 
			
		||||
        // 获用户列表,只要开启状态的
 | 
			
		||||
        List<AdminUserDO> list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus());
 | 
			
		||||
        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);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断密码是否匹配
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 | 
			
		||||
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
 | 
			
		||||
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdatePasswordReqVO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.profile.UserProfileUpdateReqVO;
 | 
			
		||||
@@ -74,10 +74,6 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Resource
 | 
			
		||||
    private FileApi fileApi;
 | 
			
		||||
 | 
			
		||||
    @Resource
 | 
			
		||||
    @Lazy // 循环依赖(自己依赖自己),避免报错
 | 
			
		||||
    private AdminUserServiceImpl self;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public Long createUser(UserCreateReqVO reqVO) {
 | 
			
		||||
@@ -89,7 +85,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        // 校验正确性
 | 
			
		||||
        self.checkCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
 | 
			
		||||
        validateUserForCreateOrUpdate(null, reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
 | 
			
		||||
                reqVO.getDeptId(), reqVO.getPostIds());
 | 
			
		||||
        // 插入用户
 | 
			
		||||
        AdminUserDO user = UserConvert.INSTANCE.convert(reqVO);
 | 
			
		||||
@@ -108,7 +104,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void updateUser(UserUpdateReqVO reqVO) {
 | 
			
		||||
        // 校验正确性
 | 
			
		||||
        self.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
 | 
			
		||||
        validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(),
 | 
			
		||||
                reqVO.getDeptId(), reqVO.getPostIds());
 | 
			
		||||
        // 更新用户
 | 
			
		||||
        AdminUserDO updateObj = UserConvert.INSTANCE.convert(reqVO);
 | 
			
		||||
@@ -142,9 +138,9 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) {
 | 
			
		||||
        // 校验正确性
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        checkEmailUnique(id, reqVO.getEmail());
 | 
			
		||||
        checkMobileUnique(id, reqVO.getMobile());
 | 
			
		||||
        validateUserExists(id);
 | 
			
		||||
        validateEmailUnique(id, reqVO.getEmail());
 | 
			
		||||
        validateMobileUnique(id, reqVO.getMobile());
 | 
			
		||||
        // 执行更新
 | 
			
		||||
        userMapper.updateById(UserConvert.INSTANCE.convert(reqVO).setId(id));
 | 
			
		||||
    }
 | 
			
		||||
@@ -152,7 +148,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateUserPassword(Long id, UserProfileUpdatePasswordReqVO reqVO) {
 | 
			
		||||
        // 校验旧密码密码
 | 
			
		||||
        checkOldPassword(id, reqVO.getOldPassword());
 | 
			
		||||
        validateOldPassword(id, reqVO.getOldPassword());
 | 
			
		||||
        // 执行更新
 | 
			
		||||
        AdminUserDO updateObj = new AdminUserDO().setId(id);
 | 
			
		||||
        updateObj.setPassword(encodePassword(reqVO.getNewPassword())); // 加密密码
 | 
			
		||||
@@ -161,7 +157,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String updateUserAvatar(Long id, InputStream avatarFile) throws Exception {
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        validateUserExists(id);
 | 
			
		||||
        // 存储文件
 | 
			
		||||
        String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
 | 
			
		||||
        // 更新路径
 | 
			
		||||
@@ -175,7 +171,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateUserPassword(Long id, String password) {
 | 
			
		||||
        // 校验用户存在
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        validateUserExists(id);
 | 
			
		||||
        // 更新密码
 | 
			
		||||
        AdminUserDO updateObj = new AdminUserDO();
 | 
			
		||||
        updateObj.setId(id);
 | 
			
		||||
@@ -186,7 +182,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateUserStatus(Long id, Integer status) {
 | 
			
		||||
        // 校验用户存在
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        validateUserExists(id);
 | 
			
		||||
        // 更新状态
 | 
			
		||||
        AdminUserDO updateObj = new AdminUserDO();
 | 
			
		||||
        updateObj.setId(id);
 | 
			
		||||
@@ -198,7 +194,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class)
 | 
			
		||||
    public void deleteUser(Long id) {
 | 
			
		||||
        // 校验用户存在
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        validateUserExists(id);
 | 
			
		||||
        // 删除用户
 | 
			
		||||
        userMapper.deleteById(id);
 | 
			
		||||
        // 删除用户关联数据
 | 
			
		||||
@@ -228,7 +224,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsersByDeptIds(Collection<Long> deptIds) {
 | 
			
		||||
    public List<AdminUserDO> getUserListByDeptIds(Collection<Long> deptIds) {
 | 
			
		||||
        if (CollUtil.isEmpty(deptIds)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
@@ -236,7 +232,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsersByPostIds(Collection<Long> postIds) {
 | 
			
		||||
    public List<AdminUserDO> getUserListByPostIds(Collection<Long> postIds) {
 | 
			
		||||
        if (CollUtil.isEmpty(postIds)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
@@ -248,7 +244,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsers(Collection<Long> ids) {
 | 
			
		||||
    public List<AdminUserDO> getUserList(Collection<Long> ids) {
 | 
			
		||||
        if (CollUtil.isEmpty(ids)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
@@ -256,7 +252,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void validUsers(Set<Long> ids) {
 | 
			
		||||
    public void validateUserList(Collection<Long> ids) {
 | 
			
		||||
        if (CollUtil.isEmpty(ids)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -276,20 +272,15 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsers(UserExportReqVO reqVO) {
 | 
			
		||||
    public List<AdminUserDO> getUserList(UserExportReqVO reqVO) {
 | 
			
		||||
        return userMapper.selectList(reqVO, getDeptCondition(reqVO.getDeptId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsersByNickname(String nickname) {
 | 
			
		||||
    public List<AdminUserDO> getUserListByNickname(String nickname) {
 | 
			
		||||
        return userMapper.selectListByNickname(nickname);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsersByUsername(String username) {
 | 
			
		||||
        return userMapper.selectListByUsername(username);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 获得部门条件:查询指定部门的子部门编号们,包括自身
 | 
			
		||||
     * @param deptId 部门编号
 | 
			
		||||
@@ -305,25 +296,27 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
        return deptIds;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @DataPermission(enable = false) // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
 | 
			
		||||
    public void checkCreateOrUpdate(Long id, String username, String mobile, String email,
 | 
			
		||||
                                     Long deptId, Set<Long> postIds) {
 | 
			
		||||
        // 校验用户存在
 | 
			
		||||
        checkUserExists(id);
 | 
			
		||||
        // 校验用户名唯一
 | 
			
		||||
        checkUsernameUnique(id, username);
 | 
			
		||||
        // 校验手机号唯一
 | 
			
		||||
        checkMobileUnique(id, mobile);
 | 
			
		||||
        // 校验邮箱唯一
 | 
			
		||||
        checkEmailUnique(id, email);
 | 
			
		||||
        // 校验部门处于开启状态
 | 
			
		||||
        deptService.validateDeptList(CollectionUtils.singleton(deptId));
 | 
			
		||||
        // 校验岗位处于开启状态
 | 
			
		||||
        postService.validatePostList(postIds);
 | 
			
		||||
    private void validateUserForCreateOrUpdate(Long id, String username, String mobile, String email,
 | 
			
		||||
                                              Long deptId, Set<Long> postIds) {
 | 
			
		||||
        // 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
 | 
			
		||||
        DataPermissionUtils.executeIgnore(() -> {
 | 
			
		||||
            // 校验用户存在
 | 
			
		||||
            validateUserExists(id);
 | 
			
		||||
            // 校验用户名唯一
 | 
			
		||||
            validateUsernameUnique(id, username);
 | 
			
		||||
            // 校验手机号唯一
 | 
			
		||||
            validateMobileUnique(id, mobile);
 | 
			
		||||
            // 校验邮箱唯一
 | 
			
		||||
            validateEmailUnique(id, email);
 | 
			
		||||
            // 校验部门处于开启状态
 | 
			
		||||
            deptService.validateDeptList(CollectionUtils.singleton(deptId));
 | 
			
		||||
            // 校验岗位处于开启状态
 | 
			
		||||
            postService.validatePostList(postIds);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkUserExists(Long id) {
 | 
			
		||||
    void validateUserExists(Long id) {
 | 
			
		||||
        if (id == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -334,7 +327,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkUsernameUnique(Long id, String username) {
 | 
			
		||||
    void validateUsernameUnique(Long id, String username) {
 | 
			
		||||
        if (StrUtil.isBlank(username)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -352,7 +345,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkEmailUnique(Long id, String email) {
 | 
			
		||||
    void validateEmailUnique(Long id, String email) {
 | 
			
		||||
        if (StrUtil.isBlank(email)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -370,7 +363,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkMobileUnique(Long id, String mobile) {
 | 
			
		||||
    void validateMobileUnique(Long id, String mobile) {
 | 
			
		||||
        if (StrUtil.isBlank(mobile)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -393,7 +386,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
     * @param oldPassword 旧密码
 | 
			
		||||
     */
 | 
			
		||||
    @VisibleForTesting
 | 
			
		||||
    public void checkOldPassword(Long id, String oldPassword) {
 | 
			
		||||
    void validateOldPassword(Long id, String oldPassword) {
 | 
			
		||||
        AdminUserDO user = userMapper.selectById(id);
 | 
			
		||||
        if (user == null) {
 | 
			
		||||
            throw exception(USER_NOT_EXISTS);
 | 
			
		||||
@@ -405,7 +398,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
 | 
			
		||||
    public UserImportRespVO importUsers(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
 | 
			
		||||
    public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
 | 
			
		||||
        if (CollUtil.isEmpty(importUsers)) {
 | 
			
		||||
            throw exception(USER_IMPORT_LIST_IS_EMPTY);
 | 
			
		||||
        }
 | 
			
		||||
@@ -414,7 +407,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
        importUsers.forEach(importUser -> {
 | 
			
		||||
            // 校验,判断是否有不符合的原因
 | 
			
		||||
            try {
 | 
			
		||||
                checkCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
 | 
			
		||||
                validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
 | 
			
		||||
                        importUser.getDeptId(), null);
 | 
			
		||||
            } catch (ServiceException ex) {
 | 
			
		||||
                respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
 | 
			
		||||
@@ -442,7 +435,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<AdminUserDO> getUsersByStatus(Integer status) {
 | 
			
		||||
    public List<AdminUserDO> getUserListByStatus(Integer status) {
 | 
			
		||||
        return userMapper.selectListByStatus(status);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user