From 12f2fafc574afb4c534ab59244f2b954d1876e9f Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 22 九月 2025 19:37:20 +0800
Subject: [PATCH] 解决回传工控网记录无法撤销的问题

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java |  146 +++++++++++++++++++-----------------------------
 1 files changed, 59 insertions(+), 87 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
index 01f6c61..5708e6f 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
@@ -18,6 +18,9 @@
 import org.springblade.core.tool.utils.Func;
 import org.springblade.mdm.basesetting.machine.entity.Machine;
 import org.springblade.mdm.basesetting.machine.service.MachineService;
+import org.springblade.mdm.basesetting.producedivision.entity.QinzheFgb;
+import org.springblade.mdm.basesetting.producedivision.service.QinzheFgbService;
+import org.springblade.mdm.commons.contants.RegExpConstants;
 import org.springblade.mdm.commons.service.ParamService;
 import org.springblade.mdm.flow.entity.FlowProgramFile;
 import org.springblade.mdm.flow.service.CureFlowService;
@@ -31,6 +34,7 @@
 import org.springblade.mdm.program.vo.DncSendBackFile;
 import org.springblade.mdm.program.vo.ProgramAnnotation;
 import org.springblade.mdm.utils.FileContentUtil;
+import org.springblade.mdm.utils.ProgramFileNameParser;
 import org.springblade.mdm.utils.ZipTextFileContentUtil;
 import org.springblade.system.pojo.entity.DictBiz;
 import org.springframework.stereotype.Service;
@@ -38,12 +42,12 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
-import java.lang.annotation.Annotation;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardOpenOption;
 import java.time.Duration;
 import java.util.*;
+import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -58,7 +62,7 @@
 @AllArgsConstructor
 public class DNCSendBackService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> {
 	private final CureFlowService cureFlowService;
-	private final ProgramAnnotationService programAnnotationService;
+	private final QinzheFgbService qinzheFbgService;
 	private final NcNodeService ncNodeService;
 	private final OssTemplate ossTemplate;
 	private final BladeRedis bladeRedis;
@@ -66,7 +70,6 @@
 	private final DncBackFileService dncBackFileService;
 	private final MachineService machineService;
 	private final ParamService paramService;
-	private final MachineAnnotationConfig machineAnnotationConfig;
 
 	/**
 	 * 鍋忕鍗曟枃浠舵湯灏剧殑妯″紡锛歅+鏁板瓧
@@ -133,56 +136,48 @@
 				}
 			}
 
-			List<DictBiz> annotionDictList = programAnnotationService.getAnnotionDictList();
 			NcNode programPackageNode;
 			//鐩綍鍒楄〃锛屽嵆绋嬪簭鍖呭垪琛�
 			for(String entryName : dirEntryNameList){
 				DncSendBackData progData = new DncSendBackData();
-				String folderName = StringUtils.removeEnd(entryName,"/");
+				String packageName = StringUtils.removeEnd(entryName,"/");
 
-				//PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName);
-				String packageName = folderName;//pkgAndEdition.getProgramPackageName();
-				//String processEdition = pkgAndEdition.getProcessEdition();
-				/*
-				if(StringUtils.isBlank(packageName) || StringUtils.isBlank(processEdition)){
-					throw new ServiceException("鍖呭唴鏂囦欢澶瑰悕鏍煎紡閿欒锛屽簲璇ヤ负[闆剁粍浠跺彿-宸ュ簭鍙�-宸ュ簭鐗堟]:"+folderName);
-				}*/
-
-				progData.setProgramName(packageName);
-				String statusLine;
 				Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(entryName)).findFirst();
 				if(optFilename.isPresent()){
 					entry = zipFile.getEntry(optFilename.get());
 					InputStream ins = zipFile.getInputStream(entry);
-					ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(ins));;
+					ByteArrayInputStream byteArrayIns = new ByteArrayInputStream(IOUtils.toByteArray(ins));
+
+					//瑙f瀽鏈哄簥
 					progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant()));
 
 					AnnotationProperties defAnnoProperties =AnnotationProperties.getDefault();
-					statusLine = FileContentUtil.readLineAt(bais,defAnnoProperties.getStatusLineIndex());//鐘舵�佹敞閲婅
-					bais.reset();
+					String statusLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getStatusLineIndex());//鐘舵�佹敞閲婅
+					byteArrayIns.reset();
+					String sendPathLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getSendPathLineIndex());//鐘舵�佹敞閲婅
+					byteArrayIns.reset();
 
-					if(statusLine.contains("SQ")){
+					if(statusLine.contains(AnnotationUtil.GH)){
+						//鍥哄寲锛屼笉搴斿洖浼狅紝蹇界暐
+						log.warn("鐘舵�亄},涓嶅簲鍥炰紶锛屽拷鐣�",statusLine);
+						continue;
+					}
+
+					Machine machine = this.machineService.getMachineBySendPathAnnotation(sendPathLine);
+					if(machine == null){
+						throw new ServiceException("鏍规嵁涓嬪彂璺緞鏈壘鍒扮▼搴忓搴旂殑鏈哄簥:"+sendPathLine);
+					}
+
+					progData.setProgramName(packageName);
+
+					if(statusLine.contains(AnnotationUtil.SQ)){
 						//璇曞垏
 						programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName);//TODO 杩橀渶鏍规嵁鏈哄簥缁勶紙濡備綍鑾峰彇锛熸牴鎹笅鍙戣矾寰勮幏鍙栨満搴婏紝杩涜�岃幏鍙栵級锛�,processEdition
-					}else if(statusLine.contains("GH")){
-						//TODO 鍥哄寲锛屾牴鏈笉闇�瑕佸洖浼狅紝搴旇鎻愮ず鎶ラ敊銆傛垨鑰呬笉杩涘叆鍒楄〃锛屾垨鍒楄〃涓笉鍙�夊垯鍏ュ簱
-						programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName);
-					}else if(statusLine.contains("PL")){
-						//鍋忕
+					}else if(statusLine.contains(AnnotationUtil.LG)){
+						//涓存椂鏇存敼鍗�
 						programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName);
 					}else{
-						//鏌ヨ鏄惁杞﹀簥/鐜板満缂栧埗锛屾槸杞﹀簥鍙互鏀捐繃锛屾寜璇曞垏澶勭悊锛�
-						//TODO 鐜板満缂栧埗鐨勭▼搴忥紝鎵撳寘鏃跺繀椤诲湪鏂囦欢涓鍔犱笅鍙戣矾寰勶紙鍔犲叆鍚庯級
-						programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName);
-						if(programPackageNode!=null){
-							Machine machine = machineService.getByCode(programPackageNode.getMachineCode());
-							String chechuangVal = paramService.turninngValue();
-							if(StringUtils.equals(machine.getMachineSpec(),chechuangVal)){
-								//杞﹀簥
-								ProgramAnnotation pa = AnnotationUtil.getProgramAnnotationFormat(machine.getControlSystem(),annotionDictList);
-								statusLine = pa.addAnnotation(ProgramAnnotationService.SQ);
-							}
-						}
+						throw new ServiceException("鐘舵�佹敞閲婁笉鍦ㄨ寖鍥村唴:"+statusLine+",浠呰瘯鍒囥�佷复鏃舵洿鏀瑰崟鍙互鍥炰紶");
 					}
 
 					if(programPackageNode != null) {
@@ -214,25 +209,35 @@
 	}
 
 	/**
-	 * 浠庢枃浠跺す鍚嶈В鏋愬嚭绋嬪簭鍖呭悕鍜屽拰宸ュ簭鐗堟
-	 * @param folderName 鏂囦欢澶瑰悕
-	 * @return 缁撴瀯鏁版嵁
+	 * 淇绋嬪簭鍖呭悕,fanuc涓嶈瘑鍒笅鍒掔嚎锛屼笅鍙戞椂杞崲涓轰簡-锛岃繖閲岄渶瑕佺‘璁ゃ�傚簲璇ユ槸浠庡鍑鸿褰曚腑鏌ユ壘淇敼鍚庣殑鍖呭悕锛屼絾鏄幇鍦虹紪鍒剁殑娌℃湁鍜嬪姙锛�
+	 * @param packageNameInZip
+	 * @return
 	 */
 	/*
-	PackageAndProcessEdition parseProgramPackageFromFolderName(String folderName){
-		int index = StringUtils.lastIndexOf(folderName,'-');
-		String processEditon = "";
-		String packageName = "";
-		if(index != -1){
-			processEditon = folderName.substring(index+1);
-			packageName = folderName.substring(0,index);
+	private String fixProgramPackageName(String packageNameInZip) {
+		Matcher matcher = RegExpConstants.PROGRAM_PACKAGE_PATTERN.matcher(packageNameInZip);
+
+		String drawingNo = null;
+		if(matcher.find()) {
+			drawingNo = matcher.group(1);
+		}
+		String processNo = null;
+		if(matcher.find()) {
+			processNo = matcher.group(2);
 		}
 
-		PackageAndProcessEdition result = new PackageAndProcessEdition();;
-		result.setProgramPackageName(packageName);
-		result.setProcessEdition(processEditon);
-		return result;
-	}*/
+		String processEdition = null;
+		if(matcher.find()) {
+			processEdition = matcher.group(3);
+		}
+		if(drawingNo != null && processNo != null && processEdition != null) {
+			if(drawingNo.contains("_")) {
+
+			}
+		}
+		return packageNameInZip;
+	}
+	*/
 
 	/**
 	 * 鍏ュ簱鍥炰紶鏂囦欢,骞跺惎鍔ㄥ浐鍖栨祦绋�
@@ -280,10 +285,7 @@
 			//鏍规嵁鍐呴儴鏂囦欢锛岃鍙栧拰鍒嗘瀽绋嬪簭鍖呭拰绋嬪簭鏂囦欢鏁版嵁
 			List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
 			for(String dir : dirList){
-				String folderName = StringUtils.removeEnd(dir,"/");
-
-				//PackageAndProcessEdition pkgAndEdition = folderName;//parseProgramPackageFromFolderName(folderName);
-				String programPackageName = folderName; //pkgAndEdition.getProgramPackageName();
+				String programPackageName = StringUtils.removeEnd(dir,"/");
 
 				Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst();
 
@@ -323,7 +325,7 @@
 							FlowProgramFile newFlowFile = new FlowProgramFile();
 							newFlowFile.setProgramName(packageNode.getName());
 							newFlowFile.setProcessInstanceId(null);//鍏堢疆涓虹┖锛屽惎鍔ㄦ祦绋嬪悗璁剧疆璇ュ��
-							newFlowFile.setFileType("program");
+							newFlowFile.setFileType(FlowProgramFile.TYPE_PROGRAM);
 							newFlowFile.setName(fileName);
 							InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName));
 							BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins);
@@ -387,37 +389,6 @@
 		String zipFileName = bladeRedis.get(getFileKey());
 		return ZipTextFileContentUtil.getTextContent(this.ossTemplate.statFileStream(zipFileName),entryName);
 
-		/*
-		try(InputStream inputStream = this.ossTemplate.statFileStream(zipFileName);){
-			Path tempZipFile = createTempFile(inputStream);
-
-			ZipEntry entry;
-			try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) {
-				Enumeration<? extends ZipEntry> entries = zipFile.entries();
-				while (entries.hasMoreElements()) {
-					entry = entries.nextElement();
-					if (!entryName.equals(entry.getName())) {
-						continue;
-					}
-					try (InputStream fileIns = zipFile.getInputStream(zipFile.getEntry(entryName))) {
-						ByteArrayInputStream bos = new ByteArrayInputStream(fileIns.readAllBytes());
-						boolean isText = StringUtils.endsWithIgnoreCase(entryName,".txt") || StringUtils.endsWithIgnoreCase(entryName,".nc")|| StringUtils.endsWithIgnoreCase(entryName,".xml");
-						if(!isText) {
-							isText = FileContentUtil.isTextFile(bos);
-						}
-						if (isText) {
-							bos.reset();
-							result = FileContentUtil.getContentFromStream(bos);
-						} else {
-							result = "<闈炴枃鏈枃浠�>";
-						}
-					}
-
-				}
-			}
-		}
-
-		return result;*/
 	}
 
 }
@@ -431,3 +402,4 @@
 		return programPackageName+"-"+processEdition;
 	}
 }
+

--
Gitblit v1.9.3