|
|
@@ -0,0 +1,163 @@
|
|
|
+package com.sooka.sponest.monitor.device.controller;
|
|
|
+
|
|
|
+import com.dahuatech.hutool.core.bean.BeanUtil;
|
|
|
+import com.dahuatech.hutool.json.JSONObject;
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
+import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
|
|
+import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
+import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.web.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.log.annotation.Log;
|
|
|
+import com.ruoyi.common.log.enums.BusinessType;
|
|
|
+import com.ruoyi.common.security.annotation.RequiresPermissions;
|
|
|
+import com.sooka.sponest.monitor.device.domain.*;
|
|
|
+import com.sooka.sponest.monitor.device.service.ICentermonitorTMonitoringDeviceService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 温控设备Controller
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@RequestMapping("/temperatureControl")
|
|
|
+public class CentermonitorTTemperatureControlDeviceController extends BaseController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ICentermonitorTMonitoringDeviceService centermonitorTMonitoringDeviceService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接收温控设备信息
|
|
|
+ */
|
|
|
+ @Log(title = "传感器", businessType = BusinessType.OTHER)
|
|
|
+ @ApiOperation(value = "接收温控设备数据", notes = "用于接收温控设备上传的原始数据")
|
|
|
+ @PostMapping("/receiveTemperatureControl")
|
|
|
+ public AjaxResult receiveTemperatureControl(@RequestBody JSONObject json) {
|
|
|
+ log.error("=== 温控设备数据接收开始 ===");
|
|
|
+ log.error("接收原始报文:{}", json);
|
|
|
+ log.error("接口接收时间: {}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 将JSON中的"-"替换为"_"
|
|
|
+// String jsonStr = json.toString().replaceAll("-", "_");
|
|
|
+ String jsonStr = json.toString().replaceAll("\"([^\"]+)-([^\"]+)\":", "\"$1_$2\":");
|
|
|
+ // 转换为实体类
|
|
|
+ CentermonitorTMonitoringDeviceData deviceData = com.dahuatech.hutool.json.JSONUtil.toBean(
|
|
|
+ jsonStr, CentermonitorTMonitoringDeviceData.class);
|
|
|
+ String deviceId = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ deviceData.setDeviceId(deviceId);
|
|
|
+ // 设置时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ deviceData.setCreateTime(java.util.Date.from(now.atZone(java.time.ZoneId.systemDefault()).toInstant()));
|
|
|
+ deviceData.setUploadTime(java.util.Date.from(now.atZone(java.time.ZoneId.systemDefault()).toInstant()));
|
|
|
+
|
|
|
+ // 保存数据
|
|
|
+ int result = centermonitorTMonitoringDeviceService.insertTemperatureControlData(deviceData);
|
|
|
+
|
|
|
+ log.error("数据保存结果: {}", result > 0 ? "成功" : "失败");
|
|
|
+ log.error("=== 温控设备数据接收结束 ===");
|
|
|
+
|
|
|
+ return AjaxResult.success("数据接收成功", deviceData);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("数据处理异常: {}", e.getMessage());
|
|
|
+ log.error("=== 温控设备数据接收结束 ===");
|
|
|
+ return AjaxResult.error("数据处理失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询温控设备数据列表
|
|
|
+ */
|
|
|
+ @Log(title = "传感器", businessType = BusinessType.OTHER)
|
|
|
+ @ApiOperation(value = "查询温控设备数据列表", notes = "查询温控设备的监测数据列表")
|
|
|
+ @RequiresPermissions("camera:device:data")
|
|
|
+ @GetMapping("/selectTemperatureControlMonitoringData")
|
|
|
+ public TableDataInfo selectTemperatureControlMonitoringData(CentermonitorTMonitoringDeviceData centermonitorTMonitoringDeviceData) {
|
|
|
+ startPage();
|
|
|
+ List<CentermonitorTMonitoringDeviceData> list = centermonitorTMonitoringDeviceService.selectTemperatureControlMonitoringData(centermonitorTMonitoringDeviceData);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取温控设备温度图表数据
|
|
|
+ */
|
|
|
+ @Log(title = "传感器", businessType = BusinessType.OTHER)
|
|
|
+ @ApiOperation(value = "获取温控设备温度图表数据", notes = "获取温控设备的温度折线图数据")
|
|
|
+ @GetMapping("/getTemperatureChartData")
|
|
|
+ public AjaxResult getTemperatureChartData(String deviceId) {
|
|
|
+ try {
|
|
|
+ // 创建查询参数
|
|
|
+ CentermonitorTMonitoringDeviceData query = new CentermonitorTMonitoringDeviceData();
|
|
|
+ query.setDeviceId(StringUtils.isNotBlank(deviceId) ? deviceId: null);
|
|
|
+ // 查询数据
|
|
|
+ List<CentermonitorTMonitoringDeviceData> dataList = centermonitorTMonitoringDeviceService.selectTemperatureControlMonitoringData(query);
|
|
|
+ // 构建返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ // 准备categories(时间轴)
|
|
|
+ List<String> categories = new ArrayList<>();
|
|
|
+ // 准备series(温度数据系列)
|
|
|
+ List<Map<String, Object>> series = new ArrayList<>();
|
|
|
+ Map<String, List<Double>> tempDataMap = new HashMap<>();
|
|
|
+ // 初始化5个温度层级的数据列表
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
+ String seriesName = "温度层级" + i;
|
|
|
+ tempDataMap.put(seriesName, new ArrayList<>());
|
|
|
+ }
|
|
|
+ // 填充数据
|
|
|
+ if (dataList != null && !dataList.isEmpty()) {
|
|
|
+ for (CentermonitorTMonitoringDeviceData data : dataList) {
|
|
|
+ // 添加时间到categories
|
|
|
+ categories.add(String.valueOf(data.getUploadTime() != null ? data.getUploadTime() : data.getCreateTime()));
|
|
|
+
|
|
|
+ // 处理电缆1的5个温度层级
|
|
|
+ if (data.getT1_01() != null) tempDataMap.get("温度层级1").add(Double.parseDouble(data.getT1_01()));
|
|
|
+ if (data.getT1_02() != null) tempDataMap.get("温度层级2").add(Double.parseDouble(data.getT1_02()));
|
|
|
+ if (data.getT1_03() != null) tempDataMap.get("温度层级3").add(Double.parseDouble(data.getT1_03()));
|
|
|
+ if (data.getT1_04() != null) tempDataMap.get("温度层级4").add(Double.parseDouble(data.getT1_04()));
|
|
|
+ if (data.getT1_05() != null) tempDataMap.get("温度层级5").add(Double.parseDouble(data.getT1_05()));
|
|
|
+
|
|
|
+ // 处理电缆1的5个温度层级
|
|
|
+ if (data.getT2_01() != null) tempDataMap.get("温度层级1").add(Double.parseDouble(data.getT2_01()));
|
|
|
+ if (data.getT2_02() != null) tempDataMap.get("温度层级2").add(Double.parseDouble(data.getT2_02()));
|
|
|
+ if (data.getT2_03() != null) tempDataMap.get("温度层级3").add(Double.parseDouble(data.getT2_03()));
|
|
|
+ if (data.getT2_04() != null) tempDataMap.get("温度层级4").add(Double.parseDouble(data.getT2_04()));
|
|
|
+ if (data.getT2_05() != null) tempDataMap.get("温度层级5").add(Double.parseDouble(data.getT2_05()));
|
|
|
+
|
|
|
+ // 处理电缆1的5个温度层级
|
|
|
+ if (data.getT3_01() != null) tempDataMap.get("温度层级1").add(Double.parseDouble(data.getT3_01()));
|
|
|
+ if (data.getT3_02() != null) tempDataMap.get("温度层级2").add(Double.parseDouble(data.getT3_02()));
|
|
|
+ if (data.getT3_03() != null) tempDataMap.get("温度层级3").add(Double.parseDouble(data.getT3_03()));
|
|
|
+ if (data.getT3_04() != null) tempDataMap.get("温度层级4").add(Double.parseDouble(data.getT3_04()));
|
|
|
+ if (data.getT3_05() != null) tempDataMap.get("温度层级5").add(Double.parseDouble(data.getT3_05()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建series对象
|
|
|
+ for (Map.Entry<String, List<Double>> entry : tempDataMap.entrySet()) {
|
|
|
+ Map<String, Object> seriesItem = new HashMap<>();
|
|
|
+ seriesItem.put("name", entry.getKey());
|
|
|
+ seriesItem.put("data", entry.getValue());
|
|
|
+ series.add(seriesItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("categories", categories);
|
|
|
+ result.put("series", series);
|
|
|
+
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取温控设备温度图表数据异常: {}", e.getMessage());
|
|
|
+ return AjaxResult.error("获取数据异常,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|