From 4319627cf67d19093a18ff724c21782e34fc7a26 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 10 Oct 2023 15:44:27 +0800
Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb

---
 screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |   47 +++++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index 005d4ca..ea2d2a4 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -205,6 +205,7 @@
 
         QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
         queryWrapper.select("mac", "name").in("mac", macs);
+        queryWrapper.orderByAsc("dev_num","name","id");
         List<Device> devices = deviceMapper.selectList(queryWrapper);
         Map<String,Object> devicesInfo = new HashMap<>();
         for (Device device:devices) {
@@ -228,10 +229,11 @@
             Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_EN);
             List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
             for (String mac:macs) {
-                QueryWrapper<HistoryHourly> wrapper = new QueryWrapper<>();
-                wrapper.eq("mac", mac);
-                wrapper.between("time", startDate, endDate);
-                List<HistoryHourly> historyHourlies = multiTableQuery(wrapper, tableNames);
+                Map<String, Object> mapParams = new HashMap<>();
+                mapParams.put("startDate",startDate);
+                mapParams.put("endDate",endDate);
+                mapParams.put("mac",mac);
+                List<HistoryHourly> historyHourlies = multiTableQuery(mapParams, tableNames);
                 historyHourlies = historyHourlies.stream().distinct().collect(Collectors.toList());
                 List<HistoryHourly> distinctHistoryHourlies = new ArrayList<>();
                 Map<String, Object> disMap = new HashMap<>();
@@ -246,8 +248,8 @@
                 for (HistoryHourly historyHourly:distinctHistoryHourlies) {
                     Map<String,Object> historyHourlyMap = new HashMap<>();
                     historyHourlyMap.put("mac",mac);
-                    JSONObject value = JSONObject.parseObject(historyHourly.getValue());
-                    Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
+                    JSONObject  value= JSONObject.parseObject(historyHourly.getValue());
+                    Double sensorValue = Objects.nonNull(value)&&Objects.nonNull(value.get(sensorCode))?Double.parseDouble(value.get(sensorCode).toString()):0d;
                     historyHourlyMap.put(sensorCode,sensorValue);
                     Date time = historyHourly.getTime();
                     String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_EN);
@@ -339,10 +341,11 @@
             Date endDate = DateUtils.getDate(endTime,DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
             List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
             for (String mac:macs) {
-                QueryWrapper<HistoryFiveMinutely> wrapper = new QueryWrapper<>();
-                wrapper.eq("mac", mac);
-                wrapper.between("time", startDate, endDate);
-                List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(wrapper, tableNames);
+                Map<String, Object> mapParams = new HashMap<>();
+                mapParams.put("startDate",startDate);
+                mapParams.put("endDate",endDate);
+                mapParams.put("mac",mac);
+                List<HistoryFiveMinutely> HistoryFiveMinutelys = FiveMinuteTableQuery(mapParams, tableNames);
                 HistoryFiveMinutelys = HistoryFiveMinutelys.stream().distinct().collect(Collectors.toList());
                 List<HistoryFiveMinutely> distinctHistoryHourlies = new ArrayList<>();
                 Map<String, Object> disMap = new HashMap<>();
@@ -358,8 +361,14 @@
                     Map<String,Object> historyHourlyMap = new HashMap<>();
                     historyHourlyMap.put("mac",mac);
                     JSONObject value = JSONObject.parseObject(historyFiveMinutely.getValue());
-                    Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
-                    historyHourlyMap.put(sensorCode,sensorValue);
+                    if (value.get(sensorCode)==null){
+                        historyHourlyMap.put(sensorCode,0.0);
+                    }else {
+                        Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
+                        historyHourlyMap.put(sensorCode,sensorValue);
+                    }
+//                    Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
+//                    historyHourlyMap.put(sensorCode,sensorValue);
                     Date time = historyFiveMinutely.getTime();
                     String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
                     historyHourlyMap.put("time",timeStr);
@@ -532,25 +541,23 @@
      * @Author: ���������
      * @Date: 2021/9/23
      */
-    private List<HistoryHourly> multiTableQuery(QueryWrapper<HistoryHourly> wrapper, List<String> tableNames) {
+    private List<HistoryHourly> multiTableQuery(Map<String, Object> params, List<String> tableNames) {
         List<HistoryHourly> result = new ArrayList<>();
         for (String tableName : tableNames) {
-            MybatisPlusConfig.tableName.set(tableName);
-            List<HistoryHourly> datas = historyHourlyMapper.selectList(wrapper);
+            params.put("table",tableName);
+            List<HistoryHourly> datas = historyHourlyMapper.listResult(params);
             result.addAll(datas);
         }
-        MybatisPlusConfig.tableName.remove();
         return result;
     }
 
-    private List<HistoryFiveMinutely> FiveMinuteTableQuery(QueryWrapper<HistoryFiveMinutely> wrapper, List<String> tableNames) {
+    private List<HistoryFiveMinutely> FiveMinuteTableQuery(Map<String, Object> params, List<String> tableNames) {
         List<HistoryFiveMinutely> result = new ArrayList<>();
         for (String tableName : tableNames) {
-            MybatisPlusConfig.tableName.set(tableName);
-            List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.selectList(wrapper);
+            params.put("table",tableName);
+            List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.listResult(params);
             result.addAll(datas);
         }
-        MybatisPlusConfig.tableName.remove();
         return result;
     }
 

--
Gitblit v1.8.0