From 1911be8941e5fe2705c2c56e74e52bd426468793 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 06 八月 2025 15:26:34 +0800
Subject: [PATCH] 固化流程,建立node;
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java | 137 +++++++++++++++++++++++++++++----------------
1 files changed, 89 insertions(+), 48 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
index 81ce4fb..8923526 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java
@@ -1,14 +1,9 @@
package org.springblade.mdm.program.service;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipFile;
-import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BizEntity;
@@ -17,16 +12,16 @@
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.FileUtil;
import org.springblade.core.tool.utils.Func;
-import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.mdm.flow.entity.FlowProgramFile;
import org.springblade.mdm.flow.service.CureFlowService;
+import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.program.entity.NcNode;
-import org.springblade.mdm.program.entity.NcProgram;
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.CustomBinaryReader;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -35,10 +30,11 @@
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
import java.time.Duration;
-import java.time.LocalDateTime;
import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
/**
* DNC鍥炰紶鏂囦欢澶勭悊鏈嶅姟
@@ -50,7 +46,7 @@
@AllArgsConstructor
public class DNCSendBackService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> {
private final CureFlowService cureFlowService;
- private final NcProgramService ncProgramService;
+ private final FlowProgramFileService flowProgramFileService;
private final NcNodeService ncNodeService;
private final OssTemplate ossTemplate;
private final BladeRedis bladeRedis;
@@ -72,8 +68,8 @@
InputStream zipFileInputStream = file.getInputStream();//test
- byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream);
- list = parseDncZipFromByteArray(bytes);
+ //byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream);
+ list = parseDncZipFromByteArray(zipFileInputStream);
} catch (IOException e) {
log.error("涓婁紶dnc鍥炰紶鏂囦欢澶辫触",e);
@@ -85,22 +81,20 @@
/**
* 浠庡帇缂╁寘 瑙f瀽鍥炰紶绋嬪簭鍒楄〃锛岃繖閲岃В鏋愮洰褰曞嵆鍙紝鐩綍灏辨槸绋嬪簭鍖呭悕
- * @param zipData 鍘嬬缉鍖呭瓧鑺�
+ * @param inputStream 鍘嬬缉鍖呰緭鍏ユ祦
* @return 鍥炰紶绋嬪簭鍒楄〃
- * @throws IOException
+ * @throws IOException 鏂囦欢鎿嶄綔寮傚父
*/
- List<DncSendBackData> parseDncZipFromByteArray(byte[] zipData) throws IOException {
+ List<DncSendBackData> parseDncZipFromByteArray(InputStream inputStream) throws IOException {
List<DncSendBackData> list = new ArrayList<>();
+ Path tempZipFile = createTempFile(inputStream);
- //Map<String,String> fileMd5Map = new HashMap<>();
- Map<String,DncSendBackData> fileDataMap = new HashMap<>();
- try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(zipData);
- ZipFile zipFile = new ZipFile(channel)) {
+ try (ZipFile zipFile = new ZipFile(tempZipFile.toFile())) {
- ZipArchiveEntry entry;
- Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
+ ZipEntry entry;
+ Enumeration<? extends ZipEntry> zipEntris = zipFile.entries();
+ while (zipEntris.hasMoreElements()) {
+ entry = zipEntris.nextElement();
DncSendBackData progData = new DncSendBackData();
String entryName = entry.getName();
if (entry.isDirectory()){
@@ -112,7 +106,8 @@
NcNode programPackageNode = pkgList.get(0);
progData.setId(programPackageNode.getId());
progData.setProgramName(packageName);
- progData.setFileBackTime(LocalDateTime.now());
+
+ progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant()));
progData.setProgramNo(programPackageNode.getProgramNo());
list.add(progData);
}
@@ -128,17 +123,20 @@
/**
* 鍏ュ簱鍥炰紶鏂囦欢,骞跺惎鍔ㄥ浐鍖栨祦绋�
* @param ids id鍒楄〃閫楀彿鍒嗛殧,绋嬪簭鍖呭悕 鑺傜偣鐨刬d
- * @return
*/
@Transactional
public void dncFileAccept(String ids) throws IOException {
List<Long> idList = Func.toLongList(ids);
//
NcProgramExchange exchange;
- String pkgFileName = bladeRedis.get(getFileKey());
- updateNodeDataByDNCBackData(pkgFileName,idList);
- List<NcNode> pkgList = ncNodeService.listByIds(idList);
- for(NcNode pkgNode :pkgList){
+ String filekey = getFileKey();
+ String pkgFileName = bladeRedis.get(filekey);
+ log.info("filekey={},鏂囦欢鍚�={}",filekey,pkgFileName);
+
+ Map<Long,List<NcNode>> programPackageSubMap = new HashMap<>();
+ List<NcNode> newProgramPckageList = updateNodeDataByDNCBackData(pkgFileName,idList,programPackageSubMap);
+ log.info("闇�瑕佸惎鍔ㄥ浐鍖栨祦绋嬬殑绋嬪簭鍖呭悕鏁伴噺:{}",newProgramPckageList.size());
+ for(NcNode pkgNode :newProgramPckageList){
exchange = new NcProgramExchange();
exchange.setName(pkgNode.getName());
exchange.setExchangeType(2);//鍥炰紶
@@ -146,29 +144,31 @@
this.save(exchange);
}
+ bladeRedis.del(filekey);
+ this.ossTemplate.removeFile(pkgFileName);
+ log.info("鍒犻櫎oss鏂囦欢:{}",pkgFileName);
- //cureFlowService.startCure(pkgList);
+ cureFlowService.startCure(newProgramPckageList,programPackageSubMap);
}
/**
* 鏇存柊鑺傜偣锛屼富瑕佹槸鍒涘缓 绋嬪簭鍖呭悕 鐨勬柊鐗堟湰銆�
* @param pkgFileName zip鏂囦欢鍚�
* @param programPackageIdList 绋嬪簭鍖呭悕 鑺傜偣鐨刬d鍒楄〃
+ * @param programPackageSubMap 鏂扮殑 绋嬪簭鍖呰妭鐐筰d -> =鏂囦欢鍒楄〃 map锛岀敤浜庡洖浼犳暟鎹�
* @throws IOException 璁块棶鏂囦欢寮傚父
*/
- void updateNodeDataByDNCBackData(String pkgFileName, List<Long> programPackageIdList) throws IOException {
+ List<NcNode> updateNodeDataByDNCBackData(String pkgFileName, List<Long> programPackageIdList,Map<Long,List<NcNode>> programPackageSubMap) throws IOException {
InputStream inputStream = this.ossTemplate.statFileStream(pkgFileName);
- byte[] bytes = FileUtil.copyToByteArray(inputStream);
-
- List<NcNode> nodeList = new ArrayList<>();
+ Path tempZipFile = createTempFile(inputStream);
+ List<NcNode> newProgramPackageNodeList = new ArrayList<>();
List<String> entryNameList = new ArrayList<>();
- try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
- ZipFile zipFile = new ZipFile(channel)) {
- ZipArchiveEntry entry;
- Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
+ ZipEntry entry;
+ try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) {
+ Enumeration<? extends ZipEntry> entris = zipFile.entries();
+ while(entris.hasMoreElements()) {
+ entry = entris.nextElement();
entryNameList.add(entry.getName());
}
@@ -176,6 +176,7 @@
List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
for(String dir : dirList){
String programPackageName = StringUtils.removeEnd(dir,"/");
+
NcNode oriProgramPkg = this.ncNodeService.getLastEditionProgramPackage(programPackageName);
if(oriProgramPkg == null){
log.warn("鏈彂鐜板尮閰嶇殑绋嬪簭鍖呭悕{}",programPackageName);
@@ -184,22 +185,23 @@
if(!programPackageIdList.contains(oriProgramPkg.getId())){
//涓嶅湪鍕鹃�夌殑鑼冨洿鍐�
+ log.info("{}涓嶅湪鍕鹃�夎寖鍥村唴",programPackageName);
continue;
}
- //涓存椂娴嬭瘯娉ㄩ噴
-
NcNode newProgramPkg = new NcNode();
BeanUtils.copyProperties(oriProgramPkg, newProgramPkg);
-
clearBaseProperties(newProgramPkg);
newProgramPkg.setIsLastEdition(1);
-
ncNodeService.save(newProgramPkg);
+ newProgramPackageNodeList.add(newProgramPkg);
//鏃ф暟鎹洿鏂颁负鑰佺増鏈�
+ oriProgramPkg.setIsLocked(1);//鏃х増鑷姩閿佸畾
oriProgramPkg.setIsLastEdition(0);;
ncNodeService.updateById(oriProgramPkg);
+ //List<FlowProgramFile> newFlowFiles = new ArrayList<>();
+ List<NcNode> newProgramNodes = new ArrayList<>();
//鏌ユ壘鍖呬笅鐨勬枃浠舵暟鎹�,
entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> {
log.info("{}涓嬬殑鏂囦欢锛歿}",dir,entryName);
@@ -213,21 +215,60 @@
}
NcNode newProgramNode = new NcNode();
- BeanUtils.copyProperties(oriProgramPkg, newProgramNode);
+ BeanUtils.copyProperties(oldProgramNode, newProgramNode);
clearBaseProperties(newProgramNode);
newProgramNode.setIsLastEdition(1);
- ncNodeService.save(newProgramNode);
+ newProgramNode.setParentId(newProgramPkg.getId());
+ newProgramNode.setParentIds(newProgramPkg.getParentIds()+","+newProgramPkg.getId());
+ //ncNodeService.save(newProgramNode);
+ //灏嗗洖浼犳枃浠朵笂浼狅紝骞惰褰曞埌鏁版嵁搴�
- ncNodeService.updateById(oriProgramPkg);
+ FlowProgramFile oldFlowFile = flowProgramFileService.getById(newProgramNode.getFlowProgramFileId());
+ FlowProgramFile newFlowFile = new FlowProgramFile();//TODO
+ BeanUtils.copyProperties(oldFlowFile, newFlowFile);
+ newFlowFile.setProcessInstanceId(null);
+ clearBaseProperties(newFlowFile);
+
+ try {
+ InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName));
+ BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins);
+ newFlowFile.setOssName(newOssFile.getName());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ newProgramNode.setFlowProgramFile(newFlowFile);
+ newProgramNode.setVersionNumber(oldProgramNode.genNewVersionNumber());
+ newProgramNodes.add(newProgramNode);
+ oldProgramNode.setIsLastEdition(0);
+ oldProgramNode.setIsLocked(1);
+ ncNodeService.updateById(oldProgramNode);
}
});
+
+ programPackageSubMap.put(newProgramPkg.getId(),newProgramNodes);
}
}
+
+ return newProgramPackageNodeList;
}
+ /**
+ * 鍒涘缓涓�涓复鏃秡ip鏂囦欢
+ * @param inputStream 鏂囦欢鐨勮緭鍏ユ祦
+ * @return path 鏂囦欢
+ * @throws IOException
+ */
+ Path createTempFile(InputStream inputStream) throws IOException {
+ byte[] zipData = FileUtil.copyToByteArray(inputStream);
+ Path tempFile = Files.createTempFile("tempzip"+System.currentTimeMillis(), ".zip");
+ // 鍐欏叆瀛楄妭鏁版嵁鍒颁复鏃舵枃浠�
+ Files.write(tempFile, zipData, StandardOpenOption.WRITE);
+
+ return tempFile;
+ }
void setBaseProperties(BizEntity entity, JSONObject jsonObject){
entity.setCreateTime(jsonObject.getDate("createTime"));
entity.setUpdateTime(jsonObject.getDate("updateTime"));
--
Gitblit v1.9.3