|
|
@ -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<String, Object> 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<String, Object> props = new HashMap<>(); |
|
|
|
// 设置查询条件的键为“timestamp$BTW”,表示时间戳在一定范围内
|
|
|
|
props.put("terms[0].column", "timestamp$BTW"); |
|
|
|
ArrayList<String> 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<JSONObject> jsonObjectList = dataVale.toJavaList(JSONObject.class); |
|
|
|
// 定义一个时间格式转换的工具
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); |
|
|
|
// 使用Stream API提取每个JSONObject中的timestamp和propertyName值
|
|
|
|
List<Map<String, String>> 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<String, String> 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<JSONObject> jsonObjectList = dataValue.toJavaList(JSONObject.class); |
|
|
|
// 定义一个时间格式转换的工具
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); |
|
|
|
List<HashMap<String, String>> 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<String, String> 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; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|