dengsixing 5 hónapja
szülő
commit
b2438ca318

+ 69 - 0
src/main/java/com/fdkankan/scene/dto/GeoPoint.java

@@ -0,0 +1,69 @@
+package com.fdkankan.scene.dto;
+
+import lombok.Data;
+
+/**
+ * @author Xiewj
+ * @date 2021/11/9
+ */
+@Data
+public class GeoPoint {
+
+    public GeoPoint() {
+    }
+
+    public GeoPoint(Double lon, Double lat) {
+        this.lon = lon;
+        this.lat = lat;
+    }
+    public GeoPoint(Double[] point) {
+        if (point != null && point.length != 0) {
+            if (point.length == 1) {
+                this.lon = point[0];
+            } else {
+                this.lon = point[0];
+                this.lat = point[1];
+            }
+        } else {
+            this.lon = 0.0D;
+            this.lat = 0.0D;
+        }
+    }
+    public Double[] getCoordinates() {
+        return new Double[]{this.lon, this.lat, this.alt};
+    }
+
+    public void setCoordinates(Double[] coordinates) {
+        if (coordinates != null && coordinates.length != 0) {
+            if (coordinates.length == 1) {
+                this.lon = coordinates[0];
+            } else {
+                this.lon = coordinates[0];
+                this.lat = coordinates[1];
+                this.alt = coordinates[2];
+            }
+        } else {
+            this.lon = 0.0D;
+            this.lat = 0.0D;
+            this.alt = 0.0D;
+        }
+    }
+
+    /* 经度 */
+    private Double lon;
+    /* 纬度 */
+    private Double lat;
+
+    private Double alt;
+
+    private Double[] location;
+
+    private Long id;
+    private Long uuid;
+
+    private int statusIndicator;
+
+    private boolean pointA;
+
+    private boolean pointB;
+}

+ 2 - 0
src/main/java/com/fdkankan/scene/service/ISceneMarkShapeService.java

@@ -29,4 +29,6 @@ public interface ISceneMarkShapeService extends IService<SceneMarkShape> {
     void editTrainStatus(SceneMarkShapeParamVO param);
 
     List<SceneMarkShape> findByNumAndType(String num,Integer type);
+
+    List<SceneMarkShape> findByNum(String num);
 }

+ 2 - 1
src/main/java/com/fdkankan/scene/service/IVisionService.java

@@ -1,5 +1,6 @@
 package com.fdkankan.scene.service;
 
+import com.fdkankan.scene.dto.GeoPoint;
 import com.fdkankan.web.response.ResultData;
 
 import java.util.List;
@@ -7,6 +8,6 @@ import java.util.Map;
 
 public interface IVisionService {
 
-    List<Map<String, Object>> getPointLatAndLon(String num);
+    List<GeoPoint> getPointLatAndLon(String num);
 
 }

+ 20 - 1
src/main/java/com/fdkankan/scene/service/impl/SceneCopyServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fdkankan.scene.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.qrcode.QrCodeUtil;
@@ -22,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.util.*;
 
@@ -50,10 +52,13 @@ public class SceneCopyServiceImpl implements ISceneCopyService {
 
     @Autowired
     ILaserService laserService;
-    @Autowired
+    @Resource
     FYunFileServiceInterface fYunFileServiceInterface;
     @Autowired
     RabbitMqProducer rabbitMqProducer;
+    @Autowired
+    ISceneMarkShapeService sceneMarkShapeService;
+
     @Override
     public void copyScene(String oldNum, String newNum) {
         ScenePro scenePro = sceneProService.getByNum(oldNum);
@@ -162,6 +167,20 @@ public class SceneCopyServiceImpl implements ISceneCopyService {
 
     }
 
+    private void copyMarkShape(String oldNum, String newNum){
+        List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNum(oldNum);
+        if(CollUtil.isEmpty(sceneMarkShapes)){
+            return;
+        }
+        sceneMarkShapes.stream().forEach(v->{
+            v.setId(null);
+            v.setNum(newNum);
+            v.setCreateTime(new Date());
+            v.setUpdateTime(null);
+        });
+        sceneMarkShapeService.saveBatch(sceneMarkShapes);
+    }
+
     private void cpV3(ScenePro scenePro ,String oldNum,String newNum) {
         try {
             Long sceneProId = scenePro.getId();

+ 6 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneMarkShapeServiceImpl.java

@@ -186,4 +186,10 @@ public class SceneMarkShapeServiceImpl extends ServiceImpl<MarkShapeMapper, Scen
         return list(wrapper);
     }
 
+    @Override
+    public List<SceneMarkShape> findByNum(String num) {
+        LambdaQueryWrapper<SceneMarkShape> wrapper = Wrappers.lambdaQuery();
+        wrapper.eq(SceneMarkShape::getNum,num);
+        return list(wrapper);
+    }
 }

+ 56 - 13
src/main/java/com/fdkankan/scene/service/impl/VisionServiceImpl.java

@@ -1,22 +1,23 @@
 package com.fdkankan.scene.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.scene.dto.GeoPoint;
 import com.fdkankan.scene.service.IVisionService;
+import com.fdkankan.scene.util.CoordinateUtil;
 import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -26,33 +27,75 @@ public class VisionServiceImpl implements IVisionService {
     private FYunFileServiceInterface fYunFileService;
 
     @Override
-    public List<Map<String, Object>> getPointLatAndLon(String num) {
+    public List<GeoPoint> getPointLatAndLon(String num) {
         List<Map<String, Object>> list = Lists.newArrayList();
         String visionTxt = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
         JSONObject visionJson = JSON.parseObject(visionTxt);
         if(!visionJson.containsKey("sweepLocations")){
-            return list;
+            return null;
         }
         JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
+        List<GeoPoint> geoPoints = new ArrayList<>();
         for (int i = 0; i < sweepLocations.size(); ++i) {
             JSONObject sweepItem = sweepLocations.getJSONObject(i);
-            String id = sweepItem.getString("id");
-            String uuid = sweepItem.getString("uuid");
+            Long id = sweepItem.getLong("id");
+            Long uuid = sweepItem.getLong("uuid");
             JSONObject ggaLocation = sweepItem.getJSONObject("ggaLocation");
+            GeoPoint geoPoint = new GeoPoint();
             if (Objects.nonNull(ggaLocation)
                     && StrUtil.isNotEmpty(ggaLocation.getString("lon"))
                     && StrUtil.isNotEmpty(ggaLocation.getString("lat"))
                     && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) {
                 Map<String, Object> item = new HashMap<>();
-                item.put("lon", ggaLocation.getString("lon"));
-                item.put("lat", ggaLocation.getString("lat"));
-                item.put("alt", ggaLocation.getString("alt"));
                 item.put("id", id);
                 item.put("uuid", uuid);
                 list.add(item);
+                Double[] ggaLocationGps = new Double[3];
+                ggaLocationGps[0] = ggaLocation.getDouble("lon");
+                ggaLocationGps[1] = ggaLocation.getDouble("lat");
+                ggaLocationGps[2] = ggaLocation.getDouble("alt");
+
+                geoPoint.setId(id);
+                geoPoint.setUuid(uuid);
+                geoPoint.setCoordinates(ggaLocationGps);
+                geoPoint.setStatusIndicator(ggaLocation.getInteger("StatusIndicator"));
+
+
+
+            }
+            if (sweepItem.containsKey("puck")){
+                JSONObject puck = sweepItem.getJSONObject("puck");
+                Double[] floor_location = new Double[3];
+                floor_location[0] = puck.getDouble("x");
+                floor_location[1] = puck.getDouble("y");
+                floor_location[2] = puck.getDouble("z");
+                geoPoint.setLocation(floor_location);
             }
+            geoPoints.add(geoPoint);
         }
-
-        return list;
+        if (CollUtil.isNotEmpty(geoPoints) && geoPoints.size() >= 2) {
+            Map<String, GeoPoint> res = new HashMap<>();
+            List<GeoPoint> statusFourPoints  = geoPoints.stream().filter(item -> item.getStatusIndicator() == 4).collect(Collectors.toList());
+            if (statusFourPoints.size() >= 2) {
+                CoordinateUtil.divide(0, statusFourPoints.size() - 1, statusFourPoints.toArray(new GeoPoint[0]), res);
+            }else {
+                return null ;
+            }
+            for (GeoPoint geoPoint : geoPoints) {
+                if (res.containsKey("pointA")) {
+                    GeoPoint pointA = res.get("pointA");
+                    if (geoPoint.getId()==pointA.getId()){
+                        geoPoint.setPointA(true);
+                    }
+                }
+                if (res.containsKey("pointB")) {
+                    GeoPoint pointB = res.get("pointB");
+                    if (geoPoint.getId()==pointB.getId()){
+                        geoPoint.setPointB(true);
+                    }
+                }
+            }
+        }
+        return geoPoints;
     }
 }

+ 162 - 0
src/main/java/com/fdkankan/scene/util/CoordinateUtil.java

@@ -0,0 +1,162 @@
+package com.fdkankan.scene.util;
+
+
+import com.fdkankan.scene.dto.GeoPoint;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 距离 范围 计算工具类
+ * @author Xiewj
+ * @date 2021/11/23
+ */
+public class CoordinateUtil {
+   /**
+    * 计算经纬度围成的实际面积(平方公里)
+    * @return
+    */
+   public static BigDecimal getArea(List<GeoPoint> ring){
+      double sJ = 6378137;
+      double Hq = 0.017453292519943295;
+      double c = sJ *Hq;
+      double d = 0;
+
+      if (3 > ring.size()) {
+         return new BigDecimal( 0);
+      }
+
+      for (int i = 0; i < ring.size() - 1; i ++){
+         GeoPoint h = ring.get(i);
+         GeoPoint k = ring.get(i + 1);
+         double u = h.getLon() * c * Math.cos(h.getLat() * Hq);
+
+         double hhh = h.getLat() * c;
+         double v = k.getLon() * c * Math.cos(k.getLat() *Hq);
+         d = d + (u * k.getLat() * c - v * hhh);
+      }
+
+      GeoPoint g1 = ring.get(ring.size()-1);
+      GeoPoint point = ring.get(0);
+      double eee = g1.getLon() * c * Math.cos(g1.getLat() * Hq);
+      double g2 = g1.getLat() * c;
+
+      double k = point.getLon() * c * Math.cos(point.getLat() * Hq);
+      d += eee * point.getLat() * c - k * g2;
+      return new BigDecimal( 0.5*Math.abs(d));
+   }
+
+   // WGS84标准参考椭球中的地球长半径(单位:米)
+   private static final double EARTH_RADIUS_WGS84 = 6378137.0;
+   public static  GeoPoint pointA = new GeoPoint();
+   public static  GeoPoint pointB = new GeoPoint();
+
+   /**
+    * 计算两个坐标的距离(粗略计算,单位:米)
+    * 计算公式参照 google map 的距离计算
+    *
+    * @param gps1 坐标1
+    * @param gps2 坐标2
+    * @return
+    */
+   public static double distance(GeoPoint gps1, GeoPoint gps2) {
+
+      double radLat1 = Math.toRadians(gps1.getLat());
+      double radLat2 = Math.toRadians(gps2.getLat());
+
+      double a = radLat1 - radLat2;
+      double b = Math.toRadians(gps1.getLon()) - Math.toRadians(gps2.getLon());
+
+      double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
+              Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
+
+      return Math.round(s * EARTH_RADIUS_WGS84);
+
+   }
+
+
+   public static void distance(List<Object> pointList) {
+
+
+   }
+   /*
+    * @Title divide
+    * @Description 求平面上距离最近的两个点
+    * @author 滑技工厂
+    * @Date 2020/3/28
+    * @param [left, right, points]
+    * @return double
+    * @throws
+    */
+   public static double divide(int left, int right, GeoPoint[] points, Map<String, GeoPoint> res) {
+      // 当前最小两点距离,初始值设置为无穷大
+      double curMaxDis = 1e20;
+      // 如果只有一个点,则不存在最近两点距离,返回无穷大
+      if (left == right) {
+         return curMaxDis;
+      }
+      // 这里是判断是否为只有两个点,如果只有两个点的话那么直接求解。
+      if (left + 1 == right) {
+         res.put("pointA",points[left]);
+         res.put("pointB",points[right]);
+         return distance(points[left], points[right]);
+      }
+
+      // 分治法:第一步:分区,并求取左右分区最小两点距离
+      // 通过右移运算除2,对区域进行合理的划分,使得左右两边保持大致相等个数点
+      int middle = (left + right) >> 1;
+      double leftMinDis = divide(left, middle, points,res);
+      double rightMinDis = divide(middle, right, points,res);
+
+      curMaxDis = (leftMinDis <= rightMinDis) ? leftMinDis : leftMinDis;
+
+      // 分治法:第二步:假设距离最近的两点分别在左右分区中
+      // 关键代码,距离最近的两个点,一个位于左边区域,一个位于右边区域,x轴搜索范围[middle-curMaxDis, middle+curMaxDis]
+      // 记录搜索区间内的点的索引,便于进一步计算最小距离
+      List<Integer> validPointIndex = new ArrayList<>();
+      for (int i = left; i <= right; i++) {
+         if (Math.abs(points[middle].getLat() - points[i].getLat()) <= curMaxDis) {
+            validPointIndex.add(i);
+         }
+      }
+      // 基于索引,进一步计算区间内最小两点距离
+      for (int i = 0; i < validPointIndex.size() - 1; i++) {
+         for (int j = i + 1; j < validPointIndex.size(); j++) {
+            // 如果区间内的两点y轴距离大于curMinDis,则没必要计算了,因为,它们的距离肯定大于curMinDis,
+            if (Math.abs(points[validPointIndex.get(i)].getLon()
+                    - points[validPointIndex.get(j)].getLon()) > curMaxDis) {
+               continue;
+            }
+            double tempDis = distance(points[validPointIndex.get(i)],
+                    points[validPointIndex.get(j)]);
+
+            if (tempDis > curMaxDis){
+               curMaxDis=tempDis;
+               res.put("pointA",points[validPointIndex.get(i)]);
+               res.put("pointB",points[validPointIndex.get(j)]);
+            }
+         }
+      }
+      return curMaxDis;
+   }
+
+
+   public static void main(String[] args) {
+//      int i=500;
+//      List<GeoPoint> ring = new ArrayList<>();
+//
+//      for (int i1 = i; i1 > 0; i1--) {
+//         double a = RandomUtil.randomDouble(113.0000001, 113.9999999);
+//         double b = RandomUtil.randomDouble(22.0000001,22.9999999);
+//         GeoPoint d=new GeoPoint(a,b);
+//         ring.add(d);
+//      }
+//      JSONObject res=new JSONObject();
+//      TimeInterval timer = DateUtil.timer();
+//      System.out.println(divide(0, ring.size()-1, ring.toArray(new GeoPoint[0]),res));
+//      System.out.println(res);
+//      System.out.println("使用秒数"+timer.intervalMs());
+   }
+}