From 8a0db337026a6ab4587766a52761722fae5b2da1 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 02 八月 2025 12:34:53 +0800
Subject: [PATCH] 程序上传接口,验证通过

---
 blade-service/blade-mdm/src/test/java/org/springblade/mdm/flow/service/FlowProgramFileServiceTest.java |   52 +++++++++++++++++
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowProgramFileService.java     |   93 +++++++++++++++++++++++++++++-
 2 files changed, 140 insertions(+), 5 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 f74c5d5..a4593ff 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
@@ -11,11 +11,16 @@
 import org.springblade.core.mp.base.BizServiceImpl;
 import org.springblade.core.oss.OssTemplate;
 import org.springblade.core.oss.model.BladeFile;
+import org.springblade.core.tool.api.IResultCode;
+import org.springblade.core.tool.api.ResultCode;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.NumberUtil;
 import org.springblade.mdm.flow.entity.FlowProgramFile;
 import org.springblade.mdm.flow.mapper.FlowProgramFileMapper;
 import org.springblade.mdm.flow.vo.ProgramUploadVO;
 import org.springblade.mdm.program.entity.NcProgram;
 import org.springblade.mdm.program.service.ProcessProgRefService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -32,11 +37,14 @@
  */
 @Slf4j
 @Service
-@AllArgsConstructor
 public class FlowProgramFileService extends BizServiceImpl<FlowProgramFileMapper, FlowProgramFile> {
-	private final OssTemplate ossTemplate;
-	private final RuntimeService runtimeService;
-	private final FlowCommonService flowCommonService;
+	@Autowired
+	private OssTemplate ossTemplate;
+	@Autowired
+	private RuntimeService runtimeService;
+	@Autowired
+	private FlowCommonService flowCommonService;
+
 	public void uploadFlowProgramFile(ProgramUploadVO uploadVO) {
 
 		//Map<String, Object> vars = runtimeService.getVariables(uploadVO.getProcessInstanceId());
@@ -84,11 +92,86 @@
 		}
 	}
 
+	/**
+	 * 妫�鏌ユ枃浠跺悕鍚堟硶鎬�
+	 * @param filename
+	 * @param programProperties
+	 */
 	void checkFilename(String filename,FlowProgramProperties programProperties){
 		//绋嬪簭鍚嶇О锛氶浂浠跺彿鍔犲伐搴忓彿锛屾枃浠跺悕搴旇浠ユ寮�澶�
 		String expectedProgramName = programProperties.getDrawingNo()+"-"+programProperties.getProcessNo();
 		if(!StringUtils.startsWith(filename,expectedProgramName)){
-			throw new ServiceException("绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕");
+
+			IResultCode rc = new IResultCode() {
+				@Override
+				public String getMessage() {
+					return "绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕";
+				}
+
+				@Override
+				public int getCode() {
+					return 1;
+				}
+			};
+			throw new ServiceException(rc);
+			//throw new ServiceException("绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕");
+		}
+
+		//鎴彇鍚庨潰鐨勬鏁板拰绗嚑娈�
+		String endPart = StringUtils.removeStart(filename,expectedProgramName+"-"+programProperties.getCraftEdition()+"-");
+
+		//鍘绘帀鎵╁睍鍚�
+		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 "绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕";
+				}
+
+				@Override
+				public int getCode() {
+					return 2;
+				}
+			};
+			throw new ServiceException(rc);
+			//throw new ServiceException("绋嬪簭鏂囦欢鍚嶄笉鍚堟硶锛屽簲涓猴細"+expectedProgramName+"-"+programProperties.getCraftEdition()+"-[娈垫暟]-[娈靛彿].[鏂囦欢鎵╁睍鍚峕");
+		}
+
+		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);
 		}
 	}
 
diff --git a/blade-service/blade-mdm/src/test/java/org/springblade/mdm/flow/service/FlowProgramFileServiceTest.java b/blade-service/blade-mdm/src/test/java/org/springblade/mdm/flow/service/FlowProgramFileServiceTest.java
new file mode 100644
index 0000000..2cfe108
--- /dev/null
+++ b/blade-service/blade-mdm/src/test/java/org/springblade/mdm/flow/service/FlowProgramFileServiceTest.java
@@ -0,0 +1,52 @@
+package org.springblade.mdm.flow.service;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Assertions;
+import org.springblade.core.log.exception.ServiceException;
+
+public class FlowProgramFileServiceTest {
+
+	@Test
+	public void testCheckFilename() {
+		FlowProgramFileService service = new FlowProgramFileService();
+
+		String drawingNo = "闆朵欢鍙�";
+		String processNo = "10";
+		String craftEdition = "A";//宸ヨ壓鐗堟
+
+		String progName = drawingNo+"-"+processNo;
+
+
+		FlowProgramProperties programProperties = new FlowProgramProperties();
+		programProperties.setDrawingNo(drawingNo);
+		programProperties.setProcessNo(processNo);
+		programProperties.setCraftEdition(craftEdition);
+		try {
+			service.checkFilename("abc.txt", programProperties);
+		}catch(ServiceException e){
+			Assertions.assertEquals(1,e.getResultCode().getCode());
+		}
+
+		String filename = progName+"-"+craftEdition+"-4-1.txt";//4娈电涓�娈�
+		try {
+			service.checkFilename(filename, programProperties);
+
+		}catch(ServiceException e){
+			Assertions.fail("搴旇楠岃瘉閫氳繃锛屽疄闄卌ode="+e.getResultCode().getCode());
+		}
+
+		filename = progName+"-"+craftEdition+"-101-1.txt";//娈垫暟瓒�2浣嶆暟娴嬭瘯
+		try {
+			service.checkFilename(filename, programProperties);
+		}catch(ServiceException e){
+			Assertions.assertEquals(3,e.getResultCode().getCode());
+		}
+
+		filename = progName+"-"+craftEdition+"-3-5.txt";//娈靛彿瓒呰繃鎬绘鏁�
+		try {
+			service.checkFilename(filename, programProperties);
+		}catch(ServiceException e){
+			Assertions.assertEquals(4,e.getResultCode().getCode());
+		}
+	}
+}

--
Gitblit v1.9.3