feat: 企标部门权限导入

This commit is contained in:
2023-12-04 15:02:28 +08:00
parent d14e911b0c
commit 1d2b568cdc
2 changed files with 72 additions and 21 deletions
@@ -33,11 +33,23 @@ public class ESAuthDept {
@ApiModelProperty(value = "标准分类")
private String standardType;
@Excel(name = "旧上级组织")
@ApiModelProperty(value = "上级组织")
private String oldHigherDeptName;
@Excel(name = "旧组织部门")
@ApiModelProperty(value = "组织部门")
private String oldDeptName;
@Excel(name = "再上一级组织(部分存在)")
@ApiModelProperty(value = "再上一级组织(部分存在)")
private String higherHigherDeptName;
@Excel(name = "上级组织")
@ApiModelProperty(value = "上级组织")
private String higherDeptName;
@Excel(name = "组织部门")
@Excel(name = "部门")
@ApiModelProperty(value = "组织部门")
private String deptName;
@@ -51,6 +63,9 @@ public class ESAuthDept {
standardNumber == null &&
standardName == null &&
standardType == null &&
oldHigherDeptName == null &&
oldDeptName == null &&
higherHigherDeptName == null &&
higherDeptName == null &&
deptName == null;
}
@@ -246,7 +246,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
fb.setStandardNumber(newBzh);
String cybzh = dto.getCybzh();
// 采用标准号为空跳过拆分
if (StrUtil.isNotBlank(cybzh)){
if (StrUtil.isNotBlank(cybzh)) {
// 执行拆分
Map<String, String> map = StandardSplitUtils.simpleSplitStandardNumber(newBzh, cybzh);
fb.setStandardClass(map.get(FieldCommon.STANDARD_CLASS));
@@ -580,6 +580,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
// 获取数据
List<ESAuthDept> datalist;
List<EnterpriseStandardAuthDept> correctDataList = new ArrayList<>();
try {
// 获取当前时间戳(毫秒)
long startTime = System.currentTimeMillis();
@@ -594,6 +595,10 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
datalist = datalist.stream().filter(data -> StrUtil.isNotBlank(data.getStandardType()))
.filter(data -> data.getStandardType().startsWith("企业标准")).collect(Collectors.toList());
log.info("企标相关数据条数:{}", datalist.size());
// 过滤掉新部门为空的数据
datalist = datalist.stream().filter(dr -> dr.getDeptName() != null && !dr.getDeptName().isEmpty()).collect(Collectors.toList());
log.info("过滤掉新部门为空的数据后数据条数:{}", datalist.size());
// 获取当前时间戳(毫秒)
long endTime = System.currentTimeMillis();
// 计算执行时间(毫秒)
@@ -607,13 +612,10 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
// 获取所有有关联的新部门
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
sysDeptWrapper.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
sysDeptWrapper.eq(SysDepart::getDelFlag, YesOrNoEnum.NO.getValue());
sysDeptWrapper.eq(SysDepart::getStatus, 1);
List<SysDepart> curDeptList = sysDepartService.list(sysDeptWrapper);
curDeptList.add(sysDepartService.getById("0"));
List<OldSystemDepartRelation> drList = oldSystemDepartRelationService.list();
Map<String, OldSystemDepartRelation> drMap = drList.stream().collect(Collectors.toMap(o -> o.getOldOrgName() + "-" + o.getOldOrgSuperior(), o -> o));
Map<String, List<SysDepart>> curDeptNameMap = curDeptList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
for (ESAuthDept ad : datalist) {
try {
@@ -621,17 +623,49 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
if (es == null) {
throw new JeroBootException("系统中未找到标准编号:" + ad.getStandardNumber());
}
String oldDeptName = ad.getDeptName();
String oldHigherDeptName = ad.getHigherDeptName();
// 根据老部门名称从关系表中找到新部门名称
OldSystemDepartRelation oldSystemDepartRelation = drMap.get(oldDeptName + "-" + oldHigherDeptName);
if (oldSystemDepartRelation == null) {
throw new JeroBootException("未找到该部门的现部门名称:" + oldDeptName + ",上级部门名称:" + oldHigherDeptName + ",标准编号:" + ad.getStandardNumber());
List<SysDepart> sysDeparts = curDeptNameMap.get(ad.getDeptName());
if (sysDeparts == null || sysDeparts.isEmpty()) {
throw new JeroBootException("系统中未找到同名的现部门");
} else {
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
authDept.setStandardId(es.getId());
authDept.setAuthDept(oldSystemDepartRelation.getCurOrgId());
esAuthDeptService.save(authDept);
if (sysDeparts.size() > 1) {
// 根据上级部门名称再次匹配
for (SysDepart sysDepart : sysDeparts) {
String parentDeptName = ad.getHigherDeptName();
List<SysDepart> sysParentDeparts = curDeptNameMap.get(parentDeptName);
if (sysParentDeparts == null || sysParentDeparts.isEmpty()) {
throw new JeroBootException("匹配到多个同名部门,但系统中未找到同名的上级部门");
}
if (sysParentDeparts.size() > 1) {
String parentParentDeptName = ad.getHigherHigherDeptName();
if (StrUtil.isBlank(parentParentDeptName)) {
throw new JeroBootException("匹配到多个同名部门,匹配到多个同名上级部门,但缺失上级部门的上级部门");
}
List<SysDepart> sysParentParentDeparts = curDeptNameMap.get(parentParentDeptName);
if (sysParentParentDeparts.size() == 1) {
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
authDept.setStandardId(es.getId());
authDept.setAuthDept(sysDepart.getId());
correctDataList.add(authDept);
break;
} else {
throw new JeroBootException("匹配到多个同名部门,但无法通过上级部门的上级部门名称确定具体部门");
}
} else {
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
authDept.setStandardId(es.getId());
authDept.setAuthDept(sysDepart.getId());
correctDataList.add(authDept);
break;
}
}
} else {
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
SysDepart sysDepart = sysDeparts.get(0);
authDept.setStandardId(es.getId());
authDept.setAuthDept(sysDepart.getId());
correctDataList.add(authDept);
}
}
} catch (Exception e) {
log.error("导入部门对应出现错误:{}", e.getMessage());
@@ -643,6 +677,8 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
} catch (Exception e) {
log.error("导入失败;{}", e.getMessage());
}
esAuthDeptService.saveBatch(correctDataList, correctDataList.size());
log.info("企标部门权限导入成功,成功条数{}", correctDataList.size());
if (!errImportList.isEmpty()) {
log.info("导入失败数据条数:{}", errImportList.size());
this.exportWithExcel(response, errImportList, "ESAuthDeptErrorData.xls");
@@ -745,7 +781,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
if (allDatalist == null) {
throw new JeroBootException("导入失败,数据为空");
}
// 查询所有企标
LambdaQueryWrapper<LawsEnterpriseStandard> esWrapper = new LambdaQueryWrapper<>();
esWrapper.eq(LawsEnterpriseStandard::getDelFlag, YesOrNoEnum.NO.getValue());
@@ -847,9 +883,9 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
private void oldSysGBImport(List<OldSystemImportDTO> allDatalist, List<OldSystemImportDTO> errImportList) {
List<OldSystemImportDTO> gbDatalist = allDatalist.stream().filter(o ->
o.getBzfl().contains("国家标准/") || // “/”是为了避免匹配到“美国国家标准”这个外标
o.getBzfl().contains("团体标准") ||
o.getBzfl().contains("地方标准") ||
o.getBzfl().contains("行业标准")).collect(Collectors.toList());
o.getBzfl().contains("团体标准") ||
o.getBzfl().contains("地方标准") ||
o.getBzfl().contains("行业标准")).collect(Collectors.toList());
log.info("国标相关数据条数:{}", gbDatalist.size());
// 过滤字段 根据标准号字段去重
@@ -891,7 +927,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
gb.setStandardNumber(newBzh);
String cybzh = dto.getCybzh();
// 采用标准号为空跳过拆分
if (StrUtil.isNotBlank(cybzh)){
if (StrUtil.isNotBlank(cybzh)) {
// 执行拆分
Map<String, String> map = StandardSplitUtils.simpleSplitStandardNumber(newBzh, cybzh);
gb.setStandardClass(map.get(FieldCommon.STANDARD_CLASS));