From f77951077aa87daae6460c0161868bd5661efb2f Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 16 八月 2025 14:16:52 +0800
Subject: [PATCH] bug修复

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/task/cure/CureFinishOperateTask.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/task/cure/CureFinishOperateTask.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/task/cure/CureFinishOperateTask.java
index 9d1720b..67eb5c3 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/task/cure/CureFinishOperateTask.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/task/cure/CureFinishOperateTask.java
@@ -4,8 +4,12 @@
 import lombok.extern.slf4j.Slf4j;
 import org.checkerframework.checker.units.qual.N;
 import org.flowable.engine.delegate.DelegateExecution;
+import org.springblade.core.oss.OssTemplate;
+import org.springblade.core.oss.model.BladeFile;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.DateUtil;
+import org.springblade.mdm.basesetting.machine.MachineService;
+import org.springblade.mdm.basesetting.machine.entity.Machine;
 import org.springblade.mdm.commons.contants.ParamConstants;
 import org.springblade.mdm.flow.entity.FlowProgramFile;
 import org.springblade.mdm.flow.service.FlowCommonService;
@@ -14,9 +18,15 @@
 import org.springblade.mdm.program.entity.NcNode;
 import org.springblade.mdm.program.service.NcNodeAutoCreateService;
 import org.springblade.mdm.program.service.NcNodeService;
+import org.springblade.mdm.program.service.ProgramAnnotationService;
+import org.springblade.mdm.utils.FileContentUtil;
 import org.springblade.system.feign.ISysClient;
+import org.springblade.system.pojo.entity.Dict;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.time.LocalDate;
 import java.util.Arrays;
 import java.util.Date;
@@ -31,6 +41,13 @@
 	private final FlowCommonService flowCommonService;
 	private final FlowProgramFileService flowProgramFileService;
 	private final ISysClient sysClient;
+	private final OssTemplate ossTemplate;
+	private final ProgramAnnotationService programAnnotationService;
+	private final MachineService machineService;
+
+	public static final String GH = "GH";
+
+
 	/**
 	 * 榛樿鏈夋晥鏈熼棿锛堟湀鏁帮級,2骞�
 	 */
@@ -41,10 +58,10 @@
 	 * 鍥哄寲瀹℃壒閫氳繃澶勭悊浠诲姟锛�
 	 * @param execution 娴佺▼execution
 	 */
-	public void execute(DelegateExecution execution) {
+	@Transactional
+	public void execute(DelegateExecution execution) throws IOException {
 		log.info("鎵ц鍥哄寲绋嬪簭浠诲姟鏈嶅姟,娴佺▼瀹炰緥id={}", execution.getProcessInstanceId());
 		//鍥哄寲绋嬪簭妫�鏌ユ湁鏁堟湡锛�
-		//1.灏嗘祦绋嬭缃�
 		dealWithNode(execution.getProcessInstanceId());
 	}
 
@@ -52,7 +69,7 @@
 	 * 澶勭悊node鐘舵�併��
 	 * @param processInstanceId 娴佺▼瀹炰緥id
 	 */
-	void dealWithNode(String processInstanceId) {
+	void dealWithNode(String processInstanceId) throws IOException {
 		//绋嬪簭鍖呰妭鐐瑰拰涓嬪睘绋嬪簭鑺傜偣(鍖呮嫭鍘嗗彶鑺傜偣闈炴渶鏂扮増鏈殑)浠庤瘯鍒囨尓鍒板浐鍖栦笅闈�
 		//绋嬪簭鍖呰妭鐐� 璁剧疆鏈凡鍥哄寲
 		NcNode pkgNode =  nodeService.lambdaQuery().eq(NcNode::getProcessInstanceId, processInstanceId).one();
@@ -78,7 +95,7 @@
 	 * @param pkgNode 瑕佹尓鍔ㄧ殑鑺傜偣
 	 * @param historyProgramPackageNodes 绋嬪簭鍖呭悕 鍘嗗彶鑺傜偣
 	 */
-	void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) {
+	void moveNodeToCuredTree(NcNode pkgNode,List<NcNode> historyProgramPackageNodes, FlowProgramProperties programProperties) throws IOException {
 		//鍒涘缓鑺傜偣鍒版満搴婄骇鍒�.(鍥哄寲鏍�)
 		NcNode machineNode = ncNodeAutoCreateService.createNodeTreeToMachine(programProperties);
 
@@ -104,6 +121,8 @@
 		}
 		nodeService.updateBatchById(historyProgramPackageNodes);
 
+		Machine machine = machineService.getByCode(pkgNode.getMachineCode());
+		List<Dict> annoDicts = programAnnotationService.getAnnotionList();
 		//鏂扮殑娴佺▼鏂囦欢锛岄渶瑕佸湪鍖呰妭鐐逛笅鏂板缓锛屼笉鑳界敤鑰佺殑
 		List<FlowProgramFile> files = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId,pkgNode.getProcessInstanceId()).list();
 		for(FlowProgramFile flowProgramFile : files){
@@ -117,6 +136,39 @@
 			newProgNode.setFlowProgramFileId(flowProgramFile.getId());
 			newProgNode.setIsCured(1);
 			ncNodeService.save(newProgNode);
+
+			//淇敼鏂囦欢鍐呭鏇存柊娉ㄩ噴锛屽苟鏇存柊鏂囦欢鏁版嵁鐨勫湴鍧�
+			///鏇挎崲娉ㄩ噴鍚庢�绘槸涓嶈鍟�
+			setGhAnnotation(flowProgramFile,machine.getMachineGroupCode(),annoDicts);
+
+			flowProgramFileService.updateById(flowProgramFile);
+		}
+	}
+
+	/**
+	 * 璁剧疆鍥哄寲娉ㄩ噴,瀹炵幇鏂瑰紡锛岃幏鍙栨枃浠跺瓧鑺備笅锛屼慨鏀瑰悗鏇挎崲鏂囦欢
+	 * @param flowProgramFile oss 鏂囦欢
+	 *
+	 */
+	void setGhAnnotation(FlowProgramFile flowProgramFile,String machineGroup,List<Dict> annoDicts) throws IOException {
+		String ossName = flowProgramFile.getOssName();
+		//
+		try(InputStream ins = ossTemplate.statFileStream(ossName);){
+			String annoTxt = programAnnotationService.generateAnnotation("GH",machineGroup,annoDicts);
+			int statusLineIndex = 2;
+			String line2 = FileContentUtil.readLineAt(ins,statusLineIndex);//绗笁琛屽簲璇ユ槸鐘舵�佹敞閲�
+			InputStream finishedStream;
+			if(programAnnotationService.isAnnotation(line2,machineGroup,annoDicts)){
+				finishedStream = FileContentUtil.replaceAtLine(ins,statusLineIndex,annoTxt);
+			}else{
+				finishedStream = FileContentUtil.insertLine(ins,statusLineIndex,annoTxt);
+			}
+			try(finishedStream) {
+				finishedStream.reset();
+				BladeFile bfile = ossTemplate.putFile(flowProgramFile.getName(), finishedStream);
+				//鏇挎崲鍘熸湁鐨勬枃浠跺湴鍧�
+				flowProgramFile.setOssName(bfile.getName());
+			}
 		}
 	}
 

--
Gitblit v1.9.3