Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package com.solution.web.controller.algo;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -37,6 +43,51 @@ public class AlgorithmController extends BaseController {
|
||||
@Autowired
|
||||
private IAlgorithmService algorithmService;
|
||||
|
||||
/**
|
||||
* 导出规则列表
|
||||
*/
|
||||
@ApiOperation("运行python程序")
|
||||
@PostMapping("/run")
|
||||
public Object run(@RequestBody Algorithm algorithm) {
|
||||
List<Algorithm> list = algorithmService.selectAlgorithmList(algorithm);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
for (Algorithm al : list) {
|
||||
String codePath = al.getCodePath();
|
||||
|
||||
try {
|
||||
String jsonInput = objectMapper.writeValueAsString(al);
|
||||
String pythonExe = "E:\\Apps\\anaconda3\\python.exe";
|
||||
ProcessBuilder pb = new ProcessBuilder(pythonExe, codePath);
|
||||
Process process = pb.start();
|
||||
|
||||
try (OutputStream os = process.getOutputStream()) {
|
||||
os.write(jsonInput.getBytes(StandardCharsets.UTF_8));
|
||||
os.flush();
|
||||
}
|
||||
|
||||
String result;
|
||||
// 修改你 Java 代码中的这一段
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
result = reader.lines().collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode != 0) {
|
||||
return "Python执行失败,错误码:" + exitCode;
|
||||
}
|
||||
|
||||
return objectMapper.readTree(result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "执行异常: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
return "未找到算法";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询规则列表
|
||||
*/
|
||||
@@ -56,7 +107,7 @@ public class AlgorithmController extends BaseController {
|
||||
@PreAuthorize("@ss.hasPermi('algo:algorithm:export')")
|
||||
@Log(title = "规则", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Algorithm algorithm) {
|
||||
public void export(HttpServletResponse response, @RequestBody Algorithm algorithm) {
|
||||
List<Algorithm> list = algorithmService.selectAlgorithmList(algorithm);
|
||||
ExcelUtil<Algorithm> util = new ExcelUtil<Algorithm>(Algorithm.class);
|
||||
util.exportExcel(response, list, "规则数据");
|
||||
|
||||
@@ -34,6 +34,10 @@ public class Algorithm
|
||||
@Excel(name = "算法描述")
|
||||
private String description;
|
||||
|
||||
/** 算法配置 */
|
||||
@Excel(name = "算法配置")
|
||||
private String algoConfig;
|
||||
|
||||
/** 算法参数定义信息 */
|
||||
private List<AlgorithmParam> algorithmParamList;
|
||||
|
||||
@@ -87,6 +91,16 @@ public class Algorithm
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setAlgoConfig(String algoConfig)
|
||||
{
|
||||
this.algoConfig = algoConfig;
|
||||
}
|
||||
|
||||
public String getAlgoConfig()
|
||||
{
|
||||
return algoConfig;
|
||||
}
|
||||
|
||||
public List<AlgorithmParam> getAlgorithmParamList()
|
||||
{
|
||||
return algorithmParamList;
|
||||
@@ -105,6 +119,7 @@ public class Algorithm
|
||||
.append("type", getType())
|
||||
.append("codePath", getCodePath())
|
||||
.append("description", getDescription())
|
||||
.append("algoConfig", getAlgoConfig())
|
||||
.append("algorithmParamList", getAlgorithmParamList())
|
||||
.toString();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="type" column="type" />
|
||||
<result property="codePath" column="code_path" />
|
||||
<result property="description" column="description" />
|
||||
<result property="algoConfig" column="algo_config" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="AlgorithmAlgorithmParamResult" type="Algorithm" extends="AlgorithmResult">
|
||||
@@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAlgorithmVo">
|
||||
select id, name, type, code_path, description from algorithm
|
||||
select id, name, type, code_path, description, algo_config from algorithm
|
||||
</sql>
|
||||
|
||||
<select id="selectAlgorithmList" parameterType="Algorithm" resultMap="AlgorithmAlgorithmParamResult">
|
||||
@@ -35,11 +36,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||
<if test="codePath != null and codePath != ''"> and code_path = #{codePath}</if>
|
||||
<if test="description != null and description != ''"> and description = #{description}</if>
|
||||
<if test="algoConfig != null and algoConfig != ''"> and algo_config = #{algoConfig}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectAlgorithmById" parameterType="Long" resultMap="AlgorithmAlgorithmParamResult">
|
||||
select id, name, type, code_path, description
|
||||
select id, name, type, code_path, description, algo_config
|
||||
from algorithm
|
||||
where id = #{id}
|
||||
</select>
|
||||
@@ -57,12 +59,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="type != null and type != ''">type,</if>
|
||||
<if test="codePath != null">code_path,</if>
|
||||
<if test="description != null">description,</if>
|
||||
<if test="algoConfig != null">algo_config,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="name != null and name != ''">#{name},</if>
|
||||
<if test="type != null and type != ''">#{type},</if>
|
||||
<if test="codePath != null">#{codePath},</if>
|
||||
<if test="description != null">#{description},</if>
|
||||
<if test="algoConfig != null">#{algoConfig},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
@@ -73,6 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="type != null and type != ''">type = #{type},</if>
|
||||
<if test="codePath != null">code_path = #{codePath},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="algoConfig != null">algo_config = #{algoConfig},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
Reference in New Issue
Block a user