Compare commits

..

No commits in common. "c494013360a31ee8747225afd9e8abf98b9559a3" and "85b2be2b790937352565f0168b8c78d3d20b2a08" have entirely different histories.

2 changed files with 11 additions and 46 deletions

View File

@ -118,15 +118,8 @@ public class UserController {
@ApiOperation("导入用户列表") @ApiOperation("导入用户列表")
@PostMapping("/importUserTable") @PostMapping("/importUserTable")
public Response importUserTable(@RequestPart(value = "file") MultipartFile file) { public Response importUserTable(@RequestPart(value = "file") MultipartFile file, @RequestPart(value = "corpFlag") Integer corpFlag) {
userService.importUserTable(file, 1); userService.importUserTable(file, corpFlag);
return SingleResponse.buildSuccess();
}
@ApiOperation("导入用户列表")
@PostMapping("/importUserTableByCorp2")
public Response importUserTableByCorp2(@RequestPart(value = "file") MultipartFile file) {
userService.importUserTable(file, 2);
return SingleResponse.buildSuccess(); return SingleResponse.buildSuccess();
} }

View File

@ -6,10 +6,8 @@ import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cola.dto.MultiResponse; import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.exception.BizException; import com.alibaba.cola.exception.BizException;
import com.jjb.saas.framework.auth.utils.AuthContext; import com.jjb.saas.framework.auth.utils.AuthContext;
import com.jjb.saas.system.client.dept.facade.DeptFacade;
import com.jjb.saas.system.client.role.facade.RoleFacade; import com.jjb.saas.system.client.role.facade.RoleFacade;
import com.jjb.saas.system.client.role.response.RoleCO; import com.jjb.saas.system.client.role.response.RoleCO;
import com.jjb.saas.system.client.user.facade.UserFacade;
import com.zcloud.basic.info.domain.gateway.DepartmentGateway; import com.zcloud.basic.info.domain.gateway.DepartmentGateway;
import com.zcloud.basic.info.domain.gateway.PostGateway; import com.zcloud.basic.info.domain.gateway.PostGateway;
import com.zcloud.basic.info.domain.gateway.UserEmploymentLogGateway; import com.zcloud.basic.info.domain.gateway.UserEmploymentLogGateway;
@ -62,10 +60,6 @@ public class UserImportExe {
private final DepartmentGateway departmentGateway; private final DepartmentGateway departmentGateway;
@DubboReference @DubboReference
private RoleFacade roleFacade; private RoleFacade roleFacade;
@DubboReference
private DeptFacade deptFacade;
@DubboReference
private UserFacade userFacade;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void importUserTable(MultipartFile file, Integer corpFlag) { public void importUserTable(MultipartFile file, Integer corpFlag) {
@ -82,12 +76,10 @@ public class UserImportExe {
} }
// 部门数据 // 部门数据
List<DepartmentDO> departmentDOList = departmentRepository.listByCorpInfoId(corpinfoId); List<DepartmentDO> departmentDOList = departmentRepository.listByCorpInfoId(corpinfoId);
List<DepartmentDO> departmentDOTempList = new ArrayList<>();
// 岗位数据 // 岗位数据
List<PostDO> postDOList = postRepository.listByCorpInfoId(corpinfoId); List<PostDO> postDOList = postRepository.listByCorpInfoId(corpinfoId);
// 用户名数据 // 用户名数据
List<UserDO> userDOList = userRepository.listByCorpInfoId(corpinfoId); List<UserDO> userDOList = userRepository.listByCorpInfoId(corpinfoId);
List<UserDO> userDOTempList = new ArrayList<>();
List<UserExcelImportEntity> list = new ArrayList<>(); List<UserExcelImportEntity> list = new ArrayList<>();
try { try {
@ -102,19 +94,8 @@ public class UserImportExe {
// 开始处理导入逻辑 // 开始处理导入逻辑
for (UserExcelImportEntity importEntity : list) { for (UserExcelImportEntity importEntity : list) {
try { try {
processSingleUser(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentDOList, departmentDOTempList, postDOList, userDOList, userDOTempList, roleCOMultiResponse.getData()); processSingleUser(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentDOList, postDOList, userDOList, roleCOMultiResponse.getData());
} catch (Exception e) { } catch (Exception e) {
if(CollUtil.isNotEmpty(departmentDOTempList)){
// 删除底座创建的部门
for (DepartmentDO departmentDO : departmentDOTempList) {
deptFacade.deleteById(departmentDO.getId());
}
}
if(CollUtil.isNotEmpty(userDOTempList)){
for (UserDO userDO : userDOTempList) {
userFacade.delete(userDO.getId());
}
}
throw new BizException("导入该用户失败: " + importEntity.getUsername() + ", 原因: " + e.getMessage()); throw new BizException("导入该用户失败: " + importEntity.getUsername() + ", 原因: " + e.getMessage());
} }
} }
@ -126,15 +107,11 @@ public class UserImportExe {
private void processSingleUser(UserExcelImportEntity importEntity, Integer corpFlag, private void processSingleUser(UserExcelImportEntity importEntity, Integer corpFlag,
Long corpinfoId, Long corpinfoId,
CorpInfoDO corpInfoDO, CorpInfoDO corpInfoDO,
List<DepartmentDO> departmentDOList, List<DepartmentDO> departmentDOList, List<PostDO> postDOList,
List<DepartmentDO> departmentDOTempList, List<UserDO> userDOList, List<RoleCO> roleList) {
List<PostDO> postDOList,
List<UserDO> userDOList,
List<UserDO> userDOTempList,
List<RoleCO> roleList) {
// 1. 处理部门层级获取最终部门ID // 1. 处理部门层级获取最终部门ID
Long departmentId = processDepartmentHierarchy(importEntity, corpinfoId, departmentDOList, departmentDOTempList); Long departmentId = processDepartmentHierarchy(importEntity, corpinfoId, departmentDOList);
// 2. 处理岗位获取岗位ID // 2. 处理岗位获取岗位ID
Long postId = processPost(importEntity, corpinfoId, corpInfoDO, departmentId, postDOList); Long postId = processPost(importEntity, corpinfoId, corpInfoDO, departmentId, postDOList);
@ -143,15 +120,14 @@ public class UserImportExe {
Long roleId = processRoleInfo(importEntity, roleList); Long roleId = processRoleInfo(importEntity, roleList);
// 4. 处理用户信息 // 4. 处理用户信息
processUserInfo(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentId, postId, userDOList, userDOTempList, roleId); processUserInfo(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentId, postId, userDOList, roleId);
} }
/** /**
* *
*/ */
private Long processDepartmentHierarchy(UserExcelImportEntity importEntity, Long corpinfoId, private Long processDepartmentHierarchy(UserExcelImportEntity importEntity, Long corpinfoId,
List<DepartmentDO> allDepartments, List<DepartmentDO> allDepartments) {
List<DepartmentDO> departmentDOTempList) {
if(StringUtils.isEmpty(importEntity.getDepartmentName1()) if(StringUtils.isEmpty(importEntity.getDepartmentName1())
&& StringUtils.isEmpty(importEntity.getDepartmentName2()) && StringUtils.isEmpty(importEntity.getDepartmentName2())
@ -199,7 +175,7 @@ public class UserImportExe {
} }
// 查找或创建部门(从二级部门开始) // 查找或创建部门(从二级部门开始)
currentDept = findOrCreateDepartment(deptName, currentParentId, level + 1, corpinfoId, allDepartments, departmentDOTempList); currentDept = findOrCreateDepartment(deptName, currentParentId, level + 1, corpinfoId, allDepartments);
if (currentDept == null) { if (currentDept == null) {
throw new BizException("创建部门失败: " + deptName + " (层级: " + (level + 1) + ")"); throw new BizException("创建部门失败: " + deptName + " (层级: " + (level + 1) + ")");
@ -237,7 +213,7 @@ public class UserImportExe {
* 使 * 使
*/ */
private DepartmentDO findOrCreateDepartment(String deptName, Long parentId, int level, private DepartmentDO findOrCreateDepartment(String deptName, Long parentId, int level,
Long corpinfoId, List<DepartmentDO> allDepartments,List<DepartmentDO> departmentDOTempList) { Long corpinfoId, List<DepartmentDO> allDepartments) {
// 在现有部门中查找 // 在现有部门中查找
DepartmentDO existingDept = findDepartmentInList(allDepartments, parentId, deptName); DepartmentDO existingDept = findDepartmentInList(allDepartments, parentId, deptName);
if (existingDept != null) { if (existingDept != null) {
@ -249,7 +225,6 @@ public class UserImportExe {
// 将新部门添加到列表中 // 将新部门添加到列表中
allDepartments.add(newDept); allDepartments.add(newDept);
departmentDOTempList.add(newDept);
return newDept; return newDept;
} }
@ -363,9 +338,7 @@ public class UserImportExe {
private void processUserInfo(UserExcelImportEntity importEntity, Integer corpFlag, private void processUserInfo(UserExcelImportEntity importEntity, Integer corpFlag,
Long corpinfoId, Long corpinfoId,
CorpInfoDO corpInfoDO, CorpInfoDO corpInfoDO,
Long departmentId, Long postId, Long departmentId, Long postId, List<UserDO> allUsers,
List<UserDO> allUsers,
List<UserDO> userDOTempList,
Long roleId) { Long roleId) {
// 检查用户名是否已存在 // 检查用户名是否已存在
boolean usernameExists = allUsers.stream() boolean usernameExists = allUsers.stream()
@ -401,7 +374,6 @@ public class UserImportExe {
UserDO userDO = new UserDO(); UserDO userDO = new UserDO();
BeanUtils.copyProperties(user, userDO); BeanUtils.copyProperties(user, userDO);
allUsers.add(userDO); allUsers.add(userDO);
userDOTempList.add(userDO);
} }
} }