修复: 全局参数和设备参数保存接口添加 JSON 格式验证

This commit is contained in:
2026-04-13 15:48:42 +08:00
parent 3dbe38becd
commit fca2630998

View File

@@ -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);
}
}