Browse Source

算法管理

twzydn20000928 1 năm trước cách đây
mục cha
commit
986790050a

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

@@ -125,4 +125,15 @@ public class AlgorithmController extends BaseController
 
     @GetMapping("/getOption")
     public AjaxResult getOption() { return success(algorithmService.getOption()); }
+
+    /**
+     * 运行算法
+     */
+    @PreAuthorize("@ss.hasPermi('algoManager:algorithm:edit')")
+    @Log(title = "算法", businessType = BusinessType.UPDATE)
+    @GetMapping(value = "/runAlgorithms/{id}")
+    public AjaxResult runAlgorithms(@PathVariable("id") Long id)
+    {
+        return success(algorithmService.runAlgorithms(id));
+    }
 }

+ 23 - 9
pdaaphm-admin/src/main/java/com/pdaaphm/biz/domain/AlgorithmSubType.java

@@ -7,7 +7,7 @@ import com.pdaaphm.common.core.domain.BaseEntity;
 
 /**
  * 算法子类型对象 t_algorithm_sub_type
- * 
+ *
  * @author allen
  * @date 2023-07-26
  */
@@ -30,42 +30,55 @@ public class AlgorithmSubType extends BaseEntity
     @Excel(name = "算法url")
     private String url;
 
-    public void setId(Long id) 
+    /** 运行类型 */
+    @Excel(name = "运行类型")
+    private String runType;
+
+    public void setId(Long id)
     {
         this.id = id;
     }
 
-    public Long getId() 
+    public Long getId()
     {
         return id;
     }
-    public void setType(String type) 
+    public void setType(String type)
     {
         this.type = type;
     }
 
-    public String getType() 
+    public String getType()
     {
         return type;
     }
-    public void setName(String name) 
+    public void setName(String name)
     {
         this.name = name;
     }
 
-    public String getName() 
+    public String getName()
     {
         return name;
     }
-    public void setUrl(String url) 
+    public void setUrl(String url)
     {
         this.url = url;
     }
 
-    public String getUrl() 
+    public String getUrl()
     {
         return url;
     }
+    public void setRunType(String runType)
+    {
+        this.runType = runType;
+    }
+
+    public String getRunType()
+    {
+        return runType;
+    }
 
     @Override
     public String toString() {
@@ -74,6 +87,7 @@ public class AlgorithmSubType extends BaseEntity
             .append("type", getType())
             .append("name", getName())
             .append("url", getUrl())
+            .append("runType", getRunType())
             .append("createBy", getCreateBy())
             .append("createTime", getCreateTime())
             .append("updateBy", getUpdateBy())

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

@@ -0,0 +1,25 @@
+package com.pdaaphm.biz.factory;
+
+import com.pdaaphm.biz.service.RunAlgorithmService;
+import com.pdaaphm.biz.service.impl.RunMatlabImpl;
+import com.pdaaphm.biz.service.impl.RunPythonImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AlgorithmFactory {
+    @Autowired
+    private RunMatlabImpl runMatlabImpl;
+    @Autowired
+    private RunPythonImpl runPythonImpl;
+
+    public RunAlgorithmService createRun(String type) {
+        if (type.equals("python")) {
+            return runPythonImpl;
+        } else if (type.equals("cat")) {
+            return runMatlabImpl;
+        } else {
+            return null;
+        }
+    }
+}

+ 3 - 1
pdaaphm-admin/src/main/java/com/pdaaphm/biz/mapper/AlgorithmMapper.java

@@ -62,5 +62,7 @@ public interface AlgorithmMapper
      */
     public int deleteAlgorithmByIds(Long[] ids);
 
-    List<Map> getOption();
+    public List<Map> getOption();
+
+    public int runAlgorithm(Long id);
 }

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

@@ -79,4 +79,6 @@ public interface IAlgorithmService
      * @return 算法
      */
     public AlgorithmDTO getAlgorithmDto(Long id);
+
+    public int runAlgorithms(Long id);
 }

+ 5 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/RunAlgorithmService.java

@@ -0,0 +1,5 @@
+package com.pdaaphm.biz.service;
+
+public interface RunAlgorithmService {
+    public void runAlgorithm(Long id);
+}

+ 17 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/AlgorithmServiceImpl.java

@@ -6,8 +6,10 @@ import java.util.Map;
 import com.pdaaphm.biz.domain.SubAlgorithm;
 import com.pdaaphm.biz.dto.AlgorithmDTO;
 import com.pdaaphm.biz.dto.SubAlgorithmDTO;
+import com.pdaaphm.biz.factory.AlgorithmFactory;
 import com.pdaaphm.biz.mapper.AlgorithmIoFieldMapper;
 import com.pdaaphm.biz.mapper.SubAlgorithmMapper;
+import com.pdaaphm.biz.service.RunAlgorithmService;
 import com.pdaaphm.common.utils.DateUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +33,8 @@ public class AlgorithmServiceImpl implements IAlgorithmService
     private SubAlgorithmMapper subAlgorithmMapper;
     @Autowired
     private AlgorithmIoFieldMapper algorithmIoFieldMapper;
+    @Autowired
+    private AlgorithmFactory algorithmFactory;
 
     /**
      * 查询算法
@@ -152,4 +156,17 @@ public class AlgorithmServiceImpl implements IAlgorithmService
 
     @Override
     public List<Map> getOption() { return algorithmMapper.getOption(); }
+
+    @Override
+    public int runAlgorithms(Long id) {
+        int res = 0;
+        //1. update Algorithm.startTime to now
+        //2. run algorithmImpl
+        Algorithm algorithm = this.selectAlgorithmById(id);
+        RunAlgorithmService runAlgorithmService = algorithmFactory.createRun(algorithm);
+        runAlgorithmService.runAlgorithm(id);
+        //3. update Algorithm.completedTime and Algorithm.costSecond
+        //4. res = 1;
+        return res;
+    }
 }

+ 12 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunMatlabImpl.java

@@ -0,0 +1,12 @@
+package com.pdaaphm.biz.service.impl;
+
+import com.pdaaphm.biz.service.RunAlgorithmService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class RunMatlabImpl implements RunAlgorithmService {
+    @Override
+    public void runAlgorithm(Long id) {
+        System.out.println("runMatlab!");
+    }
+}

+ 12 - 0
pdaaphm-admin/src/main/java/com/pdaaphm/biz/service/impl/RunPythonImpl.java

@@ -0,0 +1,12 @@
+package com.pdaaphm.biz.service.impl;
+
+import com.pdaaphm.biz.service.RunAlgorithmService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class RunPythonImpl implements RunAlgorithmService {
+    @Override
+    public void runAlgorithm(Long id) {
+        System.out.println("runPython!");
+    }
+}

+ 7 - 2
pdaaphm-admin/src/main/resources/mapper/conf/AlgorithmSubTypeMapper.xml

@@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="type"    column="type"    />
         <result property="name"    column="name"    />
         <result property="url"    column="url"    />
+        <result property="runType"    column="run_type"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
         <result property="updateBy"    column="update_by"    />
@@ -17,7 +18,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectAlgorithmSubTypeVo">
-        select id, `type`, `name`, url, create_by, create_time, update_by, update_time, remark from t_algorithm_sub_type
+        select id, `type`, `name`, url, run_type, create_by, create_time, update_by, update_time, remark from t_algorithm_sub_type
     </sql>
 
     <select id="selectAlgorithmSubTypeList" parameterType="AlgorithmSubType" resultMap="AlgorithmSubTypeResult">
@@ -26,6 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="type != null  and type != ''"> and `type` = #{type}</if>
             <if test="name != null  and name != ''"> and `name` like concat('%', #{name}, '%')</if>
             <if test="url != null  and url != ''"> and url = #{url}</if>
+            <if test="runType != null  and runType != ''"> and run_type = #{runType}</if>
         </where>
     </select>
 
@@ -40,6 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="type != null">`type`,</if>
             <if test="name != null">`name`,</if>
             <if test="url != null">url,</if>
+            <if test="runType != null">run_type,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>
@@ -50,6 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="type != null">#{type},</if>
             <if test="name != null">#{name},</if>
             <if test="url != null">#{url},</if>
+            <if test="runType != null">#{runType},</if>
             <if test="createBy != null">#{createBy},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="updateBy != null">#{updateBy},</if>
@@ -61,9 +65,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <update id="updateAlgorithmSubType" parameterType="AlgorithmSubType">
         update t_algorithm_sub_type
         <trim prefix="SET" suffixOverrides=",">
-            <if test="type != null">type = #{type},</if>
+            <if test="type != null">`type` = #{type},</if>
             <if test="name != null">`name` = #{name},</if>
             <if test="url != null">url = #{url},</if>
+            <if test="runType != null">run_type = #{runType},</if>
             <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>

+ 2 - 2
pdaaphm-ui/src/api/algoManager/algorithm.js

@@ -69,9 +69,9 @@ export function addOrUpdateDto(data) {
 }
 
 // 运行算法
-export function runAlgorithm(id) {
+export function runAlgorithms(id) {
   return request({
-    url: '/algoManager/algorithm/addOrUpdateDto/' + id,
+    url: '/algoManager/algorithm/runAlgorithms/' + id,
     method: 'get'
   })
 }

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

@@ -237,7 +237,7 @@
 </template>
 
 <script>
-import { listAlgorithm, getAlgorithmDto, delAlgorithm, addOrUpdateDto, runAlgorithm } from "@/api/algoManager/algorithm";
+import { listAlgorithm, getAlgorithmDto, delAlgorithm, addOrUpdateDto, runAlgorithms } from "@/api/algoManager/algorithm";
 import { getAlgoSubOption } from "@/api/algoManager/algorithm";
 import { getIoSubList } from "@/api/conf/field";
 import { getFileList } from "@/api/algoManager/file";
@@ -415,7 +415,7 @@ export default {
     /** 运行算法按钮操作 */
     handleRun() {
       const id = row.id || this.ids
-      runAlgorithm(id).then(response => {
+      runAlgorithms(id).then(response => {
         this.$modal.msgSuccess("成功");
         this.getList();
       });

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

@@ -89,6 +89,7 @@
       </el-table-column>
       <el-table-column label="算法子名称" align="center" prop="name" />
       <el-table-column label="算法url" align="center" prop="url" />
+      <el-table-column label="运行类型" align="center" prop="runType" />
       <el-table-column label="备注" align="center" prop="remark" />
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
@@ -182,6 +183,7 @@ export default {
         type: null,
         name: null,
         url: null,
+        runType: null,
       },
       // 表单参数
       form: {},
@@ -215,6 +217,7 @@ export default {
         type: null,
         name: null,
         url: null,
+        runType: null,
         createBy: null,
         createTime: null,
         updateBy: null,