|
|
@ -398,17 +398,17 @@ public class AdminUserServiceImpl implements AdminUserService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
|
public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, Integer mode, boolean updatePart) { |
|
|
|
public List<UserImportExcelVO> importUserList(List<UserImportExcelVO> importUsers, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(importUsers)) { |
|
|
|
throw exception(USER_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()).updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); |
|
|
|
List<UserImportExcelVO> errorList = new ArrayList<>(); |
|
|
|
importUsers.forEach(importUser -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), importUser.getDeptId(), null); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); |
|
|
|
errorList.add(importUser); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
@ -416,19 +416,17 @@ public class AdminUserServiceImpl implements AdminUserService { |
|
|
|
//不存在并非覆盖类型
|
|
|
|
if (existUser == null && mode != 3) { |
|
|
|
userMapper.insert(UserConvert.INSTANCE.convert(importUser).setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
|
|
|
|
respVO.getCreateUsernames().add(importUser.getUsername()); |
|
|
|
} else if (existUser != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
AdminUserDO updateUser = UserConvert.INSTANCE.convert(importUser); |
|
|
|
updateUser.setId(existUser.getId()); |
|
|
|
userMapper.updateById(updateUser); |
|
|
|
respVO.getUpdateUsernames().add(importUser.getUsername()); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(respVO.getUpdateUsernames().isEmpty() && !updatePart) { |
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return respVO; |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|