| | |
| | | package com.xiaopeng.operation.utils; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.xiaopeng.api.dto.automaticPilot.PushOrderDto; |
| | |
| | | import com.xiaopeng.api.vo.automaticPilot.protobuf.TaskActionType; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | | import com.xiaopeng.api.vo.operation.VehiclePositionVo; |
| | | import com.xiaopeng.api.vo.operation.XpTargetedServiceVehicleVo; |
| | | import com.xiaopeng.api.vo.operation.XpTradingStrategyDetailVO; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.constant.Constants; |
| | |
| | | import com.xiaopeng.operation.config.UidVinBindingConfig; |
| | | import com.xiaopeng.operation.dto.PriorityMatchResult; |
| | | import com.xiaopeng.operation.mapper.XpElectronicFenceMapper; |
| | | import com.xiaopeng.operation.service.IXpElectronicFenceAreaService; |
| | | import com.xiaopeng.operation.service.IXpTradingStrategyService; |
| | | import com.xiaopeng.operation.service.UidVinPriorityMatcher; |
| | | import com.xiaopeng.operation.service.XpPointService; |
| | | import com.xiaopeng.operation.service.*; |
| | | import com.xiaopeng.operation.utils.mango.VehiclePositionService; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | public class TaskOrderUtil { |
| | | |
| | | |
| | | @Resource |
| | | XpTargetedServiceService xpTargetedServiceService; |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | |
| | | |
| | | /** |
| | | * 5秒执行一次 |
| | | * 播单 |
| | | * 播单 在下单的时候会存一个 redis 队列 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | public void taskOrder() { |
| | |
| | | for (String name : quoteMatchName) { |
| | | String firstElement = redisService.getFirstElement(name); |
| | | if (firstElement != null) { |
| | | String[] split = firstElement.toString().split("_"); |
| | | String[] split = firstElement.split("_"); |
| | | if(split.length>8){ |
| | | String targetedVal = split[8]; |
| | | if (!"0".equals(targetedVal)) { |
| | | continue; |
| | | } |
| | | } |
| | | // 如果未处理 创建新任务 |
| | | if (split[2].equals("0")) { |
| | | if ("0".equals(split[2])) { |
| | | String value = split[0] + "_" + split[1] + "_1" + "_" + split[3] + "_" + split[4] + "_" + split[5] + "_" + split[6] + "_" + split[7]; |
| | | // 状态改为处理中 |
| | | redisService.updateFirst(name, value); |
| | | threadPoolTaskExecutor.submit(() -> { |
| | | orderProcess(name, firstElement.toString()); |
| | | orderProcess(name, firstElement); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 定向订单 |
| | | */ |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | public void taskOrder_targeted() { |
| | | System.out.println("5秒执行一次"); |
| | | Set<String> quoteMatchName = redisService.getQuoteMatchName(CacheConstants.QUEUE_POINT_ID); |
| | | for (String name : quoteMatchName) { |
| | | String firstElement = redisService.getFirstElement(name); |
| | | if (firstElement != null) { |
| | | String[] split = firstElement.split("_"); |
| | | if(split.length>8){ |
| | | String targetedVal = split[8]; |
| | | if (!"0".equals(targetedVal)) { |
| | | // 如果未处理 创建新任务 |
| | | if ("0".equals(split[2])) { |
| | | String value = split[0] + "_" + split[1] + "_1" + "_" + split[3] + "_" + split[4] + "_" + split[5] + "_" + split[6] + "_" + split[7]; |
| | | // 状态改为处理中 |
| | | redisService.updateFirst(name, value); |
| | | threadPoolTaskExecutor.submit(() -> { |
| | | orderProcess(name, firstElement); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | log.info("[人车订单绑定测试] 总开关未开启(enabled=false), 跳过优先匹配, uid={}, orderNo={}", uid, orderNo); |
| | | } |
| | | // ===== 新增结束 ===== |
| | | |
| | | //根据 用户id 和 城市编码 查询 定向服务的 车辆信息 |
| | | List<String> targetedServiceVehicleVinList = xpTargetedServiceService.findSetVehicleVinByUserIdAndCityCode(xpOrder.getAppUserId(), xpOrder.getCityCode()); |
| | | for (int i = 0; i < count; i++) { |
| | | //等到sleepTime秒钟 |
| | | Thread.sleep(sleepTime * 1000); |
| | |
| | | if (vehiclePositionVos.getCode() != 200) { |
| | | continue; |
| | | } |
| | | List<VehiclePositionVo> availableVehiclesNearby = BeanUtil.copyToList(positionList, VehiclePositionVo.class); |
| | | List<String> data = vehiclePositionVos.getData(); |
| | | List<String> data = vehiclePositionVos.getData(); //指定区域的车 |
| | | // 计算交集:指定区域的车辆 与 定向服务车辆列表的交集 |
| | | if (targetedServiceVehicleVinList != null && !targetedServiceVehicleVinList.isEmpty() && data != null) { |
| | | Collection<String> newVehicleVinList = CollUtil.intersection(data,targetedServiceVehicleVinList); |
| | | if(CollUtil.isNotEmpty(newVehicleVinList)){ |
| | | data = (List<String>) newVehicleVinList; |
| | | } |
| | | } |
| | | |
| | | List<VehiclePositionVo> availableVehiclesNearby = BeanUtil.copyToList(positionList, VehiclePositionVo.class); |
| | | // 找出符合条件的 |
| | | availableVehiclesNearby = availableVehiclesNearby.stream().filter(e -> data.contains(e.getVin())).collect(Collectors.toList()); |
| | | List<String> finalData = data; |
| | | availableVehiclesNearby = availableVehiclesNearby.stream().filter(e -> finalData.contains(e.getVin())).collect(Collectors.toList()); |
| | | // List<VehiclePositionVo> availableVehiclesNearby =vehiclePositionVos.getData(); |
| | | |
| | | if (!availableVehiclesNearby.isEmpty()) { |
| | |
| | | XpOrderReassign entity = new XpOrderReassign(data.getId(),data.getVehicleId(),data.getFleetId(),longitude,latitude,"接驾故障"); |
| | | entity.setIsComplete(false); |
| | | entity.setAppUserId(Long.valueOf(uid)); |
| | | |
| | | // 根据城市编码获取 定向服务设置的车辆 |
| | | List<String> targetedServiceVehicleVinList = xpTargetedServiceService.findSetVehicleVinByUserIdAndCityCode(data.getAppUserId(), data.getCityCode()); |
| | | |
| | | //循环找车 |
| | | for (int i = 0; i < count; i++) { |
| | | log.info("进入找车环节"); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 直接派单 定义一个锁来锁定车辆 |
| | | VehiclePosition vehiclePosition = positionList.get(0); |
| | | if(CollUtil.isNotEmpty(targetedServiceVehicleVinList)){//定向服务获取的车 |
| | | for (VehiclePosition position : positionList) { |
| | | if(targetedServiceVehicleVinList.contains(position.getVin())){ |
| | | vehiclePosition = position; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | String vehicleVin = vehiclePosition.getVin(); |
| | | |
| | | |
| | | RLock lock = redissonClient.getLock("FIND_CAR_" + vehiclePosition.getVin()); |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | try { |