From 3d685203e77cd8deb2982856ee70f4d51d7ce8db Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Fri, 20 May 2022 11:33:42 +0800
Subject: [PATCH] 千灯转发数据添加恶臭两台微站数据

---
 src/main/java/com/moral/task/RabbitMQInsertQiandengPark.java |   27 +++++++++++++++++++++++++++
 src/main/java/com/moral/mapper/HistoryMapper.java            |    2 ++
 src/main/resources/mapper/HistoryMapper.xml                  |    7 +++++++
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/moral/mapper/HistoryMapper.java b/src/main/java/com/moral/mapper/HistoryMapper.java
index 08e6a4c..16557f3 100644
--- a/src/main/java/com/moral/mapper/HistoryMapper.java
+++ b/src/main/java/com/moral/mapper/HistoryMapper.java
@@ -37,4 +37,6 @@
 
     void dropHistoryTable(@Param("yearMonthDay") String yearMonthDay);
 
+    History selectLastDataByMac(@Param("yearMonthDay") String yearMonthDay, @Param("mac") String mac);
+
 }
\ No newline at end of file
diff --git a/src/main/java/com/moral/task/RabbitMQInsertQiandengPark.java b/src/main/java/com/moral/task/RabbitMQInsertQiandengPark.java
index 2e8e03e..86e7c94 100644
--- a/src/main/java/com/moral/task/RabbitMQInsertQiandengPark.java
+++ b/src/main/java/com/moral/task/RabbitMQInsertQiandengPark.java
@@ -1,6 +1,9 @@
 package com.moral.task;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.moral.entity.History;
+import com.moral.mapper.HistoryMapper;
 import com.moral.service.*;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
@@ -15,6 +18,7 @@
 import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.ChronoUnit;
@@ -42,6 +46,9 @@
 
     @Resource
     private HistoryHourlyService historyHourlyService;
+
+    @Resource
+    private HistoryMapper historyMapper;
 
     @Resource
     private OrganizationRelationService organizationRelationService;
@@ -94,6 +101,16 @@
             devices.put("macs", macList);
             devices.put("yearAndMonth", yearAndMonth);
             List<Map<String, Object>> minutelyData = historyMinutelyService.getMinutelySensorData(devices);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            String yearMonthDay = sdf.format(new Date());
+            History guodu = historyMapper.selectLastDataByMac(yearMonthDay, "jsxlqxpc000001");
+            History baihua = historyMapper.selectLastDataByMac(yearMonthDay, "jsxlqxpc000002");
+            Map<String,Object> guoduValue = JSONObject.parseObject(guodu.getValue().toString());
+            JSONObject baihuaValue = JSONObject.parseObject(baihua.getValue().toString());
+            guoduValue.put("mac","jsxlqxpc000001");
+            baihuaValue.put("mac","jsxlqxpc000002");
+            minutelyData.add(guoduValue);
+            minutelyData.add(baihuaValue);
             XxlJobLogger.log("RabbitMQMinutelyData:" + minutelyData.size());
             if (!CollectionUtils.isEmpty(minutelyData)) {
                 for (Map<String, Object> deviceData : minutelyData) {
@@ -151,6 +168,16 @@
             devices.put("end", endTime);
             devices.put("macs", macList);
             List<Map<String, Object>> minutelyData = historyHourlyService.getHourlySensorData(devices);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            String yearMonthDay = sdf.format(new Date());
+            History guodu = historyMapper.selectLastDataByMac(yearMonthDay, "jsxlqxpc000001");
+            History baihua = historyMapper.selectLastDataByMac(yearMonthDay, "jsxlqxpc000002");
+            Map<String,Object> guoduValue = JSONObject.parseObject(guodu.getValue().toString());
+            JSONObject baihuaValue = JSONObject.parseObject(baihua.getValue().toString());
+            guoduValue.put("mac","jsxlqxpc000001");
+            baihuaValue.put("mac","jsxlqxpc000002");
+            minutelyData.add(guoduValue);
+            minutelyData.add(baihuaValue);
             XxlJobLogger.log("RabbitMQHourlyData:" + minutelyData.size());
             if (!CollectionUtils.isEmpty(minutelyData)) {
                 for (Map<String, Object> deviceData : minutelyData) {
diff --git a/src/main/resources/mapper/HistoryMapper.xml b/src/main/resources/mapper/HistoryMapper.xml
index 1cd78ce..aa4967d 100644
--- a/src/main/resources/mapper/HistoryMapper.xml
+++ b/src/main/resources/mapper/HistoryMapper.xml
@@ -263,4 +263,11 @@
     <delete id="dropHistoryTable" parameterType="String">
         drop table history_${yearMonthDay}
     </delete>
+
+    <select id="selectLastDataByMac" resultType="com.moral.entity.History">
+        select * from history_${yearMonthDay}
+        where mac = #{mac}
+        order by time desc
+        limit 1
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0