From 8b5439ba2748f91720975f73e7479a751d6a452b Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Sat, 07 Oct 2023 14:55:52 +0800
Subject: [PATCH] Merge branch 'cjl' into qa

---
 screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java |   54 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
index 5a43e82..893e445 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -59,19 +59,24 @@
     DeviceMapper deviceMapper;
 
     @Override
-    public List<DeviceAndFiveMinuteDataDTO> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) {
+    public List<Map<String, Object>> queryDeviceAndFiveMinuteData(QueryDeviceAndFiveMinuteDataForm form) {
         //������
+        String times = DateUtils.dateToDateString(new Date(),DateUtils.yyyyMM_EN);
         Integer organizationId = form.getOrganizationId();
         Integer regionCode = form.getRegionCode();
         String sensorCode = form.getSensorCode();
-        Map<String, Object> params = new HashMap<>();
+        String type = "$."+ sensorCode;
         String region = null;
+        String endHourlyTime = null;
         if (regionCode != null && organizationId!=24) {
             region = RegionCodeUtils.regionCodeConvertToName(regionCode);
-            params.put("region",region);
-            params.put("regionCode",regionCode);
         }
-        params.put("organizationId",organizationId);
+        if (form.getChooseTime().equals("true")) {
+            endHourlyTime = form.getTime();
+            Date time = DateUtils.convertDate(endHourlyTime);
+            times = DateUtils.dateToDateString(time,DateUtils.yyyyMM_EN);
+        }
+        List<Map<String, Object>> listAll = deviceMapper.deviceList(organizationId,regionCode,region,type,sensorCode,times,endHourlyTime);
         //���������������������������������������������������
         /*List<MonitorPoint> monitorPoints = monitorPointService.queryByOrgIdAndRegionCode(new MonitorPointQueryForm(organizationId, regionCode));
         List<Device> devices = new ArrayList<>();
@@ -87,7 +92,7 @@
 
         }*/
         //���������������������������������
-        List<Device> devices = deviceMapper.deviceList(organizationId,regionCode,region);
+        /*List<Device> devices = new ArrayList<>();
         List<DeviceAndFiveMinuteDataDTO> dtos = new ArrayList<>();
         if (form.getChooseTime().equals("true")) {
             String time = form.getTime();
@@ -125,8 +130,8 @@
             dto.setDevice(device);
             dto.setSensorValue(sensorValue);
             dtos.add(dto);
-        }
-        return dtos;
+        }*/
+        return listAll;
     }
 
     @Override
@@ -136,14 +141,12 @@
         //������������������������������������
         if (sensorValues != null)
             return sensorValues;
-        QueryWrapper<HistoryFiveMinutely> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("mac", mac);
-        queryWrapper.orderByDesc("time");
-        queryWrapper.last("limit 0,1");
+        Map<String, Object> mapParams = new HashMap<>();
+        mapParams.put("mac",mac);
         //���������������������
         Date date = new Date();
         List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date, date, SeparateTableType.MONTH);
-        List<HistoryFiveMinutely> datas = multiTableQuery(queryWrapper, tableNames);
+        List<HistoryFiveMinutely> datas = multiTableQuery(mapParams, tableNames);
         if (ObjectUtils.isEmpty(datas))
             return null;
         HistoryFiveMinutely historyFiveMinutely = datas.get(0);
@@ -475,11 +478,12 @@
      * @Date: 2021/9/23
      */
     public List<HistoryFiveMinutely> getValueByMacAndTime(String mac, Date startDate, Date endDate) {
-        QueryWrapper<HistoryFiveMinutely> wrapper = new QueryWrapper<>();
-        wrapper.eq("mac", mac);
-        wrapper.between("time", startDate, endDate);
+        Map<String, Object> mapParams = new HashMap<>();
+        mapParams.put("startDate",startDate);
+        mapParams.put("endDate",endDate);
+        mapParams.put("mac",mac);
         List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
-        List<HistoryFiveMinutely> datas = multiTableQuery(wrapper, tableNames);
+        List<HistoryFiveMinutely> datas = multiTableQueryResult(mapParams, tableNames);
         return datas;
     }
 
@@ -491,14 +495,22 @@
      * @Author: ���������
      * @Date: 2021/9/23
      */
-    private List<HistoryFiveMinutely> multiTableQuery(QueryWrapper<HistoryFiveMinutely> wrapper, List<String> tableNames) {
+    private List<HistoryFiveMinutely> multiTableQuery(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.listResultOne(params);
             result.addAll(datas);
         }
-        MybatisPlusConfig.tableName.remove();
+        return result;
+    }
+    private List<HistoryFiveMinutely> multiTableQueryResult(Map<String, Object> params, List<String> tableNames) {
+        List<HistoryFiveMinutely> result = new ArrayList<>();
+        for (String tableName : tableNames) {
+            params.put("table",tableName);
+            List<HistoryFiveMinutely> datas = historyFiveMinutelyMapper.listResult(params);
+            result.addAll(datas);
+        }
         return result;
     }
 }

--
Gitblit v1.8.0