From 18d9c0bdc04e71cf3903c30c139f59dab744cf3f Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期五, 22 八月 2025 15:09:35 +0800
Subject: [PATCH] 偏离回传 流程改名

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java |  141 +++++++++++++---------------------------------
 1 files changed, 41 insertions(+), 100 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java
index 17c3597..1dd1748 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java
@@ -1,6 +1,8 @@
 
 package org.springblade.mdm.flow.service;
 
+import jakarta.servlet.ServletOutputStream;
+import jakarta.servlet.http.HttpServletResponse;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.IOUtils;
@@ -22,6 +24,7 @@
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
@@ -53,9 +56,9 @@
 		if(file.getSize() == 0){
 			throw new ServiceException("绋嬪簭鏂囦欢涓嶅彲涓虹┖鏂囦欢");
 		}
-		ProgramFileNameCheckUtil.checkFilename(file.getOriginalFilename(),progProps);
-
-		String programName = NcNodeService.genProgramName(progProps.getDrawingNo(),progProps.getProcessNo());
+		if(FlowProgramFile.TYPE_PROGRAM.equals(uploadVO.getFileType())) {
+			ProgramFileNameCheckUtil.checkFilename(file.getOriginalFilename(), progProps);
+		}
 
 		BladeFile bfile = ossTemplate.putFile(file);
 
@@ -63,95 +66,13 @@
 		progFile.setName(file.getOriginalFilename());
 		progFile.setOssName(bfile.getName());
 		progFile.setProcessInstanceId(uploadVO.getProcessInstanceId());
-		progFile.setProgramName(programName);
+		progFile.setProgramName(NcNodeService.genProgramName(progProps.getDrawingNo(),progProps.getProcessNo()));
 		progFile.setFileType(uploadVO.getFileType());
 		save(progFile);
 
 	}
 
 
-	/**
-	 * 妫�鏌ユ枃浠跺悕鍚堟硶鎬�
-	 * @param filename 鏂囦欢鍚�
-	 * @param programProperties 绋嬪簭灞炴�э紝鍙戣捣鏃跺~鍐欑殑
-	 */
-	/*
-	void checkFilename(String filename,FlowProgramProperties programProperties){
-		//绋嬪簭鍚嶇О锛氶浂浠跺彿鍔犲伐搴忓彿锛屾枃浠跺悕搴旇浠ユ寮�澶�
-		String programNamePrefix = NcNodeService.genProgramName(programProperties.getDrawingNo(),programProperties.getProcessNo()) + "-"+programProperties.getProcessEdition();
-		if(!StringUtils.startsWith(filename,programNamePrefix)){
-
-			IResultCode rc = new IResultCode() {
-				@Override
-				public String getMessage() {
-					return "绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+programNamePrefix+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕";
-				}
-
-				@Override
-				public int getCode() {
-					return 1;
-				}
-			};
-			throw new ServiceException(rc);
-		}
-
-		//鎴彇鍚庨潰鐨勬鏁板拰绗嚑娈�
-		String endPart = StringUtils.removeStart(filename,programNamePrefix+"-");
-
-		//鍘绘帀鎵╁睍鍚�
-		if(endPart.contains(".")){
-			endPart = endPart.substring(0,endPart.indexOf("."));
-		}
-
-		int sepCount = StringUtils.countMatches(endPart,"-");
-		if(sepCount != 1){//- 鍙峰簲璇ユ槸1涓�
-			IResultCode rc = new IResultCode() {
-				@Override
-				public String getMessage() {
-					return "绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+programNamePrefix+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕";
-				}
-
-				@Override
-				public int getCode() {
-					return 2;
-				}
-			};
-			throw new ServiceException(rc);
-		}
-
-		String[] arr = StringUtils.split(endPart,"-");
-		if(!StringUtils.isNumeric(arr[0]) || Func.toInt(arr[0]) >99 || Func.toInt(arr[0]) < 1){
-			IResultCode rc = new IResultCode() {
-				@Override
-				public String getMessage() {
-					return "绋嬪簭娈垫暟涓嶅悎娉曪紝搴斾负涓や綅浠ュ唴鏁存暟";
-				}
-
-				@Override
-				public int getCode() {
-					return 3;
-				}
-			};
-			throw new ServiceException(rc);
-		}
-		int segCount = Func.toInt(arr[0]);
-
-		if(!StringUtils.isNumeric(arr[1]) || Func.toInt(arr[1]) < 1 || Func.toInt(arr[1]) > segCount){
-			IResultCode rc = new IResultCode() {
-				@Override
-				public String getMessage() {
-					return "绋嬪簭娈靛彿涓嶅悎娉曪紝搴斾负涓や綅浠ュ唴鏁存暟涓斿皬浜庣瓑浜庢鏁般��";
-				}
-
-				@Override
-				public int getCode() {
-					return 4;
-				}
-			};
-			throw new ServiceException(rc);
-		}
-	}
-*/
 	/**
 	 * 鑾峰彇鏂囦欢鍐呭
 	 * @param id 鏂囦欢id
@@ -161,18 +82,20 @@
 		String result  ="";
 
 		FlowProgramFile programFile = this.getById(id);
-		/*
-			String fileName = programFile.getOssName();
-			try (InputStream inputStream = ossTemplate.statFileStream(fileName)) {
-				result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
-			} catch (IOException e) {
-				throw new RuntimeException(e);
-			}
-		*/
 
 		String fileName = programFile.getOssName();
 		try (InputStream inputStream = ossTemplate.statFileStream(fileName)) {
-			result = FileContentUtil.getContentFromStream(inputStream);
+			ByteArrayInputStream bos = new ByteArrayInputStream(inputStream.readAllBytes());
+			boolean isText = StringUtils.endsWithIgnoreCase(fileName,".txt") || StringUtils.endsWithIgnoreCase(fileName,".nc")|| StringUtils.endsWithIgnoreCase(fileName,".xml");
+			if(!isText){
+				isText= FileContentUtil.isTextFile(bos);
+			}
+			if(isText){
+				bos.reset();
+				result = FileContentUtil.getContentFromStream(bos);
+			}else{
+				result = "<闈炴枃鏈枃浠�>";
+			}
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}
@@ -186,21 +109,39 @@
 	 */
 	public void checkProgramFiles(String processInstanceId,boolean isPass) {
 		List<FlowProgramFile> flowPrograms = this.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId, processInstanceId).orderByAsc(FlowProgramFile::getCreateTime).list();
-		if(isPass && flowPrograms.isEmpty()){
+		List<FlowProgramFile> purePrograms = flowPrograms.stream().filter(FlowProgramFile::isProgram).toList();
+		if(isPass && purePrograms.isEmpty()){
 			throw new ServiceException("璇蜂笂浼犵▼搴忔枃浠�");
 		}
 		int totalSeg = 0;
-		if(!flowPrograms.isEmpty()){
-			FlowProgramFile progFile = flowPrograms.get(0);
+
+		if(!purePrograms.isEmpty()){
+			FlowProgramFile progFile = purePrograms.get(0);
 			totalSeg = ProgramFileNameCheckUtil.getProgramSegCount(progFile.getName());
 		}
 
-		if(totalSeg != flowPrograms.size()){
+		if(totalSeg != purePrograms.size()){
 			throw new ServiceException("搴斾笂浼�"+totalSeg+"娈电▼搴忥紝瀹為檯涓婁紶"+flowPrograms.size()+"娈�");
 		}
 
-
 	}
 
+	public void download(Long id, HttpServletResponse response) throws IOException {
+		FlowProgramFile flowFile = this.getById(id);
+		response.setHeader("Content-Disposition", "attachment; filename="+flowFile.getName());
+		response.setContentType("application/octet-stream");
+		try(InputStream ins = ossTemplate.statFileStream(flowFile.getOssName());){
+			IOUtils.copy(ins,response.getOutputStream());
+		}
+	}
 
+	/**
+	 * 鑾峰彇鍏充簬娴佺▼鐨勬墍鏈夋枃浠�
+	 * @param processInstanceId 娴佺▼瀹炰緥id
+	 * @return 娴佺▼鍏宠仈鐨勬枃浠跺垪琛�
+	 */
+	public List<FlowProgramFile> listByProcessInstanceId(String processInstanceId){
+		return lambdaQuery()
+		.eq(FlowProgramFile::getProcessInstanceId, processInstanceId).list();
+	}
 }

--
Gitblit v1.9.3