浏览代码

fix some bugs

allen 7 月之前
父节点
当前提交
802d6589e4

+ 52 - 3
pdaaphm-admin/src/main/java/com/pdaaphm/biz/utils/MatlabUtils.java

@@ -13,9 +13,58 @@ public class MatlabUtils {
     public void runMatExe(String url) {
         logger.info("exe 运行开始,url:{}", url);
         try {
-            // 启动程序
-            Process process = Runtime.getRuntime().exec(url);
-            process.waitFor();  // 等待进程结束
+            // 使用Process
+//            // 启动程序
+//            Process process = Runtime.getRuntime().exec(url);
+//            process.waitFor();  // 等待进程结束
+
+            // 使用 ProcessBuilder
+//            ProcessBuilder processBuilder = new ProcessBuilder(url);
+//            // 启动进程
+//            Process process = processBuilder.start();
+//            // 等待程序执行完成
+//            process.waitFor();
+
+            // 小夏的代码
+            // 指定要执行的外部程序和参数
+            ProcessBuilder processBuilder = new ProcessBuilder(url);
+            // 启动外部程序
+            Process process = processBuilder.start();
+
+            // Thread to handle the output stream.
+            Thread outputThread = new Thread(() -> {
+                try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+                    String line;
+                    while ((line = reader.readLine()) != null) {
+                        logger.info(line);
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
+
+            // Thread to handle the error stream.
+            Thread errorThread = new Thread(() -> {
+                try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
+                    String line;
+                    while ((line = reader.readLine()) != null) {
+                        logger.error(line);
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
+
+            outputThread.start();
+            errorThread.start();
+
+            // Wait for the external process to finish.
+            int exitCode = process.waitFor();
+
+            // Optionally, wait for the threads to finish reading.
+            outputThread.join();
+            errorThread.join();
+            logger.info("外部程序执行完成,退出码:{}", exitCode);
             logger.info("exe 运行结束,url:{}", url);
         } catch (IOException | InterruptedException e) {
             throw new RuntimeException(e);

+ 13 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/system/controller/TDataProcessController.java

@@ -71,6 +71,19 @@ public class TDataProcessController extends BaseController
         util.exportExcel(response, list, "数据处理数据");
     }
 
+    /**
+     * 导出数据处理列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:process:export')")
+    @Log(title = "数据处理", businessType = BusinessType.EXPORT)
+    @PostMapping("/preprocessExport")
+    public void preprocessExport(HttpServletResponse response, TDataProcess tDataProcess)
+    {
+        List<TDataProcess> list = tDataProcessService.selectPreprocessDataList(tDataProcess);
+        ExcelUtil<TDataProcess> util = new ExcelUtil<TDataProcess>(TDataProcess.class);
+        util.exportExcel(response, list, "数据处理数据");
+    }
+
     /**
      * 获取数据处理详细信息
      */

+ 3 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/system/service/impl/DataServiceImpl.java

@@ -64,6 +64,9 @@ public class DataServiceImpl implements IDataService
         String dataName = data.getDataName();
         if(StringUtils.isEmpty(dataName)){
             String dataPath = data.getDataPath();
+            if(StringUtils.isEmpty(dataPath)){
+                dataPath = data.getImagePath();
+            }
             String nameNotSuffix = FileUtils.getNameNotSuffix(dataPath);
             String originalFileName = nameNotSuffix.split("_")[0];
             data.setDataName(originalFileName);

+ 10 - 5
pdaaphm-admin/src/main/java/com/pdaaphm/system/service/impl/TDataProcessServiceImpl.java

@@ -189,9 +189,11 @@ public class TDataProcessServiceImpl implements ITDataProcessService {
             String resultPath = StringUtils.substringAfter(algConfig.getOutUrl(), Constants.RESOURCE_PREFIX);
             // 复制输出
             // 复制csv
-            String targetCsvPath = StringUtils.format("{}/{}/{}_{}_{}.csv", PadaphmConfig.getUploadPath(), DateUtils.datePath(), getOriginaFileName(data.getDataPath()), bizAlgType, Seq.getId(Seq.uploadSeqType));
-            copyFile(algConfig.getOutUrl() + Constants.ALG_OUTPUT_CSV, targetCsvPath);
-            returnMap.put("resultPath", targetCsvPath);
+            if (checkFileExist(algConfig.getOutUrl() + Constants.ALG_OUTPUT_CSV)) {
+                String targetCsvPath = StringUtils.format("{}/{}/{}_{}_{}.csv", PadaphmConfig.getUploadPath(), DateUtils.datePath(), getOriginaFileName(data.getDataPath()), bizAlgType, Seq.getId(Seq.uploadSeqType));
+                copyFile(algConfig.getOutUrl() + Constants.ALG_OUTPUT_CSV, targetCsvPath);
+                returnMap.put("resultPath", targetCsvPath);
+            }
             // 复制jpg
             if (checkFileExist(algConfig.getOutUrl() + Constants.ALG_OUTPUT_JPG)) {
                 String targetJpgPath = StringUtils.format("{}/{}/{}_{}_{}.jpg", PadaphmConfig.getUploadPath(), DateUtils.datePath(), getOriginaFileName(data.getDataPath()), bizAlgType, Seq.getId(Seq.uploadSeqType));
@@ -226,7 +228,7 @@ public class TDataProcessServiceImpl implements ITDataProcessService {
         return content.toString();
     }
 
-    private static void copyFile(String realDataPath, String inputUrl) {
+    private void copyFile(String realDataPath, String inputUrl) {
         Path sourcePath = Paths.get(realDataPath);  // 源文件路径
         Path targetPath = Paths.get(inputUrl);  // 目标文件路径
         try {
@@ -237,6 +239,7 @@ public class TDataProcessServiceImpl implements ITDataProcessService {
             }
             // 使用Files.copy()复制文件
             Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING);
+            logger.info("文件已成功复制!source:{},target:{}",sourcePath, targetPath);
             System.out.println("文件已成功复制!");
         } catch (IOException e) {
             throw new RuntimeException(e);
@@ -256,7 +259,9 @@ public class TDataProcessServiceImpl implements ITDataProcessService {
             Data newData = new Data();
             String resultPath = resultMap.get("resultPath");
             String resultImagePath = resultMap.get("resultImagePath");
-            newData.setDataPath(resultPath.replaceFirst(PadaphmConfig.getProfile(),"/profile"));
+            if (checkFileExist(resultPath)) {
+                newData.setDataPath(resultPath.replaceFirst(PadaphmConfig.getProfile(), "/profile"));
+            }
             if (checkFileExist(resultImagePath)) {
                 newData.setImagePath(resultImagePath.replaceFirst(PadaphmConfig.getProfile(),"/profile"));
             }

+ 2 - 2
pdaaphm-admin/src/main/resources/application-druid.yml

@@ -6,9 +6,9 @@ spring:
         druid:
             # 主库数据源
             master:
-                url: jdbc:mysql://47.108.150.237:3306/pdaaphm?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                url: jdbc:mysql://127.0.0.1:3306/pdaaphm?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
-                password: w.cf123321
+                password: 123456
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭

+ 2 - 2
pdaaphm-admin/src/main/resources/application.yml

@@ -72,13 +72,13 @@ spring:
   # redis 配置
   redis:
     # 地址
-    host: 101.126.133.7
+    host: 127.0.0.1
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 0
     # 密码
-    password: Z;G4AS:Vor'YF#p?
+    password:
     # 连接超时时间
     timeout: 10s
     lettuce: