bug: ticket#16, frontend send mistaken datas. extract correct ip address and now fixed.
This commit is contained in:
parent
8b44975cb1
commit
b724a835e5
@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* 雷达控制链路
|
||||
@ -18,6 +20,8 @@ public class SarControlController {
|
||||
@Autowired
|
||||
private ISarControlService controlInfoService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
/**
|
||||
* 发送控制指令
|
||||
* @param param
|
||||
@ -37,7 +41,26 @@ public class SarControlController {
|
||||
*/
|
||||
@RequestMapping("/turnon")
|
||||
public Result turnOn(@RequestBody String ip) {
|
||||
controlInfoService.turnOn(ip);
|
||||
String ipVal = "";
|
||||
try {
|
||||
// 1. 使用 ObjectMapper 将 JSON 字符串解析成一个 JsonNode 树
|
||||
JsonNode rootNode = objectMapper.readTree(ip);
|
||||
|
||||
// 2. 从树中获取 "payloadId" 节点,并将其值转换为文本
|
||||
ipVal = rootNode.path("payloadId").asText();
|
||||
|
||||
// 检查是否成功获取
|
||||
if (ipVal == null || ipVal.isEmpty()) {
|
||||
// 根据你的业务逻辑返回错误,例如
|
||||
return Result.error("请求体中缺少 'payloadId' 或其值为空");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理JSON解析异常
|
||||
// 记录日志 e.g., log.error("Failed to parse turnOn payload", e);
|
||||
return Result.error("请求体JSON格式错误");
|
||||
}
|
||||
// 3. 调用服务层
|
||||
controlInfoService.turnOn(ipVal);
|
||||
return Result.successData("发送成功");
|
||||
}
|
||||
|
||||
@ -48,7 +71,27 @@ public class SarControlController {
|
||||
*/
|
||||
@RequestMapping("/endall")
|
||||
public Result endAll(@RequestBody String ip) {
|
||||
controlInfoService.endAll(ip);
|
||||
String ipVal = "";
|
||||
try {
|
||||
// 1. 使用 ObjectMapper 将 JSON 字符串解析成一个 JsonNode 树
|
||||
JsonNode rootNode = objectMapper.readTree(ip);
|
||||
|
||||
// 2. 从树中获取 "payloadId" 节点,并将其值转换为文本
|
||||
ipVal = rootNode.path("payloadId").asText();
|
||||
|
||||
// 检查是否成功获取
|
||||
if (ipVal == null || ipVal.isEmpty()) {
|
||||
// 根据你的业务逻辑返回错误,例如
|
||||
return Result.error("请求体中缺少 'payloadId' 或其值为空");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 处理JSON解析异常
|
||||
// 记录日志 e.g., log.error("Failed to parse turnOn payload", e);
|
||||
return Result.error("请求体JSON格式错误");
|
||||
}
|
||||
// 3. 调用服务层
|
||||
controlInfoService.endAll(ipVal);
|
||||
return Result.successData("发送成功");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user