新增计算模块接口

This commit is contained in:
谷成伟 2024-11-07 14:11:58 +08:00
parent d523c33576
commit bd25f3bbbf
3 changed files with 38 additions and 15 deletions

View File

@ -50,6 +50,9 @@ public class CalcController {
@PostMapping("/module/register")
public R<?> registerCalcModule(MultipartFile file) throws IOException {
try {
if (file.isEmpty()){
throw new IOException("无效的计算模块脚本文件");
}
String content = new String(file.getBytes(), StandardCharsets.UTF_8);
calcService.registerCalcModule(content);
}
@ -63,7 +66,7 @@ public class CalcController {
/**
* 移除计算模块
* @param params 请求参数
* @param params moduleName 模块名称
* @return
* @throws IOException
*/
@ -86,7 +89,7 @@ public class CalcController {
/**
* 激活计算模块
* @param moduleName
* @param params moduleName 模块名称
* @return
* @throws IOException
*/
@ -122,4 +125,24 @@ public class CalcController {
}
/**
* 获取计算模块脚本内容
* @param params moduleName 模块名称
* @return
*/
@PostMapping("/module/script")
public R<String> getScriptContent(@RequestBody Map<String,Object> params){
try {
String moduleName = (String) params.get("moduleName");
if (moduleName == null){
return R.fail("参数错误");
}
return R.data(calcService.getScriptContent(moduleName));
} catch (Exception e) {
log.error("获取计算模块脚本内容失败", e);
return R.fail(String.format("获取计算模块脚本内容失败, %s",e.getMessage()));
}
}
}

View File

@ -213,4 +213,12 @@ public class CalcService {
stopCalcJob(moduleName);
}
}
public String getScriptContent(String moduleName) throws IOException {
CalcModule calcModule = calcModuleMapper.selectById(moduleName);
if (calcModule != null) {
return calcModule.getScript();
}
throw new IOException("无效的模块名");
}
}

View File

@ -79,7 +79,7 @@ POST 请求接口, form-data方式
}
```
### 1.1.3 修改节点信息
### 1.1.3 卸载计算模块
POST 请求接口
@ -95,21 +95,13 @@ POST 请求接口
```json
{
"code": 200,
"success": true,
"data": {
"id": "73535240297775104",
"nodeName": "测试节点1",
"nodeIp": "127.0.0.3",
"orgName": "某风电场",
"orgId": "1",
"revision": 3
},
"msg": "操作成功"
"code": 200,
"success": true,
"msg": "删除成功"
}
```
### 1.1.4 删除节点信息
### 1.1.4 激活计算模块
POST 请求接口