From 31c65cd4f338256b76efebdb2f1f29deb170969f Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 08 Nov 2023 11:01:22 +0800
Subject: [PATCH] chore:权限修改提交

---
 screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java |   83 ++++++++++++++++++++++++++++++++---------
 1 files changed, 65 insertions(+), 18 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 74d4260..453be39 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
@@ -2,7 +2,9 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.moral.api.config.Interceptor.UserHelper;
 import com.moral.api.config.mybatis.MybatisPlusConfig;
 import com.moral.api.entity.*;
 import com.moral.api.mapper.DeviceMapper;
@@ -10,6 +12,8 @@
 import com.moral.api.mapper.HistoryHourlyMapper;
 import com.moral.api.mapper.OrganizationUnitAlarmMapper;
 import com.moral.api.mapper.UnitConversionMapper;
+import com.moral.api.pojo.vo.device.AppDeviceVo;
+import com.moral.api.pojo.vo.user.QxUser;
 import com.moral.api.service.DeviceService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.moral.api.service.SensorService;
@@ -229,10 +233,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<>();
@@ -340,10 +345,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<>();
@@ -359,8 +365,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);
@@ -487,6 +499,43 @@
         return device;
     }
 
+    /**
+     * ������������
+     *
+     * @param mac
+     * @return
+     */
+    @Override
+    public List<AppDeviceVo> getFuzzySearch(String mac) {
+        QxUser user = UserHelper.getCurrentUser();
+        Integer organizationId = user.getOrganizationId();
+//        Integer organizationId = 24;
+        List<AppDeviceVo> devices;
+        if (organizationId!=24){
+             devices = deviceMapper.getDevices(mac,organizationId);
+        }else {
+             devices = deviceMapper.getDevices(mac,null);
+        }
+        return devices;
+    }
+
+
+    /**
+     * ������������������������
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public List<Device> getOrganizationDevice(Integer id) {
+        LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(Device::getMonitorPointId,id);
+        wrapper.eq(Device::getIsDelete,Constants.NOT_DELETE);
+        wrapper.orderByAsc(Device::getCreateTime);
+        List<Device> devices = deviceMapper.selectList(wrapper);
+        return devices;
+    }
+
     private Device getDeviceUnitAlramInforByMacFromDb(String mac){
         QueryWrapper<Device> wrapper = new QueryWrapper<>();
         wrapper.eq("mac",mac);
@@ -533,25 +582,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