From 8e680f301f31c91391579213661be4af04810e8c Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期五, 01 八月 2025 10:47:34 +0800 Subject: [PATCH] 特殊区域,价格修改 --- DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java | 245 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 165 insertions(+), 80 deletions(-) diff --git a/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java b/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java index debbc89..999e374 100644 --- a/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java +++ b/DriverZYTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/specialTrain/server/impl/OrderPrivateCarServiceImpl.java @@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.annotation.Resource; @@ -32,6 +33,8 @@ import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.*; @@ -89,6 +92,8 @@ @Autowired private IIncomeService incomeService; + @Autowired + private ISpecialAreaBillingService specialAreaBillingService; @Value("${filePath}") @@ -235,8 +240,16 @@ public void run() { if(pushMinistryOfTransport){ //上传数据 - pushMinistryOfTransportUtil.orderCreate(orderId); - pushMinistryOfTransportUtil.orderMatch(orderId); + try { + pushMinistryOfTransportUtil.orderCreate(orderId); + } catch (Exception e) { + throw new RuntimeException(e); + } + try { + pushMinistryOfTransportUtil.orderMatch(orderId); + } catch (Exception e) { + throw new RuntimeException(e); + } } } }).start(); @@ -323,99 +336,104 @@ // 结束服务时查询轨迹,计算距离 Driver driver = driverService.selectById(orderPrivateCar.getDriverId()); - String tid = gdFalconUtil.selectTerminal(driver.getPhone()); - String result = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); - - JSONObject jsonObject = JSONObject.parseObject(result); - JSONArray tracks = jsonObject.getJSONArray("tracks"); - Integer counts = jsonObject.getInteger("counts"); - JSONArray points = new JSONArray(); - // 如果一单轨迹点数大于999,需进行分页查询,将所有的点查询出 - if(counts > 999){ - int i = counts%999; - for (int j = 1; j < i + 1; j++) { - String res = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); - JSONObject jsonObject1 = JSONObject.parseObject(res); - JSONArray tracks1 = jsonObject1.getJSONArray("tracks"); - Object ob = tracks1.get(0); + double sum = 0; + try { + String tid = gdFalconUtil.selectTerminal(driver.getPhone()); + String result = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); + + JSONObject jsonObject = JSONObject.parseObject(result); + JSONArray tracks = jsonObject.getJSONArray("tracks"); + Integer counts = jsonObject.getInteger("counts"); + JSONArray points = new JSONArray(); + // 如果一单轨迹点数大于999,需进行分页查询,将所有的点查询出 + if(counts > 999){ + int i = counts%999; + for (int j = 1; j < i + 1; j++) { + String res = gdFalconUtil.selectTrack(tid, orderPrivateCar.getTrackId(),1); + JSONObject jsonObject1 = JSONObject.parseObject(res); + JSONArray tracks1 = jsonObject1.getJSONArray("tracks"); + Object ob = tracks1.get(0); + String obs = JSONObject.toJSONString(ob); + JSONObject object = JSONObject.parseObject(obs); + JSONArray point = object.getJSONArray("points"); + points.addAll(point); + } + } + // 轨迹点数小于999,一页查询出即可 + if(counts > 0 && counts < 999){ + Object ob = tracks.get(0); String obs = JSONObject.toJSONString(ob); JSONObject object = JSONObject.parseObject(obs); JSONArray point = object.getJSONArray("points"); points.addAll(point); } - } - // 轨迹点数小于999,一页查询出即可 - if(counts > 0 && counts < 999){ - Object ob = tracks.get(0); - String obs = JSONObject.toJSONString(ob); - JSONObject object = JSONObject.parseObject(obs); - JSONArray point = object.getJSONArray("points"); - points.addAll(point); - } - - System.out.println("轨迹坐标点=====:"+points); - String toLonLat = ""; - double sum = 0; - List<OrderPosition> orderPositions = new ArrayList<>(); - for (Object o : points) { - String s = JSONObject.toJSONString(o); - JSONObject obj = JSONObject.parseObject(s); - String fromLonLat = obj.getString("location"); - String[] split = fromLonLat.split(","); - Long locatetime = obj.getLong("locatetime"); - Date date = new Date(locatetime); - if(date.after(orderPrivateCar.getStartServiceTime()) && date.before(orderPrivateCar.getEndServiceTime())){ - // 封装定位文件里的单个定位对象 - OrderPosition orderPosition = new OrderPosition(); - orderPosition.setOrderId(orderId); - orderPosition.setOrderType(1); - orderPosition.setDriverId(orderPrivateCar.getDriverId()); - orderPosition.setLat(split[1]); - orderPosition.setLon(split[0]); - orderPosition.setAltitude("0"); - orderPosition.setDirectionAngle("0"); - //先计算里程,在存储最新位置 - orderPosition.setInsertTime(new Date()); - orderPositions.add(orderPosition); + + String toLonLat = ""; + List<OrderPosition> orderPositions = new ArrayList<>(); + for (Object o : points) { + String s = JSONObject.toJSONString(o); + JSONObject obj = JSONObject.parseObject(s); + String fromLonLat = obj.getString("location"); + String[] split = fromLonLat.split(","); + Long locatetime = obj.getLong("locatetime"); + Date date = new Date(locatetime); + if(date.after(orderPrivateCar.getStartServiceTime()) && date.before(orderPrivateCar.getEndServiceTime())){ + // 封装定位文件里的单个定位对象 + OrderPosition orderPosition = new OrderPosition(); + orderPosition.setOrderId(orderId); + orderPosition.setOrderType(1); + orderPosition.setDriverId(orderPrivateCar.getDriverId()); + orderPosition.setLat(split[1]); + orderPosition.setLon(split[0]); + orderPosition.setAltitude("0"); + orderPosition.setDirectionAngle("0"); + //先计算里程,在存储最新位置 + orderPosition.setInsertTime(new Date()); + orderPositions.add(orderPosition); + if(StringUtils.hasLength(fromLonLat) && StringUtils.hasLength(toLonLat)){ + String[] from = fromLonLat.split(","); + String[] to = toLonLat.split(","); + GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(from[1]), Double.valueOf(from[0])); + GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(to[1]), Double.valueOf(to[0])); + double WGS84 = getDistanceMeter(source, target, Ellipsoid.WGS84); + sum += WGS84; + } + toLonLat = fromLonLat; + } + } + + //存储轨迹 + // 将数据存储到文件中 + File file = new File(filePath + orderId + "_" + 1 + ".txt"); + if(!file.exists()){ + file.getParentFile().mkdirs(); + file.createNewFile(); + } + //写入相应的文件 + PrintWriter out = new PrintWriter(new FileWriter(file)); + out.write(JSON.toJSONString(orderPositions)); + out.flush(); + out.close(); + }catch (Exception e){ + e.printStackTrace(); + System.err.println("查询高德轨迹出错,使用本地轨迹计算"); + List<OrderPosition> list = orderPositionService.queryPosition(orderId, 1); + String fromLonLat = ""; + for (OrderPosition orderPosition : list) { + String toLonLat = orderPosition.getLon() + "," + orderPosition.getLat(); if(StringUtils.hasLength(fromLonLat) && StringUtils.hasLength(toLonLat)){ String[] from = fromLonLat.split(","); String[] to = toLonLat.split(","); GlobalCoordinates source = new GlobalCoordinates(Double.valueOf(from[1]), Double.valueOf(from[0])); GlobalCoordinates target = new GlobalCoordinates(Double.valueOf(to[1]), Double.valueOf(to[0])); double WGS84 = getDistanceMeter(source, target, Ellipsoid.WGS84); - System.err.println("WGS84坐标系计算结果:"+WGS84 + "米"); sum += WGS84; } - toLonLat = fromLonLat; + fromLonLat = toLonLat; } } - - //存储轨迹 - // 将数据存储到文件中 - File file = new File(filePath + orderId + "_" + 1 + ".txt"); - if(!file.exists()){ - file.getParentFile().mkdirs(); - file.createNewFile(); - } - //写入相应的文件 - PrintWriter out = new PrintWriter(new FileWriter(file)); - out.write(JSON.toJSONString(orderPositions)); - out.flush(); - out.close(); - - - //获取预估里程,使用预估里程作为行驶里程计算金额 - String origins = orderPrivateCar.getStartLon() + "," + orderPrivateCar.getStartLat(); - String destination = orderPrivateCar.getGetoffLon() + "," + orderPrivateCar.getGetoffLat(); - Map<String, String> distance = gdMapElectricFenceUtil.getDistance(origins, destination, 1); - Double distance1 = Double.valueOf(distance.get("distance")); - if(distance1 - sum > 1000){ - orderPrivateCar.setMileage(distance1); - orderPrivateCar.setIsAbnormal(1); - }else{ - orderPrivateCar.setMileage(sum); - orderPrivateCar.setIsAbnormal(0); - } + orderPrivateCar.setMileage(sum); + orderPrivateCar.setIsAbnormal(0); break; } this.updateById(orderPrivateCar); @@ -458,6 +476,47 @@ orderPrivateCar.setArriveTime(orderPrivateCar.getStartServiceTime()); } orderPrivateCar = this.setMoney(orderPrivateCar, 0D, 0D);//计算费用 + + // 查询起点或者终点在特殊区域中 + List<SpecialAreaBilling> specialAreaBillings = specialAreaBillingService.selectList(new EntityWrapper<SpecialAreaBilling>() + .eq("state", 1)); + if(!CollectionUtils.isEmpty(specialAreaBillings)){ + // 判断起点或者终点在特殊区域中 + Iterator<SpecialAreaBilling> iterator = specialAreaBillings.iterator(); + while (iterator.hasNext()) { + SpecialAreaBilling specialAreaBilling = iterator.next(); + // 起点 + Double startLon = orderPrivateCar.getStartLon(); + Double startLat = orderPrivateCar.getStartLat(); + boolean start = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), startLon + "," + startLat); + // 终点 + Double endLon = orderPrivateCar.getEndLon(); + Double endLat = orderPrivateCar.getEndLat(); + boolean end = ElectricFenceUtil.monitorElectricFenc(specialAreaBilling.getCoordinate(), endLon + "," + endLat); + if(!start && !end){ + iterator.remove(); + } + } + if(!CollectionUtils.isEmpty(specialAreaBillings)){ + // 拿到价格系数最高的特殊区域 + specialAreaBillings.sort(new Comparator<SpecialAreaBilling>() { + @Override + public int compare(SpecialAreaBilling o1, SpecialAreaBilling o2) { + return o2.getPriceCoefficient().compareTo(o1.getPriceCoefficient()); + } + }); + BigDecimal priceCoefficient = specialAreaBillings.get(0).getPriceCoefficient(); + orderPrivateCar.setOrderMoney(Objects.nonNull(orderPrivateCar.getOrderMoney())?new BigDecimal(orderPrivateCar.getOrderMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setStartMoney(Objects.nonNull(orderPrivateCar.getStartMoney())?new BigDecimal(orderPrivateCar.getStartMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setMileageMoney(Objects.nonNull(orderPrivateCar.getMileageMoney())?new BigDecimal(orderPrivateCar.getMileageMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setDurationMoney(Objects.nonNull(orderPrivateCar.getDurationMoney())?new BigDecimal(orderPrivateCar.getDurationMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setWaitMoney(Objects.nonNull(orderPrivateCar.getWaitMoney())?new BigDecimal(orderPrivateCar.getWaitMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setLongDistanceMoney(Objects.nonNull(orderPrivateCar.getLongDistanceMoney())?new BigDecimal(orderPrivateCar.getLongDistanceMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setParkMoney(Objects.nonNull(orderPrivateCar.getParkMoney())?new BigDecimal(orderPrivateCar.getParkMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + orderPrivateCar.setRoadTollMoney(Objects.nonNull(orderPrivateCar.getRoadTollMoney())?new BigDecimal(orderPrivateCar.getRoadTollMoney()).multiply(priceCoefficient).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue():0D); + } + } + orderPrivateCar.setPayManner(type); orderPrivateCar.setParkMoney(null == parkingFee ? 0D : parkingFee); orderPrivateCar.setRoadTollMoney(null == crossingFee ? 0D : crossingFee); @@ -513,6 +572,13 @@ // orderPrivateCar.setTelX(""); // orderPrivateCar.setBindId(""); // } + // 判断预估金额和订单金额差异是否大于3元 + if(BigDecimal.valueOf(orderPrivateCar.getOrderMoney()).subtract(orderPrivateCar.getEstimatedPrice()).abs().doubleValue() > 3){ + orderPrivateCar.setIsException(1); + } + if(orderPrivateCar.getIsException() == 1){ + orderPrivateCar.setState(13); + } this.updateById(orderPrivateCar); @@ -592,6 +658,16 @@ @Override public boolean calculateMileage(Integer orderId, String lon, String lat) throws Exception { OrderPrivateCar orderPrivateCar = this.selectById(orderId); + // 判断距离上一次推送时间是否超过1分钟 + if(Objects.nonNull(orderPrivateCar.getLastPushTime())){ + LocalDateTime now = LocalDateTime.now(); + if(Duration.between(orderPrivateCar.getLastPushTime(), now).toMinutes() > 1){ + orderPrivateCar.setIsException(1); + } + orderPrivateCar.setLastPushTime(now); + }else { + orderPrivateCar.setLastPushTime(LocalDateTime.now()); + } OrderPosition orderPosition = orderPositionService.queryNew(orderId, 1); String now = lon + "," + lat; String old = null; @@ -853,4 +929,13 @@ orderPrivateCar.setTrackId(String.valueOf(trackId)); this.updateById(orderPrivateCar); } + + @Override + public void updatePrice(Integer orderId, Integer priceType, BigDecimal updatePrice) { + OrderPrivateCar orderPrivateCar = this.selectById(orderId); + orderPrivateCar.setPriceType(priceType); + orderPrivateCar.setUpdatePrice(updatePrice); + orderPrivateCar.setPriceAuditState(1); + this.updateById(orderPrivateCar); + } } -- Gitblit v1.7.1