mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 21:32:07 +08:00
处理新增用户的异常
This commit is contained in:
+5
-2
@@ -199,9 +199,12 @@ public class UserController {
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('system:user:import')")
|
||||
public CommonResult<UserImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
|
||||
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
|
||||
@RequestParam(value = "organId", required = false) Long organId
|
||||
) throws Exception {
|
||||
List<UserImportExcelVO> list = ExcelUtils.read(file, UserImportExcelVO.class);
|
||||
return success(userService.importUserList(list, updateSupport));
|
||||
organId = organId==null? OrganContextHolder.getOrganId() : organId;
|
||||
return success(userService.importUserList(list, updateSupport, organId));
|
||||
}
|
||||
|
||||
@GetMapping("/list-terms-simple")
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ public interface AdminUserService {
|
||||
* @param isUpdateSupport 是否支持更新
|
||||
* @return 导入结果
|
||||
*/
|
||||
UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport);
|
||||
UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport, Long organId);
|
||||
|
||||
/**
|
||||
* 获得指定状态的用户们
|
||||
|
||||
+13
-12
@@ -128,10 +128,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUser(UserSaveReqVO updateReqVO) {
|
||||
Long organId = updateReqVO.getOrganId() == null ? OrganContextHolder.getOrganId(): updateReqVO.getOrganId();
|
||||
updateReqVO.setPassword(null); // 特殊:此处不更新密码
|
||||
// 校验正确性
|
||||
validateUserForCreateOrUpdate(updateReqVO.getId(), updateReqVO.getUsername(),
|
||||
updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds(), updateReqVO.getOrganId());
|
||||
updateReqVO.getMobile(), updateReqVO.getEmail(), updateReqVO.getDeptId(), updateReqVO.getPostIds(), organId);
|
||||
// 更新用户
|
||||
AdminUserDO updateObj = BeanUtils.toBean(updateReqVO, AdminUserDO.class);
|
||||
|
||||
@@ -174,10 +175,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
public void updateUserProfile(Long id, UserProfileUpdateReqVO reqVO) {
|
||||
Long organId = reqVO.getOrganId() == null ? OrganContextHolder.getOrganId() : reqVO.getOrganId();
|
||||
// 校验正确性
|
||||
validateUserExists(id);
|
||||
validateEmailUnique(id, reqVO.getEmail());
|
||||
validateMobileUnique(id, reqVO.getMobile());
|
||||
validateEmailUnique(id, reqVO.getEmail(), organId);
|
||||
validateMobileUnique(id, reqVO.getMobile(), organId);
|
||||
// 执行更新
|
||||
userMapper.updateById(BeanUtils.toBean(reqVO, AdminUserDO.class).setId(id));
|
||||
}
|
||||
@@ -356,9 +358,9 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
// 校验用户名唯一
|
||||
validateUsernameUnique(id, username, organId);
|
||||
// 校验手机号唯一
|
||||
validateMobileUnique(id, mobile);
|
||||
validateMobileUnique(id, mobile, organId);
|
||||
// 校验邮箱唯一
|
||||
validateEmailUnique(id, email);
|
||||
validateEmailUnique(id, email, organId);
|
||||
// 校验部门处于开启状态
|
||||
deptService.validateDeptList(CollectionUtils.singleton(deptId));
|
||||
// 校验岗位处于开启状态
|
||||
@@ -397,11 +399,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateEmailUnique(Long id, String email) {
|
||||
void validateEmailUnique(Long id, String email, Long organId) {
|
||||
if (StrUtil.isBlank(email)) {
|
||||
return;
|
||||
}
|
||||
AdminUserDO user = userMapper.selectByEmail(email);
|
||||
AdminUserDO user = userMapper.selectOne(AdminUserDO::getOrganId, organId, AdminUserDO::getEmail, email);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
@@ -415,11 +417,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateMobileUnique(Long id, String mobile) {
|
||||
void validateMobileUnique(Long id, String mobile, Long organId) {
|
||||
if (StrUtil.isBlank(mobile)) {
|
||||
return;
|
||||
}
|
||||
AdminUserDO user = userMapper.selectByMobile(mobile);
|
||||
AdminUserDO user = userMapper.selectOne(AdminUserDO::getOrganId, organId, AdminUserDO::getMobile, mobile);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
@@ -451,7 +453,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
||||
public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) {
|
||||
public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport, Long organId) {
|
||||
if (CollUtil.isEmpty(importUsers)) {
|
||||
throw ServiceExceptionUtil.exception(ErrorCodeConstants.USER_IMPORT_LIST_IS_EMPTY);
|
||||
}
|
||||
@@ -461,12 +463,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
// 校验,判断是否有不符合的原因
|
||||
try {
|
||||
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(),
|
||||
importUser.getDeptId(), null, null);
|
||||
importUser.getDeptId(), null, organId);
|
||||
} catch (ServiceException ex) {
|
||||
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage());
|
||||
return;
|
||||
}
|
||||
Long organId = SecurityFrameworkUtils.getLoginUser().getOrganId();
|
||||
// 判断如果不存在,在进行插入
|
||||
AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername(), organId);
|
||||
if (existUser == null) {
|
||||
|
||||
Reference in New Issue
Block a user