| | |
| | | import com.xiaopeng.operation.utils.mango.VehiclePositionService; |
| | | import com.xiaopeng.api.vo.operation.VehiclePositionVo; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class TaskOrderUtil { |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 订单处理 |
| | | * @param count 轮数 |
| | | * @param uid |
| | | * @param longitude 经度 |
| | | * @param latitude 纬度 |
| | | * @param orderNo 订单号 |
| | | */ |
| | | @SneakyThrows |
| | | public void reassignPushOrder(int count, String uid, Double longitude, Double latitude, String orderNo) { |
| | | System.out.println("进入推单环环节"); |
| | | if(count==0){ |
| | | count=1; |
| | | } |
| | | // 订单状态 |
| | | R<XpOrder> xpOrderR = xpOrderClient.queryOrderByOrderNo(orderNo); |
| | | if (xpOrderR.getCode() != 200) { |
| | | return; |
| | | } |
| | | if (xpOrderR.getData().getStatus() != 1) { |
| | | return; |
| | | } |
| | | XpTradingStrategy xpTradingStrategy = xpTradingStrategyService.getOne(null); |
| | | for (int i = 0; i < count; i++) { |
| | | log.info("进入找车环节"); |
| | | List<VehiclePosition> positionList = vehiclePositionService.findAvailableVehiclesNearby(longitude, latitude, xpTradingStrategy.getOnePushDistance(), xpTradingStrategy.getSimultaneouslyOrderCount()); |
| | | |
| | | // 获取车辆的区域信息 |
| | | if (positionList.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | // 直接派单 定义一个锁来锁定车辆 |
| | | VehiclePosition vehiclePosition = positionList.get(0); |
| | | String vehicleVin = vehiclePosition.getVin(); |
| | | |
| | | RLock lock = redissonClient.getLock("FIND_CAR_" + vehiclePosition.getVin()); |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | try { |
| | | // 查询车辆状态 |
| | | R<XpVehicle> vehicleR = xpVehicleClient.findByVehicleVin(vehicleVin); |
| | | if(vehicleR.getCode()!=200){ |
| | | continue; |
| | | } |
| | | XpVehicle vehicleId1 = vehicleR.getData(); |
| | | if (vehicleId1.getStatus() != 1 || vehicleId1.getState() != 0) { |
| | | lock.unlock(); |
| | | continue; |
| | | } |
| | | if (vehiclePosition.getHasOrder() == 1) { |
| | | // 关闭巡游单子 TODO |
| | | } |
| | | AddTaxiPassengerVo addTaxiPassengerVo = new AddTaxiPassengerVo(); |
| | | addTaxiPassengerVo.setVin(vehiclePosition.getVin()); |
| | | addTaxiPassengerVo.setUid(uid); |
| | | addTaxiPassengerVo.setOrderNo(orderNo); |
| | | // TODO appid |
| | | addTaxiPassengerVo.setAppId(""); |
| | | BaseVehicleUserDto baseVehicleUserDto = userVehicleClient.addTaxiPassenger(addTaxiPassengerVo); |
| | | if (baseVehicleUserDto.getCode() == 200) { |
| | | lock.unlock(); |
| | | return; |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } finally { |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |