From 432198337fb3d8a99fadb4b7825771d68bb10b9e Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 20 八月 2025 19:58:22 +0800
Subject: [PATCH] 去掉mail依赖
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramExportDNCService.java | 182 ++++++++-------------------------------------
1 files changed, 32 insertions(+), 150 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 74f6e91..9fe865e 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
@@ -8,6 +8,7 @@
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;
@@ -33,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;
@@ -58,6 +56,7 @@
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";
@@ -79,25 +78,20 @@
*/
public void exportDnc(Long[] approvedIdArray, OutputStream os) throws IOException {
//FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip");
- try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os
-
- //ArrayList<Long> programPackageNodeIdList = new ArrayList<Long>();
+ try (ZipOutputStream zipOut = new ZipOutputStream(os);os) {//os
for (Long approvedId : approvedIdArray) {
NcProgramApproved approved = approvedService.getById(approvedId);
- //programPackageNodeIdList.add(approved.getNcNodeId());
-
addProgramPackageToZip(zipOut,approved);
+
+ approved.setStatus(NcProgramApproved.STATUS_EXPORTED);
+ approvedService.updateById(approved);
}
- //鐘舵�佷慨鏀逛负宸插鍑�
- approvedService.lambdaUpdate().in(NcProgramApproved::getId, approvedIdArray)
- .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update();
- //addDataJson(zipOut, programPackageNodeIdList);
+ }catch(Exception e){
+ Throwable [] err = e.getSuppressed();
+ throw new ServiceException("瀵煎嚭宸ユ帶缃戦敊璇�"+e.getMessage());
}
-
- os.close();
-
}
/**
@@ -111,6 +105,9 @@
zipOut.putNextEntry(zipEntry);
zipOut.closeEntry();
+ NcNode packageNode = ncNodeService.getById(approved.getNcNodeId());
+ Machine machine = machineService.getByCode(packageNode.getMachineCode());//绋嬪簭鍖呰妭鐐癸紝鑾峰彇娉ㄩ噴鐢�
+
List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getIsLastEdition,1).eq(NcNode::getParentId, approved.getNcNodeId()).list();
FlowProgramFile programFile;
@@ -121,47 +118,36 @@
}else if(programPackageNode.hasCured()){
status = "GH";
}
- List<Dict> annotationList = 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());
+ //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);
+ }
}
}
- /**
- * 鑾峰彇瀛楀吀涓厤缃殑娉ㄩ噴
- * @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 {
//妫�娴嬬浜岃鏄惁鏄矾寰�
- String annotationText = generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY: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);
- }
+ }*/
/**
* 娣诲姞绋嬪簭涓撴敼鐨勬敞閲�
@@ -172,10 +158,12 @@
* @return
* @throws IOException
*/
+ /*
InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException {
- String annoText= generateAnnotation(status,machine.getMachineGroupCode(),annotationList);
+ String annoText= programAnnotationService.generateAnnotation(status,machine.getMachineGroupCode(),annotationList);
+
return FileContentUtil.insertLine(inputStream,2,annoText);
- }
+ }*/
/**
* 鍒ゆ柇涓�琛屾枃鏈槸鍚︽槸娉ㄩ噴
@@ -183,14 +171,15 @@
* @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;
@@ -212,114 +201,7 @@
return annotation;
}
- /**
- * 瀵煎叆鏁版嵁鏂囦欢
- * @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
--
Gitblit v1.9.3