修复: 全局参数和设备参数保存接口添加 JSON 格式验证
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.aiot.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiAlgorithm;
|
||||
import com.genersoft.iot.vmp.aiot.bean.AiRoiAlgoBind;
|
||||
import com.genersoft.iot.vmp.aiot.service.IAiAlgorithmService;
|
||||
@@ -65,6 +66,14 @@ public class AiAlgorithmController {
|
||||
@PostMapping("/global-params/{algoCode}")
|
||||
public void saveGlobalParams(@PathVariable String algoCode, @RequestBody Map<String, String> body) {
|
||||
String globalParams = body.get("globalParams");
|
||||
if (globalParams == null || globalParams.isBlank()) {
|
||||
throw new IllegalArgumentException("参数不能为空");
|
||||
}
|
||||
try {
|
||||
JSON.parseObject(globalParams);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("参数不是合法的 JSON: " + e.getMessage());
|
||||
}
|
||||
algorithmService.saveGlobalParams(algoCode, globalParams);
|
||||
}
|
||||
|
||||
@@ -80,6 +89,14 @@ public class AiAlgorithmController {
|
||||
@PathVariable String algoCode,
|
||||
@RequestBody Map<String, String> body) {
|
||||
String params = body.get("params");
|
||||
if (params == null || params.isBlank()) {
|
||||
throw new IllegalArgumentException("参数不能为空");
|
||||
}
|
||||
try {
|
||||
JSON.parseObject(params);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("参数不是合法的 JSON: " + e.getMessage());
|
||||
}
|
||||
algorithmService.updateDeviceAlgoParams(deviceId, algoCode, params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user