From 4c7296d45efe849dc70a3b2e2240c905481a91c9 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 29 九月 2025 17:44:46 +0800
Subject: [PATCH] 工控网涉密网联调
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/machinefile/service/NcProgramExportInnerService.java | 93 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 75 insertions(+), 18 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/machinefile/service/NcProgramExportInnerService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/machinefile/service/NcProgramExportInnerService.java
index fafafe7..a23a423 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/machinefile/service/NcProgramExportInnerService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/machinefile/service/NcProgramExportInnerService.java
@@ -5,14 +5,17 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.basesetting.machine.service.MachineService;
+import org.springblade.mdm.gkw.task.entity.MachineBackTask;
+import org.springblade.mdm.gkw.task.service.MachineBackTaskService;
import org.springblade.mdm.machinefile.entity.MachineAcceptedFile;
import org.springblade.mdm.machinefile.entity.MachineFile;
+import org.springblade.mdm.machinefile.events.ExportedToInnerEvent;
import org.springblade.mdm.program.entity.NcProgramExchange;
import org.springblade.mdm.program.mapper.NcProgramExchangeMapper;
import org.springblade.mdm.program.service.ProgramAnnotationService;
@@ -43,22 +46,25 @@
private final OssTemplate ossTemplate;
private final MachineFileService machineFileService;
private final MachineService machineService;
- private final MachineAnnotationConfig annoConfig;
+ private final AnnotationProcessorHelper annotationProcessorHelper;
private final ProgramAnnotationService programAnnotationService;
+
+ private final MachineBackTaskService machineBackTaskService;
/**
* 瀵煎嚭鍒版秹瀵嗙綉
- * @param acceptedFileIds
- * @param os
- * @throws IOException
+ * @param acceptedFileIds 鎺ュ彈鐨勬枃浠秈d绂讳簡鍚�
+ * @param os 杈撳嚭娴�
+ * @throws IOException 鎿嶄綔zip鍙兘瀵艰嚧鐨処O寮傚父
*/
@Transactional
public void exportToInner(List<Long> acceptedFileIds, ServletOutputStream os) throws IOException {
+ List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.lambdaQuery().in(MachineAcceptedFile::getId,acceptedFileIds).list();
try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os
-
- List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.lambdaQuery().in(MachineAcceptedFile::getId,acceptedFileIds).list();
Map<String,List<MachineAcceptedFile>> map = acceptedFiles.stream()
.collect(Collectors.groupingBy(s -> ProgramFileNameParser.parseProgramName(s.getName()).logicProgramName()));
+
+ this.createFoldersInZip(zipOut,map.keySet());
for (Map.Entry<String, List<MachineAcceptedFile>> entry : map.entrySet()) {
String programName = entry.getKey();
@@ -69,17 +75,68 @@
addInputStreamToZip(zipOut,ins , programName + "/" + acceptedFile.getName(),acceptedFile.getName(),machineFile.getMachineCode());
}
acceptedFile.setExportTime(DateUtil.now());
+ acceptedFile.setStatus(MachineAcceptedFile.STATUS_EXPORTED);
}
-
}
machineAcceptedService.updateBatchById(acceptedFiles);
+
+ //鏇存柊浠诲姟鐘舵��
+ List<Long> backTaskIdList = acceptedFiles.stream().map(MachineAcceptedFile::getBackTaskId).filter(Objects::nonNull).toList();
+ this.finishTask(backTaskIdList);
+
+ SpringUtil.publishEvent(new ExportedToInnerEvent("exportToInner",acceptedFiles));
}
os.close();
+
+
+ }
+
+ /**
+ * 鍒涘缓宸﹀彸鐨勭▼搴忓寘鍚嶆枃浠跺す
+ * @param zipOut zip杈撳嚭娴�
+ * @param folderSet 绋嬪簭鎶ュ悕鏂囦欢澶归泦鍚�
+ * @throws IOException zipIO鎿嶄綔寮傚父
+ */
+ void createFoldersInZip(ZipOutputStream zipOut,Set<String> folderSet) throws IOException {
+ for(String folderName : folderSet){
+ ZipEntry zipEntry = new ZipEntry(folderName+"/");// "/"缁撳熬琛ㄧず鏂囦欢澶�
+ zipOut.putNextEntry(zipEntry);
+ zipOut.closeEntry();
+ }
+
+
}
+ void finishTask(List<Long> backTaskIdList){
+ if(backTaskIdList.isEmpty()){
+ return;
+ }
+ for(Long backTaskId : backTaskIdList){
+ MachineBackTask backTask = machineBackTaskService.getById(backTaskId);
+ List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.listByBackTaskId(backTaskId);
+
+ if(acceptedFiles.size() == backTask.getSegCount()) {
+ backTask.setStatus(MachineBackTask.STATUS_FINISHED);
+ backTask.setFinishTime(new Date());
+
+ machineBackTaskService.updateById(backTask);
+ }
+
+ }
+ }
+
+ /**
+ * j灏嗚緭鍏ユ祦鍔犲叆zip
+ * @param zipOut zip鏂囦欢杈撳嚭閲岃矾
+ * @param inputStream 鏂囦欢鐨勮緭鍏ユ祦
+ * @param entryName entryName
+ * @param filename 鍘熷鏂囦欢鍚�
+ * @param machineCode 鏈哄簥浠g爜
+ * @throws IOException 寮傚父
+ */
public void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName,String filename,String machineCode)
throws IOException {
// 鍒涘缓鏂扮殑 ZIP 鏉$洰
@@ -99,15 +156,15 @@
/**
* 缁欏鍑烘枃浠跺鍔犳敞閲婏紝娑夊瘑缃戣鐢�
- * @param inputStream
- * @param filename
- * @param machineCode
- * @return
- * @throws IOException
+ * @param inputStream 杈撳叆娴�
+ * @param filename 鏂囦欢鍚�
+ * @param machineCode 鏈哄簥浠g爜
+ * @return 瀹屾垚鍚庣殑stream
+ * @throws IOException 鎿嶄綔寮傚父
*/
InputStream setAnnotations(InputStream inputStream,String filename,String machineCode) throws IOException {
Machine machine = this.machineService.getByCode(machineCode);
- AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annoConfig);
+ AnnotationProcessor annoProcessor = annotationProcessorHelper.getProcessor(machine.getControlSystem());
AnnotationData annoData = new AnnotationData();
annoData.setFilename(filename);
@@ -115,8 +172,8 @@
AnnotationProperties annoProps = annoProcessor.getAnnotationProperties();
- ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
- String statusLine = FileContentUtil.readLineAt(bais,annoProps.getStatusLineIndex());
+ ByteArrayInputStream byteInsStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
+ String statusLine = FileContentUtil.readLineAt(byteInsStream,annoProps.getStatusLineIndex());
String text = programAnnotationService.removeAnnotation(machine.getControlSystem(),statusLine);
if(AnnotationUtil.isStatusContent(text)){
@@ -126,9 +183,9 @@
//娌℃湁鎸夎瘯鍒囧鐞�
annoData.setProgramStatus(AnnotationUtil.SQ);
}
- bais.reset();
+ byteInsStream.reset();
//
- return annoProcessor.putAnnotation(annoData,bais);
+ return annoProcessor.putAnnotation(annoData,byteInsStream);
}
}
--
Gitblit v1.9.3