From dc9b5820c1e9b672edb417a7b17d3f34c1b96055 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期四, 03 七月 2025 19:25:30 +0800 Subject: [PATCH] bug修改 --- DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/ElectricFenceUtil.java | 123 +++++++++++++++++++++++++++++++++++++++++ DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java | 13 +--- 2 files changed, 126 insertions(+), 10 deletions(-) diff --git a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java index f272069..fd17f6b 100644 --- a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java +++ b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/crossCity/server/impl/LineSiteServiceImpl.java @@ -12,10 +12,7 @@ import com.stylefeng.guns.modular.crossCity.warpper.SiteWarpper; import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar; import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService; -import com.stylefeng.guns.modular.system.util.DateUtil; -import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; -import com.stylefeng.guns.modular.system.util.RedisUtil; -import com.stylefeng.guns.modular.system.util.SystemException; +import com.stylefeng.guns.modular.system.util.*; import com.stylefeng.guns.modular.taxi.model.OrderTaxi; import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; import org.springframework.beans.factory.annotation.Autowired; @@ -303,12 +300,8 @@ } } if(Integer.valueOf(map.get("type").toString()) == 2){//电子围栏 - String gid = map.get("gid").toString(); - List<String> list1 = gdMapElectricFenceUtil.monitorElectricFenc("", lonLat); - if(list1.contains(gid)){ - return true; - } - continue; + String coordinate = map.get("coordinate").toString(); + return ElectricFenceUtil.monitorElectricFenc(coordinate, lonLat); } } return false; diff --git a/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/ElectricFenceUtil.java b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/ElectricFenceUtil.java new file mode 100644 index 0000000..3a4b007 --- /dev/null +++ b/DriverOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/ElectricFenceUtil.java @@ -0,0 +1,123 @@ +package com.stylefeng.guns.modular.system.util; + +import java.util.ArrayList; +import java.util.List; + +/** + * 电子围栏工具类 + */ +public class ElectricFenceUtil { + + + + /** + * @return + */ + public static boolean monitorElectricFenc(String coordinate, String locations){ + return areaMonitoring(coordinate, locations); + } + public static boolean areaMonitoring(String coordinate, String lonLat){ + boolean flag = false; + String[] split = coordinate.split(";"); + List<Double> pointsX = new ArrayList<>(); + List<Double> pointsY = new ArrayList<>(); + for (String s : split) { + pointsX.add(Double.valueOf(s.split(",")[0])); + pointsY.add(Double.valueOf(s.split(",")[1])); + } + String lon1 = lonLat.split(",")[0]; + String lat1 = lonLat.split(",")[1]; + boolean inPolygon = isInPolygon(Double.valueOf(lon1), Double.valueOf(lat1), pointsX, pointsY); + if (inPolygon){ + flag = true; + } + return flag; + } + + + /** + // * 判断点是否在多边形内 + // * @param px 测试点 + // * @param polygonXA 多边形的点 + // * @return boolean true:在多边形内, false:在多边形外 + // * @throws + // * @Title: IsPointInPoly + // */ + public static boolean isInPolygon(double px, double py,List<Double> polygonXA, List<Double> polygonYA) { + boolean isInside = false; + double ESP = 1e-9; + int count = 0; + double linePoint1x; + double linePoint1y; + double linePoint2x = 180; + double linePoint2y; + + linePoint1x = px; + linePoint1y = py; + linePoint2y = py; + + for (int i = 0; i < polygonXA.size() - 1; i++) { + double cx1 = polygonXA.get(i); + double cy1 = polygonYA.get(i); + double cx2 = polygonXA.get(i + 1); + double cy2 = polygonYA.get(i + 1); + if (isPointOnLine(px, py, cx1, cy1, cx2, cy2)) { + return true; + } + if (Math.abs(cy2 - cy1) < ESP) { + continue; + } + + if (isPointOnLine(cx1, cy1, linePoint1x, linePoint1y, linePoint2x, + linePoint2y)) { + if (cy1 > cy2) + count++; + } else if (isPointOnLine(cx2, cy2, linePoint1x, linePoint1y, + linePoint2x, linePoint2y)) { + if (cy2 > cy1) + count++; + } else if (isIntersect(cx1, cy1, cx2, cy2, linePoint1x, + linePoint1y, linePoint2x, linePoint2y)) { + count++; + } + } + if (count % 2 == 1) { + isInside = true; + } + + return isInside; + } + public static double Multiply(double px0, double py0, double px1, double py1, + double px2, double py2) { + return ((px1 - px0) * (py2 - py0) - (px2 - px0) * (py1 - py0)); + } + + public static boolean isPointOnLine(double px0, double py0, double px1, + double py1, double px2, double py2) { + boolean flag = false; + double ESP = 1e-9; + if ((Math.abs(Multiply(px0, py0, px1, py1, px2, py2)) < ESP) + && ((px0 - px1) * (px0 - px2) <= 0) + && ((py0 - py1) * (py0 - py2) <= 0)) { + flag = true; + } + return flag; + } + + public static boolean isIntersect(double px1, double py1, double px2, double py2, + double px3, double py3, double px4, double py4) { + boolean flag = false; + double d = (px2 - px1) * (py4 - py3) - (py2 - py1) * (px4 - px3); + if (d != 0) { + double r = ((py1 - py3) * (px4 - px3) - (px1 - px3) * (py4 - py3)) + / d; + double s = ((py1 - py3) * (px2 - px1) - (px1 - px3) * (py2 - py1)) + / d; + if ((r >= 0) && (r <= 1) && (s >= 0) && (s <= 1)) { + flag = true; + } + } + return flag; + } + +} -- Gitblit v1.7.1