feat: 老法规外标体系关联导入

This commit is contained in:
2023-12-05 14:35:45 +08:00
parent a92e9d1869
commit 3e6b549e06
3 changed files with 39 additions and 29 deletions
@@ -136,13 +136,4 @@ public class OldSystemController {
oldSystemService.importGbStandSystem(file, response);
}
@PostMapping("/importFbStandSystem")
@AutoLog(value = "老法规系统-导入外标体系")
@ApiOperation(value="老法规系统-导入外标体系", notes="老法规系统-导入外标体系", produces = "application/octet-stream")
@ApiOperationSupport(order = 11)
public void importFbStandSystem(@RequestParam("file") MultipartFile file,
HttpServletResponse response) throws IOException {
oldSystemService.importFbStandSystem(file, response);
}
}
@@ -82,11 +82,4 @@ public interface OldSystemService {
*/
void importGbStandSystem(MultipartFile file, HttpServletResponse response);
/**
* 导入外标体系
* @param file
* @param response
*/
void importFbStandSystem(MultipartFile file, HttpServletResponse response);
}
@@ -217,6 +217,14 @@ public class OldSystemServiceImpl implements OldSystemService {
if (defaultUser == null) {
throw new JeroBootException("未找到默认用户");
}
// 获取所有企标体系节点并转为Map
String moduleCode = TableNameEnum.FOREIGN_REGULATIONS.getValue();
LambdaQueryWrapper<LawsTreeNode> treeNodeWrapper = new LambdaQueryWrapper<>();
treeNodeWrapper.eq(LawsTreeNode::getModuleCode, moduleCode);
treeNodeWrapper.eq(LawsTreeNode::getDelFlag, YesOrNoEnum.NO.getValue());
List<LawsTreeNode> treeNodeList = treeNodeService.list(treeNodeWrapper);
Map<String, LawsTreeNode> nodeNameMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, o -> o));
// 转换数据
List<LawsOverseasStandard> fbList = new ArrayList<>();
for (OldSystemImportDTO dto : fbDatalist) {
@@ -313,6 +321,22 @@ public class OldSystemServiceImpl implements OldSystemService {
ossFileList.add(ossFile);
}
}
// 校验体系
String bzfl = dto.getBzfl();
if (StrUtil.isNotBlank(bzfl)) {
// 如果有/的话,只取第一个/后面的数据,无论后面有没有/
if (bzfl.contains("/")) {
bzfl = bzfl.substring(bzfl.indexOf("/") + 1);
}
// 到Map中找到对应的体系
LawsTreeNode treeNode = nodeNameMap.get(bzfl.trim());
if (treeNode != null) {
fb.setStandardSystem(treeNode.getId());
} else {
throw new JeroBootException("未找到对应的体系,标准编号:" + dto.getBzh() + "体系名称:" + bzfl);
}
}
fbList.add(fb);
} catch (Exception e) {
log.error("导入转换外标数据时发生错误:{}", e.getMessage());
@@ -332,7 +356,7 @@ public class OldSystemServiceImpl implements OldSystemService {
}
// 3. 将文件关系列表转为Map,用于快速查找
// Map<String, List<OSSFile>> standardNumberToFileMap = ossFileList.stream().collect(Collectors.groupingBy(OSSFile::getStandardNo));
Map<String, List<OSSFile>> standardNumberToFileMap = ossFileList.stream().collect(Collectors.groupingBy(OSSFile::getStandardNo));
// 4. 遍历待保存或更新的列表,设置ID
StringBuilder oldIds = new StringBuilder();
@@ -367,18 +391,25 @@ public class OldSystemServiceImpl implements OldSystemService {
}
entity.setSubstituteStandardNumber(null);
entity.setReplacedByStandardNumber(null);
// 构建updateWrapper 将其余字段全部设为null
String nodeId = entity.getStandardSystem();
entity.setStandardSystem(null);
overseasStandardService.saveOrUpdate(entity);
String standardId = entity.getId();
// 保存文件关联
// List<OSSFile> ossFiles = standardNumberToFileMap.get(entity.getStandardNumber());
// if (ossFiles != null && !ossFiles.isEmpty()) {
// OSSFile ossFile = ossFiles.get(0);
// ossFile.setStandardId(standardId);
// ossFileService.save(ossFile);
// }
List<OSSFile> ossFiles = standardNumberToFileMap.get(entity.getStandardNumber());
if (ossFiles != null && !ossFiles.isEmpty()) {
OSSFile ossFile = ossFiles.get(0);
ossFile.setStandardId(standardId);
ossFileService.save(ossFile);
}
// 保存体系
if (StrUtil.isNotBlank(nodeId)) {
lawsNodeRelationService.removeByStandardId(standardId);
lawsNodeRelationService.addRelation(nodeId, null, standardId);
}
}
log.info("老法规外标覆盖导入完成");
// 获取当前时间戳(毫秒)
@@ -972,11 +1003,6 @@ public class OldSystemServiceImpl implements OldSystemService {
}
@Override
public void importFbStandSystem(MultipartFile file, HttpServletResponse response) {
}
public boolean containsChinese(String text) {
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
Matcher matcher = pattern.matcher(text);