From c9433fab340a766a99b2c01ca018609cac407cee Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期日, 24 八月 2025 15:17:29 +0800
Subject: [PATCH] 偏离单文件名+P1

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java        |  135 ++++----------------------
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java |   92 +++++-------------
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java             |   18 +++
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/controller/DispatchTaskController.java    |    2 
 4 files changed, 70 insertions(+), 177 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/controller/DispatchTaskController.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/controller/DispatchTaskController.java
index 010b1a8..2c23788 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/controller/DispatchTaskController.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/controller/DispatchTaskController.java
@@ -87,7 +87,7 @@
 
 			TaskAssignVO startVO = new TaskAssignVO();
 			BeanUtils.copyProperties(dispatch, startVO);
-			startVO.setTitle(startVO.getTitle()+"-"+startVO.getProcessNo()+"-"+startVO.getProcessEdition()+"鏁版帶绋嬪簭缂栧埗");
+			startVO.setTitle(startVO.getDrawingNo()+"-"+startVO.getProcessNo()+"-"+startVO.getProcessEdition()+"鏁版帶绋嬪簭缂栧埗");
 			try {
 				String instId = dispatcher.start(startVO);
 				dispatch.setStatus(TaskDispatch.STATUS_STARTED);
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 9b05349..aa96d07 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
@@ -4,6 +4,7 @@
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BizServiceImpl;
@@ -35,6 +36,7 @@
 import java.nio.file.StandardOpenOption;
 import java.time.Duration;
 import java.util.*;
+import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -55,6 +57,12 @@
 	private final FlowCommonService flowCommonService;
 	private final DncBackFileService dncBackFileService;
 	private final ProgramFlowStatusQueryService programFlowStatusQueryService;
+
+	/**
+	 * 鍋忕鍗曟枃浠舵湯灏剧殑妯″紡锛歅+鏁板瓧
+	 */
+	private static final String P_NUMBER_PATTERN = "(?i)P\\d+";
+
 	private String getFileKey(){
 		return "dncimpfile-"+ AuthUtil.getUserId();
 	}
@@ -243,7 +251,7 @@
 			//鏍规嵁鍐呴儴鏂囦欢锛岃鍙栧拰鍒嗘瀽绋嬪簭鍖呭拰绋嬪簭鏂囦欢鏁版嵁
 			List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
 			for(String dir : dirList){
-				String programPackageName1 = StringUtils.removeEnd(dir,"/");
+				//String programPackageName1 = StringUtils.removeEnd(dir,"/");
 				String folderName = StringUtils.removeEnd(dir,"/");
 
 				PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName);
@@ -254,17 +262,14 @@
 				if(optPackageNode.isEmpty()){
 					throw new ServiceException("鎵句笉鍒扮▼搴�"+programPackageName);
 				}
-
 				NcNode packageNode = optPackageNode.get();
 				if(packageNode.hasCured()) {
 					throw new ServiceException(programPackageName + "宸茬粡鍥哄寲锛岃鍕块噸澶嶅叆搴撱��");
 				}
-
 				//鍋忕绋嬪簭鍒ゆ柇鏄惁閲嶅鍥炰紶
 				if(packageNode.isDeviationProgram() && packageNode.hasLocked()) {
 					throw new ServiceException(programPackageName + "宸查攣瀹氱殑绋嬪簭涓嶅彲浠ュ啀娆″洖浼犮��");
 				}
-
 				//妫�鏌ユ槸鍚﹀湪瀹℃壒杩囩▼涓�
 				boolean active = flowCommonService.isProcessInstanceActive(packageNode.getProcessInstanceId());
 				if(active){
@@ -285,7 +290,7 @@
 					if(!entryName.endsWith("/")){
 						//瀹為檯鐨勬枃浠�
 						String fileName = StringUtils.removeStart(entryName,dir);//鍘婚櫎鏂囦欢鍚嶈矾寰勯儴鍒�
-
+						fileName = removeDeviationPart(fileName);
 						try {
 							FlowProgramFile newFlowFile = new FlowProgramFile();
 							newFlowFile.setProgramName(packageNode.getName());
@@ -306,121 +311,29 @@
 
 				pkgIdFileMap.put(packageNode.getId(),flowFiles);
 			}
-
 		}
 
 		return pkgIdFileMap;
 	}
 
-	/**
-	 * 鏇存柊鑺傜偣锛屼富瑕佹槸鍒涘缓 绋嬪簭鍖呭悕 鐨勬柊鐗堟湰銆�
-	 * @param pkgFileName zip鏂囦欢鍚�
-	 * @param programPackageIdList 绋嬪簭鍖呭悕 鑺傜偣鐨刬d鍒楄〃
-	 * @param programPackageSubMap 鏂扮殑 绋嬪簭鍖呰妭鐐筰d -> =鏂囦欢鍒楄〃 map锛岀敤浜庡洖浼犳暟鎹�
-	 * @throws IOException 璁块棶鏂囦欢寮傚父
-	 */
-	/*
-	List<NcNode> updateNodeDataByDNCBackData(String pkgFileName, List<Long> programPackageIdList,Map<Long,List<NcNode>> programPackageSubMap) throws IOException {
-		InputStream inputStream = this.ossTemplate.statFileStream(pkgFileName);
-		Path tempZipFile = createTempFile(inputStream);
-		List<NcNode> newProgramPackageNodeList = new ArrayList<>();
-		List<String> entryNameList = new ArrayList<>();
-
-		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();
-				entryNameList.add(entry.getName());
+	String removeDeviationPart(String filename){
+		String finalFilename  = filename;
+		//鍘绘帀鏂囦欢鍚嶄腑鍙兘甯︽湁鐨勫亸绂诲崟閮ㄥ垎锛�-P[搴忓彿]
+		String ext = FilenameUtils.getExtension(filename);
+		String dotExt = StringUtils.isNotBlank(ext)?"."+ext:ext;//甯︾偣鐨勬墿灞曞悕
+		String notExtName = StringUtils.removeEnd(filename,dotExt);
+		int idx = notExtName.lastIndexOf("-");
+		if(idx != -1){
+			String endPart = notExtName.substring(idx+1);
+			//Pattern.CASE_INSENSITIVE
+			boolean containsPld = endPart.matches(P_NUMBER_PATTERN);
+			if(containsPld){
+				finalFilename = notExtName.substring(0, idx)+dotExt;
 			}
-			log.info("allentrynames:{}",entryNameList);
-
-			List<NcNode> allAcceptPackages =  this.ncNodeService.lambdaQuery().in(NcNode::getId,programPackageIdList).list();
-			//鏍规嵁鍐呴儴鏂囦欢锛岃鍙栧拰鍒嗘瀽绋嬪簭鍖呭拰绋嬪簭鏂囦欢鏁版嵁
-			List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
-			for(String dir : dirList){
-				String programPackageName = StringUtils.removeEnd(dir,"/");
-				Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst();
-
-				if(optPackageNode.isEmpty()){
-					throw new ServiceException("鎵句笉鍒扮▼搴�"+programPackageName);
-				}
-
-				NcNode packageNode = optPackageNode.get();
-				if(packageNode.hasCured()) {
-					throw new ServiceException(programPackageName + "宸茬粡鍥哄寲锛岃鍕块噸澶嶅叆搴撱��");
-				}
-
-				//妫�鏌ユ槸鍚﹀湪瀹℃壒杩囩▼涓�
-				//鏍规嵁鑺傜偣淇℃伅鏌ヨ娴佺▼
-				boolean active = flowCommonService.isProcessInstanceActive(packageNode.getProcessInstanceId());
-				if(active){
-					throw new ServiceException(programPackageName+"姝e湪瀹℃壒涓紝璇峰嬁閲嶅鍏ュ簱銆�");
-				}
-
-				NcNode newProgramPkg = new NcNode();
-				BeanUtils.copyProperties(packageNode, newProgramPkg);
-				EntityUtil.clearBaseProperties(newProgramPkg);
-				newProgramPkg.setIsLastEdition(1);
-				ncNodeService.save(newProgramPkg);
-				newProgramPackageNodeList.add(newProgramPkg);
-
-				//鏃ф暟鎹洿鏂颁负鑰佺増鏈�
-				packageNode.setIsLocked(1);//鏃х増鑷姩閿佸畾
-				packageNode.setIsLastEdition(0);;
-				ncNodeService.updateById(packageNode);
-
-				//List<FlowProgramFile> newFlowFiles = new ArrayList<>();
-				List<NcNode> newProgramNodes = new ArrayList<>();
-				//鏌ユ壘鍖呬笅鐨勬枃浠舵暟鎹�,
-				entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> {
-					log.info("{}涓嬬殑鏂囦欢锛歿}",dir,entryName);
-					if(!entryName.endsWith("/")){
-						//瀹為檯鐨勬枃浠�
-						String fileName = StringUtils.removeStart(entryName,dir);//鍘婚櫎鏂囦欢鍚嶈矾寰勯儴鍒�
-						NcNode oldProgramNode = this.ncNodeService.getLastEditionProgramFile(fileName,packageNode.getId());
-						if(oldProgramNode == null){
-							log.info("{}鎵句笉鍒扮▼搴忔枃浠�",entryName);
-							throw new ServiceException(programPackageName+"涓嬫壘涓嶅埌绋嬪簭鏂囦欢"+fileName);
-						}
-
-						//鍒涘缓鏂扮増鏈殑绋嬪簭鑺傜偣
-						NcNode newProgramNode = new NcNode();
-						BeanUtils.copyProperties(oldProgramNode, newProgramNode);
-						EntityUtil.clearBaseProperties(newProgramNode);
-						newProgramNode.setIsLastEdition(1);
-						newProgramNode.setParentId(newProgramPkg.getId());
-						newProgramNode.setParentIds(newProgramPkg.getParentIds()+","+newProgramPkg.getId());
-
-						FlowProgramFile oldFlowFile = flowProgramFileService.getById(newProgramNode.getFlowProgramFileId());
-
-						FlowProgramFile newFlowFile = new FlowProgramFile();
-						BeanUtils.copyProperties(oldFlowFile, newFlowFile);
-						newFlowFile.setProcessInstanceId(null);//鍏堢疆涓虹┖锛屽惎鍔ㄦ祦绋嬪悗璁剧疆璇ュ��
-						EntityUtil.clearBaseProperties(newFlowFile);
-
-						try {
-							InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName));
-							BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins);
-							newFlowFile.setOssName(newOssFile.getName());
-						} catch (IOException e) {
-							throw new RuntimeException(e);
-						}
-						newProgramNode.setFlowProgramFile(newFlowFile);
-						newProgramNode.setVersionNumber(oldProgramNode.genNewVersionNumber());
-						newProgramNodes.add(newProgramNode);
-						//鏃ц妭鐐瑰鐞嗭紝鍜嬪姙锛熷鏋滃鍑哄伐鎺х綉 閲嶅瀵煎嚭鍛紵锛宨sLastEdition涓嶇敤璁剧疆浜嗭紝鍥犱负 绋嬪簭鍖呰妭鐐� 鏄柊鐨�
-					}
-				});
-
-				programPackageSubMap.put(newProgramPkg.getId(),newProgramNodes);
-			}
-
 		}
 
-		return newProgramPackageNodeList;
+		return finalFilename;
 	}
-	*/
 	/**
 	 * 鍒涘缓涓�涓复鏃秡ip鏂囦欢
 	 * @param inputStream 鏂囦欢鐨勮緭鍏ユ祦
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
index 21d0558..62d36d6 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
@@ -366,4 +366,22 @@
 		node.unlock();
 		this.updateById(node);
 	}
+
+	/**
+	 * 鏌ヨ鍋忕鍗曠殑搴忓彿
+	 * @param programPkgNode 鍋忕鍗曠殑绋嬪簭鍖呭悕鑺傜偣
+	 * @return 搴忓彿
+	 */
+    public long getDeviationSerialForNode(NcNode programPkgNode) {
+		return lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
+			.eq(NcNode::getName,programPkgNode.getName())
+
+			.eq(NcNode::getDrawingNo,programPkgNode.getDrawingNo())
+			.eq(NcNode::getProcessNo,programPkgNode.getProcessNo())
+			.eq(NcNode::getProcessEdition,programPkgNode.getProcessEdition())
+
+			.isNotNull(NcNode::getDeviation)
+			.le(NcNode::getCreateTime,programPkgNode.getCreateTime())  //鏃堕棿灏忎簬绛変簬褰撳墠鑺傜偣
+			.count();
+    }
 }
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java
index c2467a8..8c25d7c 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java
@@ -5,6 +5,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BizServiceImpl;
@@ -50,7 +51,6 @@
 	private final FlowProgramFileService flowProgramFileService;
 	private final ProgramAnnotationService programAnnotationService;
 
-	public static final String ANNOTATION_DICT = "machine_annotation";
 
 	/**
 	 * 鍒嗛〉鏌ヨ
@@ -108,10 +108,14 @@
 		}else if(programPackageNode.hasCured()){
 			status = "GH";
 		}
+		long deviationSerial = -1;//鍋忕鍗曞簭鍙� 锛�-1涓洪潪鍋忕鍗曪紝涓嶉渶瑕佸姞鍏�
+		if(packageNode.isDeviationProgram()) {
+			deviationSerial = ncNodeService.getDeviationSerialForNode(packageNode);
+		}
 
 		List<DictBiz> annotationDictList= programAnnotationService.getAnnotionList();
 		for (NcNode node : programNodes) {
-			String filePathInZip = packageFolder + node.getName();
+			String filePathInZip = genFilePathInZip(packageFolder,node,deviationSerial);
 			programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId());
 			if(programFile.isProgram()) {//绋嬪簭鏂囦欢锛屾墠浼氬姞鍏ュ帇缂╁寘
 				InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName());
@@ -130,75 +134,33 @@
 
 	}
 
-
 	/**
-	 * 鍔犲叆鏈哄簥涓嬪彂璺緞鍜岀▼搴忕姸鎬佺殑娉ㄩ噴
-	 * @param inputStream
-	 * @return
+	 * 鐢熸垚鍦▃ip涓殑鏂囦欢璺緞
+	 * @param packageFolder zip涓殑鏂囦欢澶�
+	 * @param programNode 绋嬪簭鑺傜偣
+	 * @param deviationSerial 鍋忕鍗曞簭鍙�
+	 * @return zip涓殑鏂囦欢璺緞
 	 */
-	/*
-	InputStream addSendDirAnnotation(InputStream inputStream,Machine machine,List<Dict> annotationList) throws IOException {
-		//妫�娴嬬浜岃鏄惁鏄矾寰�
-		String annotationText = programAnnotationService.generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList);
+	String genFilePathInZip(String packageFolder,NcNode programNode,long deviationSerial){
+		//涓烘枃浠跺悕澧炲姞鍋忕鍗曞彿
+		String filePathInZip;
 
-		//TODO 鏀瑰垽鏂鍐呭
-		return FileContentUtil.insertLine(inputStream,1,annotationText);
-	}*/
+		if(deviationSerial != -1){
+			//鍔犲叆鍋忕鍗曞簭鍙�
+			String ext = FilenameUtils.getExtension(programNode.getName());
+			String dotExt = StringUtils.isNotBlank(ext)?"."+ext:ext;//甯︾偣鐨勬墿灞曞悕
 
-	/**
-	 * 娣诲姞绋嬪簭涓撴敼鐨勬敞閲�
-	 * @param inputStream
-	 * @param status 绋嬪簭鐘舵��
-	 * @param machine
-	 * @param annotationList 閰嶇疆鐨勬敞閲婂瓧鍏稿垪琛�
-	 * @return
-	 * @throws IOException
-	 */
-	/*
-	InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException {
-		String annoText= programAnnotationService.generateAnnotation(status,machine.getMachineGroupCode(),annotationList);
-
-		return FileContentUtil.insertLine(inputStream,2,annoText);
-	}*/
-
-	/**
-	 * 鍒ゆ柇涓�琛屾枃鏈槸鍚︽槸娉ㄩ噴
-	 * @param line
-	 * @param annotationList
-	 * @return
-	 */
-	/*
-	boolean isAnnotation(String line,List<Dict> annotationList){
-		boolean isAnno = false;
-
-		return isAnno;
-	}*/
-
-
-	/*
-	String generateAnnotation(String oriTest,String machineGroupCode,List<Dict> annotationList) {
-		R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT);
-		String annotation = oriTest;
-		String begin = "(";
-		String end = ")";
-
-		Optional<Dict> dictOpt = dictsResult.getData().stream().filter(dict -> {return dict.getDictKey().equals(machineGroupCode);}).findFirst();
-		String annotationSetting = "(,)";
-		if(dictOpt.isPresent()) {
-			annotationSetting = dictOpt.get().getDictValue();
+			String temp = programNode.getName();
+			if(StringUtils.isNotBlank(ext)) {
+				temp = StringUtils.removeEnd(temp,dotExt);
+			}
+			filePathInZip = packageFolder + temp+"-P"+deviationSerial+dotExt;
+		}else{
+			//闈炲亸绂诲崟锛岀洿鎺ヤ娇鐢ㄥ師鏂囦欢鍚�
+			filePathInZip = packageFolder + programNode.getName();
 		}
-		String[] arr = annotationSetting.split(",");
-		if(arr.length == 2){
-			begin = arr[0];
-			end = arr[1];
-		}
-
-		annotation = begin + oriTest + end;
-		return annotation;
-
+		return filePathInZip;
 	}
-	*/
-
 	/**
 	 * 灏� 杈撳叆娴� 涓殑鍐呭鍐欏叆zip
 	 * @param zipOut zip杈撳嚭娴�

--
Gitblit v1.9.3