From 2bc0da0c44fe74b6a03e7ca530ae8037aa282efd Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Wed, 20 Mar 2024 18:05:45 +0800 Subject: [PATCH] =?UTF-8?q?dcDevice=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=BD=93=E5=A4=A9=E8=AE=BE=E5=A4=87=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=B1=9E=E6=80=A7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index d98c053a..d0b0f0c3 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -1,5 +1,6 @@ package com.zc.business.controller; +import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -207,6 +208,47 @@ public class DcDeviceController extends BaseController { return JSON.parseObject(response.body().string(), AjaxResult.class); } + /** + * 查询当天设备指定属性列表 + * @param deviceId 设备id + * @param propertyId 属性id + * @return 属性列表 + */ + @ApiOperation("查询当天设备指定属性列表") + @GetMapping("/properties/history/day/{deviceId}/{propertyId}") + public AjaxResult queryDevicePropertiesOneDay(@PathVariable @Parameter(description = "设备ID") String deviceId, + @PathVariable @Parameter(description = "属性ID") String propertyId) throws HttpException, IOException { + + HashMap props = new HashMap<>(); + // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 + props.put("terms[0].column", "timestamp$BTW"); + ArrayList dateList = new ArrayList<>(); + // 添加当前日期的开始和结束时间到列表,用于设定时间范围 + dateList.add(DateUtil.beginOfDay(new Date()).toString()); + dateList.add(DateUtil.endOfDay(new Date()).toString()); + // 将日期列表以逗号分隔并设置为查询条件的值 + props.put("terms[0].value", String.join(",", dateList)); + props.put("paging", false); + AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props); + if (!ajaxResult.get("code").equals(200)) { + return ajaxResult; + } + + Object data = JSON.parseObject(queryDeviceProperties(deviceId, propertyId, props).get("data").toString()).get("data"); + JSONArray dataArray = JSON.parseArray(data.toString()); + List list = new ArrayList<>(); + dataArray.forEach(o -> { + Map map = new HashMap<>(); + JSONObject jsonObject = JSON.parseObject(o.toString()); + JSONObject formatValue = JSON.parseObject(jsonObject.get("formatValue").toString()); + map.put("1",formatValue.get("1")); + map.put("3",formatValue.get("3")); + map.put("timestamp",jsonObject.get("timestamp")); + list.add(map); + }); + return AjaxResult.success(list); + } + /** * 查询设备指定属性列表 *