|
|
|
|
@ -2,17 +2,12 @@ package com.zcloud.basic.info.command;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
|
|
import com.alibaba.cola.dto.MultiResponse;
|
|
|
|
|
import com.alibaba.cola.exception.BizException;
|
|
|
|
|
import com.jjb.saas.config.client.dicttree.facade.ConfDictTreeFacade;
|
|
|
|
|
import com.jjb.saas.config.client.dicttree.response.ConfDictTreeCO;
|
|
|
|
|
import com.jjb.saas.framework.auth.model.SSOUser;
|
|
|
|
|
import com.jjb.saas.framework.auth.utils.AuthContext;
|
|
|
|
|
import com.jjb.saas.system.client.role.facade.RoleFacade;
|
|
|
|
|
import com.jjb.saas.system.client.role.response.RoleCO;
|
|
|
|
|
import com.zcloud.basic.info.command.convertor.UserCoConvertor;
|
|
|
|
|
import com.zcloud.basic.info.domain.gateway.DepartmentGateway;
|
|
|
|
|
import com.zcloud.basic.info.domain.gateway.PostGateway;
|
|
|
|
|
import com.zcloud.basic.info.domain.gateway.UserEmploymentLogGateway;
|
|
|
|
|
@ -21,9 +16,6 @@ import com.zcloud.basic.info.domain.model.DepartmentE;
|
|
|
|
|
import com.zcloud.basic.info.domain.model.PostE;
|
|
|
|
|
import com.zcloud.basic.info.domain.model.UserE;
|
|
|
|
|
import com.zcloud.basic.info.domain.model.UserEmploymentLogE;
|
|
|
|
|
import com.zcloud.basic.info.dto.CorpInfoAddCmd;
|
|
|
|
|
import com.zcloud.basic.info.dto.UserAddCmd;
|
|
|
|
|
import com.zcloud.basic.info.dto.UserXgfAddCmd;
|
|
|
|
|
import com.zcloud.basic.info.persistence.dataobject.CorpInfoDO;
|
|
|
|
|
import com.zcloud.basic.info.persistence.dataobject.DepartmentDO;
|
|
|
|
|
import com.zcloud.basic.info.persistence.dataobject.PostDO;
|
|
|
|
|
@ -34,6 +26,7 @@ import com.zcloud.basic.info.persistence.repository.PostRepository;
|
|
|
|
|
import com.zcloud.basic.info.persistence.repository.UserRepository;
|
|
|
|
|
import com.zcloud.gbscommon.excelEntity.UserExcelImportEntity;
|
|
|
|
|
import com.zcloud.gbscommon.utils.ExcelUtils;
|
|
|
|
|
import com.zcloud.gbscommon.utils.UuidUtil;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
@ -66,14 +59,10 @@ public class UserImportExe {
|
|
|
|
|
private final UserRepository userRepository;
|
|
|
|
|
private final DepartmentGateway departmentGateway;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private ConfDictTreeFacade confDictTreeFacade;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private RoleFacade roleFacade;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void importUserTable(MultipartFile file) {
|
|
|
|
|
public void importUserTable(MultipartFile file, Integer corpFlag) {
|
|
|
|
|
Long corpinfoId = AuthContext.getTenantId();
|
|
|
|
|
if(corpinfoId == null){
|
|
|
|
|
throw new BizException("未选择租户");
|
|
|
|
|
@ -105,9 +94,9 @@ public class UserImportExe {
|
|
|
|
|
// 开始处理导入逻辑
|
|
|
|
|
for (UserExcelImportEntity importEntity : list) {
|
|
|
|
|
try {
|
|
|
|
|
processSingleUser(importEntity, corpinfoId, corpInfoDO, departmentDOList, postDOList, userDOList, roleCOMultiResponse.getData());
|
|
|
|
|
processSingleUser(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentDOList, postDOList, userDOList, roleCOMultiResponse.getData());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new BizException("导入用户失败: " + importEntity.getUsername() + ", 原因: " + e.getMessage());
|
|
|
|
|
throw new BizException("导入该用户失败: " + importEntity.getUsername() + ", 原因: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -115,7 +104,8 @@ public class UserImportExe {
|
|
|
|
|
/**
|
|
|
|
|
* 处理单个用户导入
|
|
|
|
|
*/
|
|
|
|
|
private void processSingleUser(UserExcelImportEntity importEntity, Long corpinfoId,
|
|
|
|
|
private void processSingleUser(UserExcelImportEntity importEntity, Integer corpFlag,
|
|
|
|
|
Long corpinfoId,
|
|
|
|
|
CorpInfoDO corpInfoDO,
|
|
|
|
|
List<DepartmentDO> departmentDOList, List<PostDO> postDOList,
|
|
|
|
|
List<UserDO> userDOList, List<RoleCO> roleList) {
|
|
|
|
|
@ -130,7 +120,7 @@ public class UserImportExe {
|
|
|
|
|
Long roleId = processRoleInfo(importEntity, roleList);
|
|
|
|
|
|
|
|
|
|
// 4. 处理用户信息
|
|
|
|
|
processUserInfo(importEntity, corpinfoId, corpInfoDO, departmentId, postId, userDOList, roleId);
|
|
|
|
|
processUserInfo(importEntity, corpFlag, corpinfoId, corpInfoDO, departmentId, postId, userDOList, roleId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -161,7 +151,7 @@ public class UserImportExe {
|
|
|
|
|
// 验证一级部门名称是否与Excel中的部门1匹配
|
|
|
|
|
if (StringUtils.isNotBlank(importEntity.getDepartmentName1()) &&
|
|
|
|
|
!importEntity.getDepartmentName1().equals(rootDept.getName())) {
|
|
|
|
|
throw new BizException("一级部门名称与公司名称不一致: Excel中的" + importEntity.getDepartmentName1() + " vs 系统中的" + rootDept.getName());
|
|
|
|
|
throw new BizException("所属部门1名称与公司名称不一致: 所属部门1应该为:" + rootDept.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Long currentParentId = rootDept.getId(); // 从一级部门开始
|
|
|
|
|
@ -345,7 +335,8 @@ public class UserImportExe {
|
|
|
|
|
/**
|
|
|
|
|
* 处理用户信息
|
|
|
|
|
*/
|
|
|
|
|
private void processUserInfo(UserExcelImportEntity importEntity, Long corpinfoId,
|
|
|
|
|
private void processUserInfo(UserExcelImportEntity importEntity, Integer corpFlag,
|
|
|
|
|
Long corpinfoId,
|
|
|
|
|
CorpInfoDO corpInfoDO,
|
|
|
|
|
Long departmentId, Long postId, List<UserDO> allUsers,
|
|
|
|
|
Long roleId) {
|
|
|
|
|
@ -359,7 +350,11 @@ public class UserImportExe {
|
|
|
|
|
|
|
|
|
|
// 创建用户
|
|
|
|
|
UserE user = new UserE();
|
|
|
|
|
user.setUserId(UuidUtil.get32UUID());
|
|
|
|
|
user.setUsername(importEntity.getUsername());
|
|
|
|
|
user.setPhone(importEntity.getUsername());
|
|
|
|
|
user.setUserType(corpFlag);
|
|
|
|
|
user.setMainCorpFlag(0);
|
|
|
|
|
user.setRoleId(roleId);
|
|
|
|
|
user.setDepartmentId(departmentId);
|
|
|
|
|
user.setPostId(postId);
|
|
|
|
|
|