fix (farm): 土壤传感器
- 历史数据格式重构
This commit is contained in:
@@ -19,6 +19,15 @@ public class HistoryDataListPageRespVO {
|
||||
private String code;
|
||||
private String message;
|
||||
private HistoryDataList data;
|
||||
private List<HistoryDataListPlus> list;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public static class HistoryDataListPlus{
|
||||
private Integer nodeId;
|
||||
private List<Row> rows;
|
||||
}
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
||||
@@ -128,6 +128,8 @@ public class SoilService extends AbstractDeviceService {
|
||||
// 调用土壤设备厂商API获取历史数据 GET 请求方式
|
||||
HistoryDataListPageRespVO vendorResponse = callSoilHistoryDataApi(token, soilRequest);
|
||||
|
||||
// 格式转换
|
||||
vendorResponse = convertDataToList(vendorResponse);
|
||||
// TODO: 2025/9/26 模拟保存到MySQL
|
||||
// saveHistoryDataToDatabase(vendorResponse, soilRequest);
|
||||
|
||||
@@ -138,6 +140,20 @@ public class SoilService extends AbstractDeviceService {
|
||||
}
|
||||
}
|
||||
|
||||
public HistoryDataListPageRespVO convertDataToList(HistoryDataListPageRespVO source) {
|
||||
HistoryDataListPageRespVO.HistoryDataList data = source.getData();
|
||||
|
||||
// 按 nodeId 分组
|
||||
Map<Integer, List<HistoryDataListPageRespVO.Row>> groupedByNodeId = data.getRows().stream().collect(Collectors.groupingBy(HistoryDataListPageRespVO.Row::getNodeId));
|
||||
|
||||
// 转换为 HistoryDataListPlus 列表
|
||||
List<HistoryDataListPageRespVO.HistoryDataListPlus> list = groupedByNodeId.entrySet().stream()
|
||||
.map(entry -> new HistoryDataListPageRespVO.HistoryDataListPlus(entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new HistoryDataListPageRespVO(source.getCode(), source.getMessage(), null, list);
|
||||
}
|
||||
|
||||
private UserLoginRespVO callSoilVendorApi(UserLoginReqVO request) {
|
||||
try {
|
||||
String url = deviceConf.getFourSituations().getHosts() +
|
||||
|
||||
Reference in New Issue
Block a user