From 3baca21e0e6563f8379359ef2ba78c224eb4bc80 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期二, 23 九月 2025 22:45:51 +0800
Subject: [PATCH] 修复审批表,确认表内容
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/DNCSendBackService.java | 219 ++++++++++++++++++++++++++++--------------------------
1 files changed, 113 insertions(+), 106 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 a9dfc6a..31630c3 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,10 +1,10 @@
package org.springblade.mdm.program.service;
-import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BizServiceImpl;
@@ -17,7 +17,7 @@
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.basesetting.machine.service.MachineService;
-import org.springblade.mdm.commons.service.ParamService;
+import org.springblade.mdm.commons.contants.ZipConstants;
import org.springblade.mdm.flow.entity.FlowProgramFile;
import org.springblade.mdm.flow.service.CureFlowService;
import org.springblade.mdm.flow.service.FlowCommonService;
@@ -25,17 +25,18 @@
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.entity.NcProgramExchange;
import org.springblade.mdm.program.mapper.NcProgramExchangeMapper;
+import org.springblade.mdm.program.service.programannotation.*;
import org.springblade.mdm.program.vo.DncSendBackData;
import org.springblade.mdm.program.vo.DncSendBackFile;
-import org.springblade.mdm.program.vo.ProgramAnnotation;
import org.springblade.mdm.utils.FileContentUtil;
import org.springblade.mdm.utils.ZipTextFileContentUtil;
-import org.springblade.system.pojo.entity.DictBiz;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -51,22 +52,27 @@
*/
@Slf4j
@Service
-@AllArgsConstructor
public class DNCSendBackService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> {
- private final CureFlowService cureFlowService;
- private final ProgramAnnotationService programAnnotationService;
- private final NcNodeService ncNodeService;
- private final OssTemplate ossTemplate;
- private final BladeRedis bladeRedis;
- private final FlowCommonService flowCommonService;
- private final DncBackFileService dncBackFileService;
- private final MachineService machineService;
- private final ParamService paramService;
+ @Autowired
+ private CureFlowService cureFlowService;
+ @Autowired
+ private NcNodeService ncNodeService;
+ @Autowired
+ private OssTemplate ossTemplate;
+ @Autowired
+ private BladeRedis bladeRedis;
+ @Autowired
+ private FlowCommonService flowCommonService;
+ @Autowired
+ private DncBackFileService dncBackFileService;
+ @Autowired
+ private MachineService machineService;
+
/**
* 鍋忕鍗曟枃浠舵湯灏剧殑妯″紡锛歅+鏁板瓧
*/
private static final String P_NUMBER_PATTERN = "(?i)P\\d+";
-
+ //static String[] encodings = {"UTF-8","GBK", "GB2312", "ISO-8859-1"};
private String getFileKey(){
return "dncimpfile-"+ AuthUtil.getUserId();
}
@@ -103,19 +109,47 @@
/**
* 浠庡帇缂╁寘 瑙f瀽鍥炰紶绋嬪簭鍒楄〃锛岃繖閲岃В鏋愮洰褰曞嵆鍙紝鐩綍灏辨槸绋嬪簭鍖呭悕
* @param inputStream 鍘嬬缉鍖呰緭鍏ユ祦
+ * @return 鏂囦欢鎿嶄綔寮傚父
+ */
+ List<DncSendBackData> parseProgramListFromZip(InputStream inputStream) throws IOException {
+ List<DncSendBackData> result = null;
+
+ ByteArrayInputStream byteInsStream = new ByteArrayInputStream(FileUtil.copyToByteArray(inputStream));
+ for (String encoding : ZipConstants.TRY_ENCODINGS) {
+ try {
+ result = parseProgramListByCharset(byteInsStream,Charset.forName(encoding));
+ log.error("浣跨敤缂栫爜 {} 瑙f瀽鎴愬姛 ",encoding);
+ break;
+ } catch (Exception e) {
+ byteInsStream.reset();
+ log.error("浣跨敤缂栫爜 {} 瑙f瀽澶辫触: ",encoding,e);
+ }
+ }
+ if(result != null) {
+ return result;
+ }else{
+ return Collections.emptyList();
+ }
+ }
+ /**
+ * 浠庡帇缂╁寘 瑙f瀽鍥炰紶绋嬪簭鍒楄〃锛岃繖閲岃В鏋愮洰褰曞嵆鍙紝鐩綍灏辨槸绋嬪簭鍖呭悕
+ * @param inputStream 鍘嬬缉鍖呰緭鍏ユ祦
* @return 鍥炰紶绋嬪簭鍒楄〃
* @throws IOException 鏂囦欢鎿嶄綔寮傚父
*/
- List<DncSendBackData> parseProgramListFromZip(InputStream inputStream) throws IOException {
+ List<DncSendBackData> parseProgramListByCharset(InputStream inputStream,Charset charset) throws IOException {
List<DncSendBackData> list = new ArrayList<>();
+
Path tempZipFile = createTempFile(inputStream);
List<String> fileEntryNameList = new ArrayList<>();
List<String> dirEntryNameList = new ArrayList<>();//绋嬪簭鍖呭悕+宸ュ簭鐗堟 浣滀负鏂囦欢澶瑰悕
- try (ZipFile zipFile = new ZipFile(tempZipFile.toFile())) {
+
+ ZipEntry entry;
+ try (ZipFile zipFile = new ZipFile(tempZipFile.toFile(),charset)) {
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
- ZipEntry entry;
+
//鑾峰彇鎵�鏈夌殑entry鍚嶇О
while (zipEntries.hasMoreElements()) {
entry = zipEntries.nextElement();
@@ -127,49 +161,48 @@
}
}
- List<DictBiz> annotionDictList = programAnnotationService.getAnnotionDictList();
NcNode programPackageNode;
//鐩綍鍒楄〃锛屽嵆绋嬪簭鍖呭垪琛�
for(String entryName : dirEntryNameList){
DncSendBackData progData = new DncSendBackData();
- String folderName = StringUtils.removeEnd(entryName,"/");
+ String packageName = StringUtils.removeEnd(entryName,"/");
- PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName);
- String packageName = pkgAndEdition.getProgramPackageName();
- String processEdition = pkgAndEdition.getProcessEdition();
- if(StringUtils.isBlank(packageName) || StringUtils.isBlank(processEdition)){
- throw new ServiceException("鍖呭唴鏂囦欢澶瑰悕鏍煎紡閿欒搴旇涓篬闆剁粍浠跺彿-宸ュ簭鍙�-宸ュ簭鐗堟]:"+folderName);
- }
-
- progData.setProgramName(packageName);
- String statusLine;
Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(entryName)).findFirst();
if(optFilename.isPresent()){
entry = zipFile.getEntry(optFilename.get());
InputStream ins = zipFile.getInputStream(entry);
+ ByteArrayInputStream byteArrayIns = new ByteArrayInputStream(IOUtils.toByteArray(ins));
+
+ //瑙f瀽鏈哄簥
progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant()));
- statusLine = FileContentUtil.readLineAt(ins,2);
- if(statusLine.contains("SQ")){
+
+ AnnotationProperties defAnnoProperties =AnnotationProperties.getDefault();
+ String statusLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getStatusLineIndex());//鐘舵�佹敞閲婅
+ byteArrayIns.reset();
+ String sendPathLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getSendPathLineIndex());//鐘舵�佹敞閲婅
+ byteArrayIns.reset();
+
+ if(statusLine.contains(AnnotationUtil.GH)){
+ //鍥哄寲锛屼笉搴斿洖浼狅紝蹇界暐
+ log.warn("鐘舵�亄},涓嶅簲鍥炰紶锛屽拷鐣�",statusLine);
+ continue;
+ }
+
+ Machine machine = this.machineService.getMachineBySendPathAnnotation(sendPathLine);
+ if(machine == null){
+ throw new ServiceException("鏍规嵁涓嬪彂璺緞鏈壘鍒扮▼搴忓搴旂殑鏈哄簥:"+sendPathLine);
+ }
+
+ progData.setProgramName(packageName);
+
+ if(statusLine.contains(AnnotationUtil.SQ)){
//璇曞垏
- programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition);
- }else if(statusLine.contains("GH")){
- //鍥哄寲
- programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName,processEdition);
- }else if(statusLine.contains("PL")){
- //鍋忕
- programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName,processEdition);
+ programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName);//TODO 杩橀渶鏍规嵁鏈哄簥缁勶紙濡備綍鑾峰彇锛熸牴鎹笅鍙戣矾寰勮幏鍙栨満搴婏紝杩涜�岃幏鍙栵級锛�,processEdition
+ }else if(statusLine.contains(AnnotationUtil.LG)){
+ //涓存椂鏇存敼鍗�
+ programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName);
}else{
- //鏌ヨ鏄惁杞﹀簥锛屾槸杞﹀簥鍙互鏀捐繃锛屾寜璇曞垏澶勭悊
- programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition);
- if(programPackageNode!=null){
- Machine machine = machineService.getByCode(programPackageNode.getMachineCode());
- String chechuangVal = paramService.turninngValue();
- if(StringUtils.equals(machine.getMachineSpec(),chechuangVal)){
- //杞﹀簥
- ProgramAnnotation pa = programAnnotationService.getProgramAnnotationFormat(machine.getControlSystem(),annotionDictList);
- statusLine = pa.addAnnotation(ProgramAnnotationService.SQ);
- }
- }
+ throw new ServiceException("鐘舵�佹敞閲婁笉鍦ㄨ寖鍥村唴:"+statusLine+",浠呰瘯鍒囥�佷复鏃舵洿鏀瑰崟鍙互鍥炰紶");
}
if(programPackageNode != null) {
@@ -200,26 +233,7 @@
return list;
}
- /**
- * 浠庢枃浠跺す鍚嶈В鏋愬嚭绋嬪簭鍖呭悕鍜屽拰宸ュ簭鐗堟
- * @param folderName 鏂囦欢澶瑰悕
- * @return 缁撴瀯鏁版嵁
- */
- PackageAndProcessEdition parseProgramPackageFromFolderName(String folderName){
- int index = StringUtils.lastIndexOf(folderName,'-');
- String processEditon = "";
- String temp;
- String packageName = "";
- if(index != -1){
- processEditon = folderName.substring(index+1);
- packageName = folderName.substring(0,index);
- }
- PackageAndProcessEdition result = new PackageAndProcessEdition();;
- result.setProgramPackageName(packageName);
- result.setProcessEdition(processEditon);
- return result;
- }
/**
* 鍏ュ簱鍥炰紶鏂囦欢,骞跺惎鍔ㄥ浐鍖栨祦绋�
@@ -239,7 +253,6 @@
cureFlowService.startCureNew(pkgIdFileMap);
}
-
/**
* 澶勭悊鍥炰紶鏂囦欢
* @param ossFileName
@@ -250,12 +263,36 @@
private Map<Long, List<FlowProgramFile>> dealWithBackFile(String ossFileName, List<Long> acceptIdList) throws IOException{
Map<Long, List<FlowProgramFile>> pkgIdFileMap = new HashMap<>();
+ //ByteArrayInputStream byteInsStream = new ByteArrayInputStream(FileUtil.copyToByteArray(inputStream));
+ for (String encoding : ZipConstants.TRY_ENCODINGS) {
+ try {
+ pkgIdFileMap = dealWithBackFileWithCharset(ossFileName,acceptIdList,Charset.forName(encoding));
+ log.error("浣跨敤缂栫爜 {} 瑙f瀽鎴愬姛 ",encoding);
+ break;
+ } catch (Exception e) {
+ //byteInsStream.reset();
+ log.error("浣跨敤缂栫爜 {} 瑙f瀽澶辫触: ",encoding,e);
+ }
+ }
+
+ return pkgIdFileMap;
+ }
+
+ /**
+ * 澶勭悊鍥炰紶鏂囦欢
+ * @param ossFileName
+ * @param acceptIdList
+ * @return
+ * @throws IOException
+ */
+ private Map<Long, List<FlowProgramFile>> dealWithBackFileWithCharset(String ossFileName, List<Long> acceptIdList,Charset charset) throws IOException{
+ Map<Long, List<FlowProgramFile>> pkgIdFileMap = new HashMap<>();
InputStream inputStream = this.ossTemplate.statFileStream(ossFileName);
Path tempZipFile = createTempFile(inputStream);
List<String> entryNameList = new ArrayList<>();
ZipEntry entry;
- try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) {
+ try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile(),charset)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while(entries.hasMoreElements()) {
entry = entries.nextElement();
@@ -267,10 +304,7 @@
//鏍规嵁鍐呴儴鏂囦欢锛岃鍙栧拰鍒嗘瀽绋嬪簭鍖呭拰绋嬪簭鏂囦欢鏁版嵁
List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList();
for(String dir : dirList){
- String folderName = StringUtils.removeEnd(dir,"/");
-
- PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName);
- String programPackageName = pkgAndEdition.getProgramPackageName();
+ String programPackageName = StringUtils.removeEnd(dir,"/");
Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst();
@@ -310,7 +344,7 @@
FlowProgramFile newFlowFile = new FlowProgramFile();
newFlowFile.setProgramName(packageNode.getName());
newFlowFile.setProcessInstanceId(null);//鍏堢疆涓虹┖锛屽惎鍔ㄦ祦绋嬪悗璁剧疆璇ュ��
- newFlowFile.setFileType("program");
+ newFlowFile.setFileType(FlowProgramFile.TYPE_PROGRAM);
newFlowFile.setName(fileName);
InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName));
BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins);
@@ -374,37 +408,6 @@
String zipFileName = bladeRedis.get(getFileKey());
return ZipTextFileContentUtil.getTextContent(this.ossTemplate.statFileStream(zipFileName),entryName);
- /*
- try(InputStream inputStream = this.ossTemplate.statFileStream(zipFileName);){
- Path tempZipFile = createTempFile(inputStream);
-
- ZipEntry entry;
- try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) {
- Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while (entries.hasMoreElements()) {
- entry = entries.nextElement();
- if (!entryName.equals(entry.getName())) {
- continue;
- }
- try (InputStream fileIns = zipFile.getInputStream(zipFile.getEntry(entryName))) {
- ByteArrayInputStream bos = new ByteArrayInputStream(fileIns.readAllBytes());
- boolean isText = StringUtils.endsWithIgnoreCase(entryName,".txt") || StringUtils.endsWithIgnoreCase(entryName,".nc")|| StringUtils.endsWithIgnoreCase(entryName,".xml");
- if(!isText) {
- isText = FileContentUtil.isTextFile(bos);
- }
- if (isText) {
- bos.reset();
- result = FileContentUtil.getContentFromStream(bos);
- } else {
- result = "<闈炴枃鏈枃浠�>";
- }
- }
-
- }
- }
- }
-
- return result;*/
}
}
@@ -414,4 +417,8 @@
private String programPackageName;
private String processEdition;
+ public String programName(){
+ return programPackageName+"-"+processEdition;
+ }
}
+
--
Gitblit v1.9.3