Compare commits
No commits in common. "c494013360a31ee8747225afd9e8abf98b9559a3" and "85b2be2b790937352565f0168b8c78d3d20b2a08" have entirely different histories.
c494013360
...
85b2be2b79
|
|
@ -118,15 +118,8 @@ public class UserController {
|
|||
|
||||
@ApiOperation("导入用户列表")
|
||||
@PostMapping("/importUserTable")
|
||||
public Response importUserTable(@RequestPart(value = "file") MultipartFile file) {
|
||||
userService.importUserTable(file, 1);
|
||||
return SingleResponse.buildSuccess();
|
||||
}
|
||||
|
||||
@ApiOperation("导入用户列表")
|
||||
@PostMapping("/importUserTableByCorp2")
|
||||
public Response importUserTableByCorp2(@RequestPart(value = "file") MultipartFile file) {
|
||||
userService.importUserTable(file, 2);
|
||||
public Response importUserTable(@RequestPart(value = "file") MultipartFile file, @RequestPart(value = "corpFlag") Integer corpFlag) {
|
||||
userService.importUserTable(file, corpFlag);
|
||||
return SingleResponse.buildSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ import com.alibaba.cloud.commons.lang.StringUtils;
|
|||
import com.alibaba.cola.dto.MultiResponse;
|
||||
import com.alibaba.cola.exception.BizException;
|
||||
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.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.PostGateway;
|
||||
import com.zcloud.basic.info.domain.gateway.UserEmploymentLogGateway;
|
||||
|
|
@ -62,10 +60,6 @@ public class UserImportExe {
|
|||
private final DepartmentGateway departmentGateway;
|
||||
@DubboReference
|
||||
private RoleFacade roleFacade;
|
||||
@DubboReference
|
||||
private DeptFacade deptFacade;
|
||||
@DubboReference
|
||||
private UserFacade userFacade;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void importUserTable(MultipartFile file, Integer corpFlag) {
|
||||
|
|
@ -82,12 +76,10 @@ public class UserImportExe {
|
|||
}
|
||||
// 部门数据
|
||||
List<DepartmentDO> departmentDOList = departmentRepository.listByCorpInfoId(corpinfoId);
|
||||
List<DepartmentDO> departmentDOTempList = new ArrayList<>();
|
||||
// 岗位数据
|
||||
List<PostDO> postDOList = postRepository.listByCorpInfoId(corpinfoId);
|
||||
// 用户名数据
|
||||
List<UserDO> userDOList = userRepository.listByCorpInfoId(corpinfoId);
|
||||
List<UserDO> userDOTempList = new ArrayList<>();
|
||||
|
||||
List<UserExcelImportEntity> list = new ArrayList<>();
|
||||
try {
|
||||
|
|
@ -102,19 +94,8 @@ public class UserImportExe {
|
|||
// 开始处理导入逻辑
|
||||
for (UserExcelImportEntity importEntity : list) {
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -126,15 +107,11 @@ public class UserImportExe {
|
|||
private void processSingleUser(UserExcelImportEntity importEntity, Integer corpFlag,
|
||||
Long corpinfoId,
|
||||
CorpInfoDO corpInfoDO,
|
||||
List<DepartmentDO> departmentDOList,
|
||||
List<DepartmentDO> departmentDOTempList,
|
||||
List<PostDO> postDOList,
|
||||
List<UserDO> userDOList,
|
||||
List<UserDO> userDOTempList,
|
||||
List<RoleCO> roleList) {
|
||||
List<DepartmentDO> departmentDOList, List<PostDO> postDOList,
|
||||
List<UserDO> userDOList, List<RoleCO> roleList) {
|
||||
|
||||
// 1. 处理部门层级,获取最终部门ID
|
||||
Long departmentId = processDepartmentHierarchy(importEntity, corpinfoId, departmentDOList, departmentDOTempList);
|
||||
Long departmentId = processDepartmentHierarchy(importEntity, corpinfoId, departmentDOList);
|
||||
|
||||
// 2. 处理岗位,获取岗位ID
|
||||
Long postId = processPost(importEntity, corpinfoId, corpInfoDO, departmentId, postDOList);
|
||||
|
|
@ -143,15 +120,14 @@ public class UserImportExe {
|
|||
Long roleId = processRoleInfo(importEntity, roleList);
|
||||
|
||||
// 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,
|
||||
List<DepartmentDO> allDepartments,
|
||||
List<DepartmentDO> departmentDOTempList) {
|
||||
List<DepartmentDO> allDepartments) {
|
||||
|
||||
if(StringUtils.isEmpty(importEntity.getDepartmentName1())
|
||||
&& 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) {
|
||||
throw new BizException("创建部门失败: " + deptName + " (层级: " + (level + 1) + ")");
|
||||
|
|
@ -237,7 +213,7 @@ public class UserImportExe {
|
|||
* 查找或创建部门(从二级部门开始使用)
|
||||
*/
|
||||
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);
|
||||
if (existingDept != null) {
|
||||
|
|
@ -249,7 +225,6 @@ public class UserImportExe {
|
|||
|
||||
// 将新部门添加到列表中
|
||||
allDepartments.add(newDept);
|
||||
departmentDOTempList.add(newDept);
|
||||
|
||||
return newDept;
|
||||
}
|
||||
|
|
@ -363,9 +338,7 @@ public class UserImportExe {
|
|||
private void processUserInfo(UserExcelImportEntity importEntity, Integer corpFlag,
|
||||
Long corpinfoId,
|
||||
CorpInfoDO corpInfoDO,
|
||||
Long departmentId, Long postId,
|
||||
List<UserDO> allUsers,
|
||||
List<UserDO> userDOTempList,
|
||||
Long departmentId, Long postId, List<UserDO> allUsers,
|
||||
Long roleId) {
|
||||
// 检查用户名是否已存在
|
||||
boolean usernameExists = allUsers.stream()
|
||||
|
|
@ -401,7 +374,6 @@ public class UserImportExe {
|
|||
UserDO userDO = new UserDO();
|
||||
BeanUtils.copyProperties(user, userDO);
|
||||
allUsers.add(userDO);
|
||||
userDOTempList.add(userDO);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue