From fcee672452c02cc29e0e17ebc27a8c51698c6d0d Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 20 九月 2025 17:28:44 +0800
Subject: [PATCH] 优化程序注释

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java |   77 ++++++++------------------------------
 1 files changed, 17 insertions(+), 60 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
index ca948ba..25e96d7 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
@@ -16,6 +16,7 @@
 import org.springblade.mdm.machinefile.service.FileSendRecordService;
 import org.springblade.mdm.program.entity.NcProgramExchange;
 import org.springblade.mdm.program.mapper.NcProgramExchangeMapper;
+import org.springblade.mdm.program.service.programannotation.AnnotationProperties;
 import org.springblade.mdm.program.vo.MdmProgramImportVO;
 import org.springblade.mdm.utils.FileContentUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -86,15 +87,6 @@
 			extractZipToTempDir(tempZipFile,extractDir);
 
 			//璇诲彇鏂囦欢鐩綍
-			/*
-			BladeFile bfile = ossTemplate.putFile(file);//涓婁紶锛屼緵鍚庣画鍏ュ簱浣跨敤
-
-			//璁剧疆涓�涓紦瀛橈紝2灏忔椂杩囨湡
-			InputStream zipFileInputStream = file.getInputStream();//test
-
-			byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream);
-			list = parseMdmZipFromByteArray(bytes);
-			*/
 			list = readTempDir(extractDir);
 		} catch (IOException e) {
 			log.error("瀵煎叆娑夊瘑缃戞憜娓℃枃浠跺け璐�",e);
@@ -109,9 +101,6 @@
 		Path tempPath = Paths.get(tempDir);
 
 		// 鍒涘缓瑙e帇鐩爣鐩綍锛堝湪涓存椂鐩綍涓嬪垱寤轰竴涓敮涓�瀛愮洰褰曪級
-		//Path extractDir = Files.createTempDirectory(tempPath, "unzip_");
-		System.out.println("瑙e帇鐩綍: " + extractDir.toString());
-		//Files.newInputStream(Paths.get(zipFilePath));
 		try (InputStream fis = Files.newInputStream(zipFilePath);
 			 ZipInputStream zis = new ZipInputStream(fis)) {
 
@@ -161,51 +150,16 @@
 
 		return normalizePath;
 	}
-	/*
-	public static List<MdmProgramImportVO> parseMdmZipFromByteArray(byte[] zipData) throws IOException {
-		List<MdmProgramImportVO> list = new ArrayList<>();
-		Map<String,String> fileMd5Map = new HashMap<>();
-		Map<String,MdmProgramImportVO> fileDataMap = new HashMap<>();
-		try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(zipData);
-			 ZipFile zipFile = new ZipFile(channel)) {
 
-			ZipArchiveEntry entry;
-			Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
-			while (entries.hasMoreElements()) {
-				entry = entries.nextElement();
-
-				String entryName = entry.getName();
-
-				if (!entry.isDirectory()) {
-					//鐩存帴瑙f瀽绋嬪簭鐨刯son鏂囦欢
-
-
-				}
-
-			}
-
-		}
-		//璁剧疆md5鍊�
-		fileDataMap.forEach((k,v)->{
-			if(fileMd5Map.containsKey(k)){
-				v.setMd5(fileMd5Map.get(k));
-			}
-		});
-		return list;
-	}
-	*/
 
 	public List<MdmProgramImportVO> readTempDir(Path extractDir) throws IOException {
 		List<MdmProgramImportVO> list = new ArrayList<>();
 
-		List<Machine> machines = machineService.lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).list();
+		//List<Machine> machines = machineService.getEnableMachines();
 		//璇诲彇鎵�鏈夋枃浠跺す
-		//List<Path> dirs = Files.list(extractDir).filter(Files::isDirectory).toList();
 		try (DirectoryStream<Path> stream = Files.newDirectoryStream(extractDir)) {
 			for (Path path : stream) {
 				if (Files.isDirectory(path)) {
-
-
 
 					// 濡傛灉鏄瓙鐩綍锛岃鍙栧叾涓殑鏂囦欢
 					try (DirectoryStream<Path> subStream = Files.newDirectoryStream(path)) {
@@ -215,8 +169,6 @@
 							}
 						}
 					}
-					//vo.setFiles(files);
-
 				} else if (Files.isRegularFile(path)) {
 					System.out.println("鎵惧埌鏂囦欢2: " + path);
 					//杩欓噷 鎵惧埌鐨勬枃浠朵笉鏄�
@@ -237,19 +189,25 @@
 					try (InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ)) {
 						// 浣跨敤杈撳叆娴佽鍙栨枃浠跺唴瀹�
 						ByteArrayInputStream bas = new ByteArrayInputStream(inputStream.readAllBytes());
-						String line1 = FileContentUtil.readLineAt(bas,1);
+
+						AnnotationProperties defAnnoProperties = AnnotationProperties.getDefault();
+						String sendPathLine = FileContentUtil.readLineAt(bas,defAnnoProperties.getSendPathLineIndex());
 						//bas.mark(0);
 						bas.reset();
-						String line2 = FileContentUtil.readLineAt(bas,2);
-						System.out.println("line1="+line1);
-						Machine matchedMachine = null;
+						String statusLine = FileContentUtil.readLineAt(bas,defAnnoProperties.getStatusLineIndex());
+						log.info("sendPathLine={}", sendPathLine);
+
+						Machine matchedMachine = machineService.getMachineBySendPathAnnotation(sendPathLine);
+						/*
 						for (Machine machine : machines) {
-							if(Func.isNotBlank(machine.getProgSendDir()) && line1.contains(machine.getProgSendDir())){
+							if(Func.isNotBlank(machine.getProgSendDir()) && sendPathLine.contains(machine.getProgSendDir())){
 								matchedMachine = machine;
 								break;
 							}
 
 						}
+
+						 */
 						if (matchedMachine != null) {
 							vo.setName(parseProgramName(vo.getFilename()));
 							vo.setMachineCode(matchedMachine.getCode());
@@ -257,7 +215,7 @@
 							vo.setFullPath(path.toString());//鏂囦欢鍦板潃
 							vo.setSendPath(matchedMachine.getProgSendDir());
 							vo.setId(vo.getFullPath());
-							vo.setProgramStatus(programAnnotationService.removeAnnotation(matchedMachine.getControlSystem(),line2));
+							vo.setProgramStatus(programAnnotationService.removeAnnotation(matchedMachine.getControlSystem(),statusLine));
 
 							list.add(vo);
 						}
@@ -341,13 +299,15 @@
 		List<String> idList = Func.toStrList(ids);
 
 		String dictStr = bladeRedis.get(getFileKey());
+		if(dictStr == null){
+			throw new ServiceException("");
+		}
 		Path extractDir = Paths.get(dictStr);
 
 		List<MdmProgramImportVO> list = readTempDir(extractDir);
 
 		String destFileFull;
 		for(String str : idList){
-			//System.out.println(str);
 			for(MdmProgramImportVO vo : list){
 				if(StringUtils.equals(vo.getFullPath(),str)){
 					destFileFull = vo.getSendPath()+File.separator+vo.getFilename();
@@ -366,8 +326,5 @@
 			}
 		}
 
-
 	}
-
-
 }

--
Gitblit v1.9.3