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/program/service/programannotation/AbstractProcessor.java |   99 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 76 insertions(+), 23 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/programannotation/AbstractProcessor.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/programannotation/AbstractProcessor.java
index 7933d98..f788405 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/programannotation/AbstractProcessor.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/programannotation/AbstractProcessor.java
@@ -19,28 +19,34 @@
 	private ProgramAnnotationService programAnnotationService;
 
 	protected AnnotationProperties annotationProperties;
+
+	protected List<DictBiz> getAnnotationDictList(){
+		return programAnnotationService.getAnnotionDictList();
+	}
+
 	@Override
 	public InputStream putSendPathAnnotation(String sendPath, InputStream inputStream,List<DictBiz> annoDicts) throws IOException{
+		String sendPathRepl = StringUtils.replace(sendPath,"\\","/");
 		InputStream finishedStream;
 		try(inputStream){
 			ByteArrayInputStream byteInputStream =  new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
 
 			//1鍔犲叆鍙戦�佽矾寰勭殑娉ㄩ噴
-			String sendPathAnnotation = AnnotationUtil.generateAnnotation(sendPath,getControlSystem(),annoDicts);//鍔犱簡娉ㄩ噴涔嬪悗鐨勬枃鏈�
+			String sendPathAnnotation = AnnotationUtil.generateAnnotation(sendPathRepl,getControlSystem(),annoDicts);//鍔犱簡娉ㄩ噴涔嬪悗鐨勬枃鏈�
 
-			String sendDirLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//绗�2琛屾槸鍙戦�佽矾寰�
+			String sendPathLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//绗�2琛屾槸鍙戦�佽矾寰�
 			byteInputStream.reset();
 
-			if(AnnotationUtil.isAnnotation(sendDirLine,getControlSystem(),annoDicts)){
-				String planText = AnnotationUtil.removeAnnotation(getControlSystem(),sendDirLine,annoDicts);
-				if(!planText.equals(sendPath)) {
+			if(AnnotationUtil.isAnnotation(sendPathLine,getControlSystem(),annoDicts)){
+				String planText = AnnotationUtil.removeAnnotation(getControlSystem(),sendPathLine,annoDicts);
+				//String planTextRepl = StringUtils.replace(planText,"\\","/");
+				if(!planText.equals(sendPath) && !planText.equals(sendPathRepl)) {
 					//闈炶矾寰勭殑娉ㄩ噴锛屾彃鍏�
 					finishedStream = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
 				}else{
 					//鏄矾寰勶紝涓嶅鐞嗙洿鎺ヨ繑鍥炲師杈撳叆娴�
 					finishedStream = inputStream;
 				}
-				//finishedStream = FileContentUtil.replaceAtLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
 			}else{
 				finishedStream = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
 			}
@@ -76,12 +82,7 @@
 			//闈炴敞閲婏紝鎻掑叆鐘舵��
 			insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation);
 		}
-		/*
-		if(isAnnotation){
-			insAfter = FileContentUtil.replaceAtLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine);
-		}else{
-			insAfter = FileContentUtil.insertLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine);
-		}*/
+
 		return insAfterProgramName;
 	}
 
@@ -95,18 +96,7 @@
 
 			//1鍔犲叆鍙戦�佽矾寰勭殑娉ㄩ噴
 			InputStream insAfterSetSendDir = putSendPathAnnotation(annoData.getSendPath(),byteInputStream,annoDicts);
-			/*
-			String statusLine = FileContentUtil.readLineAt(insAfterSetSendDir,annotationProperties.getStatusLineIndex());//鐘舵�佹敞閲�
-			insAfterSetSendDir.reset();
 
-			//鍔犲叆鐘舵�佹敞閲婅
-			InputStream insAfterStatus;
-			String statusAnnotation = AnnotationUtil.generateAnnotation(annoData.getProgramStatus(),getControlSystem(),annoDicts);//娉ㄩ噴鍚庣殑鐘舵�佹枃鏈�
-			if(AnnotationUtil.isAnnotation(statusLine,getControlSystem(),annoDicts)){
-				insAfterStatus = FileContentUtil.replaceAtLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation);
-			}else{
-				insAfterStatus = FileContentUtil.insertLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation);
-			}*/
 			InputStream insAfterStatus = putStatusAnnotation(annoData.getProgramStatus(),insAfterSetSendDir,annoDicts);
 
 			if(StringUtils.isNotBlank(annoData.getDeviation())){
@@ -186,4 +176,67 @@
 	}
 	public abstract String getControlSystem();
 
+	@Override
+	public AnnotationData readAnnotationData(InputStream inputStream) {
+		AnnotationData data = new AnnotationData();
+
+		int maxLineIndex = maxAnnotationLineIndex();
+		try {
+			int lineCount = maxLineIndex+1;
+			List<String> lines = FileContentUtil.readFirstNLines(inputStream,lineCount);
+			fixLine(lines,lineCount);
+
+			String programNameLine = lines.get(this.getAnnotationProperties().getProgramNameLineIndex());
+			String sendPathLine = lines.get(this.getAnnotationProperties().getSendPathLineIndex());
+			String statusLine = lines.get(this.getAnnotationProperties().getStatusLineIndex());
+			String devLine =  lines.get(this.getAnnotationProperties().getDeviationLineIndex());
+
+			List<DictBiz> annoDictList= this.programAnnotationService.getAnnotionDictList();
+			data.setFilename(AnnotationUtil.removeAnnotation(this.getControlSystem(),programNameLine,annoDictList));
+			data.setSendPath(AnnotationUtil.removeAnnotation(this.getControlSystem(),sendPathLine,annoDictList));
+
+			String statusText = AnnotationUtil.removeAnnotation(this.getControlSystem(),statusLine,annoDictList);
+			if(AnnotationUtil.isStatusContent(statusText)){
+				data.setProgramStatus(statusText);
+
+				if(AnnotationUtil.LG.equals(statusText)) {
+					data.setDeviation(AnnotationUtil.removeAnnotation(this.getControlSystem(), devLine, annoDictList));
+				}
+			}
+
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+
+		return data;
+	}
+
+	/**
+	 * 娌℃湁鐨勮濉厖鏈┖涓�
+	 * @param lines
+	 * @return
+	 */
+	void fixLine(List<String> lines,int fixLineCount){
+		int needFix = fixLineCount - lines.size();
+		if(needFix > 0){
+			for(int i = 0 ; i < needFix ; i++){
+				lines.add(StringUtils.EMPTY);
+			}
+		}
+	}
+
+	private int maxAnnotationLineIndex(){
+		int max = this.getAnnotationProperties().getDeviationLineIndex();
+		if(max < this.getAnnotationProperties().getStatusLineIndex()){
+			max = this.getAnnotationProperties().getStatusLineIndex();
+		}
+
+		if(max < this.getAnnotationProperties().getSendPathLineIndex()){
+			max = this.getAnnotationProperties().getSendPathLineIndex();
+		}
+		if(max < this.getAnnotationProperties().getProgramNameLineIndex()){
+			max = this.getAnnotationProperties().getProgramNameLineIndex();
+		}
+		return max;
+	}
 }

--
Gitblit v1.9.3