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 | 227 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 191 insertions(+), 36 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 4574869..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
@@ -2,6 +2,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springblade.mdm.program.service.ProgramAnnotationService;
import org.springblade.mdm.utils.FileContentUtil;
import org.springblade.system.pojo.entity.DictBiz;
@@ -19,27 +20,74 @@
protected AnnotationProperties annotationProperties;
- @Override
- public InputStream setFilenameAnnotation(String fileName, InputStream inputStream) throws IOException {
- List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList();
- ByteArrayInputStream bais = new ByteArrayInputStream(com.qiniu.util.IOUtils.toByteArray(inputStream));
-
- String line = FileContentUtil.readLineAt(bais, annotationProperties.getProgramNameLineIndex());
- bais.reset();
- boolean isAnnotation = AnnotationUtil.isAnnotation(line,this.getControlSystem(),annoDicts);
- InputStream insAfter;
- //鍔犲叆绋嬪簭鍚嶆敞閲婅
- String proNameLine = AnnotationUtil.generateAnnotation(FilenameUtils.removeExtension(fileName),getControlSystem(),annoDicts);
- if(isAnnotation){
- insAfter = FileContentUtil.replaceAtLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine);
- }else{
- insAfter = FileContentUtil.insertLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine);
- }
- return insAfter;
+ protected List<DictBiz> getAnnotationDictList(){
+ return programAnnotationService.getAnnotionDictList();
}
@Override
- public InputStream setAnnotation(AnnotationData annoData,InputStream inputStream) throws IOException {
+ 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(sendPathRepl,getControlSystem(),annoDicts);//鍔犱簡娉ㄩ噴涔嬪悗鐨勬枃鏈�
+
+ String sendPathLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//绗�2琛屾槸鍙戦�佽矾寰�
+ byteInputStream.reset();
+
+ 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;
+ }
+ }else{
+ finishedStream = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
+ }
+ finishedStream.reset();
+ }
+
+ return finishedStream;
+
+ }
+ @Override
+ public InputStream putFilenameAnnotation(String fileName, InputStream inputStream) throws IOException {
+ List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList();//TODO 杩欓噷搴旇涓嶇敤鍔犺浇锛屽弬鏁颁紶杩囨潵灏辫
+ ByteArrayInputStream byteStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
+
+ String programNameLine = FileContentUtil.readLineAt(byteStream, annotationProperties.getProgramNameLineIndex());
+ byteStream.reset();
+ boolean isAnnotation = AnnotationUtil.isAnnotation(programNameLine,this.getControlSystem(),annoDicts);
+ InputStream insAfterProgramName;
+ //鍔犲叆绋嬪簭鍚嶆敞閲婅
+ String proNameAnnotation = AnnotationUtil.generateAnnotation(FilenameUtils.removeExtension(fileName),getControlSystem(),annoDicts);
+
+ if(isAnnotation){//鏄敞閲�
+ //鎻愬彇娉ㄩ噴鍐呮枃瀛�
+ //String planText = AnnotationUtil.removeAnnotation(getControlSystem(),programNameline,annoDicts);
+ if(!StringUtils.equals(programNameLine,proNameAnnotation)) {
+ //娉ㄩ噴涓嶆槸绋嬪簭鍚嶏紙宸ヨ壓鍛樿嚜宸卞啓鐨勬敞閲婏級锛屾彃鍏�
+ insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation);
+ }else{
+ //鏄▼搴忓悕娉ㄩ噴锛屼笉澶勭悊锛岃繑鍥炲師stream
+ insAfterProgramName = byteStream;
+ }
+ }else{
+ //闈炴敞閲婏紝鎻掑叆鐘舵��
+ insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation);
+ }
+
+ return insAfterProgramName;
+ }
+
+ @Override
+ public InputStream putAnnotation(AnnotationData annoData, InputStream inputStream) throws IOException {
List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList();
InputStream finishedStream;
@@ -47,31 +95,71 @@
ByteArrayInputStream byteInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
//1鍔犲叆鍙戦�佽矾寰勭殑娉ㄩ噴
- String sendPathAnnotation = AnnotationUtil.generateAnnotation(annoData.getSendPath(),getControlSystem(),annoDicts);//鍔犱簡娉ㄩ噴涔嬪悗鐨勬枃鏈�
+ InputStream insAfterSetSendDir = putSendPathAnnotation(annoData.getSendPath(),byteInputStream,annoDicts);
- String sendDirLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//绗�2琛屾槸鍙戦�佽矾寰�
- byteInputStream.reset();
- String statusLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getStatusLineIndex());//鐘舵�佹敞閲�
- byteInputStream.reset();
+ InputStream insAfterStatus = putStatusAnnotation(annoData.getProgramStatus(),insAfterSetSendDir,annoDicts);
- InputStream insAfterSetSendDir ;
- if(AnnotationUtil.isAnnotation(sendDirLine,getControlSystem(),annoDicts)){
- insAfterSetSendDir = FileContentUtil.replaceAtLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
+ if(StringUtils.isNotBlank(annoData.getDeviation())){
+ finishedStream = putDeviationAnnotation(annoData.getDeviation(),insAfterStatus,annoDicts);
}else{
- insAfterSetSendDir = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation);
- }
-
- insAfterSetSendDir.reset();
- //鍔犲叆鐘舵�佹敞閲婅
- String statusAnnotation = AnnotationUtil.generateAnnotation(annoData.getProgramStatus(),getControlSystem(),annoDicts);//娉ㄩ噴鍚庣殑鐘舵�佹枃鏈�
- if(AnnotationUtil.isAnnotation(statusLine,getControlSystem(),annoDicts)){
- finishedStream = FileContentUtil.replaceAtLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation);
- }else{
- finishedStream = FileContentUtil.insertLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation);
+ //鏄洿鏀瑰崟鍙凤紝涓嶅鐞嗙洿鎺ヨ繑鍥炲師杈撳叆娴�
+ finishedStream = insAfterStatus;
}
}
return finishedStream;
+ }
+
+ protected InputStream putStatusAnnotation(String status,InputStream inputStream,List<DictBiz> annoDicts) throws IOException {
+ InputStream insAfterStatus;
+ //鍔犲叆lg鍗曞彿
+
+ String statusLine = FileContentUtil.readLineAt(inputStream,annotationProperties.getStatusLineIndex());//鐘舵�佹敞閲�
+ String stationAnnotation = AnnotationUtil.generateAnnotation(status,getControlSystem(),annoDicts);
+
+ inputStream.reset();
+ if(AnnotationUtil.isAnnotation(statusLine,getControlSystem(),annoDicts) ){
+ //鏄敞閲�
+ //鎻愬彇娉ㄩ噴鍐呮枃瀛�
+ String planText = AnnotationUtil.removeAnnotation(getControlSystem(),statusLine,annoDicts);
+ if(!StringUtils.equalsAny(planText,AnnotationUtil.SQ,AnnotationUtil.GH,AnnotationUtil.LG)) {
+ //娉ㄩ噴涓嶆槸鐘舵�侊紙宸ヨ壓鍛樿嚜宸卞啓鐨勬敞閲婏級锛屾彃鍏�
+ insAfterStatus = FileContentUtil.insertLine(inputStream,annotationProperties.getStatusLineIndex(),stationAnnotation);
+ }else{
+ //鏄姸鎬佹敞閲婏紝鏇挎崲
+ insAfterStatus = FileContentUtil.replaceAtLine(inputStream,annotationProperties.getStatusLineIndex(),stationAnnotation);
+ }
+ }else{
+ //闈炴敞閲婏紝鎻掑叆鐘舵��
+ insAfterStatus = FileContentUtil.insertLine(inputStream,annotationProperties.getStatusLineIndex(),stationAnnotation);
+ }
+ return insAfterStatus;
+ }
+
+ protected InputStream putDeviationAnnotation(String deviation,InputStream inputStream,List<DictBiz> annoDicts) throws IOException {
+ InputStream insAfter1;
+ //鍔犲叆lg鍗曞彿
+ String devLine = FileContentUtil.readLineAt(inputStream,annotationProperties.getDeviationLineIndex());//鐘舵�佹敞閲�
+
+ String devAnnotation = AnnotationUtil.generateAnnotation(deviation,getControlSystem(),annoDicts);
+
+ inputStream.reset();
+ if(AnnotationUtil.isAnnotation(devLine,getControlSystem(),annoDicts) ){
+ //鏄敞閲�
+ //鎻愬彇娉ㄩ噴鍐呮枃瀛�
+ String planText = AnnotationUtil.removeAnnotation(getControlSystem(),devLine,annoDicts);
+ if(!planText.equals(deviation)) {
+ //娉ㄩ噴涓嶆槸涓存椂鏇存敼鍗曞彿锛堝伐鑹哄憳鑷繁鍐欑殑娉ㄩ噴锛夛紝鎻掑叆
+ insAfter1 = FileContentUtil.insertLine(inputStream,annotationProperties.getDeviationLineIndex(),devAnnotation);
+ }else{
+ //鏄洿鏀瑰崟鍙凤紝涓嶅鐞嗙洿鎺ヨ繑鍥炲師杈撳叆娴�
+ insAfter1 = inputStream;
+ }
+ }else{
+ //闈炴敞閲婏紝鎬庢彃鍏g鍙�
+ insAfter1 = FileContentUtil.insertLine(inputStream,annotationProperties.getDeviationLineIndex(),devAnnotation);
+ }
+ return insAfter1;
}
@Override
@@ -82,6 +170,73 @@
this.annotationProperties= annotationProperties;
}
+ @Override
+ public AnnotationProperties getAnnotationProperties(){
+ return annotationProperties;
+ }
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