feat: 新老部门对应关系导入
This commit is contained in:
+44
-36
@@ -117,6 +117,9 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
|
||||
@Resource
|
||||
private ISysDepartService sysDepartService;
|
||||
|
||||
@Resource
|
||||
private OldSystemDepartRelationService oldSystemDepartRelationService;
|
||||
|
||||
@Override
|
||||
public LawsEnterpriseStandard queryByStandardNumber(String standardNumber) {
|
||||
@@ -393,6 +396,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
|
||||
@Override
|
||||
public void importOldESAuthDeptExcel(MultipartFile file, HttpServletResponse response) {
|
||||
List<ESAuthDept> errImportList = new ArrayList<>();
|
||||
// 验证文件是否为压缩格式file.getContentType()).contains("xls")
|
||||
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
||||
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
||||
@@ -417,7 +421,12 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
i--;
|
||||
}
|
||||
}
|
||||
log.info("获取数据成功,数据条数:{}", datalist.size());
|
||||
// 区分数据
|
||||
log.info("获取数据成功,总数据条数:{}", datalist.size());
|
||||
// 删选标准分类不为空且是企标的数据
|
||||
datalist = datalist.stream().filter(data -> StrUtil.isNotBlank(data.getStandardType()))
|
||||
.filter(data -> data.getStandardType().startsWith("企业标准")).collect(Collectors.toList());
|
||||
log.info("企标相关数据条数:{}", datalist.size());
|
||||
// 获取当前时间戳(毫秒)
|
||||
long endTime = System.currentTimeMillis();
|
||||
// 计算执行时间(毫秒)
|
||||
@@ -428,52 +437,46 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
|
||||
List<LawsEnterpriseStandard> esList = this.list(esWrapper.isNotNull(LawsEnterpriseStandard::getOldSystemId));
|
||||
Map<String, LawsEnterpriseStandard> esMap = esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getOldSystemId, o -> o));
|
||||
Map<String, List<ESAuthDept>> auMap = datalist.stream().collect(Collectors.groupingBy(ESAuthDept::getStandardId));
|
||||
|
||||
// 将Excel中涉及到的老部门名称和老上级部门名称找出来
|
||||
Set<String> oldDeptNameList = new HashSet<>();
|
||||
for (ESAuthDept ad : datalist) {
|
||||
oldDeptNameList.add(ad.getDeptName());
|
||||
oldDeptNameList.add(ad.getHigherDeptName());
|
||||
}
|
||||
|
||||
// 根据老部门名称获取新部门Id
|
||||
LambdaQueryWrapper<OldSystemDepartRelation> oldDeptWrapper = new LambdaQueryWrapper<>();
|
||||
oldDeptWrapper.in(OldSystemDepartRelation::getOldOrgName, oldDeptNameList);
|
||||
List<OldSystemDepartRelation> oldDeptList = oldDeptService.list(oldDeptWrapper);
|
||||
|
||||
|
||||
// 获取所有有关联的新部门
|
||||
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
||||
sysDeptWrapper.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
|
||||
sysDeptWrapper.eq(SysDepart::getStatus, 1);
|
||||
List<SysDepart> curDeptList = sysDepartService.list(sysDeptWrapper);
|
||||
Map<String, List<SysDepart>> curDeptNameMap = curDeptList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
|
||||
Map<String, SysDepart> curDeptIdMap = curDeptList.stream().collect(Collectors.toMap(SysDepart::getId, o -> o));
|
||||
curDeptList.add(sysDepartService.getById("0"));
|
||||
Map<String, SysDepart> allCurDeptMap = curDeptList.stream().collect(Collectors.toMap(SysDepart::getId, o -> o));
|
||||
|
||||
Map<String, SysDepart> curDeptNameMap = new HashMap<>();
|
||||
for (SysDepart d : curDeptList) {
|
||||
if (StrUtil.isNotBlank(d.getParentId())) {
|
||||
String departName = d.getDepartName();
|
||||
SysDepart sysDepart = allCurDeptMap.get(d.getParentId());
|
||||
if (sysDepart != null) {
|
||||
departName = departName + "-" + sysDepart.getDepartName();
|
||||
}
|
||||
curDeptNameMap.put(departName, d);
|
||||
}
|
||||
}
|
||||
List<OldSystemDepartRelation> drList = oldSystemDepartRelationService.list();
|
||||
Map<String, OldSystemDepartRelation> drMap = drList.stream().collect(Collectors.toMap(o -> o.getOldOrgName() + "-" + o.getOldOrgSuperior(), o -> o));
|
||||
|
||||
for (ESAuthDept ad : datalist) {
|
||||
try {
|
||||
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
|
||||
authDept.setStandardId(esMap.get(ad.getStandardId()).getId());
|
||||
String curDeptId = curDeptNameMap.get(ad.getDeptName() + "-" + ad.getHigherDeptName()).getId();
|
||||
if (StrUtil.isBlank(curDeptId)) {
|
||||
log.error("导入部门对应出现错误:{}", "找不到对应的新部门");
|
||||
log.error("错误数据:{}", ad.toString());
|
||||
continue;
|
||||
String oldDeptName = ad.getDeptName();
|
||||
String oldHigherDeptName = ad.getHigherDeptName();
|
||||
// 根据老部门名称从关系表中找到新部门名称
|
||||
OldSystemDepartRelation oldSystemDepartRelation = drMap.get(oldDeptName + "-" + oldHigherDeptName);
|
||||
if (oldSystemDepartRelation == null) {
|
||||
throw new JeroBootException("未找到该部门的现部门名称:" + oldDeptName + ",上级部门名称:" + oldHigherDeptName + ",标准编号:" + ad.getStandardNumber());
|
||||
} else {
|
||||
// 通过现部门名称找到对应的新部门
|
||||
List<SysDepart> curDepts = curDeptNameMap.get(oldSystemDepartRelation.getCurOrgName());
|
||||
if (curDepts == null || curDepts.isEmpty()) {
|
||||
throw new JeroBootException("未找到该部门,部门名称:" + oldDeptName + ",上级部门名称:" + oldHigherDeptName + ",标准编号:" + ad.getStandardNumber());
|
||||
}
|
||||
}
|
||||
authDept.setAuthDept(curDeptId);
|
||||
esAuthDeptService.save(authDept);
|
||||
// 如果只有一个则找到
|
||||
// List<String> deptNameList = "";
|
||||
// String curDeptId = curDeptNameMap.get(ad.getDeptName() + "-" + ad.getHigherDeptName()).getId();
|
||||
// if (StrUtil.isBlank(curDeptId)) {
|
||||
// log.error("导入部门对应出现错误:{}", "找不到对应的新部门");
|
||||
// log.error("错误数据:{}", ad.toString());
|
||||
// continue;
|
||||
// }
|
||||
// EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
|
||||
// authDept.setStandardId(esMap.get(ad.getStandardId()).getId());
|
||||
// authDept.setAuthDept(curDeptId);
|
||||
// esAuthDeptService.save(authDept);
|
||||
} catch (Exception e) {
|
||||
log.error("导入部门对应出现错误:{}", e.getMessage());
|
||||
log.error("错误数据:{}", ad.toString());
|
||||
@@ -482,6 +485,11 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
||||
} catch (Exception e) {
|
||||
log.error("导入失败;{}", e.getMessage());
|
||||
}
|
||||
if (!errImportList.isEmpty()) {
|
||||
log.info("导入失败数据条数:{}", errImportList.size());
|
||||
this.exportWithExcel(response, errImportList, "ESAuthDeptErrorData.xls");
|
||||
}
|
||||
log.info("企标部门权限导入结束");
|
||||
}
|
||||
|
||||
public <T> void exportWithExcel(HttpServletResponse response, List<T> dtoList, String fileName) {
|
||||
|
||||
Reference in New Issue
Block a user