feat: 企标授权部门导入
This commit is contained in:
+9
@@ -107,4 +107,13 @@ public class OldSystemController {
|
|||||||
enterpriseStandardService.importFileRelationExcel(file, response);
|
enterpriseStandardService.importFileRelationExcel(file, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/findDuplicateStandardNoData")
|
||||||
|
@AutoLog(value = "老法规系统-找到标准号重复的数据")
|
||||||
|
@ApiOperation(value="老法规系统-找到标准号重复的数据", notes="老法规系统-找到标准号重复的数据", produces = "application/octet-stream")
|
||||||
|
@ApiOperationSupport(order = 8)
|
||||||
|
public void findDuplicateStandardNoData(@RequestParam("file") MultipartFile file,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
enterpriseStandardService.findDuplicateStandardNoData(file, response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -78,6 +78,26 @@ public class OldSystemDepartRelationServiceImpl extends ServiceImpl<OldSystemDep
|
|||||||
log.info("导入数据条数:{}", list.size());
|
log.info("导入数据条数:{}", list.size());
|
||||||
// 过滤掉新部门为空的数据
|
// 过滤掉新部门为空的数据
|
||||||
list = list.stream().filter(dr -> dr.getCurOrgName() != null && !dr.getCurOrgName().isEmpty()).collect(Collectors.toList());
|
list = list.stream().filter(dr -> dr.getCurOrgName() != null && !dr.getCurOrgName().isEmpty()).collect(Collectors.toList());
|
||||||
|
// 将所获取到的所有数据去除前后空格
|
||||||
|
list = list.stream().peek(dr -> {
|
||||||
|
// 判断是否为空
|
||||||
|
if (dr.getOldOrgSuperior() == null) {
|
||||||
|
dr.setOldOrgSuperior("");
|
||||||
|
}
|
||||||
|
if (dr.getOldOrgName() == null) {
|
||||||
|
dr.setOldOrgName("");
|
||||||
|
}
|
||||||
|
if (dr.getCurOrgSuperior() == null) {
|
||||||
|
dr.setCurOrgSuperior("");
|
||||||
|
}
|
||||||
|
if (dr.getCurOrgName() == null) {
|
||||||
|
dr.setCurOrgName("");
|
||||||
|
}
|
||||||
|
dr.setOldOrgSuperior(dr.getOldOrgSuperior().trim());
|
||||||
|
dr.setOldOrgName(dr.getOldOrgName().trim());
|
||||||
|
dr.setCurOrgSuperior(dr.getCurOrgSuperior().trim());
|
||||||
|
dr.setCurOrgName(dr.getCurOrgName().trim());
|
||||||
|
}).collect(Collectors.toList());
|
||||||
log.info("过滤掉新部门为空的数据后数据条数:{}", list.size());
|
log.info("过滤掉新部门为空的数据后数据条数:{}", list.size());
|
||||||
// 获取所有有关联的新部门
|
// 获取所有有关联的新部门
|
||||||
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|||||||
+7
@@ -68,4 +68,11 @@ public interface ILawsEnterpriseStandardService extends IService<LawsEnterpriseS
|
|||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
void importFileRelationExcel(MultipartFile file, HttpServletResponse response);
|
void importFileRelationExcel(MultipartFile file, HttpServletResponse response);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 找到标准号重复的数据
|
||||||
|
* @param file
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
void findDuplicateStandardNoData(MultipartFile file, HttpServletResponse response);
|
||||||
}
|
}
|
||||||
|
|||||||
+72
-49
@@ -580,7 +580,7 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
|
|
||||||
// 获取数据
|
// 获取数据
|
||||||
List<ESAuthDept> datalist;
|
List<ESAuthDept> datalist;
|
||||||
List<EnterpriseStandardAuthDept> correctDataList = new ArrayList<>();
|
List<EnterpriseStandardAuthDept> correctList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// 获取当前时间戳(毫秒)
|
// 获取当前时间戳(毫秒)
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
@@ -614,8 +614,9 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDepart> sysDeptWrapper = new LambdaQueryWrapper<>();
|
||||||
sysDeptWrapper.eq(SysDepart::getDelFlag, YesOrNoEnum.NO.getValue());
|
sysDeptWrapper.eq(SysDepart::getDelFlag, YesOrNoEnum.NO.getValue());
|
||||||
sysDeptWrapper.eq(SysDepart::getStatus, 1);
|
sysDeptWrapper.eq(SysDepart::getStatus, 1);
|
||||||
List<SysDepart> curDeptList = sysDepartService.list(sysDeptWrapper);
|
|
||||||
Map<String, List<SysDepart>> curDeptNameMap = curDeptList.stream().collect(Collectors.groupingBy(SysDepart::getDepartName));
|
List<OldSystemDepartRelation> drList = oldSystemDepartRelationService.list();
|
||||||
|
Map<String, OldSystemDepartRelation> drMap = drList.stream().collect(Collectors.toMap(o -> o.getOldOrgName().trim() + "-" + o.getOldOrgSuperior().trim(), o -> o));
|
||||||
|
|
||||||
for (ESAuthDept ad : datalist) {
|
for (ESAuthDept ad : datalist) {
|
||||||
try {
|
try {
|
||||||
@@ -623,49 +624,17 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
if (es == null) {
|
if (es == null) {
|
||||||
throw new JeroBootException("系统中未找到标准编号:" + ad.getStandardNumber());
|
throw new JeroBootException("系统中未找到标准编号:" + ad.getStandardNumber());
|
||||||
}
|
}
|
||||||
|
String oldDeptName = ad.getOldDeptName().trim();
|
||||||
|
String oldHigherDeptName = ad.getOldHigherDeptName().trim();
|
||||||
// 根据老部门名称从关系表中找到新部门名称
|
// 根据老部门名称从关系表中找到新部门名称
|
||||||
List<SysDepart> sysDeparts = curDeptNameMap.get(ad.getDeptName());
|
OldSystemDepartRelation oldSystemDepartRelation = drMap.get(oldDeptName + "-" + oldHigherDeptName);
|
||||||
if (sysDeparts == null || sysDeparts.isEmpty()) {
|
if (oldSystemDepartRelation == null) {
|
||||||
throw new JeroBootException("系统中未找到同名的现部门");
|
throw new JeroBootException("未找到该部门的现部门名称:" + oldDeptName + ",上级部门名称:" + oldHigherDeptName + ",标准编号:" + ad.getStandardNumber());
|
||||||
} else {
|
} else {
|
||||||
if (sysDeparts.size() > 1) {
|
EnterpriseStandardAuthDept authDept = new EnterpriseStandardAuthDept();
|
||||||
// 根据上级部门名称再次匹配
|
authDept.setStandardId(es.getId());
|
||||||
for (SysDepart sysDepart : sysDeparts) {
|
authDept.setAuthDept(oldSystemDepartRelation.getCurOrgId());
|
||||||
String parentDeptName = ad.getHigherDeptName();
|
correctList.add(authDept);
|
||||||
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) {
|
} catch (Exception e) {
|
||||||
log.error("导入部门对应出现错误:{}", e.getMessage());
|
log.error("导入部门对应出现错误:{}", e.getMessage());
|
||||||
@@ -677,8 +646,10 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("导入失败;{}", e.getMessage());
|
log.error("导入失败;{}", e.getMessage());
|
||||||
}
|
}
|
||||||
esAuthDeptService.saveBatch(correctDataList, correctDataList.size());
|
// 打印成功数量
|
||||||
log.info("企标部门权限导入成功,成功条数{}", correctDataList.size());
|
log.info("企标部门权限导入成功,成功条数{}", correctList.size());
|
||||||
|
// 批量保存
|
||||||
|
esAuthDeptService.saveBatch(correctList, correctList.size());
|
||||||
if (!errImportList.isEmpty()) {
|
if (!errImportList.isEmpty()) {
|
||||||
log.info("导入失败数据条数:{}", errImportList.size());
|
log.info("导入失败数据条数:{}", errImportList.size());
|
||||||
this.exportWithExcel(response, errImportList, "ESAuthDeptErrorData.xls");
|
this.exportWithExcel(response, errImportList, "ESAuthDeptErrorData.xls");
|
||||||
@@ -855,6 +826,52 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void findDuplicateStandardNoData(MultipartFile file, HttpServletResponse response) {
|
||||||
|
List<OldSystemImportDTO> duplicateDataList = new ArrayList<>();
|
||||||
|
|
||||||
|
// 验证文件是否为压缩格式
|
||||||
|
if (!Objects.requireNonNull(file.getOriginalFilename()).contains("xls")) {
|
||||||
|
throw new JeroBootException("文件格式不正确,请上传Excel。");
|
||||||
|
}
|
||||||
|
ImportParams params = new ImportParams();
|
||||||
|
params.setTitleRows(0);
|
||||||
|
params.setNeedSave(true);
|
||||||
|
// 获取数据
|
||||||
|
List<OldSystemImportDTO> allDatalist = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
@Cleanup
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
allDatalist = ExcelImportUtil.importExcel(inputStream, OldSystemImportDTO.class, params);
|
||||||
|
// 删除空行
|
||||||
|
allDatalist.removeIf(OldSystemImportDTO::isEmptyRow);
|
||||||
|
log.info("获取数据成功,数据条数:{}", allDatalist.size());
|
||||||
|
// 获取当前时间戳(毫秒)
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
// 计算执行时间(毫秒)
|
||||||
|
long executionTime = endTime - startTime;
|
||||||
|
log.info("数据转换执行时间:" + executionTime + " 毫秒");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("导入失败;{}", e.getMessage());
|
||||||
|
}
|
||||||
|
if (allDatalist == null) {
|
||||||
|
throw new JeroBootException("导入失败,数据为空");
|
||||||
|
}
|
||||||
|
//找到所欲标准编号重复的数据
|
||||||
|
Map<String, List<OldSystemImportDTO>> duplicateMap = allDatalist.stream().collect(Collectors.groupingBy(OldSystemImportDTO::getBzh));
|
||||||
|
for (String key : duplicateMap.keySet()) {
|
||||||
|
List<OldSystemImportDTO> list = duplicateMap.get(key);
|
||||||
|
if (list.size() > 1) {
|
||||||
|
duplicateDataList.addAll(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 导出
|
||||||
|
this.exportWithExcel(response, duplicateDataList, "DuplicateStandardNoData.xls");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean containsChinese(String text) {
|
public boolean containsChinese(String text) {
|
||||||
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
||||||
Matcher matcher = pattern.matcher(text);
|
Matcher matcher = pattern.matcher(text);
|
||||||
@@ -1138,10 +1155,16 @@ public class LawsEnterpriseStandardServiceImpl extends ServiceImpl<LawsEnterpris
|
|||||||
|
|
||||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
||||||
log.info("企标相关数据条数:{}", esDatalist.size());
|
log.info("企标相关数据条数:{}", esDatalist.size());
|
||||||
|
|
||||||
// 过滤字段 根据标准号字段去重
|
// 过滤字段 根据标准号字段去重
|
||||||
esDatalist = esDatalist.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
|
// esDatalist = esDatalist.stream()
|
||||||
-> new TreeSet<>(Comparator.comparing(OldSystemImportDTO::getBzh))), ArrayList::new));
|
// .collect(Collectors.collectingAndThen(
|
||||||
log.info("根据标准号去重后的企标相关数据条数:{}", esDatalist.size());
|
// Collectors.toCollection(() -> new TreeSet<>(Comparator
|
||||||
|
// .comparing(OldSystemImportDTO::getBzh)
|
||||||
|
// .thenComparing(dto -> !dto.getBzzt().equals("现行有效")))), // 确保“现行有效”状态的记录优先
|
||||||
|
// ArrayList::new));
|
||||||
|
|
||||||
|
log.info("根据标准号和标准状态去重后的企标相关数据条数:{}", esDatalist.size());
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
// 转换数据
|
// 转换数据
|
||||||
|
|||||||
Reference in New Issue
Block a user