import
parent
09301a18b6
commit
f0ebc579ab
|
|
@ -1,15 +1,20 @@
|
|||
package org.qinan.safetyeval.app.support;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.jjb.saas.framework.auth.utils.AuthContext;
|
||||
import com.jjb.saas.system.client.user.request.RoleDeptAddCmd;
|
||||
import com.jjb.saas.system.client.user.request.UserAddCmd;
|
||||
import com.zcloud.gbscommon.utils.MD5;
|
||||
import com.zcloud.gbscommon.utils.Sm2Util;
|
||||
import org.qinan.safetyeval.client.co.OrgPersonnelImportErrorCO;
|
||||
import org.qinan.safetyeval.client.co.OrgPersonnelImportResultCO;
|
||||
import org.qinan.safetyeval.domain.constant.QualificationLevelEnum;
|
||||
import org.qinan.safetyeval.domain.entity.OrgDepartmentEntity;
|
||||
import org.qinan.safetyeval.domain.entity.OrgPersonnelEntity;
|
||||
import org.qinan.safetyeval.domain.entity.OrgPositionEntity;
|
||||
import org.qinan.safetyeval.domain.entity.TitleCodeCo;
|
||||
import org.qinan.safetyeval.domain.exception.BizException;
|
||||
import org.qinan.safetyeval.domain.exception.ErrorCode;
|
||||
import org.qinan.safetyeval.domain.constant.QualificationLevelEnum;
|
||||
import org.qinan.safetyeval.domain.gateway.OrgDepartmentGateway;
|
||||
import org.qinan.safetyeval.domain.gateway.OrgPersonnelGateway;
|
||||
import org.qinan.safetyeval.domain.gateway.OrgPositionGateway;
|
||||
|
|
@ -17,8 +22,10 @@ import org.qinan.safetyeval.domain.major.gateway.BasicDisciplineMajorGateway;
|
|||
import org.qinan.safetyeval.domain.major.model.BasicDisciplineMajorE;
|
||||
import org.qinan.safetyeval.domain.service.OrgPersonnelDomainService;
|
||||
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
|
||||
import org.qinan.safetyeval.infrastructure.remote.SystemRemote;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -27,15 +34,7 @@ import javax.annotation.Resource;
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -70,6 +69,19 @@ public class OrgPersonnelExcelImporter {
|
|||
@Resource
|
||||
private OrgPersonnelDomainService orgPersonnelDomainService;
|
||||
|
||||
@Resource
|
||||
private SystemRemote systemRemote;
|
||||
|
||||
@Value("${def.password:a123456}")
|
||||
private String defPassword;
|
||||
@Value("${def.publicKey:0402df2195296d4062ac85ad766994d73e871b887e18efb9a9a06b4cebc72372869b7da6c347c129dee2b46a0f279ff066b01c76208c2a052af75977c722a2ccee}")
|
||||
private String publicKey;
|
||||
|
||||
@Value("${auth.deptId.org}")
|
||||
private Long orgDeptId;
|
||||
@Value("${auth.roleCode.org}")
|
||||
private String orgRoleCode;
|
||||
|
||||
public OrgPersonnelImportResultCO importPersonnel(MultipartFile file) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BizException(ErrorCode.FILE_UPLOAD_EMPTY);
|
||||
|
|
@ -118,6 +130,8 @@ public class OrgPersonnelExcelImporter {
|
|||
// 行内枚举/数据校验未通过,已记录异常
|
||||
continue;
|
||||
}
|
||||
Long userId = addUserIfAbsentAndAppendRole(entity);
|
||||
entity.setId(userId);
|
||||
orgPersonnelDomainService.add(entity);
|
||||
successCount++;
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -133,6 +147,29 @@ public class OrgPersonnelExcelImporter {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* addUserIfAbsentAndAppendRole
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
public Long addUserIfAbsentAndAppendRole(OrgPersonnelEntity personnelEntity) {
|
||||
// 添加底座用户
|
||||
UserAddCmd userAddCmd = new UserAddCmd();
|
||||
userAddCmd.setAccount(personnelEntity.getAccount());
|
||||
userAddCmd.setTenantId(AuthContext.getTenantId());
|
||||
userAddCmd.setName(personnelEntity.getUserName());
|
||||
String encrypt = Sm2Util.encryptHex(MD5.md5(defPassword), publicKey);
|
||||
userAddCmd.setPassword(encrypt);
|
||||
|
||||
RoleDeptAddCmd roleDept = new RoleDeptAddCmd();
|
||||
roleDept.setRoleCode(orgRoleCode);
|
||||
roleDept.setDeptId(orgDeptId);
|
||||
userAddCmd.setRoleDepts(Collections.singletonList(roleDept));
|
||||
|
||||
return systemRemote.addUserIfAbsentAndAppendRole(userAddCmd
|
||||
, Collections.singletonList(orgRoleCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 Excel,过滤空行,并回填物理行号(从1开始,含表头,首条数据为第2行)。
|
||||
* <p>
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ auth:
|
|||
org: 2074857068268802050
|
||||
roleCode:
|
||||
expert: expert001
|
||||
org: org001
|
||||
|
||||
template:
|
||||
personnel:
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ auth:
|
|||
org: 2069671307598893058
|
||||
roleCode:
|
||||
expert: expert001
|
||||
org: org001
|
||||
|
||||
template:
|
||||
personnel:
|
||||
|
|
|
|||
Loading…
Reference in New Issue