From d54d4eec8eb9e03051f2d398f1ab6eea33235418 Mon Sep 17 00:00:00 2001 From: wangsixiang <2970484253@qq.com> Date: Wed, 22 May 2024 15:43:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=95=B0=E6=8D=AE=E5=88=86?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 119 ++++++++++++++++++ .../zc/business/mapper/DcDeviceMapper.java | 7 ++ .../zc/business/service/IDcDeviceService.java | 6 + .../service/impl/DcDeviceServiceImpl.java | 11 ++ .../mapper/business/DcDeviceMapper.xml | 14 +++ .../DcPerceivedEventsWarningMapper.xml | 2 +- 6 files changed, 158 insertions(+), 1 deletion(-) 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 d51047ce..6d03184b 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,16 +1,19 @@ package com.zc.business.controller; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; + import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.domain.DcDevice; @@ -25,6 +28,7 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.Parameter; import okhttp3.Response; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.StringUtils; @@ -34,6 +38,8 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -650,4 +656,117 @@ public class DcDeviceController extends BaseController { Map map = new ObjectMapper().convertValue(object, Map.class); return batchInvokedFunction(map); } + + /** + * 分页查询设备名称列表 + * @param dcDevice 请求参数 + * @return 分页查询结果 + */ + @GetMapping("/selectDeviceNameList") + public TableDataInfo selectDeviceNameList(DcDevice dcDevice) { + startPage(); + return getDataTable(dcDeviceService.selectDeviceNameList(dcDevice)); + } + @GetMapping("/deviceParameter") + public TableDataInfo selectDeviceParameterProperties(DcDevice dcDevice) { + if (dcDevice==null||dcDevice.getDeviceType()==null){ + TableDataInfo tableDataInfo = new TableDataInfo(); + tableDataInfo.setCode(500); + tableDataInfo.setMsg("参数错误"); + return tableDataInfo; + } + startPage(); + return getDataTable(dcDeviceService.selectDeviceParameterProperties(dcDevice)); + } + /** + * 查询设备指定属性属性列表 + * param参数 + * deviceId 设备id + * propertyId 属性id + * propertyName 属性名称 + * deviceType 设备类型 + * dateTime 时间 + * @return 属性列表 + */ + @PostMapping("/properties/deviceNameData") + public AjaxResult queryDevice(@RequestBody HashMap map) throws HttpException, IOException { + if (map==null||!map.containsKey("deviceId")||!map.containsKey("deviceType") + ||!map.containsKey("propertyName")||!map.containsKey("propertyId") + ||!map.containsKey("dateTime")){ + return AjaxResult.error("参数错误"); + } + String deviceType = map.get("deviceType").toString();//设备类型 + String deviceId = map.get("deviceId").toString();//设备id + String propertyId = map.get("propertyId").toString();//属性id + String propertyName = map.get("propertyName").toString();//属性名称 + HashMap props = new HashMap<>(); + // 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内 + props.put("terms[0].column", "timestamp$BTW"); + ArrayList dateList = new ArrayList<>(); + // 添加当前日期的开始和结束时间到列表,用于设定时间范围 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = dateFormat.parse((String) map.get("dateTime")); + dateList.add(DateUtil.beginOfDay(date).toString()); + dateList.add(DateUtil.endOfDay(date).toString()); + } catch (ParseException e) { + e.printStackTrace(); + } + // 将日期列表以逗号分隔并设置为查询条件的值 + props.put("terms[0].value", String.join(",", dateList)); + props.put("paging", false); + props.put("sorts[0].order", "asc"); + props.put("sorts[0].name", "timestamp"); + AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props); + String code = ajaxResult.get("code").toString(); + if ("500".equals(code)){ + return ajaxResult; + } + if ("13".equals(deviceType) || "16".equals(deviceType)) { //判断是否为设备箱/远端机 + JSONObject data = (JSONObject) ajaxResult.get("data"); + JSONArray dataVale = (JSONArray) data.get("data"); + List jsonObjectList = dataVale.toJavaList(JSONObject.class); + // 定义一个时间格式转换的工具 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + // 使用Stream API提取每个JSONObject中的timestamp和propertyName值 + List> results = jsonObjectList.stream() + .map(jsonObject -> { + long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型 + Date date = new Date(timestamp); // 将时间戳转换为Date对象 + String formattedTime = sdf.format(date); // 将Date对象格式化为字符串 + JSONObject formatValue = jsonObject.getJSONObject("formatValue"); // 获取嵌套的JSONObject + String result = formatValue.getString(propertyName); // 从嵌套的JSONObject中获取电压值 + Map hashMap = new HashMap<>(); + hashMap.put("timestamp", formattedTime); // 使用"timestamp"作为键来存储格式化后的时间 + hashMap.put("result", result); // 使用"voltage"作为键来存储电压值 + return hashMap; + }) + .collect(Collectors.toList()); + results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); + return AjaxResult.success(results); + } + if ("3".equals(deviceType)||"17".equals(deviceType)){ //气象预警/ups设备 + JSONObject data = (JSONObject) ajaxResult.get("data"); + JSONArray dataValue = (JSONArray) data.get("data"); + List jsonObjectList = dataValue.toJavaList(JSONObject.class); + // 定义一个时间格式转换的工具 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + List> results = jsonObjectList.stream() + .map(jsonObject -> { + long timestamp = jsonObject.getLongValue("timestamp"); // 假设timestamp是long类型 + Date date = new Date(timestamp); // 将时间戳转换为Date对象 + String formattedTime = sdf.format(date); // 将Date对象格式化为字符串 + String result = jsonObject.getString(propertyName); + HashMap hashMap = new HashMap<>(); + hashMap.put("timestamp", formattedTime); // 使用时间戳作为键可能不是最佳实践,但这里保持与原始逻辑一致 + hashMap.put("result", result); + return hashMap; + }) + .collect(Collectors.toList()); + results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); + return AjaxResult.success(results); + } + return null; + } + } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java index 86c480c9..64e50b2a 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java @@ -5,6 +5,7 @@ import com.zc.business.domain.DcDevice; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,4 +26,10 @@ public interface DcDeviceMapper extends BaseMapper { List selectNearBoard(@Param("direction") String direction,@Param("startMileage") Integer startMileage,@Param("endMileage") Integer endMileage); List> countTheNumberOfEligibleItems(); + + + //设备查询-设备名称列表 + public List> selectDeviceNameList(DcDevice dcDevice); + //设备查询-设备参数属性列表 + public List> selectDeviceParameterProperties(DcDevice dcDevice); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java index 342c1510..191970be 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java @@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcStakeMark; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -104,4 +105,9 @@ public interface IDcDeviceService extends IService { * 查询上游10公里内的情报板 */ AjaxResult selectNearBoard(String stakeMark, String direction); + + //设备查询-设备名称列表 + public List> selectDeviceNameList(DcDevice dcDevice); + //设备查询-设备参数属性列表 + public List> selectDeviceParameterProperties(DcDevice dcDevice); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index 81b00640..ebf7399c 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -533,5 +533,16 @@ public class DcDeviceServiceImpl extends ServiceImpl i } return AjaxResult.success(boardList); } + + //设备查询-设备名称列表 + @Override + public List> selectDeviceNameList(DcDevice dcDevice) { + return dcDeviceMapper.selectDeviceNameList(dcDevice); + } + //设备查询-设备参数属性列表 + @Override + public List> selectDeviceParameterProperties(DcDevice dcDevice) { + return dcDeviceMapper.selectDeviceParameterProperties(dcDevice); + } } diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index a98fa87e..cefa97fb 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -153,5 +153,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" GROUP BY dc_road_section.id; + + diff --git a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml index de518f99..b2a01e7c 100644 --- a/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcPerceivedEventsWarningMapper.xml @@ -543,4 +543,4 @@ - \ No newline at end of file +