From 88662935de8d8035592dc25dcddf3ce9988eb12b Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Mon, 24 Feb 2025 16:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=88=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/map/GeoUtils.java | 9 +++ .../java/com/ruoyi/system/domain/EtOrder.java | 9 +++ .../ruoyi/system/mapper/EtOrderMapper.java | 15 +++-- .../service/impl/AsDeviceServiceImpl.java | 57 +++++++++++++++---- .../service/impl/EtOrderServiceImpl.java | 3 +- .../resources/mapper/system/EtOrderMapper.xml | 13 +++++ 6 files changed, 89 insertions(+), 17 deletions(-) diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java b/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java index 3bd6431..4c7a6e4 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/map/GeoUtils.java @@ -363,4 +363,13 @@ public class GeoUtils { return false; } + /** + * 计算给定点到多边形的最短距离 + * */ + public double calculateMinDistanceToPolygon(Geometry polygon, double lon, double lat) { + Coordinate coord = new Coordinate(lon, lat); + Point point = new GeometryFactory().createPoint(coord); + return polygon.distance(point); // 返回给定点到多边形的最短距离 + } + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java index 74c6d7f..2323ace 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java @@ -366,4 +366,13 @@ public class EtOrder extends BaseEntity /** 支付渠道 */ public Long payChannel; + + /** 还车定位方式:1-设备定位;2-手机定位 */ + private String returnMode; + + /** 还车经度 */ + private String returnLon; + + /** 还车纬度 */ + private String returnLat; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java index 2c57093..62335fa 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOrderMapper.java @@ -1,16 +1,15 @@ package com.ruoyi.system.mapper; -import java.math.BigDecimal; -import java.time.LocalDate; -import java.util.List; import com.ruoyi.system.domain.EtOrder; import com.ruoyi.system.domain.EtOrderQuery; import com.ruoyi.system.domain.IncomeQuery; import com.ruoyi.system.domain.vo.IncomeVo; -import com.ruoyi.system.domain.vo.IndexVo; import com.ruoyi.system.domain.vo.RechargeVo; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; +import java.util.List; + /** * 订单Mapper接口 * @@ -141,6 +140,14 @@ public interface EtOrderMapper */ public int isInOrderBySn(@Param("sn") String sn); + /** + * 查询当前车辆是否有正在进行中的订单 + * + * @param sn 用户id + * @return 结果 + */ + public EtOrder getInOrderBySn(@Param("sn") String sn); + /** * 检验预约订单只能有一个 * diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index a0448db..1bf2035 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -2412,17 +2412,16 @@ public class AsDeviceServiceImpl extends ServiceImpl i // } private Boolean isParkingZoneByLocation(String longitude, String latitude,Long areaId) { - Boolean inCircle = false; + boolean inCircle = false; EtParkingArea parkingArea = new EtParkingArea(); parkingArea.setAreaId(areaId); parkingArea.setStatus("0"); parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_PARKFING); List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(areaId); - if(ObjectUtil.isNull(parkingAreas) || parkingAreas.size() == 0){ + if(ObjectUtil.isNull(parkingAreas) || parkingAreas.isEmpty()){ log.info("运营区【{}】没有停车区,",areaId); return true; -// throw new ServiceException("运营区【{}】没有停车区"+areaId.toString()); } double tolerance = area.getError(); // 误差距离 for (EtParkingArea etParkingArea : parkingAreas) { @@ -2433,8 +2432,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i inCircle = GeoUtils.isInPolygonWithTolerance(longitude, latitude, geometry, tolerance); if(inCircle){ log.info("位置【{},{}】在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName()); - inCircle = true; - break; }else{ log.info("位置【{},{}】不在停车区【{}】内",longitude,latitude,etParkingArea.getParkingName()); } @@ -2697,22 +2694,60 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(ObjectUtil.isNotNull(latestLocation)){ BigDecimal longitude1 = BigDecimal.valueOf(latestLocation[1]).setScale(8, RoundingMode.HALF_UP); BigDecimal latitude1 = BigDecimal.valueOf(latestLocation[0]).setScale(8, RoundingMode.HALF_UP); - log.info("【判断是否在停车区】,lon:{},lat:{}",longitude1,latitude1); + log.info("【判断是否在停车区--设备的定位】,lon:{},lat:{}",longitude1,latitude1); + Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude1.toString(), latitude1.toString(), Long.parseLong(areaId)); if(parkingZoneByLocation){ - isInParkingAreaVo.setIsInParkingArea(true); - isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn())); - return isInParkingAreaVo; + return getParkingAreaVo(isInParkingAreaVo, true, area,sn,"1",longitude1.toString(),latitude1.toString()); + } + // 如果longitude1和latitude1定位距离最近的停车点的距离小于50米,则可以用手机定位判断是否在停车区,如果大于50米,则直接返回不在停车区 + double minDistanceToParkingArea = findMinDistanceToParkingAreas(Double.parseDouble(longitude1.toString()), Double.parseDouble(latitude1.toString()), Long.parseLong(areaId)); + log.info("【判断是否在停车区(不在停车点内)--距离停车点最小距离】,minDistanceToParkingArea:{}",minDistanceToParkingArea); + if (minDistanceToParkingArea > 50) { // 如果距离大于50米,直接返回不在停车区 + log.info("【判断是否在停车区--大于50米,不在停车点内】,不在停车区"); + return getParkingAreaVo(isInParkingAreaVo, false, area,sn,"1",longitude1.toString(),latitude1.toString()); } } } Boolean parkingZoneByLocation = isParkingZoneByLocation(longitude, latitude, Long.parseLong(areaId)); - isInParkingAreaVo.setIsInParkingArea(parkingZoneByLocation); - //停车点还车:0-关闭;1-开启 + return getParkingAreaVo(isInParkingAreaVo, parkingZoneByLocation, area,sn,"2",longitude,latitude); + } + + private @NotNull IsInParkingAreaVo getParkingAreaVo(IsInParkingAreaVo isInParkingAreaVo, boolean isInParkingArea, EtOperatingArea area, String sn, + String returnMode, String longitude, String latitude) { + isInParkingAreaVo.setIsInParkingArea(isInParkingArea); isInParkingAreaVo.setParkingReturn("1".equals(area.getParkingReturn())); + EtOrder inOrderBySn = etOrderMapper.getInOrderBySn(sn); + if(ObjectUtil.isNotNull(inOrderBySn)){ + EtOrder etOrder = new EtOrder(); + etOrder.setOrderNo(inOrderBySn.getOrderNo()); + etOrder.setReturnMode(returnMode); + etOrder.setReturnLon(longitude); + etOrder.setReturnLat(latitude); + etOrderMapper.updateEtOrderByOrderNo(etOrder); + } return isInParkingAreaVo; } + private double findMinDistanceToParkingAreas(double longitude, double latitude, long areaId) { + EtParkingArea parkingArea = new EtParkingArea(); + parkingArea.setAreaId(areaId); + parkingArea.setStatus("0"); + parkingArea.setType(ServiceConstants.PARKING_AREA_TYPE_PARKFING); + List parkingAreas = parkingAreaService.selectEtParkingAreaList(parkingArea); + double minDistance = Double.MAX_VALUE; + + for (EtParkingArea etParkingArea : parkingAreas) { + Geometry geometry = GeoUtils.fromWkt(etParkingArea.getBoundary()); + double distance = GeoUtils.calculateMinDistanceToPolygon(geometry, longitude, latitude); + if (distance < minDistance) { + minDistance = distance; + } + } + return minDistance; + } + + /** * 查询版本并更新 */ diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index d690ac5..e87faa3 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -2249,8 +2249,7 @@ public class EtOrderServiceImpl implements IEtOrderService */ @Override public List isInAuditOrder(Long userId,String orderNo) { - List inOrder = etOrderMapper.isInAuditOrder(userId, orderNo); - return inOrder; + return etOrderMapper.isInAuditOrder(userId, orderNo); } /** * 查询当前车辆是否有正在进行中的订单 diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml index 84ca80d..248ed81 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml @@ -141,6 +141,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" o.platform_service_fee, o.operator_dividend, o.pay_channel, + o.capped_amount, + o.rental_unit, o.cost FROM et_order o @@ -514,6 +516,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where sn = #{sn} and status =2 and type = 1 + +