From 9c483e9be881783af14ad68906e78ee557005eb4 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 16 八月 2025 22:01:45 +0800
Subject: [PATCH] 修复dnc导出无header问题

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java |  116 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 64 insertions(+), 52 deletions(-)

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 9038e78..7734274 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
@@ -1,12 +1,14 @@
 
 package org.springblade.mdm.program.service;
 
+import com.alibaba.csp.sentinel.util.StringUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BizEntity;
 import org.springblade.core.mp.base.BizServiceImpl;
 import org.springblade.core.mp.support.Condition;
@@ -32,10 +34,7 @@
 
 import java.io.*;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
@@ -57,9 +56,10 @@
 	private final NcNodeService ncNodeService;
 	private final OssTemplate ossTemplate;
 	private final FlowProgramFileService flowProgramFileService;
+	private final ProgramAnnotationService programAnnotationService;
 	//public static final String PROGRAM_JSON_FILE = "exp_mdm_nc_program.json";
-	public static final String NODE_JSON_FILE = "exp_mdm_nc_node.json";
-	public static final String APPROVE_RECORD_JSON_FILE = "exp_mdm_approve_record.json";
+	//public static final String NODE_JSON_FILE = "exp_mdm_nc_node.json";
+	//public static final String APPROVE_RECORD_JSON_FILE = "exp_mdm_approve_record.json";
 
 	public static final String ANNOTATION_DICT = "machine_annotation";
 
@@ -74,24 +74,28 @@
 
 	/**
 	 * 瀵煎嚭dnc鍘嬬缉鍖�
-	 * @param approvedIdArr 寰呭鍑哄鎵硅〃id鏁扮粍
+	 * @param approvedIdArray 寰呭鍑哄鎵硅〃id鏁扮粍
 	 */
-	public void exportDnc(Long[] approvedIdArr, OutputStream os) throws IOException {
+	public void exportDnc(Long[] approvedIdArray, OutputStream os) throws IOException {
 		//FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip");
-		try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os
+		try (ZipOutputStream zipOut = new ZipOutputStream(os);os) {//os
 
-			ArrayList<Long> programPackageNodeIdList = new ArrayList<Long>();
-
-			for (Long approvedId : approvedIdArr) {
+			for (Long approvedId : approvedIdArray) {
 				NcProgramApproved approved = approvedService.getById(approvedId);
-				programPackageNodeIdList.add(approved.getNcNodeId());
-
 				addProgramPackageToZip(zipOut,approved);
-			}
-			addDataJson(zipOut, programPackageNodeIdList);
-		}
 
-		os.close();
+				approved.setStatus(NcProgramApproved.STATUS_EXPORTED);
+				approvedService.updateById(approved);
+			}
+
+			//鐘舵�佷慨鏀逛负宸插鍑�
+			/*
+			approvedService.lambdaUpdate().in(NcProgramApproved::getId, Arrays.asList(approvedIdArray))
+				.set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update();*/
+		}catch(Exception e){
+			Throwable [] err = e.getSuppressed();
+			throw new ServiceException("瀵煎嚭宸ユ帶缃戦敊璇�"+e.getMessage());
+		}
 
 	}
 
@@ -110,48 +114,39 @@
 
 		FlowProgramFile programFile;
 		NcNode programPackageNode = this.ncNodeService.getById(approved.getNcNodeId());
-		String status = "璇曞垏";
+		String status = "SQ";
 		if(programPackageNode.isDeviationProgram()){
-			status = "鍋忕";
+			status = "PL";
 		}else if(programPackageNode.hasCured()){
-			status = "鍥哄寲";
+			status = "GH";
 		}
-		List<Dict> annotationList = getAnnotionList();
+		List<Dict> annotationList = programAnnotationService.getAnnotionList();
 		for (NcNode node : programNodes) {
 			String filePathInZip = packageFolder + node.getName();
 			programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId());
-
-			InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName());
-			Machine machine = machineService.getByCode(node.getMachineCode());
-			InputStream addedIns1 = addSendDirAnnotation(inputStream,machine,annotationList);
-			InputStream addedIns2 = addProgramStatusAnnotation(addedIns1,status,machine,annotationList);
-			this.addInputStreamToZip(zipOut,addedIns2,filePathInZip);
+			if(programFile.isProgram()) {//绋嬪簭鏂囦欢锛屾墠浼氬姞鍏ュ帇缂╁寘
+				InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName());
+				Machine machine = machineService.getByCode(node.getMachineCode());
+				InputStream addedIns1 = addSendDirAnnotation(inputStream, machine, annotationList);
+				InputStream addedIns2 = addProgramStatusAnnotation(addedIns1, status, machine, annotationList);
+				this.addInputStreamToZip(zipOut, addedIns2, filePathInZip);
+			}
 		}
 
 	}
 
-	/**
-	 * 鑾峰彇瀛楀吀涓厤缃殑娉ㄩ噴
-	 * @return 瀛楀吀椤瑰垪琛�
-	 */
-	List<Dict> getAnnotionList(){
-		List<Dict> annotationList;
-		R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT);
-		if(dictsResult.isSuccess()) {
-			annotationList = dictsResult.getData();
-		}else{
-			annotationList = Collections.emptyList();
-		}
 
-		return annotationList;
-	}
 	/**
 	 * 鍔犲叆鏈哄簥涓嬪彂璺緞鍜岀▼搴忕姸鎬佺殑娉ㄩ噴
 	 * @param inputStream
 	 * @return
 	 */
 	InputStream addSendDirAnnotation(InputStream inputStream,Machine machine,List<Dict> annotationList) throws IOException {
-		return FileContentUtil.insertLine(inputStream,1,generateAnnotation(machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList));
+		//妫�娴嬬浜岃鏄惁鏄矾寰�
+		String annotationText = programAnnotationService.generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList);
+
+		//TODO 鏀瑰垽鏂鍐呭
+		return FileContentUtil.insertLine(inputStream,1,annotationText);
 	}
 
 	/**
@@ -164,8 +159,24 @@
 	 * @throws IOException
 	 */
 	InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException {
-		return FileContentUtil.insertLine(inputStream,2,generateAnnotation(status,machine.getMachineGroupCode(),annotationList));
+		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);
@@ -192,11 +203,12 @@
 	 * 瀵煎叆鏁版嵁鏂囦欢
 	 * @param zipOut
 	 */
+	/*
 	void addDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException {
 		addNodeDataJson(zipOut, programPackageNodeIdList);
 		addApproveRecordDataJson(zipOut, programPackageNodeIdList);
 	}
-
+	*/
 
 	/**
 	 * zip淇濋噸鍔犲叆鑺傜偣鐨勬暟鎹�
@@ -204,6 +216,7 @@
 	 * @param pkgNodeIdList
 	 * @throws IOException
 	 */
+	/*
 	void  addNodeDataJson(ZipOutputStream zipOut,List<Long>  pkgNodeIdList) throws IOException {
 		List<NcNode> pkgNodes =  this.ncNodeService.lambdaQuery().in(NcNode::getId, pkgNodeIdList).list();
 
@@ -228,7 +241,8 @@
 		addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),NODE_JSON_FILE);
 
 	}
-
+	*/
+	/*
 	@NotNull
 	private static JSONObject getNodeJsonObject(NcNode node) {
 		JSONObject recObj = new JSONObject();
@@ -252,17 +266,15 @@
 		recObj.put("processInstanceId", node.getProcessInstanceId());
 		return recObj;
 	}
-
+	*/
 	/**
 	 * 瀵煎叆瀹℃壒璁板綍
 	 * @param zipOut
 	 * @param programPackageNodeIdList 绋嬪簭鍖呭悕鐨刬d鍒楄〃
 	 */
+	/*
 	void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException {
-		/*
-		List<String> instanceIds = this.ncNodeService.lambdaQuery().in(NcNode::getId, programPackageNodeIdList)
-			.list().stream().map(NcNode::getProcessInstanceId).toList();
-*/
+
 		//List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getProcessInstanceId, instanceIds).list();
 		List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getNcNodeId, programPackageNodeIdList).list();
 
@@ -284,7 +296,7 @@
 		}
 		addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),"exp_mdm_approve_record.json");
 
-	}
+	}*/
 
 	void addSuperProperties(JSONObject recObj, BizEntity entity){
 		recObj.put("tenantId",entity.getTenantId());

--
Gitblit v1.9.3