فهرست منبع

算法管理全部功能基本实现

twzydn20000928 1 سال پیش
والد
کامیت
d400da4c2e
24فایلهای تغییر یافته به همراه426 افزوده شده و 52 حذف شده
  1. 12 0
      pdaaphm-admin/pom.xml
  2. 2 2
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/controller/AlgorithmController.java
  3. 56 0
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/domain/BaseResponse.java
  4. 11 0
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/dto/RequestDTO.java
  5. 2 2
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/factory/AlgorithmFactory.java
  6. 2 0
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/AlgorithmMapper.java
  7. 14 9
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/FileMapper.java
  8. 15 8
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/SubAlgorithmMapper.java
  9. 2 1
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/IAlgorithmService.java
  10. 6 1
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/RunAlgorithmService.java
  11. 46 3
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/AlgorithmServiceImpl.java
  12. 6 1
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunMatlabImpl.java
  13. 133 3
      pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunPythonImpl.java
  14. 2 0
      pdaaphm-admin/src/main/resources/application.yml
  15. 15 0
      pdaaphm-admin/src/main/resources/mapper/algoManager/AlgorithmMapper.xml
  16. 12 0
      pdaaphm-admin/src/main/resources/mapper/algoManager/FileMapper.xml
  17. 24 6
      pdaaphm-admin/src/main/resources/mapper/algoManager/SubAlgorithmMapper.xml
  18. 19 1
      pdaaphm-common/src/main/java/com/pdaaphm/common/config/PadaphmConfig.java
  19. 29 1
      pdaaphm-common/src/main/java/com/pdaaphm/common/utils/file/FileUploadUtils.java
  20. 11 11
      pdaaphm-system/src/main/java/com/pdaaphm/system/service/impl/SysConfigServiceImpl.java
  21. 0 1
      pdaaphm-ui/src/components/FileUpload/index.vue
  22. 2 1
      pdaaphm-ui/src/views/algoManager/algorithm/index.vue
  23. 3 0
      pdaaphm-ui/src/views/conf/subType/index.vue
  24. 2 1
      sql/pdaaphm.sql

+ 12 - 0
pdaaphm-admin/pom.xml

@@ -65,6 +65,18 @@
             <artifactId>lombok</artifactId>
         </dependency>
 
+        <!-- 添加Spring WebFlux Starter依赖-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-webflux</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.14</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 2 - 2
pdaaphm-admin/src/main/java/com/pdaaphm/biz/controller/AlgorithmController.java

@@ -1,5 +1,6 @@
 package com.pdaaphm.biz.controller;
 
+import java.io.IOException;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
@@ -132,8 +133,7 @@ public class AlgorithmController extends BaseController
     @PreAuthorize("@ss.hasPermi('algoManager:algorithm:edit')")
     @Log(title = "算法", businessType = BusinessType.UPDATE)
     @GetMapping(value = "/runAlgorithms/{id}")
-    public AjaxResult runAlgorithms(@PathVariable("id") Long id)
-    {
+    public AjaxResult runAlgorithms(@PathVariable("id") Long id) throws IOException {
         return success(algorithmService.runAlgorithms(id));
     }
 }

+ 56 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/domain/BaseResponse.java

@@ -0,0 +1,56 @@
+package com.pdaaphm.biz.domain;
+
+import java.io.Serializable;
+
+/**
+ * 响应基础类
+ *
+ * @author xlk
+ */
+public class BaseResponse implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+    private Integer code;
+    private String msg;
+    private Object data;
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public Object getData() {
+        return data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return "BaseResponse{" +
+                "code=" + code +
+                ", msg='" + msg + '\'' +
+                ", data=" + data +
+                '}';
+    }
+
+    public static BaseResponse error(String msg) {
+        BaseResponse baseResponse = new BaseResponse();
+        baseResponse.setCode(500);
+        baseResponse.setMsg(msg);
+        return baseResponse;
+    }
+}

+ 11 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/dto/RequestDTO.java

@@ -0,0 +1,11 @@
+package com.pdaaphm.biz.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class RequestDTO {
+    private List<String> docList;
+    private List<String> resultList;
+}

+ 2 - 2
pdaaphm-admin/src/main/java/com/pdaaphm/biz/factory/AlgorithmFactory.java

@@ -14,9 +14,9 @@ public class AlgorithmFactory {
     private RunPythonImpl runPythonImpl;
 
     public RunAlgorithmService createRun(String type) {
-        if (type.equals("python")) {
+        if ("1".equals(type)) {
             return runPythonImpl;
-        } else if (type.equals("cat")) {
+        } else if ("2".equals(type)) {
             return runMatlabImpl;
         } else {
             return null;

+ 2 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/AlgorithmMapper.java

@@ -65,4 +65,6 @@ public interface AlgorithmMapper
     public List<Map> getOption();
 
     public int runAlgorithm(Long id);
+
+    public List<Map> selectUrlAndAddressById(Long id);
 }

+ 14 - 9
pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/FileMapper.java

@@ -7,15 +7,15 @@ import com.pdaaphm.biz.domain.File;
 
 /**
  * 文件Mapper接口
- * 
+ *
  * @author xlk
  * @date 2023-07-26
  */
-public interface FileMapper 
+public interface FileMapper
 {
     /**
      * 查询文件
-     * 
+     *
      * @param id 文件主键
      * @return 文件
      */
@@ -23,7 +23,7 @@ public interface FileMapper
 
     /**
      * 查询文件列表
-     * 
+     *
      * @param file 文件
      * @return 文件集合
      */
@@ -31,7 +31,7 @@ public interface FileMapper
 
     /**
      * 新增文件
-     * 
+     *
      * @param file 文件
      * @return 结果
      */
@@ -39,7 +39,7 @@ public interface FileMapper
 
     /**
      * 修改文件
-     * 
+     *
      * @param file 文件
      * @return 结果
      */
@@ -47,7 +47,7 @@ public interface FileMapper
 
     /**
      * 删除文件
-     * 
+     *
      * @param id 文件主键
      * @return 结果
      */
@@ -55,11 +55,16 @@ public interface FileMapper
 
     /**
      * 批量删除文件
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteFileByIds(Long[] ids);
 
-    List<Map> getOption();
+    public List<Map> getOption();
+
+    /**
+     * 查询输出文件是否已存在
+     */
+    public Long selectOutputFile(Long id);
 }

+ 15 - 8
pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/SubAlgorithmMapper.java

@@ -1,19 +1,21 @@
 package com.pdaaphm.biz.mapper;
 
 import java.util.List;
+import java.util.Map;
+
 import com.pdaaphm.biz.domain.SubAlgorithm;
 
 /**
  * 子算法Mapper接口
- * 
+ *
  * @author xlk
  * @date 2023-07-26
  */
-public interface SubAlgorithmMapper 
+public interface SubAlgorithmMapper
 {
     /**
      * 查询子算法
-     * 
+     *
      * @param id 子算法主键
      * @return 子算法
      */
@@ -21,7 +23,7 @@ public interface SubAlgorithmMapper
 
     /**
      * 查询子算法列表
-     * 
+     *
      * @param subAlgorithm 子算法
      * @return 子算法集合
      */
@@ -29,7 +31,7 @@ public interface SubAlgorithmMapper
 
     /**
      * 新增子算法
-     * 
+     *
      * @param subAlgorithm 子算法
      * @return 结果
      */
@@ -37,7 +39,7 @@ public interface SubAlgorithmMapper
 
     /**
      * 修改子算法
-     * 
+     *
      * @param subAlgorithm 子算法
      * @return 结果
      */
@@ -45,7 +47,7 @@ public interface SubAlgorithmMapper
 
     /**
      * 删除子算法
-     * 
+     *
      * @param id 子算法主键
      * @return 结果
      */
@@ -53,9 +55,14 @@ public interface SubAlgorithmMapper
 
     /**
      * 批量删除子算法
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteSubAlgorithmByIds(Long[] ids);
+
+    /**
+     * 查询算法实例的输出对应的算法关系
+     */
+    public List<Map> selectSubAlgorithmOutputList(Long id);
 }

+ 2 - 1
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/IAlgorithmService.java

@@ -1,5 +1,6 @@
 package com.pdaaphm.biz.service;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
@@ -80,5 +81,5 @@ public interface IAlgorithmService
      */
     public AlgorithmDTO getAlgorithmDto(Long id);
 
-    public int runAlgorithms(Long id);
+    public int runAlgorithms(Long id) throws IOException;
 }

+ 6 - 1
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/RunAlgorithmService.java

@@ -1,5 +1,10 @@
 package com.pdaaphm.biz.service;
 
+import com.pdaaphm.biz.domain.BaseResponse;
+import com.pdaaphm.biz.dto.RequestDTO;
+
+import java.util.List;
+
 public interface RunAlgorithmService {
-    public void runAlgorithm(Long id);
+    public BaseResponse runAlgorithm(Long id, String url, RequestDTO requestDto);
 }

+ 46 - 3
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/AlgorithmServiceImpl.java

@@ -1,22 +1,30 @@
 package com.pdaaphm.biz.service.impl;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import com.pdaaphm.biz.domain.AlgorithmSubType;
 import com.pdaaphm.biz.domain.SubAlgorithm;
 import com.pdaaphm.biz.dto.AlgorithmDTO;
+import com.pdaaphm.biz.dto.RequestDTO;
 import com.pdaaphm.biz.dto.SubAlgorithmDTO;
 import com.pdaaphm.biz.factory.AlgorithmFactory;
 import com.pdaaphm.biz.mapper.AlgorithmIoFieldMapper;
+import com.pdaaphm.biz.mapper.AlgorithmSubTypeMapper;
 import com.pdaaphm.biz.mapper.SubAlgorithmMapper;
 import com.pdaaphm.biz.service.RunAlgorithmService;
+import com.pdaaphm.common.config.PadaphmConfig;
 import com.pdaaphm.common.utils.DateUtils;
+import com.pdaaphm.common.utils.file.FileUploadUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.pdaaphm.biz.mapper.AlgorithmMapper;
 import com.pdaaphm.biz.domain.Algorithm;
 import com.pdaaphm.biz.service.IAlgorithmService;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 算法Service业务层处理
@@ -35,6 +43,8 @@ public class AlgorithmServiceImpl implements IAlgorithmService
     private AlgorithmIoFieldMapper algorithmIoFieldMapper;
     @Autowired
     private AlgorithmFactory algorithmFactory;
+    @Autowired
+    private AlgorithmSubTypeMapper algorithmSubTypeMapper;
 
     /**
      * 查询算法
@@ -158,13 +168,46 @@ public class AlgorithmServiceImpl implements IAlgorithmService
     public List<Map> getOption() { return algorithmMapper.getOption(); }
 
     @Override
-    public int runAlgorithms(Long id) {
+    public int runAlgorithms(Long id) throws IOException {
         int res = 0;
         //1. update Algorithm.startTime to now
         //2. run algorithmImpl
+        List<Map> list = algorithmMapper.selectUrlAndAddressById(id);
         Algorithm algorithm = this.selectAlgorithmById(id);
-        RunAlgorithmService runAlgorithmService = algorithmFactory.createRun(algorithm);
-        runAlgorithmService.runAlgorithm(id);
+        AlgorithmSubType algorithmSubType = algorithmSubTypeMapper.selectAlgorithmSubTypeById(algorithm.getSubTypeId());
+        RunAlgorithmService runAlgorithmService = algorithmFactory.createRun(algorithmSubType.getRunType());
+        PadaphmConfig.getProfile();
+        if(CollectionUtils.isEmpty(list)){
+            return res;
+        }
+        List<String> docAddress = new ArrayList<>(list.size());
+        List<String> resultAddress = new ArrayList<>(list.size());
+        String prefix = PadaphmConfig.getProfile();
+        String prefix2 = PadaphmConfig.getResultPath();
+        int j = 1;
+        for (int i = 0; i < list.size(); i++) {
+            if (list.get(i).get("type").equals("1")) {
+                String s = (String)list.get(i).get("path");
+                if (s.startsWith("/profile")) {
+                    s = s.replace("/profile", prefix);
+                }
+                docAddress.add(s);
+            }
+            else {
+                String fileName = "result" + j;
+                j++;
+                String filePrefix = PadaphmConfig.getResultFilePath();
+                String fileNameFinal = FileUploadUtils.upload(filePrefix, fileName);
+                if (fileNameFinal.startsWith("/profile")) {
+                    fileNameFinal = fileNameFinal.replace("/profile", prefix2);
+                }
+                resultAddress.add(fileNameFinal);
+            }
+        }
+        RequestDTO requestDto = new RequestDTO();
+        requestDto.setDocList(docAddress);
+        requestDto.setResultList(resultAddress);
+        runAlgorithmService.runAlgorithm(id, (String)list.get(0).get("url"), requestDto);
         //3. update Algorithm.completedTime and Algorithm.costSecond
         //4. res = 1;
         return res;

+ 6 - 1
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunMatlabImpl.java

@@ -1,12 +1,17 @@
 package com.pdaaphm.biz.service.impl;
 
+import com.pdaaphm.biz.domain.BaseResponse;
+import com.pdaaphm.biz.dto.RequestDTO;
 import com.pdaaphm.biz.service.RunAlgorithmService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class RunMatlabImpl implements RunAlgorithmService {
     @Override
-    public void runAlgorithm(Long id) {
+    public BaseResponse runAlgorithm(Long id, String url, RequestDTO requestDto) {
         System.out.println("runMatlab!");
+        return null;
     }
 }

+ 133 - 3
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunPythonImpl.java

@@ -1,12 +1,142 @@
 package com.pdaaphm.biz.service.impl;
 
+import com.pdaaphm.biz.domain.BaseResponse;
+import com.pdaaphm.biz.domain.File;
+import com.pdaaphm.biz.domain.SubAlgorithm;
+import com.pdaaphm.biz.dto.RequestDTO;
+import com.pdaaphm.biz.mapper.FileMapper;
+import com.pdaaphm.biz.mapper.SubAlgorithmMapper;
 import com.pdaaphm.biz.service.RunAlgorithmService;
+import com.pdaaphm.common.config.PadaphmConfig;
+import com.pdaaphm.common.utils.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.publisher.Mono;
+
+import java.io.FilenameFilter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeoutException;
 
 @Service
 public class RunPythonImpl implements RunAlgorithmService {
-    @Override
-    public void runAlgorithm(Long id) {
-        System.out.println("runPython!");
+
+    @Autowired
+    private FileMapper fileMapper;
+
+    @Autowired
+    private SubAlgorithmMapper subAlgorithmMapper;
+
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+//    @Override
+//    public void runAlgorithm(String url, List<String> docAddress) {
+//        // create httpclient, post method
+//        // url/docAddress/
+//        System.out.println("runPython!");
+//    }
+
+    public BaseResponse runAlgorithm(Long id, String url, RequestDTO requestDto) {
+        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
+        httpRequestFactory.setConnectionRequestTimeout(3000);
+        httpRequestFactory.setConnectTimeout(3000);
+        httpRequestFactory.setReadTimeout(3000);
+//        RestTemplate restTemplate = new RestTemplate(httpRequestFactory);
+//        BaseResponse response = restTemplate.postForObject(url, docAddress, BaseResponse.class);
+        WebClient webClient = WebClient.create(url);
+        Mono<BaseResponse> result = webClient.post()  // 使用POST方法
+                .uri("/request")  // 指定URI
+                .contentType(MediaType.APPLICATION_JSON)  // 设置Content-Type为application/json
+                .bodyValue(requestDto)  // 设置请求body
+                .retrieve()  // 执行请求
+                .bodyToMono(BaseResponse.class)
+                .onErrorResume(e -> {
+                    logger.error("http request error!!!",e);
+                    if (e instanceof TimeoutException) {
+                        // 对超时错误进行处理
+                        return Mono.just(BaseResponse.error("Timeout error"));
+                    } else {
+                        // 对其他错误进行处理
+                        return Mono.just(BaseResponse.error("Other error"));
+                    }
+                });  // 将响应体转换为String
+        BaseResponse res = result.block();
+        List<String> resultList = requestDto.getResultList();
+        List<Map> subAlgorithmOutputList = subAlgorithmMapper.selectSubAlgorithmOutputList(id);
+        for (int i = 0; i < resultList.size(); i++) {
+            String resultPath = resultList.get(i);
+            Map subAlgorithmOutput = subAlgorithmOutputList.get(i);
+            int lastIndex = resultPath.lastIndexOf("/");
+            String dirs = resultPath.substring(0, lastIndex);
+            String prefixName = resultPath.substring(lastIndex + 1);
+            Map<String,String> map = getFinalNameAndPath(dirs, prefixName);
+            if (map != null) {
+                String prefix = PadaphmConfig.getResultPath();
+                String s = map.get("path");
+                if (s.startsWith(prefix)) {
+                    s = s.replace(prefix,"/resultPath");
+                    map.put("path", s);
+                }
+                File resultFile = new File();
+                resultFile.setName(map.get("name"));
+                resultFile.setPath(map.get("path"));
+                resultFile.setType("2");
+                resultFile.setCreateTime(DateUtils.getNowDate());
+                Long fileId = fileMapper.selectOutputFile(id);
+                if (fileId == null) {
+                    fileMapper.insertFile(resultFile);
+                }
+                else {
+                    resultFile.setId(fileId);
+                    fileMapper.updateFile(resultFile);
+                }
+                SubAlgorithm subAlgorithm = new SubAlgorithm();
+                subAlgorithm.setId((Long) subAlgorithmOutput.get("id"));
+                subAlgorithm.setAlgorithmId((Long) subAlgorithmOutput.get("algorithm_id"));
+                subAlgorithm.setFieldId((Long) subAlgorithmOutput.get("field_id"));
+                subAlgorithm.setUploadId(resultFile.getId());
+                subAlgorithm.setCreateTime(DateUtils.getNowDate());
+                subAlgorithmMapper.updateSubAlgorithm(subAlgorithm);
+            }
+            else {
+                logger.error("存在未生成文件!");
+            }
+        }
+        return res;
+    }
+
+    public Map getFinalNameAndPath(String dirs, String prefixName) {
+        // 指定目录路径
+        java.io.File directory = new java.io.File(dirs);
+
+        // 已知的文件名前缀(不带扩展名)
+        String knownFileName = prefixName;
+
+        // 使用FilenameFilter筛选与已知文件名开头的文件
+        String[] matchingFiles = directory.list((dir, name) -> name.startsWith(knownFileName));
+
+        Map<String,String> map = new HashMap<>();
+
+        if (matchingFiles != null && matchingFiles.length == 1) {
+            System.out.println("找到匹配的文件:");
+            map.put("name",matchingFiles[0]);
+            map.put("path",dirs + '/' + matchingFiles[0]);
+            return map;
+        } else if (matchingFiles != null && matchingFiles.length > 1) {
+            System.out.println("找到多个匹配的文件,这不应该发生。");
+            return null;
+        } else {
+            System.out.println("没有找到匹配的文件。");
+            return null;
+        }
     }
 }

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

@@ -10,6 +10,8 @@ ruoyi:
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
   profile: D:/padaaphm/uploadPath
+  # 结果文件路径
+  resultPath: D:/padaaphm/resultPath
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数字计算 char 字符验证

+ 15 - 0
pdaaphm-admin/src/main/resources/mapper/algoManager/AlgorithmMapper.xml

@@ -103,4 +103,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getOption" resultType="Map">
         select id, `type`, `name` from t_algorithm_sub_type
     </select>
+
+    <select id="selectUrlAndAddressById" parameterType="Long" resultType="Map">
+        SELECT
+            tast.url,
+            tf.path,
+            taf.type
+        FROM
+            t_algorithm ta
+                LEFT JOIN t_sub_algorithm tsa ON tsa.algorithm_id = ta.id
+                LEFT JOIN t_algorithm_io_field taf ON taf.id = tsa.field_id
+                LEFT JOIN t_algorithm_sub_type tast ON tast.id = taf.algorithm_sub_id
+                LEFT JOIN t_file tf ON tf.id = tsa.upload_id
+        WHERE
+            ta.id = #{id}
+    </select>
 </mapper>

+ 12 - 0
pdaaphm-admin/src/main/resources/mapper/algoManager/FileMapper.xml

@@ -87,4 +87,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getOption" resultType="Map">
         select id, `name`, `type` from t_file
     </select>
+
+    <select id="selectOutputFile" resultType="Long">
+        SELECT
+            tf.id
+        FROM
+            t_algorithm ta
+                JOIN t_sub_algorithm tsa ON tsa.algorithm_id = ta.id
+                JOIN t_file tf ON tf.id = tsa.upload_id
+        WHERE
+            ta.id = #{id}
+          AND tf.type = 2
+    </select>
 </mapper>

+ 24 - 6
pdaaphm-admin/src/main/resources/mapper/algoManager/SubAlgorithmMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.pdaaphm.biz.mapper.SubAlgorithmMapper">
-    
+
     <resultMap type="SubAlgorithm" id="SubAlgorithmResult">
         <result property="id"    column="id"    />
         <result property="algorithmId"    column="algorithm_id"    />
@@ -22,18 +22,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectSubAlgorithmList" parameterType="SubAlgorithm" resultMap="SubAlgorithmResult">
         <include refid="selectSubAlgorithmVo"/>
-        <where>  
+        <where>
             <if test="algorithmId != null "> and algorithm_id = #{algorithmId}</if>
             <if test="fieldId != null "> and field_id = #{fieldId}</if>
             <if test="uploadId != null "> and upload_id = #{uploadId}</if>
         </where>
     </select>
-    
+
     <select id="selectSubAlgorithmById" parameterType="Long" resultMap="SubAlgorithmResult">
         <include refid="selectSubAlgorithmVo"/>
         where id = #{id}
     </select>
-        
+
     <insert id="insertSubAlgorithm" parameterType="SubAlgorithm" useGeneratedKeys="true" keyProperty="id">
         insert into t_sub_algorithm
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -78,9 +78,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteSubAlgorithmByIds" parameterType="String">
-        delete from t_sub_algorithm where id in 
+        delete from t_sub_algorithm where id in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
-</mapper>
+
+    <select id="selectSubAlgorithmOutputList" parameterType="Long" resultType="Map">
+        SELECT
+            tsa.id,
+            tsa.algorithm_id,
+            tsa.field_id
+        FROM
+            t_algorithm ta
+                JOIN t_algorithm_sub_type tast ON tast.id = ta.sub_type_id
+                JOIN t_algorithm_io_field taif ON taif.algorithm_sub_id = tast.id
+                JOIN t_sub_algorithm tsa ON tsa.field_id = taif.id
+                AND tsa.algorithm_id = ta.id
+        WHERE
+            taif.type = 2
+          AND ta.id = #{id}
+        ORDER BY
+            taif.`index`
+    </select>
+</mapper>

+ 19 - 1
pdaaphm-common/src/main/java/com/pdaaphm/common/config/PadaphmConfig.java

@@ -5,7 +5,7 @@ import org.springframework.stereotype.Component;
 
 /**
  * 读取项目相关配置
- * 
+ *
  * @author Allen
  */
 @Component
@@ -27,6 +27,9 @@ public class PadaphmConfig
     /** 上传路径 */
     private static String profile;
 
+    /** 结果文件路径 */
+    private static String resultPath;
+
     /** 获取地址开关 */
     private static boolean addressEnabled;
 
@@ -83,6 +86,16 @@ public class PadaphmConfig
         PadaphmConfig.profile = profile;
     }
 
+    public static String getResultPath()
+    {
+        return resultPath;
+    }
+
+    public void setResultPath(String resultPath)
+    {
+        PadaphmConfig.resultPath = resultPath;
+    }
+
     public static boolean isAddressEnabled()
     {
         return addressEnabled;
@@ -132,4 +145,9 @@ public class PadaphmConfig
     {
         return getProfile() + "/upload";
     }
+
+    public static String getResultFilePath()
+    {
+        return getResultPath() + "/result";
+    }
 }

+ 29 - 1
pdaaphm-common/src/main/java/com/pdaaphm/common/utils/file/FileUploadUtils.java

@@ -86,6 +86,18 @@ public class FileUploadUtils
         }
     }
 
+    public static final String upload(String baseDir, String fileName) throws IOException
+    {
+        try
+        {
+            return upload(baseDir, fileName, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
+        }
+        catch (Exception e)
+        {
+            throw new IOException(e.getMessage(), e);
+        }
+    }
+
     /**
      * 文件上传
      *
@@ -108,7 +120,7 @@ public class FileUploadUtils
             throw new FileNameLengthLimitExceededException(FileUploadUtils.DEFAULT_FILE_NAME_LENGTH);
         }
 
-        assertAllowed(file, allowedExtension);
+//        assertAllowed(file, allowedExtension);
 
         String fileName = extractFilename(file);
 
@@ -117,6 +129,16 @@ public class FileUploadUtils
         return getPathFileName(baseDir, fileName);
     }
 
+    public static final String upload(String baseDir, String fileName, String[] allowedExtension)
+            throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException,
+            InvalidExtensionException
+    {
+        String fileNameTimed = extractFilename(fileName);
+
+        String absPath = getAbsoluteFile(baseDir, fileNameTimed).getAbsolutePath();
+        return getPathFileName(baseDir, fileNameTimed);
+    }
+
     /**
      * 编码文件名
      */
@@ -126,6 +148,12 @@ public class FileUploadUtils
                 FilenameUtils.getBaseName(file.getOriginalFilename()), Seq.getId(Seq.uploadSeqType), getExtension(file));
     }
 
+    public static final String extractFilename(String fileName)
+    {
+        return StringUtils.format("{}/{}_{}", DateUtils.datePath(),
+                fileName, Seq.getId(Seq.uploadSeqType));
+    }
+
     public static final File getAbsoluteFile(String uploadDir, String fileName) throws IOException
     {
         File desc = new File(uploadDir + File.separator + fileName);

+ 11 - 11
pdaaphm-system/src/main/java/com/pdaaphm/system/service/impl/SysConfigServiceImpl.java

@@ -19,11 +19,11 @@ import com.pdaaphm.system.service.ISysConfigService;
 
 /**
  * 参数配置 服务层实现
- * 
+ *
  * @author Allen
  */
 @Service
-public class SysConfigServiceImpl implements ISysConfigService
+public class  SysConfigServiceImpl implements ISysConfigService
 {
     @Autowired
     private SysConfigMapper configMapper;
@@ -42,7 +42,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 查询参数配置信息
-     * 
+     *
      * @param configId 参数配置ID
      * @return 参数配置信息
      */
@@ -57,7 +57,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 根据键名查询参数配置信息
-     * 
+     *
      * @param configKey 参数key
      * @return 参数键值
      */
@@ -82,7 +82,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 获取验证码开关
-     * 
+     *
      * @return true开启,false关闭
      */
     @Override
@@ -98,7 +98,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 查询参数配置列表
-     * 
+     *
      * @param config 参数配置信息
      * @return 参数配置集合
      */
@@ -110,7 +110,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 新增参数配置
-     * 
+     *
      * @param config 参数配置信息
      * @return 结果
      */
@@ -127,7 +127,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 修改参数配置
-     * 
+     *
      * @param config 参数配置信息
      * @return 结果
      */
@@ -150,7 +150,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 批量删除参数信息
-     * 
+     *
      * @param configIds 需要删除的参数ID
      */
     @Override
@@ -203,7 +203,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 校验参数键名是否唯一
-     * 
+     *
      * @param config 参数配置信息
      * @return 结果
      */
@@ -221,7 +221,7 @@ public class SysConfigServiceImpl implements ISysConfigService
 
     /**
      * 设置cache key
-     * 
+     *
      * @param configKey 参数键
      * @return 缓存键key
      */

+ 0 - 1
pdaaphm-ui/src/components/FileUpload/index.vue

@@ -60,7 +60,6 @@ export default {
     // 文件类型, 例如['png', 'jpg', 'jpeg']
     fileType: {
       type: Array,
-      default: () => ["docx", "xls", "ppt", "txt", "pdf"],
     },
     // 是否显示提示
     isShowTip: {

+ 2 - 1
pdaaphm-ui/src/views/algoManager/algorithm/index.vue

@@ -413,8 +413,9 @@ export default {
       }, `algorithm_${new Date().getTime()}.xlsx`)
     },
     /** 运行算法按钮操作 */
-    handleRun() {
+    handleRun(row) {
       const id = row.id || this.ids
+      // debugger
       runAlgorithms(id).then(response => {
         this.$modal.msgSuccess("成功");
         this.getList();

+ 3 - 0
pdaaphm-ui/src/views/conf/subType/index.vue

@@ -138,6 +138,9 @@
         <el-form-item label="算法url" prop="url">
           <el-input v-model="form.url" placeholder="请输入算法url" />
         </el-form-item>
+        <el-form-item label="算法运行类型" prop="runType">
+          <el-input v-model="form.runType" placeholder="请输入算法运行类型" />
+        </el-form-item>
         <el-form-item label="备注" prop="remark">
           <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
         </el-form-item>

+ 2 - 1
sql/pdaaphm.sql

@@ -716,6 +716,7 @@ CREATE TABLE t_algorithm_sub_type (
 	type VARCHAR ( 10 ) DEFAULT '' COMMENT '类型',
 	`name` VARCHAR ( 200 ) DEFAULT '' COMMENT '算法子名称',
 	url VARCHAR ( 255 ) DEFAULT '' COMMENT '算法url',
+	run_type VARCHAR ( 255 ) DEFAULT '' COMMENT '运行类型',
 	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
 	create_time datetime COMMENT '创建时间',
 	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
@@ -767,7 +768,7 @@ CREATE TABLE t_sub_algorithm (
 	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '编号',
 	algorithm_id BIGINT ( 20 ) NOT NULL COMMENT '主表id',
 	field_id BIGINT ( 20 ) NOT NULL COMMENT '字段id',
-	upload_id BIGINT ( 20 ) NOT NULL COMMENT '文件id',
+	upload_id BIGINT ( 20 ) COMMENT '文件id',
 	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
 	create_time datetime COMMENT '创建时间',
 	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',