From b5b668d2728665ca05d15be8862ceb0a2796fc67 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 11 八月 2025 09:18:10 +0800
Subject: [PATCH] 增加替换文件上传
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java | 185 +---------------------------------------------
1 files changed, 5 insertions(+), 180 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
index 417d28b..f180476 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
@@ -9,6 +9,7 @@
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.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BizEntity;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.oss.OssTemplate;
@@ -39,7 +40,7 @@
/**
* MDM绋嬪簭瀵煎叆锛堝伐鎺х綉鍔熻兘锛�
- *
+ * 鐩墠宸ユ帶缃戝睍鐜板舰寮忔湭瀹氾紝鏆傛椂瀹炵幇鏆傚仠
* @author yangys
*/
@Slf4j
@@ -68,8 +69,7 @@
//璁剧疆涓�涓紦瀛橈紝2灏忔椂杩囨湡
bladeRedis.setEx(getFileKey(),bfile.getName(), Duration.ofHours(2));
- //String fileName = file.getOriginalFilename();
- //InputStream zipFileInputStream = FileExchangeUtil.convertFileToZip(file.getInputStream());
+ String pkgFileName = bladeRedis.get(getFileKey());
InputStream zipFileInputStream = file.getInputStream();//test
byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream);
@@ -77,37 +77,12 @@
} catch (IOException e) {
- log.error("涓婁紶dnc鍥炰紶鏂囦欢澶辫触",e);
- list = Collections.emptyList();
+ log.error("瀵煎叆娑夊瘑缃戞憜娓℃枃浠跺け璐�",e);
+ throw new ServiceException("瑙f瀽DNC鍥炰紶鏁版嵁澶辫触");
}
return list;
}
- InputStream convertFileToZip(InputStream inputStream) throws IOException {
-
- File tempFile = createTempFile();
- FileOutputStream fos = new FileOutputStream(tempFile);
- CustomBinaryReader.read(inputStream,fos);
-
-
- FileInputStream dInstream = new FileInputStream(tempFile);
-
- return dInstream;
- }
-
- /**
- * 鍒涘缓涓�涓复鏃舵枃浠�
- * @return
- * @throws IOException
- */
- File createTempFile() throws IOException {
- Path tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
- // 鍦ㄤ复鏃剁洰褰曚腑鍒涘缓鏂囦欢
- String tfilename = "t"+System.currentTimeMillis();
- Path tempFile = Files.createTempFile(tempDir, tfilename, ".tmp");
- System.out.println("鍒涘缓鐨勪复鏃舵枃浠�: " + tempFile);
- return tempFile.toFile();
- }
public static List<MdmProgramImportVO> parseMdmZipFromByteArray(byte[] zipData) throws IOException {
List<MdmProgramImportVO> list = new ArrayList<>();
Map<String,String> fileMd5Map = new HashMap<>();
@@ -124,41 +99,7 @@
if (!entry.isDirectory()) {
//鐩存帴瑙f瀽绋嬪簭鐨刯son鏂囦欢
- if(entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)){
- try (InputStream inputStream = zipFile.getInputStream(entry)) {
- String jsonStr = IoUtil.readToString(inputStream);
-
- JSONArray jsonArray = JSONArray.parseArray(jsonStr);
- for(int i=0;i<jsonArray.size();i++){
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- MdmProgramImportVO d = new MdmProgramImportVO();
- d.setName(jsonObject.getString("name"));
- d.setId(jsonObject.getLong("id"));
- d.setCode(jsonObject.getString("code"));
- d.setDescription(jsonObject.getString("description"));
- d.setCategory(jsonObject.getString("category"));
- d.setBindNcNodeId(jsonObject.getLong("bindNcNodeId"));
- d.setIsLastEdition(jsonObject.getInteger("isLastEdition"));
- d.setIsLocked(jsonObject.getInteger("isLocked"));
- d.setIsTest(jsonObject.getInteger("isTest"));
- d.setMachineCode(jsonObject.getString("machineCode"));
- d.setNcNodeId(jsonObject.getLong("ncNodeId"));
- d.setDrawingNo(jsonObject.getString("drawingNo"));
- d.setProcessEdition(jsonObject.getString("processEdition"));
-
- fileDataMap.put(d.getName(),d);
-
- list.add(d);
- }
-
- }
- }else{
- try (InputStream inputStream = zipFile.getInputStream(entry)) {
- fileMd5Map.put(entryName,DigestUtils.md5Hex(inputStream));//鑾峰彇鏂囦欢MD5
- }
-
- }
}
@@ -188,21 +129,6 @@
//
updateProgramFile(pkgFileName,idList);
- List<NcProgram> progList = ncProgramService.listByIds(idList);
- NcProgramExchange exchange;
-
- for(NcProgram prog:progList){
- exchange = new NcProgramExchange();
- exchange.setName(prog.getName());
- exchange.setExchangeType(2);//鍥炰紶
- exchange.setNcProgramId(prog.getId());
-
-
- this.save(exchange);
-
- }
-
-
}
/**
@@ -228,112 +154,11 @@
String entryName = entry.getName();
- if (!entry.isDirectory()) {
- if(entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)){
-
- try (InputStream insJson = zipFile.getInputStream(entry)) {
- String jsonStr = IoUtil.readToString(insJson);
-
- JSONArray jsonArray = JSONArray.parseArray(jsonStr);
- for(int i=0;i<jsonArray.size();i++){
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- NcProgram d = new NcProgram();
- d.setId(jsonObject.getLong("id"));
- d.setName(jsonObject.getString("name"));
-
- d.setCode(jsonObject.getString("code"));
- d.setDescription(jsonObject.getString("description"));
- d.setCategory(jsonObject.getString("category"));
- d.setBindNcNodeId(jsonObject.getLong("bindNcNodeId"));
- d.setIsLastEdition(jsonObject.getInteger("isLastEdition"));
- d.setIsLocked(jsonObject.getInteger("isLocked"));
- d.setIsTest(jsonObject.getInteger("isTest"));
- d.setMachineCode(jsonObject.getString("machineCode"));
- d.setNcNodeId(jsonObject.getLong("ncNodeId"));
- d.setDrawingNo(jsonObject.getString("drawingNo"));
- d.setProcessEdition(jsonObject.getString("processEdition"));
-
- setBaseProperties(d,jsonObject);
-
- progList.add(d);
- }
-
- }
- }else if(entryName.equals(NcProgramExportDNCService.NODE_JSON_FILE)){
- try (InputStream insJson = zipFile.getInputStream(entry)) {
- String jsonStr = IoUtil.readToString(insJson);
- JSONArray jsonArray = JSONArray.parseArray(jsonStr);
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- NcNode node = new NcNode();
- node.setId(jsonObject.getLong("id"));
- node.setName(jsonObject.getString("name"));
- node.setDescription(jsonObject.getString("description"));
- node.setNodeType(jsonObject.getString("nodeType"));
- node.setProcessName(jsonObject.getString("processName"));
- node.setDrawingNo(jsonObject.getString("drawingNo"));
- node.setMachineCode(jsonObject.getString("machineCode"));
- node.setParentId(jsonObject.getLong("parentId"));
- node.setParentIds(jsonObject.getString("parentIds"));
- node.setIsCured(jsonObject.getInteger("isCured"));
-
- setBaseProperties(node,jsonObject);
-
- nodeList.add(node);
- }
- }
- }else if(entryName.equals(NcProgramExportDNCService.APPROVE_RECORD_JSON_FILE)){
- try (InputStream insJson = zipFile.getInputStream(entry)) {
- String jsonStr = IoUtil.readToString(insJson);
- JSONArray jsonArray = JSONArray.parseArray(jsonStr);
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- ApproveRecord record = new ApproveRecord();
- record.setId(jsonObject.getLong("id"));
- record.setNcProgramId(jsonObject.getLong("ncProgramId"));
- record.setUserId(jsonObject.getLong("userId"));
- record.setUserNickname(jsonObject.getString("userNickname"));
- record.setOperateResult(jsonObject.getString("operateResult"));
- record.setOperateTime(jsonObject.getDate("operateTime"));
- setBaseProperties(record,jsonObject);
-
- recordList.add(record);
- }
- }
- }
-
- }
}
}
- try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
- ZipFile zipFile = new ZipFile(channel)) {
-
- ZipArchiveEntry entry;
- Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
-
- String entryName = entry.getName();
-
- if (!entry.isDirectory() && !entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)) {
-
- for(NcProgram prog:progList){
- if(prog.getName().equals(entryName)){
- try (InputStream ncFileStream = zipFile.getInputStream(entry)) {
- BladeFile bfile = this.ossTemplate.putFile(prog.getName(),ncFileStream);
- prog.setOssName(bfile.getName());
- prog.setUrl(bfile.getLink());
- }
- break;
- }
- }
-
- }
- }
- }
for(NcNode node:nodeList){
NcNode nodeTemp = this.ncNodeService.getById(node.getId());
--
Gitblit v1.9.3