From 79352e07eb14626268a8d4bae253706891e65ad1 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 28 Jul 2023 15:58:18 +0800
Subject: [PATCH] fix:矩形调整

---
 screen-api/src/main/java/com/moral/api/controller/UAVController.java |  162 +++++++++++++++++++++++++++--------------------------
 1 files changed, 83 insertions(+), 79 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/UAVController.java b/screen-api/src/main/java/com/moral/api/controller/UAVController.java
index b97df8d..5ab31e9 100644
--- a/screen-api/src/main/java/com/moral/api/controller/UAVController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/UAVController.java
@@ -86,45 +86,31 @@
         ArrayList<Double> flyLatList = new ArrayList<>();
         //������
         ArrayList<Double> flyLonList = new ArrayList<>();
-//        HashMap<String, Object> map = new HashMap<>();
-//        String mac ="p5dnd7a0243592";
-//        String time1 ="2023-05-14 10:40:00";
-//        String time2 ="2023-05-14 11:10:00";
-//        map.put("mac",mac);
-//        map.put("time1",time1);
-//        map.put("time2",time2);
-//        map.put("height",0.5);
-//        List<UAVResultDTO> uavResultDTOS = historySecondUavMapper.reList(map);
-//        QueryWrapper<HistorySecondUav> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.select("value");
-//        queryWrapper.eq("mac",mac);
-//        queryWrapper.between("time",time1,time2);
-//        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.selectList(queryWrapper);
-        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params);
-        if (ObjectUtils.isEmpty(historySecondUavs)){
-            return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,"null");
-        }
 
+        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params);
         for (HistorySecondUav historySecondUav : historySecondUavs) {
             String value = historySecondUav.getValue();
-            Map map1 = JSON.parseObject(value, Map.class);
-            flyLatList.add(Double.parseDouble(map1.get("flylat").toString()));
-            flyLonList.add(Double.parseDouble(map1.get("flylon").toString()));
-
+            JSONObject jsonObject = JSONObject.parseObject(value);
+            String flylon = jsonObject.get("flylon").toString();
+            String flylat = jsonObject.get("flylat").toString();
+            flyLatList.add(Double.parseDouble(flylat));
+            flyLonList.add(Double.parseDouble(flylon));
+        }
+        if (ObjectUtils.isEmpty(historySecondUavs)){
+            return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,"null");
         }
         Double maxLat = Collections.max(flyLatList);
         Double maxLon = Collections.max(flyLonList);
         Double minLat = Collections.min(flyLatList);
         Double minLon = Collections.min(flyLonList);
-
         //������������������
-        String leftTop =  minLat +";"+ maxLon;
+//        String leftTop =  minLat +";"+ maxLon;
         //������
-        String rightTop =  maxLat +";"+ maxLon;
+//        String rightTop =  maxLat +";"+ maxLon;
         //������
-        String leftBottom = minLat +";" + minLon;
+//        String leftBottom = minLat +";" + minLon;
         //������
-        String rightBottom = maxLat +";" + minLon;
+//        String rightBottom = maxLat +";" + minLon;
         //���������������������
         double distance1 = getDistance(maxLon, minLat, maxLon, maxLat);
         //���������������������
@@ -132,13 +118,13 @@
         ArrayList<UAVGteForDTO> list = new ArrayList<>();
         //������������
 
-        String [] lefts =new String[]{maxLon.toString(),minLat.toString()};
+//        String [] lefts =new String[]{maxLon.toString(),minLat.toString()};
         //������2
-        String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, 50);
+        String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, size);
         //������2
-        String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), 50);
+        String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), size);
         //������2
-        String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, 50);
+        String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, size);
 
         for (int i = 0; i <distance2 ; i+=size) {
             UAVGteForDTO dto1 = new UAVGteForDTO();
@@ -166,23 +152,8 @@
                 }
             }
         }
-        ArrayList<UAVResultDTO> uavResultDTOS1 = new ArrayList<>();
-        for (UAVGteForDTO uavGteForDTO : list) {
-            ArrayList<String[]> doubleArrayList = new ArrayList<>();
-            doubleArrayList.add(uavGteForDTO.getLeftTop());
-            doubleArrayList.add(uavGteForDTO.getLeftBottom());
-            doubleArrayList.add(uavGteForDTO.getRightTop());
-            doubleArrayList.add(uavGteForDTO.getRightBottom());
-//            UAVResultDTO result = getResult(doubleArrayList);
-//            uavResultDTOS1.add(result);
-        }
-        if (!ObjectUtils.isEmpty(uavResultDTOS1)){
-            return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),uavResultDTOS1);
-
-        }
-
-
         HashMap<String,List<String>> rsMap = new HashMap<>();
+        List<String>  stringList = new ArrayList<>();
         for (UAVGteForDTO uavGteForDTO : list) {
             ArrayList<String> list1 = new ArrayList<>();
             ArrayList<String[]> doubleArrayList = new ArrayList<>();
@@ -190,6 +161,12 @@
             doubleArrayList.add(uavGteForDTO.getLeftBottom());
             doubleArrayList.add(uavGteForDTO.getRightTop());
             doubleArrayList.add(uavGteForDTO.getRightBottom());
+            String[] leftTops = uavGteForDTO.getLeftTop();
+            String[] rightBottoms = uavGteForDTO.getRightBottom();
+            Double x1 = Double.parseDouble(leftTops[0]);
+            Double x2 = Double.parseDouble(rightBottoms[0]);
+            Double y1 = Double.parseDouble(leftTops[1]);
+            Double y2 = Double.parseDouble(rightBottoms[1]);
             //������������������
             for (int i = 0; i < historySecondUavs.size(); i++) {
                 HistorySecondUav historySecondUav = historySecondUavs.get(i);
@@ -198,32 +175,20 @@
                 String flylat = map1.get("flylat").toString();
                 String flylon = map1.get("flylon").toString();
                 //���������������������������
-                boolean flag = isInPolygon(flylon,flylat,doubleArrayList);
+                boolean flag = isInPolygon(flylon,flylat,x1,x2,y1,y2);
                 if (flag){
-                    list1.add(historySecondUav.getValue());
-                    historySecondUavs.remove(i);
+                    String time = DateUtils.dateToDateString(historySecondUav.getTime());
+                    //historySecondUavs.remove(i);
+                    if(!stringList.contains(time)){
+                        list1.add(historySecondUav.getValue());
+                        stringList.add(time);
+                    }
                 }
             }
             //���������������������
             String result = getResult(doubleArrayList);
             rsMap.put(result,list1);
-            }
-//            for (HistorySecondUav historySecondUav : historySecondUavs) {
-//                String value = historySecondUav.getValue();
-//                Map map1 = JSON.parseObject(value, Map.class);
-//                String flylat = map1.get("flylat").toString();
-//                String flylon = map1.get("flylon").toString();
-//                //���������������������������
-//                boolean flag = isInPolygon(flylon,flylat,doubleArrayList);
-//                if (flag){
-//                    historySecondUavs.remove(historySecondUav);
-//                    list1.add(historySecondUav.getValue());
-//                }
-//            }
-//            //���������������������
-//            String result = getResult(doubleArrayList);
-//            rsMap.put(result,list1);
-//        }
+        }
 
         //���������������������������������������
         ArrayList<UAVResultDTO> uavResultDTOS = new ArrayList<>();
@@ -341,16 +306,6 @@
                 O3Double = O3ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
             }
 
-//            dto.setCoAvg(CODouble);
-//            dto.setNO2Avg(NODouble);
-//            dto.setO3Avg(O3Double);
-//            dto.setTVOCAvg(TVODouble);
-//            dto.setPM10Avg(PM10Double);
-//            dto.setPM25Avg(PM25Double);
-//            dto.setSO2Avg(SODouble);
-//            dto.setWDAvg(WDDouble);
-//            dto.setSHAvg(SHDouble);
-//            dto.setQYAvg(QYDouble);
             dto.setA21005(CODouble);
             dto.setA21004(NODouble);
             dto.setA05024(O3Double);
@@ -405,8 +360,12 @@
                     ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
         //������������������
         List<UAVQueryTimeSlotDTO> dtos = historySecondUavService.queryTimeSlot(form);
+        if (ObjectUtils.isEmpty(dtos)){
+            return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,null);
+        }
         //������vo���
         UAVQueryTimeSlotVOs vo = UAVQueryTimeSlotVOs.convert(dtos);
+
         //������������
         return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo);
     }
@@ -502,6 +461,40 @@
 
         return rsLon+"_"+rsLat;
 //        return uavResultDTO;
+    }
+
+
+    //���������������
+    public static UAVResultDTO getResults(ArrayList<String[]> doubleArrayList){
+        UAVResultDTO uavResultDTO = new UAVResultDTO();
+        int total = doubleArrayList.size();
+        double X = 0, Y = 0, Z = 0;
+        for (int i = 0; i < total; i++) {
+            double lat, lon, x, y, z;
+            String[] strings = doubleArrayList.get(i);
+            lon = Double.parseDouble(strings[0]) * Math.PI / 180;
+            lat = Double.parseDouble(strings[1]) * Math.PI / 180;
+            x = Math.cos(lat) * Math.cos(lon);
+            y = Math.cos(lat) * Math.sin(lon);
+            z = Math.sin(lat);
+            X += x;
+            Y += y;
+            Z += z;
+        }
+        X = X / total;
+        Y = Y / total;
+        Z = Z / total;
+        double Lon = Math.atan2(Y, X);
+        double Hyp = Math.sqrt(X * X + Y * Y);
+        double Lat = Math.atan2(Z, Hyp);
+
+        double rsLon = Lon * 180 / Math.PI;
+        double rsLat = Lat * 180 / Math.PI;
+        uavResultDTO.setFlyLon(rsLon);
+        uavResultDTO.setFlyLat(rsLat);
+
+//        return rsLon+"_"+rsLat;
+        return uavResultDTO;
     }
 
     /**
@@ -611,9 +604,7 @@
         double p_x =Double.parseDouble(X);
         double p_y =Double.parseDouble(Y);
         Point2D.Double point = new Point2D.Double(p_x, p_y);
-
         List<Point2D.Double> pointList= new ArrayList<Point2D.Double>();
-
         for (String[] strings : doubleArrayList) {
             double polygonPoint_x=Double.parseDouble(strings[0]);
             double polygonPoint_y=Double.parseDouble(strings[1]);
@@ -624,4 +615,17 @@
 
     }
 
+    public boolean isInPolygon(String X,String Y,double x1,double x2,double y1,double y2){
+        boolean result = false;
+        double x =Double.parseDouble(X);
+        double y =Double.parseDouble(Y);
+        if(x >= Math.min(x1, x2) && x <= Math.max(x1, x2) ){
+            if(y >= Math.min(y1, y2) && y <= Math.max(y1, y2)){
+                result = true;
+            }
+        }
+        return result;
+
+    }
+
 }

--
Gitblit v1.8.0