| | |
| | | return true; |
| | | } |
| | | XpOrder xpOrder = xpOrderR.getData(); |
| | | if (xpOrder.getStatus() == 0) { |
| | | redisService.removeByPattern(quoteName, xpOrder.getOrderNumber()); |
| | | } |
| | | |
| | | // 找出围栏id |
| | | Long xpElectronicFenceAreaId = xpOrder.getXpElectronicFenceAreaId(); |
| | |
| | | for (int i = 0; i < count; i++) { |
| | | //等到sleepTime秒钟 |
| | | Thread.sleep(sleepTime * 1000); |
| | | // log.info("进入找车环节 单号 {} 第{}轮", orderNo, count++); |
| | | // 根据距离找车 |
| | | // 车多则根据配置找具体车数量 根据距离最近 |
| | | // 更改 暂不限制数量 |
| | |
| | | if (positionList.isEmpty()) { |
| | | continue; |
| | | } |
| | | List<String> vinList = positionList.stream().map(VehiclePosition::getVin).collect(Collectors.toList()); |
| | | Set<String> vinList = positionList.stream().map(VehiclePosition::getVin).collect(Collectors.toSet()); |
| | | |
| | | // 获取车辆的信息 筛选出可用车辆 |
| | | R<List<String>> vehiclePositionVos = xpVehicleClient.queryVehiclePositionByVin(new VehiclePositionByVinDto(xpElectronicFence.getId(), vinList, xpTradingStrategy.getSimultaneouslyOrderCount())); |
| | |
| | | // 时间价值 |
| | | Integer tendencyTime = xpTradingStrategy.getTendencyTime(); |
| | | |
| | | try { |
| | | |
| | | // 电量价值 |
| | | Integer tendencyElectricity = xpTradingStrategy.getTendencyElectricity(); |
| | |
| | | lonLatDto1.setLongitude(Double.valueOf(split[0])); |
| | | lonLatDto1.setLatitude(Double.valueOf(split[1])); |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | | if (distanceAndDuration.getCode() == 200) { |
| | | // 送驾- 接驾 |
| | |
| | | lonLatDto1.setLongitude(Double.valueOf(split[0])); |
| | | lonLatDto1.setLatitude(Double.valueOf(split[1])); |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | | if (distanceAndDuration.getCode() == 200) { |
| | | // 送驾- 接驾 |
| | |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | |
| | | // 算出总分 再来排序计算 |
| | | for (VehiclePositionVo vehiclePositionVo : availableVehiclesNearby) { |
| | | vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()); |
| | | vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()+vehiclePositionVo.getSecond()+vehiclePositionVo.getDistance().intValue()); |
| | | } |
| | | availableVehiclesNearby = availableVehiclesNearby.stream().sorted(Comparator.comparing(VehiclePositionVo::getOrderValueTotal).reversed()).collect(Collectors.toList()); |
| | | |
| | |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | lonLatDto1.setLongitude(Double.valueOf(split[0])); |
| | | lonLatDto1.setLatitude(Double.valueOf(split[1])); |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | | if (distanceAndDuration.getCode() == 200) { |
| | | // 送驾- 接驾 |
| | |
| | | lonLatDto1.setLongitude(Double.valueOf(split[0])); |
| | | lonLatDto1.setLatitude(Double.valueOf(split[1])); |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | R<RouteVo> distanceAndDuration = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | | if (distanceAndDuration.getCode() == 200) { |
| | | // 送驾- 接驾 |
| | |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | LonLatDto lonLatDto1 = new LonLatDto(); |
| | | lonLatDto1.setLongitude(Double.parseDouble(split[0])); |
| | | lonLatDto1.setLatitude(Double.parseDouble(split[1])); |
| | | |
| | | if(planRule!=null&& !"null".equals(planRule)){ |
| | | routeAndFareDto.setRoutePlanRule(Integer.valueOf(planRule)); |
| | | } |
| | | routeAndFareDto.setDestination(lonLatDto1); |
| | | // 调用地图 获取时间 |
| | | R<RouteVo> r = xpMapClient.getDistanceAndDuration(routeAndFareDto); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // 算出总分 再来排序计算 |
| | | for (VehiclePositionVo vehiclePositionVo : availableVehiclesNearby) { |
| | | vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()); |
| | | vehiclePositionVo.setOrderValueTotal(vehiclePositionVo.getCurrentElectricityScore() + vehiclePositionVo.getDistanceScore() + vehiclePositionVo.getTimeScore() + vehiclePositionVo.getDistanceDifference() + vehiclePositionVo.getTimeDifference()+vehiclePositionVo.getSecond()+vehiclePositionVo.getDistance().intValue()); |
| | | } |
| | | availableVehiclesNearby = availableVehiclesNearby.stream().sorted(Comparator.comparing(VehiclePositionVo::getOrderValueTotal).reversed()).collect(Collectors.toList()); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | log.error("异常", e); |
| | | } |
| | | |
| | | // 判断总分来计算 |
| | |
| | | XpVehicle vehiclePosition = vehiclePositionR.getData(); |
| | | log.info("符合条件的车辆 {} ,直接推单XPU。单号 {}", vehiclePosition.getPlateNumber(), orderNo); |
| | | log.info("当前车辆状态 {} 单号 {}", vehiclePosition.getStatus(), orderNo); |
| | | if (vehiclePosition.getStatus() != 1 || vehiclePosition.getState() != 0 || vehiclePosition.getVehicleType()==1) { |
| | | if (vehiclePosition.getOperatingStatus() != 1 || vehiclePosition.getState() != 0 || vehiclePosition.getVehicleType() == 1) { |
| | | continue; |
| | | } |
| | | // 关闭巡游单子 |
| | |
| | | orderMissionClient.pushOrder(pushOrderDto); |
| | | log.info("开始推送 {} 订单到XPU。单号 {}", xpOrder.getOrderNumber(), orderNo); |
| | | |
| | | redisService.popFirstElement(quoteName); |
| | | redisService.removeByPattern(quoteName,xpOrder.getOrderNumber()); |
| | | log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); |
| | | return true; |
| | | } catch (Exception e) { |
| | |
| | | |
| | | } else { |
| | | // 直接派单 定义一个锁来锁定车辆 |
| | | VehiclePosition vehiclePosition = positionList.get(0); |
| | | VehiclePositionVo vehiclePosition = availableVehiclesNearby.get(0); |
| | | String vehicleVin = vehiclePosition.getVin(); |
| | | |
| | | RLock lock = redissonClient.getLock("FIND_CAR_" + vehiclePosition.getVin()); |
| | |
| | | log.info("开始推送 {} 订单到XPU", xpOrder.getOrderNumber()); |
| | | redisService.popFirstElement(quoteName); |
| | | log.info("将订单 {} 从队列 {} 弹出去", orderNo, quoteName); |
| | | //判断还原车辆状态 |
| | | Object cacheObject = redisService.getCacheObject("CREATE_ORDER:" + xpOrder.getId().toString()); |
| | | if(null != cacheObject){ |
| | | JSONObject jsonObject = JSON.parseObject(cacheObject.toString()); |
| | | String vin = jsonObject.getString("vin"); |
| | | XpVehicle vehicle = xpVehicleClient.findByVehicleVin(vin).getData(); |
| | | if(null != vehicle && 0 != vehicle.getState()){ |
| | | vehicle.setState(0); |
| | | xpVehicleClient.updateVehicleById(vehicle); |
| | | } |
| | | } |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |