Parcourir la source

* 大屏接口,凹边测算

chen.cheng il y a 4 mois
Parent
commit
b34521b199

+ 11 - 4
bd-park/park-backend/park-application/src/main/java/com/huashe/park/application/web/controller/cons/PileMachineInfoController.java

@@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.repository.query.Param;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -20,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.huashe.common.domain.AjaxResult;
 import com.huashe.park.common.i18n.MessageUtils;
-import com.huashe.park.core.service.IConsUnitInfoService;
+import com.huashe.park.core.service.IPileHoleIndexRealtimeService;
 import com.huashe.park.core.service.IPileMachineInfoService;
 import com.huashe.park.domain.dto.cons.MachineBiz;
 import com.huashe.park.domain.dto.cons.MachineLogin;
@@ -49,7 +50,7 @@ public class PileMachineInfoController extends BaseController {
     private IPileMachineInfoService pileMachineInfoService;
 
     @Autowired
-    private IConsUnitInfoService consUnitInfoService;
+    private IPileHoleIndexRealtimeService pileHoleIndexRealtimeService;
 
     @Autowired
     private TokenService tokenService;
@@ -175,8 +176,14 @@ public class PileMachineInfoController extends BaseController {
      * @return the ajax result
      */
     @PreAuthorize("@ss.hasPermi('cons:pileMachineInfo:list')")
-    @GetMapping("/screen/consunit/machine/{consUnitId}")
-    public AjaxResult qryMachineByConsUnitId(@PathVariable("consUnitId") Long consUnitId) {
+    @GetMapping("/screen/consunit/machine")
+    public AjaxResult qryMachineByConsUnitId(@Param("consUnitId") Long consUnitId) {
         return AjaxResult.success(pileMachineInfoService.selectMachineByConsUnitId(consUnitId));
     }
+
+    @PreAuthorize("@ss.hasPermi('cons:pileMachineInfo:list')")
+    @GetMapping("/screen/machine/latest")
+    public AjaxResult qryMachineLatestIndex(@Param("machineId") Long machineId) {
+        return AjaxResult.success(pileHoleIndexRealtimeService.selectMachineLatestIndex(machineId));
+    }
 }

+ 167 - 0
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/geo/ConvexHullUtil.java

@@ -0,0 +1,167 @@
+package com.huashe.park.common.geo;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.huashe.park.common.geo.convex.ConcaveHull;
+import com.huashe.park.common.geo.convex.Point;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.fastjson2.JSONObject;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+public class ConvexHullUtil {
+    private static final Logger logger = LoggerFactory.getLogger(Point.class);
+
+    private double x;
+
+    private double y;
+
+    public static List<Point> convexHull(List<Point> points) {
+        // 小于三个点的情况,直接返回
+        if (points.size() < 3) {
+            return points;
+        }
+
+        Point first = points.get(0);
+        // 找到最左下角的点
+        for (int i = 0; i < points.size(); i++) {
+            if (points.get(i).getY() < first.getY()
+                || (points.get(i).getY() == first.getY() && points.get(i).getX() < first.getX())) {
+                first = points.get(i);
+            }
+        }
+        logger.info("凸包计算-最下面偏左的点位是:{}", first);
+        List<Point> sortedList = angleSorting(first, points);
+        logger.info("凸包计算-角排序结果:{}", JSONObject.toJSONString(sortedList));
+        int firstIndex = 0;
+        for (int i = 0; i < sortedList.size(); i++) {
+            if (first.getX() == sortedList.get(i).getX() && first.getY() == sortedList.get(i).getY()) {
+                firstIndex = i;
+            }
+        }
+        // 结果集合
+        List<Point> convexHullPoints = new ArrayList<>();
+        convexHullPoints.add(first);
+        int nextIndex = firstIndex + 1 == sortedList.size() ? 0 : firstIndex + 1;
+        Point next = new Point();
+        while (next != first) {
+            next = sortedList.get(nextIndex);
+
+            while (true) {
+                if (convexHullPoints.size() < 2) {
+                    convexHullPoints.add(next);
+                    break;
+                }
+                if (isEnabled(convexHullPoints.get(convexHullPoints.size() - 2),
+                    convexHullPoints.get(convexHullPoints.size() - 1), next)) {
+                    convexHullPoints.add(next);
+                    break;
+                }
+                else {
+                    convexHullPoints.remove(convexHullPoints.size() - 1);
+                }
+            }
+            nextIndex = nextIndex + 1 == sortedList.size() ? 0 : nextIndex + 1;
+        }
+        convexHullPoints = convexHullPoints.stream().distinct().collect(Collectors.toList());
+        logger.info("凸包计算-结果:{}", JSONObject.toJSONString(convexHullPoints));
+        logger.info("凸包结算-结果绘制成线:{}", point2WktLine(convexHullPoints));
+        return convexHullPoints;
+    }
+
+    public static boolean isEnabled(Point A, Point B, Point C) {
+        double mulCross = A.getX() * B.getY() - A.getY() * B.getX() + B.getX() * C.getY() - B.getY() * C.getX()
+            + C.getX() * A.getY() - C.getY() * A.getX();
+        if (mulCross >= 0) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
+    /**
+     * 以原点为中心进行角排序
+     * 
+     * @param points 点位
+     * @return 排序的点位
+     */
+    public static List<Point> angleSorting(Point first, List<Point> points) {
+        points = points.stream().sorted(Comparator.comparing(Point::getX)).collect(Collectors.toList());
+        points = points.stream().sorted(Comparator.comparing(Point::getY)).collect(Collectors.toList());
+        Map<Double, Point> pointMap = new HashMap<>();
+        List<Double> angles = new ArrayList<>();
+        for (Point point : points) {
+            double angle = Math.atan2(point.getY() - first.getY(), point.getX() - first.getX()) * 180.0 / Math.PI;
+            if (angle < 0) {
+                angle += 360.0;
+            }
+            pointMap.put(angle, point);
+            angles.add(angle);
+        }
+        angles = angles.stream().sorted().collect(Collectors.toList());
+        List<Point> result = new ArrayList<>();
+        for (Double angle : angles) {
+            result.add(pointMap.get(angle));
+        }
+        return result;
+    }
+
+    public static String point2WktLine(List<Point> points) {
+        StringBuilder sb = new StringBuilder("LINESTRING(");
+        for (Point point : points) {
+            sb.append(point.getX()).append(" ").append(point.getY()).append(", ");
+        }
+        sb.append(points.get(0).getX()).append(" ").append(points.get(0).getY()).append(")");
+        return sb.toString();
+    }
+
+    // public static List<Point> point2Wgs84(List<Point> points) {
+    // List<Point> coordinates = new ArrayList<>();
+    // for (Point point: points) {
+    // Coordinate coordinate = new Coordinate(point.getX(), point.getY(),0D);
+    // Coordinate cover = CoordinateUtils.gaussianToWgs84(coordinate, 117);
+    // coordinates.add(new Point(cover.getX(), cover.getY()));
+    // }
+    // return coordinates;
+    // }
+
+    public static String point2WktPoint(List<Point> points) {
+        StringBuilder sb = new StringBuilder("MULTIPOINT(");
+        for (Point point : points) {
+            sb.append(point.getX()).append(" ").append(point.getY()).append(", ");
+        }
+        sb.append(points.get(0).getX()).append(" ").append(points.get(0).getY()).append(")");
+        return sb.toString();
+    }
+
+
+
+    public static void main(String[] args) {
+        List<Point> points = new ArrayList<>();
+        points.add(new Point(116.51420419741034, 39.72464578059458));
+        points.add(new Point(116.5142100494552, 39.72461905019859));
+        points.add(new Point(116.51421804106533, 39.724615458020104));
+        points.add(new Point(116.51421649139034, 39.72462206236937));
+        points.add(new Point(116.51422472532401, 39.724611537067666));
+        points.add(new Point(116.51422189537502, 39.72459915116547));
+        points.add(new Point(116.51421999329702, 39.724606604151624));
+        points.add(new Point(116.51420852801604, 39.72461304201025));
+        points.add(new Point(116.51420145678534, 39.72464519351396));
+        ConcaveHull concaveHull = new ConcaveHull(points);
+        List<Point> result = concaveHull.Compute(-1D);
+        logger.info("凸包计算-结果:{}", point2WktLine(result));
+        logger.info("原始点位:{}", point2WktPoint(points));
+        logger.info("原始点位连线:{}", point2WktLine(points));
+        convexHull(points).stream().distinct().collect(Collectors.toList());
+    }
+}

+ 46 - 11
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/geo/GeoUtils.java

@@ -1,15 +1,20 @@
 package com.huashe.park.common.geo;
 
-import org.locationtech.jts.geom.*;
+import java.util.List;
+
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.geom.Point;
+import org.locationtech.jts.geom.Polygon;
 import org.locationtech.jts.io.ParseException;
 import org.locationtech.jts.io.WKTReader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-
 public class GeoUtils {
     private static final Logger log = LoggerFactory.getLogger(GeoUtils.class);
+
     /**
      * geometryFactory
      */
@@ -32,8 +37,7 @@ public class GeoUtils {
     }
 
     /**
-     * Gets poly center.
-     * POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))
+     * Gets poly center. POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))
      *
      * @param wktPolygon the wkt polygon
      * @return the poly center
@@ -46,7 +50,8 @@ public class GeoUtils {
         Geometry geometry = null;
         try {
             geometry = reader.read(wktPolygon);
-        } catch (ParseException e) {
+        }
+        catch (ParseException e) {
             log.info("Invalid WKT string: " + e.getMessage());
         }
         // 获取中心点
@@ -54,8 +59,7 @@ public class GeoUtils {
     }
 
     /**
-     * getPolygon
-     * POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))
+     * getPolygon POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))
      *
      * @param wktPolygon the wkt polygon
      * @return the poly center
@@ -68,7 +72,8 @@ public class GeoUtils {
         Polygon geometry = null;
         try {
             geometry = (Polygon) reader.read(wktPolygon);
-        } catch (ParseException e) {
+        }
+        catch (ParseException e) {
             log.info("Invalid WKT string: " + e.getMessage());
         }
         // 获取中心点
@@ -79,7 +84,7 @@ public class GeoUtils {
      * 判断指定的GPS点是否在电子围栏内
      *
      * @param fencePointsList 包含电子围栏的经纬度数据的列表,格式为 "经度,纬度"
-     * @param pointStr        指定的GPS点,格式为 "经度,纬度"
+     * @param pointStr 指定的GPS点,格式为 "经度,纬度"
      * @return 如果在电子围栏内则返回true,否则返回false
      */
     public static boolean isPointInGeoFence(List<String> fencePointsList, String pointStr) {
@@ -103,7 +108,7 @@ public class GeoUtils {
      * 判断指定的GPS点是否在电子围栏内
      *
      * @param geoFencePolygon geo fence polygon
-     * @param pointStr        指定的GPS点,格式为 "经度,纬度"
+     * @param pointStr 指定的GPS点,格式为 "经度,纬度"
      * @return 如果在电子围栏内则返回true ,否则返回false
      * @since 2.0.0
      */
@@ -142,6 +147,36 @@ public class GeoUtils {
         return createPolygon(fencePoints);
     }
 
+    // 地球半径,单位为公里
+    private static final double EARTH_RADIUS = 6371.0;
+
+    /**
+     * 使用Haversine公式计算两个地理坐标点之间的距离(公里)
+     * 
+     * @param lat1 第一个点的纬度
+     * @param lon1 第一个点的经度
+     * @param lat2 第二个点的纬度
+     * @param lon2 第二个点的经度
+     * @return 两点之间的距离,单位为公里
+     */
+    public static double haversineDistance(double lat1, double lon1, double lat2, double lon2) {
+        // 将角度转换为弧度
+        lat1 = Math.toRadians(lat1);
+        lon1 = Math.toRadians(lon1);
+        lat2 = Math.toRadians(lat2);
+        lon2 = Math.toRadians(lon2);
+
+        // 差值
+        double dLat = lat2 - lat1;
+        double dLon = lon2 - lon1;
+
+        // 应用Haversine公式
+        double a = Math.pow(Math.sin(dLat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dLon / 2), 2);
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+
+        // 返回距离,单位为公里
+        return EARTH_RADIUS * c * 1000;
+    }
 
     /**
      * 根据GPS点集合创建多边形

+ 300 - 0
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/geo/convex/ConcaveHull.java

@@ -0,0 +1,300 @@
+package com.huashe.park.common.geo.convex;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ConcaveHull {
+    // 点点之间距离列表
+    private Double[][] _distances;
+
+    // 邻居列表
+    private List<List<Integer>> _neigbours;
+
+    private Boolean[] _signs;
+
+    private List<Point> _points;
+
+    public ConcaveHull(List<Point> list) {
+        // list stream 先按x升序,再按y升序排序
+        _points = list.stream().sorted(Comparator.comparing(Point::getY) // 先按y排序
+            .thenComparing(Point::getX)) // y相同则按x排序
+            .collect(Collectors.toList());
+        _signs = new Boolean[_points.size()];
+        Arrays.fill(_signs, false);
+        InitDistance();
+        InitNeighbours();
+    }
+
+    /// <summary>
+    /// 计算默认的半径
+    /// </summary>
+    /// <returns></returns>
+    public double CalDefaultRadius() {
+        double r = Double.MIN_VALUE;
+        for (int i = 0; i < _points.size(); i++) {
+            if (_distances[i][_neigbours.get(i).get(1)] > r) {
+                r = _distances[i][_neigbours.get(i).get(1)];
+            }
+        }
+        return r;
+    }
+
+    /// <summary>
+    /// 使用滚球法获取凹包
+    /// 不输入半径时,用默认计算半径代替
+    /// </summary>
+    /// <param name="radius"></param>
+    /// <returns></returns>
+    public List<Point> Compute(Double radius) {
+        // 计算默认半径
+        if (Double.compare(radius, -1) == 0) {
+            radius = CalDefaultRadius();
+        }
+        List<Point> results = new ArrayList<>();
+        List<Integer>[] neighs = GetNeighbourList(2 * radius);
+        results.add(_points.get(0));
+        int i = 0, j = -1, pre = -1;
+        while (true) {
+            j = GetNextPoint(pre, i, neighs[i], radius);
+            if (j == -1) {
+                break;
+            }
+            Point p = CalCenterByPtsAndRadius(_points.get(i), _points.get(j), radius);
+            results.add(_points.get(j));
+            _signs[j] = true;
+            pre = i;
+            i = j;
+        }
+        return results;
+    }
+
+    /// <summary>
+    /// 初始化每个点的按距离排序的邻居列表
+    /// </summary>
+    private void InitNeighbours() {
+        _neigbours = new ArrayList<>(_points.size());
+        for (int i = 0; i < _points.size(); i++) {
+            _neigbours.add(i, SortNeighboursByDis(i));
+        }
+    }
+
+    /// <summary>
+    /// 初始化点之间的距离
+    /// </summary>
+    private void InitDistance() {
+        _distances = new Double[_points.size()][_points.size()];
+        for (int i = 0; i < _points.size(); i++) {
+            for (int j = 0; j < _points.size(); j++) {
+                _distances[i][j] = CalDistanceToPts(_points.get(i), _points.get(j));
+            }
+        }
+    }
+
+    /// <summary>
+    /// 获取下一个凹包点
+    /// </summary>
+    /// <param name="pre"></param>
+    /// <param name="cur"></param>
+    /// <param name="list"></param>
+    /// <param name="radius"></param>
+    /// <returns></returns>
+    private int GetNextPoint(Integer pre, Integer cur, List<Integer> list, Double radius) {
+        SortNeighbours(list, pre, cur);
+        for (int j = 0; j < list.size(); j++) {
+            if (_signs[list.get(j)]) {
+                continue;
+
+            }
+            Integer adjIndex = list.get(j);
+            Point xianp = _points.get(adjIndex);
+            Point rightCirleCenter = CalCenterByPtsAndRadius(_points.get(cur), xianp, radius);
+            if (!IsPointsInCircle(list, rightCirleCenter, radius, adjIndex)) {
+                return list.get(j);
+            }
+        }
+        return -1;
+    }
+
+    /// <summary>
+    /// 根据角度对邻居列表进行排序
+    /// </summary>
+    /// <param name="list"></param>
+    /// <param name="pre"></param>
+    /// <param name="cur"></param>
+    private void SortNeighbours(List<Integer> list, Integer pre, Integer cur) {
+        Point origin = _points.get(cur);
+        Point df;
+        if (pre != -1) {
+            df = new Point(_points.get(pre).getX() - origin.getX(), _points.get(pre).getY() - origin.getY());
+        }
+        else {
+            df = new Point(1, 0);
+        }
+        int temp = 0;
+        for (int i = list.size(); i > 0; i--) {
+            for (int j = 0; j < i - 1; j++) {
+                if (CompareAngle(_points.get(list.get(j)), _points.get(list.get(j + 1)), origin, df)) {
+                    temp = list.get(j);
+                    list.set(j, list.get(j + 1));
+                    list.set(j + 1, temp);
+                }
+            }
+        }
+    }
+
+    /// <summary>
+    /// 检查圆内是否存在其他点
+    /// </summary>
+    /// <param name="roundPts"></param>
+    /// <param name="center"></param>
+    /// <param name="radius"></param>
+    /// <param name="roundId"></param>
+    /// <returns></returns>
+    private Boolean IsPointsInCircle(List<Integer> roundPts, Point center, Double radius, Integer roundId) {
+        for (int k = 0; k < roundPts.size(); k++) {
+            if (!roundPts.get(k).equals(roundId)) {
+                Integer index2 = roundPts.get(k);
+                if (IsPtInCircle(_points.get(index2), center, radius)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /// <summary>
+    /// 根据两点及半径计算圆心
+    /// </summary>
+    /// <param name="a"></param>
+    /// <param name="b"></param>
+    /// <param name="r"></param>
+    /// <returns></returns>
+    private static Point CalCenterByPtsAndRadius(Point a, Point b, Double r) {
+        Double dx = b.getX() - a.getX();
+        Double dy = b.getY() - a.getY();
+        Double cx = 0.5 * (b.getX() + a.getX());
+        Double cy = 0.5 * (b.getY() + a.getY());
+        Double v = r * r / (dx * dx + dy * dy) - 0.25;
+        if (v < 0) {
+            return new Point(-1, -1);
+        }
+        Double sqrt = Math.sqrt(v);
+        return new Point(cx - dy * sqrt, cy + dx * sqrt);
+    }
+
+    /// <summary>
+    /// 检查点是否在圆内
+    /// </summary>
+    /// <param name="p"></param>
+    /// <param name="center"></param>
+    /// <param name="r"></param>
+    /// <returns></returns>
+    private static Boolean IsPtInCircle(Point p, Point center, Double r) {
+        double dis2 = (p.getX() - center.getX()) * (p.getX() - center.getX())
+            + (p.getY() - center.getY()) * (p.getY() - center.getY());
+        return dis2 < r * r;
+    }
+
+    /// <summary>
+    /// 获取半径范围内的邻居列表
+    /// </summary>
+    /// <param name="radius"></param>
+    /// <returns></returns>
+    private List<Integer>[] GetNeighbourList(double radius) {
+        List<Integer>[] adjs = new ArrayList[_points.size()];
+        for (int i = 0; i < _points.size(); i++) {
+            adjs[i] = new ArrayList<Integer>();
+        }
+        for (int i = 0; i < _points.size(); i++) {
+
+            for (int j = 0; j < _points.size(); j++) {
+                if (i < j && _distances[i][j] < radius) {
+                    adjs[i].add(j);
+                    adjs[j].add(i);
+                }
+            }
+        }
+        return adjs;
+    }
+
+    /// <summary>
+    /// 按距离排序的邻居列表
+    /// </summary>
+    /// <param name="index"></param>
+    /// <returns></returns>
+    private List<Integer> SortNeighboursByDis(int index) {
+        List<Point> pts = new ArrayList<>();
+
+        for (int i = 0; i < _points.size(); i++) {
+            Point pt = _points.get(i);
+            pt.setId(i);
+            pt.setDistance(_distances[index][i]);
+            pts.add(pt);
+        }
+        pts = pts.stream().sorted(Comparator.comparing(Point::getDistance)).collect(Collectors.toList());
+
+        List<Integer> adj = new ArrayList<>();
+        for (int i = 1; i < pts.size(); i++) {
+            adj.add(pts.get(i).getId());
+        }
+        return adj;
+    }
+
+    /// <summary>
+    /// 比较两个点相对于参考点的角度
+    /// </summary>
+    /// <param name="a"></param>
+    /// <param name="b"></param>
+    /// <param name="origin"></param>
+    /// <param name="reference"></param>
+    /// <returns></returns>
+    private Boolean CompareAngle(Point a, Point b, Point origin, Point reference) {
+
+        Point da = new Point(a.getX() - origin.getX(), a.getY() - origin.getY());
+        Point db = new Point(b.getX() - origin.getX(), b.getY() - origin.getY());
+        // b相对于参考向量的叉积
+        Double detb = CalCrossProduct(reference, db);
+        // 如果 b 的叉积为零且 b 与参考向量的夹角大于等于零度,则返回 false
+        if (detb == 0 && db.getX() * reference.getX() + db.getY() * reference.getY() >= 0) {
+            return false;
+        }
+        // a 相对于参考向量的叉积
+        Double deta = CalCrossProduct(reference, da);
+        // 如果 a 的叉积为零且 a 与参考向量的夹角大于等于零度,则返回 true
+        if (deta == 0 && da.getX() * reference.getX() + da.getY() * reference.getY() >= 0) {
+            return true;
+        }
+        // 如果 a 和 b 在参考向量的同一侧,则比较它们之间的叉积大小
+        if (deta * detb >= 0) {
+            // 如果叉积大于零,返回 true;否则返回 false
+            return CalCrossProduct(da, db) > 0;
+        }
+
+        // 向量小于零度实际上是很大的,接近 2pi
+        return deta > 0;
+    }
+
+    /// <summary>
+    /// 计算两点之间的距离
+    /// </summary>
+    /// <param name="p1"></param>
+    /// <param name="p2"></param>
+    /// <returns></returns>
+    private static Double CalDistanceToPts(Point p1, Point p2) {
+        return Math.sqrt(
+            (p1.getX() - p2.getX()) * (p1.getX() - p2.getX()) + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY()));
+    }
+
+    /// <summary>
+    /// 计算两个向量的叉积
+    /// </summary>
+    /// <param name="a"></param>
+    /// <param name="b"></param>
+    /// <returns></returns>
+    private static Double CalCrossProduct(Point a, Point b) {
+        return a.getX() * b.getY() - a.getY() * b.getX();
+    }
+}

+ 35 - 0
bd-park/park-backend/park-common/src/main/java/com/huashe/park/common/geo/convex/Point.java

@@ -0,0 +1,35 @@
+package com.huashe.park.common.geo.convex;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Point {
+    /// <summary>
+    /// x坐标
+    /// </summary>
+    public Double x;
+
+    /// <summary>
+    /// y坐标
+    /// </summary>
+    public Double y;
+
+    /// <summary>
+    /// 编号
+    /// </summary>
+    public Integer id;
+
+    /// <summary>
+    /// 到其他点的距离
+    /// </summary>
+    public double distance;
+
+    public Point(double x, double y) {
+        this.x = x;
+        this.y = y;
+    }
+}

+ 4 - 1
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/mapper/PileHoleIndexRealtimeMapper.java

@@ -2,9 +2,10 @@ package com.huashe.park.core.mapper;
 
 import java.util.List;
 
-import com.huashe.park.domain.entity.PileHoleIndexRealtime;
 import org.apache.ibatis.annotations.Param;
 
+import com.huashe.park.domain.entity.PileHoleIndexRealtime;
+
 /**
  * 桩点最新指标Mapper接口
  * 
@@ -63,4 +64,6 @@ public interface PileHoleIndexRealtimeMapper {
     public int deletePileHoleIndexRealtimeByIds(Long[] ids);
 
     public int selectMachineConstingPileHole(@Param("machineId") Long machineId, @Param("startTime") String startTime);
+
+    PileHoleIndexRealtime selectMachineLatestIndex(Long machineId);
 }

+ 2 - 0
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/IPileHoleIndexRealtimeService.java

@@ -62,4 +62,6 @@ public interface IPileHoleIndexRealtimeService {
     public int deletePileHoleIndexRealtimeById(Long id);
 
     public int cntMachineConstructingPileHole(Long machineId);
+
+    PileHoleIndexRealtime selectMachineLatestIndex(Long machineId);
 }

+ 4 - 0
bd-park/park-backend/park-core/src/main/java/com/huashe/park/core/service/impl/PileHoleIndexRealtimeServiceImpl.java

@@ -98,4 +98,8 @@ public class PileHoleIndexRealtimeServiceImpl implements IPileHoleIndexRealtimeS
         return pileHoleIndexRealtimeMapper.selectMachineConstingPileHole(machineId, date);
     }
 
+    @Override
+    public PileHoleIndexRealtime selectMachineLatestIndex(Long machineId) {
+        return pileHoleIndexRealtimeMapper.selectMachineLatestIndex(machineId);
+    }
 }

+ 2 - 1
bd-park/park-backend/park-core/src/main/resources/mapper/cons/ConsPileHoleInfoMapper.xml

@@ -53,6 +53,7 @@
             <if test="holeNum != null  and holeNum != ''">and hole_num = #{holeNum}</if>
             <if test="consStatus != null  and consStatus != ''">and cons_status = #{consStatus}</if>
         </where>
+        order by create_time desc
     </select>
 
     <select id="selectConsPileHoleRealtimeIndex" parameterType="ConsPileHoleInfo"
@@ -67,7 +68,7 @@
         cphir.end_time,
         cphir.status,
         cphir.tilt_angle,
-        cphir.forward_tilt_angle,
+        cphir.forward_tilt_angle
         from cons_pile_hole_info cphi
         left join cons_pile_hole_index_realtime cphir
         on

+ 8 - 0
bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileHoleIndexRealtimeMapper.xml

@@ -186,4 +186,12 @@
         where machine_id = #{machineId}
           and update_time > #{startTime}
     </select>
+
+    <select id="selectMachineLatestIndex" resultMap="PileHoleIndexRealtimeResult">
+        SELECT *
+        FROM cons_pile_hole_index_realtime
+        WHERE id = (SELECT MAX(id) FROM cons_pile_hole_index_realtime where machine_id = #{machineId})
+        limit 1
+    </select>
+
 </mapper>

+ 11 - 7
bd-park/park-backend/park-core/src/main/resources/mapper/cons/PileMachineInfoMapper.xml

@@ -169,13 +169,17 @@
     <select id="selectMachineByConsUnitId" resultType="PileMachineInfo">
         select cpmi.*
         from cons_pile_machine_info cpmi
-                 inner join cons_cons_unit_machine_rel ccumr
-                            on
-                                cpmi.id = ccumr.machine_id
-                 inner join cons_cons_unit_info ccui
-                            on
-                                ccui.id = ccumr.cons_unit_id
-        where FIND_IN_SET(#{consUnitId}, ccui.ancestors)
+        inner join cons_cons_unit_machine_rel ccumr
+        on
+        cpmi.id = ccumr.machine_id
+        inner join cons_cons_unit_info ccui
+        on
+        ccui.id = ccumr.cons_unit_id
+        <where>
+            <if test="consUnitId != null">
+                and (ccumr.cons_unit_id = #{consUnitId} OR FIND_IN_SET(#{consUnitId}, ccui.ancestors))
+            </if>
+        </where>
     </select>
 
 </mapper>