From 0d61b9bfca526e9c3da2209de8f9f367e76fd013 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期四, 18 九月 2025 18:09:35 +0800
Subject: [PATCH] 修改constant类名

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java |  299 +++++++++++++++--------------------------------------------
 1 files changed, 79 insertions(+), 220 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 55243df..2b10063 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
@@ -2,38 +2,33 @@
 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.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.flowable.engine.HistoryService;
+import org.flowable.engine.history.HistoricProcessInstance;
 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;
-import org.springblade.core.mp.support.Query;
 import org.springblade.core.oss.OssTemplate;
-import org.springblade.core.tool.api.R;
-import org.springblade.core.tool.utils.Func;
-import org.springblade.mdm.basesetting.machine.MachineService;
+import org.springblade.mdm.basesetting.machine.service.MachineService;
 import org.springblade.mdm.basesetting.machine.entity.Machine;
-import org.springblade.mdm.flow.entity.ApproveRecord;
+import org.springblade.mdm.flow.constants.FlowConstant;
 import org.springblade.mdm.flow.entity.FlowProgramFile;
-import org.springblade.mdm.flow.service.ApproveRecordService;
 import org.springblade.mdm.flow.service.FlowProgramFileService;
 import org.springblade.mdm.program.entity.NcNode;
+import org.springblade.mdm.program.entity.NcNodeHis;
 import org.springblade.mdm.program.entity.NcProgramApproved;
 import org.springblade.mdm.program.entity.NcProgramExchange;
 import org.springblade.mdm.program.mapper.NcProgramExchangeMapper;
-import org.springblade.mdm.program.vo.DncSendBackData;
-import org.springblade.mdm.utils.FileContentUtil;
+import org.springblade.mdm.program.service.programannotation.AnnotationData;
+import org.springblade.mdm.program.service.programannotation.AnnotationProcessor;
+import org.springblade.mdm.program.service.programannotation.MachineAnnotationConfig;
+import org.springblade.mdm.program.service.programannotation.ProcessorHelper;
 import org.springblade.system.feign.IDictClient;
-import org.springblade.system.pojo.entity.Dict;
 import org.springframework.stereotype.Service;
 
 import java.io.*;
-import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -48,30 +43,16 @@
 @AllArgsConstructor
 public class NcProgramExportDNCService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> {
 
-	//private final NcProgramService progService;
 	private final IDictClient dictClient;
 	private final MachineService machineService;
 	private final NcProgramApprovedService approvedService;
-	private final ApproveRecordService approveRecordService;
 	private final NcNodeService ncNodeService;
+	private final NcNodeHisService ncNodeHisService;
 	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";
+	private final HistoryService historyService;
 
-	public static final String ANNOTATION_DICT = "machine_annotation";
-
-	/**
-	 * 鍒嗛〉鏌ヨ
-	 * @param query 鏌ヨ鍙傛暟
-	 * @return
-	 */
-	public IPage<DncSendBackData> dncSendBackPageQuery(Query query) {
-		return this.getBaseMapper().dncSendBackpageQuery(Condition.getPage(query),query);
-	}
-
+	private final MachineAnnotationConfig annotationConfig;
 	/**
 	 * 瀵煎嚭dnc鍘嬬缉鍖�
 	 * @param approvedIdArray 寰呭鍑哄鎵硅〃id鏁扮粍
@@ -86,17 +67,22 @@
 
 				approved.setStatus(NcProgramApproved.STATUS_EXPORTED);
 				approvedService.updateById(approved);
+
+				NcNode pkgNode = this.ncNodeService.getById(approved.getNcNodeId());
+				if(pkgNode.isDeviationProgram()){
+					//鍋忕鍗曠殑绋嬪簭锛屽鏋滃鎵瑰鍑鸿褰曟槸瑙i攣褰㈡垚鐨勶紝杩樻槸闇�瑕侀攣瀹氾紱鏅�氳瘯鍒囪繃鐨勶紝涓嶉攣瀹�
+					HistoricProcessInstance hisInst = historyService.createHistoricProcessInstanceQuery().processInstanceId(approved.getProcessInstanceId()).singleResult();
+					if(hisInst != null && hisInst.getProcessDefinitionKey().equals(FlowConstant.UNLOCK_PROCESS_KEY)){
+						pkgNode.lock("涓嬪彂瀵煎嚭閿佸畾");
+						ncNodeService.updateById(pkgNode);
+					}
+				}
 			}
 
-			//鐘舵�佷慨鏀逛负宸插鍑�
-			/*
-			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());
 		}
-
 	}
 
 	/**
@@ -105,216 +91,89 @@
 	 * @param approved
 	 */
 	private void addProgramPackageToZip(ZipOutputStream zipOut, NcProgramApproved approved) throws IOException{
-		String packageFolder = approved.getProgramName()+"/";
+		NcNodeHis packageNodeHis = ncNodeHisService.getById(approved.getNcNodeId());
+
+		String packageFolder = packageNodeHis.getName()+"/";
 		ZipEntry zipEntry = new ZipEntry(packageFolder);// "/"缁撳熬琛ㄧず鏂囦欢澶�
 		zipOut.putNextEntry(zipEntry);
 		zipOut.closeEntry();
 
-		NcNode packageNode = ncNodeService.getById(approved.getNcNodeId());
-		Machine machine = machineService.getByCode(packageNode.getMachineCode());//绋嬪簭鍖呰妭鐐癸紝鑾峰彇娉ㄩ噴鐢�
+		Machine machine = machineService.getByCode(packageNodeHis.getMachineCode());//绋嬪簭鍖呰妭鐐癸紝鑾峰彇娉ㄩ噴鐢�
 
-		List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getIsLastEdition,1).eq(NcNode::getParentId, approved.getNcNodeId()).list();
+		//List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getIsLastEdition,1).eq(NcNode::getParentId, approved.getNcNodeId()).list();
+		List<NcNodeHis> programNodes = ncNodeHisService.lambdaQuery().eq(NcNodeHis::getParentId, approved.getNcNodeId()).list();
 
 		FlowProgramFile programFile;
-		NcNode programPackageNode = this.ncNodeService.getById(approved.getNcNodeId());
+		NcNodeHis programPackageNode = this.ncNodeHisService.getById(approved.getNcNodeId());
 		String status = "SQ";
 		if(programPackageNode.isDeviationProgram()){
 			status = "PL";
 		}else if(programPackageNode.hasCured()){
 			status = "GH";
 		}
-		//List<Dict> annotationList = programAnnotationService.getAnnotionList();
-		for (NcNode node : programNodes) {
-			String filePathInZip = packageFolder + node.getName();
+		long deviationSerial = -1;//鍋忕鍗曞簭鍙� 锛�-1涓洪潪鍋忕鍗曪紝涓嶉渶瑕佸姞鍏�
+		if(packageNodeHis.isDeviationProgram()) {
+			deviationSerial = ncNodeHisService.getDeviationSerialForNode(packageNodeHis);
+		}
+
+		//List<DictBiz> annotationDictList= programAnnotationService.getAnnotionDictList();
+		for (NcNodeHis node : programNodes) {
+			String filePathInZip = genFilePathInZip(packageFolder,node,deviationSerial);
 			programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId());
 			if(programFile.isProgram()) {//绋嬪簭鏂囦欢锛屾墠浼氬姞鍏ュ帇缂╁寘
 				InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName());
-				//InputStream addedIns1 = addSendDirAnnotation(inputStream, machine, annotationList);
-				//InputStream addedIns2 = addProgramStatusAnnotation(addedIns1, status, machine, annotationList);
 				String sendDir = machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir();
-				InputStream addedIns2 = programAnnotationService.setSendDirAndStatusAnnotation(sendDir,status,inputStream,machine.getMachineGroupCode());
-				this.addInputStreamToZip(zipOut, addedIns2, filePathInZip);
+
+				AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annotationConfig);
+				AnnotationData annoData = new AnnotationData();
+				annoData.setSendPath(sendDir);
+				annoData.setProgramStatus(status);
+				annoData.setDeviation(programPackageNode.getDeviation());
+				annoData.setFilename(programFile.getName());
+				InputStream addedInsFinal = annoProcessor.putAnnotation(annoData,inputStream);
+				addedInsFinal.reset();
+				/*
+				InputStream addedInsFinal;
+				InputStream addedIns2 = programAnnotationService.setSendDirAndStatusAnnotation(sendDir,status,inputStream,machine.getControlSystem());
+				if(StringUtils.isNotBlank(programPackageNode.getDeviation())) {
+					//鍋忕鍗曪紝澧炲姞鍋忕鍗曞彿
+					addedInsFinal = programAnnotationService.setPldAnnotation(programPackageNode.getDeviation(),addedIns2, machine.getControlSystem(), annotationDictList);;
+				}else{
+					addedInsFinal = addedIns2;
+				}*/
+				this.addInputStreamToZip(zipOut, addedInsFinal, filePathInZip);
 			}
 		}
 
 	}
 
-
 	/**
-	 * 鍔犲叆鏈哄簥涓嬪彂璺緞鍜岀▼搴忕姸鎬佺殑娉ㄩ噴
-	 * @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,NcNodeHis 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;
 	}
-	/**
-	 * 瀵煎叆鏁版嵁鏂囦欢
-	 * @param zipOut
-	 */
-	/*
-	void addDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException {
-		addNodeDataJson(zipOut, programPackageNodeIdList);
-		addApproveRecordDataJson(zipOut, programPackageNodeIdList);
-	}
-	*/
-
-	/**
-	 * zip淇濋噸鍔犲叆鑺傜偣鐨勬暟鎹�
-	 * @param zipOut
-	 * @param pkgNodeIdList
-	 * @throws IOException
-	 */
-	/*
-	void  addNodeDataJson(ZipOutputStream zipOut,List<Long>  pkgNodeIdList) throws IOException {
-		List<NcNode> pkgNodes =  this.ncNodeService.lambdaQuery().in(NcNode::getId, pkgNodeIdList).list();
-
-		List<Long> allNodeIds = new ArrayList<>();
-		for(NcNode node : pkgNodes){
-			allNodeIds.addAll(Func.toLongList(node.getParentIds()));
-			allNodeIds.add(node.getId());
-		}
-		//鍔犲叆绋嬪簭鍖呬笅绾х殑绋嬪簭鑺傜偣
-		List<NcNode> programNodes = ncNodeService.lambdaQuery().in(NcNode::getParentId, pkgNodes.stream().map(NcNode::getId).toList()).list();
-
-		allNodeIds.addAll(programNodes.stream().map(NcNode::getId).toList());
-		List<Long>  distinctIds = allNodeIds.stream().distinct().toList();
-		List<NcNode> allNodes = this.ncNodeService.lambdaQuery().in(NcNode::getId, distinctIds).list();
-		JSONArray jsonArray = new JSONArray();
-
-		for(NcNode node : allNodes){
-			JSONObject recObj = getNodeJsonObject(node);
-			addSuperProperties(recObj,node);
-			jsonArray.add(recObj);
-		}
-		addInputStreamToZip(zipOut,new ByteArrayInputStream(jsonArray.toJSONString().getBytes(StandardCharsets.UTF_8)),NODE_JSON_FILE);
-
-	}
-	*/
-	/*
-	@NotNull
-	private static JSONObject getNodeJsonObject(NcNode node) {
-		JSONObject recObj = new JSONObject();
-		recObj.put("id", node.getId());
-		recObj.put("name", node.getName());
-		recObj.put("drawingNo", node.getDrawingNo());
-		recObj.put("drawingNoEdition", node.getDrawingNoEdition());
-		recObj.put("productModel", node.getProductModel());
-		recObj.put("processName", node.getProcessName());
-		recObj.put("processEdition", node.getProcessEdition());
-		recObj.put("craftEdition", node.getCraftEdition());
-		recObj.put("parentIds", node.getParentIds());
-		recObj.put("processNo", node.getProcessNo());
-
-		recObj.put("isCured", node.getIsCured());
-		recObj.put("isLocked", node.getIsLocked());
-		recObj.put("nodeType", node.getNodeType());
-
-		recObj.put("machineCode", node.getMachineCode());
-		recObj.put("flowProgramFileId", node.getFlowProgramFileId());
-		recObj.put("processInstanceId", node.getProcessInstanceId());
-		return recObj;
-	}
-	*/
-	/**
-	 * 瀵煎叆瀹℃壒璁板綍
-	 * @param zipOut
-	 * @param programPackageNodeIdList 绋嬪簭鍖呭悕鐨刬d鍒楄〃
-	 */
-	/*
-	void addApproveRecordDataJson(ZipOutputStream zipOut, List<Long> programPackageNodeIdList) throws IOException {
-
-		//List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getProcessInstanceId, instanceIds).list();
-		List<ApproveRecord> records = approveRecordService.lambdaQuery().in(ApproveRecord::getNcNodeId, programPackageNodeIdList).list();
-
-		JSONArray jsonArray = new JSONArray();
-		for(ApproveRecord record : records){
-			JSONObject recObj = new JSONObject();
-			recObj.put("id", record.getId());
-			recObj.put("comment", record.getComment());
-			recObj.put("userId",record.getUserId());
-			recObj.put("userNickname",record.getUserNickname());
-			recObj.put("operateTime",record.getOperateTime());
-			recObj.put("operateResult",record.getOperateResult());
-			recObj.put("taskName",record.getTaskName());
-			recObj.put("processInstanceId",record.getProcessInstanceId());
-			recObj.put("ncNodeId",record.getNcNodeId());
-			addSuperProperties(recObj,record);
-
-			jsonArray.add(recObj);
-		}
-		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());
-		recObj.put("createTime",entity.getCreateTime());
-		recObj.put("updateTime",entity.getUpdateTime());
-		recObj.put("createUser",entity.getCreateUser());
-		recObj.put("updateUser",entity.getUpdateUser());
-		recObj.put("status",entity.getStatus());
-		recObj.put("createDept",entity.getCreateDept());
-	}
-
 	/**
 	 * 灏� 杈撳叆娴� 涓殑鍐呭鍐欏叆zip
 	 * @param zipOut zip杈撳嚭娴�

--
Gitblit v1.9.3