cr 2 dienas atpakaļ
vecāks
revīzija
04b82a2af2

+ 16 - 1
blade-service-api/blade-archive-api/src/main/java/org/springblade/archive/dto/AutoOCRDTO.java

@@ -2,9 +2,24 @@ package org.springblade.archive.dto;
 
 import lombok.Data;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Data
 public class AutoOCRDTO {
-    private List<Long> ids;
+    private String ids;  // 改为String类型
+
+    // 添加方法获取Long列表
+    public List<Long> getIdList() {
+        if (ids == null || ids.trim().isEmpty()) {
+            return new ArrayList<>();
+        }
+        return Arrays.stream(ids.split(","))
+                .map(String::trim)
+                .filter(s -> !s.isEmpty())
+                .map(Long::valueOf)
+                .collect(Collectors.toList());
+    }
 }

+ 2 - 2
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchivesAutoController.java

@@ -286,8 +286,8 @@ public class ArchivesAutoController extends BladeController {
 	@PostMapping("/atuoOCR")
 	@ApiOperationSupport(order = 5)
 	@ApiOperation(value = "档案自动识别")
-	public R atuoOCR(@RequestBody AutoOCRDTO autoOCRDTO) throws Exception {
-		archivesAutoService.atuoOCR(autoOCRDTO.getIds());
+	public R atuoOCR(@RequestBody AutoOCRDTO dto) throws Exception {
+		archivesAutoService.atuoOCR(dto.getIdList());
 		return R.success("正在识别中");
 	}
 

+ 1 - 1
blade-service/blade-archive/src/main/java/org/springblade/archive/service/IArchivesAutoService.java

@@ -188,7 +188,7 @@ public interface IArchivesAutoService extends BaseService<ArchivesAuto> {
 
     void reCreateArchiveAuto1(String ids);
 
-	boolean atuoOCR(List<Long> ids) throws Exception;
+	Boolean atuoOCR(List<Long> ids) throws Exception;
 
 	void reCreateArchiveAuto2(List<ArchivesAuto> archivesAutoList, String ids, String name);
 

+ 21 - 12
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -39,10 +39,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 
-import org.springblade.archive.dto.ArchiveWarningDTO;
-import org.springblade.archive.dto.FindAndReplaceDto;
-import org.springblade.archive.dto.JiLinQueryDto;
-import org.springblade.archive.dto.SaveApplyDTO;
+import org.springblade.archive.dto.*;
 import org.springblade.archive.entity.*;
 import org.springblade.archive.mapper.ArchiveConclusionMapper;
 import org.springblade.archive.service.*;
@@ -5342,17 +5339,25 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 
 	@Override
 	@Async
-	public boolean atuoOCR(List<Long> idsList) throws Exception {
+	public Boolean atuoOCR(List<Long> idsList) throws Exception {
 		String url="/mnt/sdc/AutoPdf/";
 		//String url="D:\\AutoPdf\\";
+		//List<Long> idsList=Func.toLongList(ids);
 		List<ArchivesAuto> archivesAutoList = this.list(new LambdaQueryWrapper<ArchivesAuto>().in(ArchivesAuto::getId, idsList));
 		for (ArchivesAuto auto : archivesAutoList) {
+			if(auto.getOutUrl()==null||auto.getOutUrl().isEmpty()){
+				continue;
+			}
 			String fileUrl=auto.getOutUrl().substring(0,auto.getOutUrl().indexOf("@"));
 			String filePath=url+auto.getName()+".pdf";
+			System.out.println("开始保存:"+fileUrl);
 			Boolean b = FileUtils.saveInputStreamByUrl(fileUrl, filePath);
+			System.out.println("保存完成:"+b);
 			try {
 				if(b){
+					System.out.println("开始识别:"+filePath);
 					List<String> list = extractTextFromPDF(filePath);
+					System.out.println("识别完成:"+list);
 					if(!list.isEmpty()){
 						StringBuilder fileName=new StringBuilder();
 						for (String result : list) {
@@ -5411,9 +5416,9 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	}
 
 	public List<String> extractTextFromPDF(String pdfFilePath) throws IOException, InterruptedException {
-//		String PYTHON_SCRIPT_PATH = "C:\\Users\\hc01\\AppData\\Local\\Programs\\Python\\Python310\\Python\\pdfTextExtractorWindows.py";
-//		String PYTHON_INTERPRETER = "C:\\Users\\hc01\\AppData\\Local\\Programs\\Python\\Python310\\python.exe";
-
+		//String PYTHON_SCRIPT_PATH = "C:\\Users\\hc01\\AppData\\Local\\Programs\\Python\\Python310\\Python\\pdfTextExtractorWindows.py";
+		//String PYTHON_INTERPRETER = "C:\\Users\\hc01\\AppData\\Local\\Programs\\Python\\Python310\\python.exe";
+		System.out.println("进入识别1");
 		String PYTHON_SCRIPT_PATH = "/www/wwwlogs/python/pdfTextExtractorWindows.py";
 		String PYTHON_INTERPRETER = "python3";
 		String[] command = {
@@ -5425,7 +5430,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		Process process = new ProcessBuilder(command)
 				.redirectErrorStream(true)
 				.start();
-
+		System.out.println("进入识别2");
 		// 读取Python输出
 		StringBuilder output = new StringBuilder();
 		try (InputStream inputStream = process.getInputStream();
@@ -5436,9 +5441,10 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 				output.append(line);
 			}
 		}
-
+		System.out.println("进入识别3");
 		int exitCode = process.waitFor();
 		if (exitCode != 0) {
+			System.out.println("进入识别4");
 			throw new RuntimeException("Python脚本执行失败,退出码: " + exitCode + ", 输出: " + output.toString());
 		}
 
@@ -5447,22 +5453,25 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		// 找到JSON的起始位置(第一个'{')和结束位置(最后一个'}')
 		int jsonStart = rawOutput.indexOf('{');
 		int jsonEnd = rawOutput.lastIndexOf('}');
+		System.out.println("进入识别5");
 		if (jsonStart == -1 || jsonEnd == -1 || jsonStart >= jsonEnd) {
+			System.out.println("进入识别6");
 			throw new RuntimeException("无法提取有效的JSON结果,原始输出: " + rawOutput);
 		}
 		// 截取纯JSON字符串
 		String jsonStr = rawOutput.substring(jsonStart, jsonEnd + 1);
-
+		System.out.println("进入识别7");
 		// 解析清理后的JSON
 		Gson gson = new Gson();
 		Type type = new TypeToken<Map<String, Object>>(){}.getType();
 		Map<String, Object> resultMap = gson.fromJson(jsonStr, type);
 
 		if (!"success".equals(resultMap.get("status"))) {
+			System.out.println("进入识别8");
 			String message = (String) resultMap.get("message");
 			throw new RuntimeException("处理PDF失败: " + (message != null ? message : "未知错误"));
 		}
-
+		System.out.println("进入识别9");
 		Type listType = new TypeToken<List<String>>(){}.getType();
 		return gson.fromJson(gson.toJson(resultMap.get("lines")), listType);
 	}