1
0
Просмотр исходного кода

test python的相关模型调用

chenendian 1 неделя назад
Родитель
Сommit
4d1c9257ff

+ 67 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/ChenController.java

@@ -3,11 +3,17 @@ package com.siwei.apply.controller;
 import com.siwei.apply.domain.res.YdysyxzRes;
 import com.siwei.apply.domain.vo.YdysyxzVo;
 import com.siwei.apply.service.YdysyxzService;
+import com.siwei.apply.utils.FixedThreadUtil;
 import com.siwei.common.core.domain.R;
+import com.siwei.common.core.utils.StringUtils;
 import com.siwei.common.core.web.controller.BaseController;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -92,8 +98,69 @@ public class ChenController extends BaseController {
         }
     }
 
+
+    @GetMapping("/testPython")
+    public R<String> testPython() {
+        try {
+            //C:\Users\siwei>python "D:\Tie-Ortho\ocr-tests\20261012-land-application\run_ocr.py"  "C:\Users\siwei\Desktop\tp_test\疑似违法用地情况说明.pdf"   --mode free
+            String retString = "测试";
+            String pythonHome = "E:\\anaconda\\envs\\py310\\python.exe";
+            String finalPyPath = "D:\\Tie-Ortho\\ocr-tests\\20261012-land-application\\run_ocr.py";
+            String imgPath = "C:\\Users\\siwei\\Desktop\\tp_test\\用地规划设计条件.jpg";
+            FixedThreadUtil.FIXED_THREAD_POOL.execute(() -> {
+                try {
+                    // 更新状态为运行中
+                    //TODO command ProcessBuilder
+                    ProcessBuilder pb = new ProcessBuilder(pythonHome, finalPyPath, imgPath, "", "", "", "");
+                    pb.redirectErrorStream(true);
+                    Process process = null;
+                    process = pb.start();
+                    BufferedReader reader = new BufferedReader(
+                            new InputStreamReader(process.getInputStream()));
+                    String line;
+                    ArrayList<String> datas = new ArrayList<>();
+                    while ((line = reader.readLine()) != null) {
+                        if (StringUtils.isNotEmpty(line)) {
+                            if (line.contains("||")) {
+                                datas.add(line.split("ERROR")[0]);
+                            }
+                        }
+                    }
+                    if (datas.size() > 0) {
+                        // 更新状态为成功
+                        for (String cur : datas) {
+                            String[] args = cur.split("\\|\\|");
+                            String id = StringUtils.getUUID();
+                            // 处理文件路径
+                            args[1] = StringUtils.replaceEach(args[1], new String[]{"D:", "\\"}, new String[]{"", "/"});
+                            // 插入制图产品表
+                            //thematicMapper.addDetails(id, uuid, args[0], args[1], args[2]);
+                            System.out.println("制图产品表插入成功:" + args[0] + " " + args[1] + " " + args[2]);
+                        }
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
+            return R.ok(retString);
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+
+
+
+
+
+
+
     // 测试用main方法
     public static void main(String[] args) {
+
+
+
+
         System.out.println("陈先生");
     }