From 45eed997edda0209d779bb90735f842d62e67788 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Wed, 29 May 2024 18:18:40 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=A2=84=E7=BA=A6=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/system/domain/EtOrder.java | 3 ++ .../service/impl/AsDeviceServiceImpl.java | 28 +++++++++++++------ .../resources/mapper/system/EtOrderMapper.xml | 8 +++++- 3 files changed, 30 insertions(+), 9 deletions(-) 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 23cdfbe..c46689c 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 @@ -206,4 +206,7 @@ public class EtOrder extends BaseEntity @TableField(exist = false) private String latitude; + /** 1-预约超时,系统自动取消 */ + private String appointmentTimeout; + } 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 630ca20..5b40ce2 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 @@ -42,6 +42,7 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /** @@ -66,12 +67,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Autowired private IEtOrderService etOrderService; - @Autowired - private ISysConfigService sysConfigService; - - @Autowired - private IEtAdminOrderService etAdminOrderService; - @Autowired private IEtFeeRuleService etFeeRuleService; @@ -87,7 +82,8 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Resource private IEtModelService etModelService; - + @Autowired + private ScheduledExecutorService scheduledExecutorService; @Value(value = "${iot.iotUrl}") private String iotUrl; @@ -752,12 +748,13 @@ public class AsDeviceServiceImpl extends ServiceImpl i /** * 车辆预约 */ + @Transactional @Override public OrderResponse deviceAppointment(EtOrderVo appointmentVo) { OrderResponse orderResponse = new OrderResponse(); String orderNo = IdUtils.randomUUID2(); AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(appointmentVo.getSn()); - //如果是正常计费模式,则按正常的订单走 + //创建订单 EtOrder order = etOrderService.createOrder(appointmentVo, orderNo); int i = etOrderService.insertEtOrder(order); if(i==0){ @@ -765,11 +762,26 @@ public class AsDeviceServiceImpl extends ServiceImpl i } orderResponse.setOrderNo(orderNo); orderResponse.setSessionId(IdUtils.randomUUIDByDigit(8)); + //改变车辆状态 asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_IN_APPOINTMENT); int u = asDeviceMapper.updateAsDevice(asDevice); if(u==0){ throw new ServiceException("【车辆预约】:更新车辆状态失败"); } + + EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId()); + int delay = 60 * area.getTimeoutMinutes(); + //定时取消预约 + scheduledExecutorService.schedule(() -> { + //订单更新最后预约时间,并结束订单,做超出预约时间标记 + order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT); + order.setAppointmentEndTime(new Date()); + order.setAppointmentTimeout("1"); + int update = etOrderService.updateEtOrder(order); + if(update==0){ + throw new ServiceException("【车辆预约】:更新订单状态失败"); + } + }, delay, TimeUnit.SECONDS); return orderResponse; } diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml index 894fcbe..5b2be60 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml @@ -29,6 +29,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -41,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select order_id, area_id, order_no, out_trade_no, user_id, rule_id, device_mac, sn, pay_time, paid, pay_type, type, total_fee, dispatch_fee, manage_fee, riding_fee, appointment_fee, mark, duration, distance, status, - create_time, appointment_start_time, appointment_end_time, unlock_time,return_time, rule_end_time, return_type, AsText(trip_route) trip_route,trip_route_str from et_order + create_time, appointment_start_time, appointment_end_time,appointment_timeout, unlock_time,return_time, rule_end_time, return_type, AsText(trip_route) trip_route,trip_route_str from et_order