|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.io.IoUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.win.framework.common.enums.CommonStatusEnum; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
@ -23,13 +24,13 @@ import com.win.module.system.service.dept.DeptService; |
|
|
|
import com.win.module.system.service.dept.PostService; |
|
|
|
import com.win.module.system.service.permission.PermissionService; |
|
|
|
import com.win.module.system.service.tenant.TenantService; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.InputStream; |
|
|
@ -397,39 +398,36 @@ public class AdminUserServiceImpl implements AdminUserService { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
|
public UserImportRespVO importUserList(List<UserImportExcelVO> importUsers, boolean isUpdateSupport) { |
|
|
|
public UserImportRespVO 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(); |
|
|
|
UserImportRespVO respVO = UserImportRespVO.builder().createUsernames(new ArrayList<>()).updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build(); |
|
|
|
importUsers.forEach(importUser -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
try { |
|
|
|
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), |
|
|
|
importUser.getDeptId(), null); |
|
|
|
validateUserForCreateOrUpdate(null, null, importUser.getMobile(), importUser.getEmail(), importUser.getDeptId(), null); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
respVO.getFailureUsernames().put(importUser.getUsername(), ex.getMessage()); |
|
|
|
return; |
|
|
|
} |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername()); |
|
|
|
if (existUser == null) { |
|
|
|
userMapper.insert(UserConvert.INSTANCE.convert(importUser) |
|
|
|
.setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
|
|
|
|
//不存在并非覆盖类型
|
|
|
|
if (existUser == null && mode != 3) { |
|
|
|
userMapper.insert(UserConvert.INSTANCE.convert(importUser).setPassword(encodePassword(userInitPassword)).setPostIds(new HashSet<>())); // 设置默认密码及空岗位编号数组
|
|
|
|
respVO.getCreateUsernames().add(importUser.getUsername()); |
|
|
|
return; |
|
|
|
} 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 (!isUpdateSupport) { |
|
|
|
respVO.getFailureUsernames().put(importUser.getUsername(), USER_USERNAME_EXISTS.getMsg()); |
|
|
|
return; |
|
|
|
} |
|
|
|
AdminUserDO updateUser = UserConvert.INSTANCE.convert(importUser); |
|
|
|
updateUser.setId(existUser.getId()); |
|
|
|
userMapper.updateById(updateUser); |
|
|
|
respVO.getUpdateUsernames().add(importUser.getUsername()); |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(respVO.getUpdateUsernames().isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return respVO; |
|
|
|
} |
|
|
|
|
|
|
|