Browse Source

project-jmga-2.0.0-2.0.1

dengsixing 1 month ago
parent
commit
d749ce558d

+ 8 - 0
src/main/java/com/fdkankan/scene/controller/SceneEditController.java

@@ -51,6 +51,8 @@ public class SceneEditController extends JmgaBaseController {
     private ISceneEditInfoExtService sceneEditInfoExtService;
     private ISceneEditInfoExtService sceneEditInfoExtService;
     @Autowired
     @Autowired
     private ICutModelService cutModelService;
     private ICutModelService cutModelService;
+    @Autowired
+    private IVisionService visionService;
 
 
     /**
     /**
      * <p>
      * <p>
@@ -978,6 +980,12 @@ public class SceneEditController extends JmgaBaseController {
         return cutModelService.deleteCutModel(param);
         return cutModelService.deleteCutModel(param);
     }
     }
 
 
+    @CheckPermit
+    @GetMapping(value = "/point/getLatAndLon")
+    public ResultData getPointLatAndLon(@RequestParam String num) throws Exception {
+        return ResultData.ok(visionService.getPointLatAndLon(num));
+    }
+
 
 
 
 
 }
 }

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

@@ -0,0 +1,74 @@
+package com.fdkankan.scene.dto;
+
+import lombok.Data;
+
+import java.util.Objects;
+
+/**
+ * @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() {
+        if(Objects.isNull(this.lon) || Objects.isNull(this.lat) || Objects.isNull(this.alt)){
+            return new Double[]{};
+        }
+        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;
+}

+ 6 - 0
src/main/java/com/fdkankan/scene/entity/SceneEditControls.java

@@ -150,6 +150,12 @@ public class SceneEditControls implements Serializable {
     private Integer showAllModel;
     private Integer showAllModel;
 
 
     /**
     /**
+     * 是否显示监控范围
+     */
+    @TableField("show_surveil_scope")
+    private Integer showSurveilScope;
+
+    /**
      * 是否显示cad底图
      * 是否显示cad底图
      */
      */
     @TableField("show_texture")
     @TableField("show_texture")

+ 13 - 0
src/main/java/com/fdkankan/scene/service/IVisionService.java

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

+ 98 - 0
src/main/java/com/fdkankan/scene/service/impl/VisionServiceImpl.java

@@ -0,0 +1,98 @@
+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.*;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class VisionServiceImpl implements IVisionService {
+
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+
+    @Override
+    public List<GeoPoint> getPointLatAndLon(String num) {
+        String visionTxt = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
+        JSONObject visionJson = JSON.parseObject(visionTxt);
+        if(!visionJson.containsKey("sweepLocations")){
+            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);
+            Long id = sweepItem.getLong("id");
+            Long uuid = sweepItem.getLong("uuid");
+            JSONObject ggaLocation = sweepItem.getJSONObject("ggaLocation");
+            GeoPoint geoPoint = new GeoPoint();
+            geoPoint.setId(id);
+            geoPoint.setUuid(uuid);
+            if (Objects.nonNull(ggaLocation)
+                    && StrUtil.isNotEmpty(ggaLocation.getString("lon"))
+                    && StrUtil.isNotEmpty(ggaLocation.getString("lat"))
+                    && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) {
+                Double[] ggaLocationGps = new Double[3];
+                if(Objects.nonNull(ggaLocation.getDouble("lon"))
+                        && Objects.nonNull(ggaLocation.getDouble("lat"))
+                        && Objects.nonNull(ggaLocation.getDouble("alt"))){
+                    ggaLocationGps[0] = ggaLocation.getDouble("lon");
+                    ggaLocationGps[1] = ggaLocation.getDouble("lat");
+                    ggaLocationGps[2] = ggaLocation.getDouble("alt");
+                }
+                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);
+        }
+        if (CollUtil.isNotEmpty(geoPoints) && geoPoints.size() >= 2) {
+            Map<String, GeoPoint> res = new HashMap<>();
+            List<GeoPoint> statusFourPoints  = geoPoints.stream().filter(item -> item.getStatusIndicator() == 4 || item.getStatusIndicator() == 100 || item.getStatusIndicator() == 104).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;
+        }
+        return null;
+    }
+}

+ 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());
+   }
+}

+ 2 - 0
src/main/java/com/fdkankan/scene/vo/SceneEditControlsParamVO.java

@@ -127,6 +127,8 @@ public class SceneEditControlsParamVO implements Serializable {
      */
      */
     private Integer showAllModel;
     private Integer showAllModel;
 
 
+    private Integer showSurveilScope;
+
     private Integer showTexture;
     private Integer showTexture;
 
 
     private Integer showPanos;
     private Integer showPanos;

+ 1 - 0
src/main/java/com/fdkankan/scene/vo/SceneEditControlsVO.java

@@ -125,5 +125,6 @@ public class SceneEditControlsVO implements Serializable {
 
 
     private Integer showTitleLogo;
     private Integer showTitleLogo;
 
 
+    private Integer showSurveilScope;
 
 
 }
 }