From ea9e0b49cafc3c08f57033448bec1c0fa1a12314 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 21 Dec 2023 09:49:49 +0800
Subject: [PATCH] chore:测试提交

---
 screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java |  163 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 135 insertions(+), 28 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
index f52c8b8..31f5cb1 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -3,27 +3,27 @@
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-
+import com.jhlabs.composite.AverageComposite;
 import com.moral.api.entity.*;
 import com.moral.api.mapper.DeviceMapper;
 import com.moral.api.mapper.HistoryMonthlyMapper;
 import com.moral.api.mapper.OrganizationMapper;
-
+import com.moral.api.pojo.dto.dataDisplay.HeatMapDTO;
 import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO;
 import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
 import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
 import com.moral.api.pojo.form.dataDisplay.SensorComparisonDisplayForm;
-
 import com.moral.api.service.*;
+import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
 import com.moral.constant.Constants;
 import com.moral.constant.SeparateTableType;
 import com.moral.pojo.AQI;
 import com.moral.util.*;
-
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
+import reactor.core.publisher.Flux;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -395,20 +395,17 @@
     }
 
     /**
-     * ���������
+     * ���������������
      * @param code
      * @param startTime
      * @param type
      * @return
      */
     @Override
-    public ArrayList<Map<String, Object>> getHeatMapData(String code, String startTime, String type,String form) {
+    public List<HeatMapDTO> getHeatMapData(String code, String startTime, String type, String form) {
         HashMap<String, Object> map = new HashMap<>();
         map.put("start",startTime);
         map.put("type","$."+ type);
-        map.put("sensorCode","count");
-        map.put("regionCode",null);
-        map.put("region",null);
 
         //������������������
         Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
@@ -427,8 +424,8 @@
             list.add(organizationId);
         }
 
-        ArrayList<Map<String, Object>> rsHeatMap = new ArrayList<>();
-//        ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
+//        ArrayList<Map<String, Object>> rsHeatMap = new ArrayList<>();
+        ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
 
         if (form.equals("hour")){ //������
             Date date1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN);
@@ -436,36 +433,146 @@
 //                for (Integer integer : list) {
                     map.put("organizationIds",list);
                     map.put("tableName",tableNames.get(0));
-                    List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
-//                   List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
+//                    List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
+                   List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
                     rsHeatMap.addAll(heatMap);
 //            }
 
         }else { //���
 //            for (Integer integer : list) {
                 map.put("organizationIds",list);
-                List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
-//                List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
+//                List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
+                List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
                 rsHeatMap.addAll(heatMap);
 //            }
         }
 
-        //������������������
-        ArrayList<Map<String, Object>> filteredList = new ArrayList<>();
-        for (Map<String, Object> map1 : rsHeatMap) {
-            boolean hasEmptyValue = false;
-            for (Object value : map1.values()) {
-                if (value == null) {
-                    hasEmptyValue = true;
-                    break;
-                }
+        return distrinList(rsHeatMap);
+    }
+
+    @Override
+    public List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form) {
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("start",startTime);
+        map.put("type","$."+ type);
+        //������������������
+//        Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
+//        Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization");
+//        Integer organizationId = (Integer) orgInfo.get("id");
+        //���������
+        ArrayList<Integer> list = new ArrayList<>();
+        list.add(id);
+//        if (organizationId==24){
+////            LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>();
+////            wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE);
+////            wrapper.eq(Organization::getId,id);
+////            List<Organization> organizations = organizationMapper.selectList(wrapper);
+////            List<Integer> collect = organizations.stream().map(organization -> organization.getId()).collect(Collectors.toList());
+////            list.addAll(collect);
+//            list.add(id);
+//        }else {
+//            list.add(id);
+//        }
+
+        ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
+
+        if (form.equals("hour")){ //������
+//            log.info(""+startTime);
+            String dateString = DateUtils.stringToDateString(startTime, DateUtils.yyyy_MM_dd_HH_EN, DateUtils.yyyyMM_EN);
+//            Date date1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN);
+//            log.info(""+dateString);
+            map.put("organizationIds",list);
+            map.put("tableName","_"+dateString);
+
+            List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
+//            log.info(heatMap.size()+"");
+
+            List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
+            if (ObjectUtils.isEmpty(collect1)){
+                return null;
             }
-            if (!hasEmptyValue) {
-                filteredList.add(map1);
+            getHeatMap(heatMap);
+            rsHeatMap.addAll(heatMap);
+
+        }else { //���
+            map.put("organizationIds",list);
+            List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
+            List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
+            if (ObjectUtils.isEmpty(collect1)){
+                return null;
+            }
+            getHeatMap(heatMap);
+            rsHeatMap.addAll(heatMap);
+        }
+
+        return distrinList(rsHeatMap);
+    }
+
+    //������������
+    private void getHeatMap(List<HeatMapDTO> heatMap) {
+        //������������
+        List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getGroupId() != null).collect(Collectors.toList());
+        if (ObjectUtils.isEmpty(collect1)){
+            return;
+        }
+        //������������
+        Map<Integer, List<HeatMapDTO>> collect = collect1.parallelStream().collect(Collectors.groupingBy(o ->o.getGroupId()));
+        Set<Integer> integers = collect.keySet();
+        int i = 0 ;
+        for (Integer integer : integers) {
+            ArrayList<Double> doubleArrayList = new ArrayList<>();
+            ArrayList<GeoCoordinate> geoCoordinates = new ArrayList<>();
+            List<HeatMapDTO> heatMapDTOS = collect.get(integer);
+            for (HeatMapDTO heatMapDTO : heatMapDTOS) {
+                GeoCoordinate geoCoordinate = new GeoCoordinate();
+                doubleArrayList.add(heatMapDTO.getCount());
+//                heatMapDTO.setCount(heatMapDTO.getCount());
+
+                heatMapDTO.setCount(0.0);
+                geoCoordinate.setLongitude(heatMapDTO.getLng());
+                geoCoordinate.setLatitude(heatMapDTO.getLat());
+                geoCoordinates.add(geoCoordinate);
+            }
+            if (!ObjectUtils.isEmpty(doubleArrayList)){
+                HeatMapDTO heatMapDTO = new HeatMapDTO();
+                //������������������
+                double asDouble = doubleArrayList.stream().mapToDouble(Double::valueOf).max().getAsDouble();
+                //���������������
+                GeoCoordinate centerPoint = GetCenterPointFromListOfCoordinates.getCenterPoint(geoCoordinates);
+                double rsCode = asDouble - doubleArrayList.size()-1;
+//                log.info(asDouble+"-----"+rsCode);
+                heatMapDTO.setCount(rsCode<=0.0?0.0:rsCode);
+//                heatMapDTO.setSum(asDouble);
+                heatMapDTO.setLng(centerPoint.getLongitude());
+                heatMapDTO.setLat(centerPoint.getLatitude());
+                heatMapDTO.setMac(i+"");
+                heatMapDTO.setName(integer+"");
+                heatMap.add(heatMapDTO);
+                i++;
             }
         }
-        log.info(filteredList.size()+"");
-        return filteredList;
+    }
+
+    /**
+     * ������������
+     * @param responseList
+     * @return
+     */
+    private List<HeatMapDTO> distrinList(List<HeatMapDTO> responseList){
+        List<HeatMapDTO> rsMap = new ArrayList<>();
+        Set<String> keysSet = new HashSet<String>();
+        for (HeatMapDTO heatMapDTO : responseList) {
+            String keys = String.valueOf(heatMapDTO.getMac());
+            int beforeSize = keysSet.size();
+            keysSet.add(keys);
+            int afterSize = keysSet.size();
+            if(afterSize == beforeSize + 1){
+                rsMap.add(heatMapDTO);
+            }
+        }
+        return rsMap;
+
+
     }
 
     /**

--
Gitblit v1.8.0