|
@@ -7,10 +7,12 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.kym.common.config.EnPlusConfig;
|
|
import com.kym.common.config.EnPlusConfig;
|
|
|
import com.kym.common.constant.ResponseEnum;
|
|
import com.kym.common.constant.ResponseEnum;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
import com.kym.common.exception.BusinessException;
|
|
|
|
|
+import com.kym.common.utils.CommUtil;
|
|
|
import com.kym.common.utils.OrderUtils;
|
|
import com.kym.common.utils.OrderUtils;
|
|
|
import com.kym.entity.admin.EquipmentInfo;
|
|
import com.kym.entity.admin.EquipmentInfo;
|
|
|
import com.kym.entity.enplus.response.EnBusinessPolicy;
|
|
import com.kym.entity.enplus.response.EnBusinessPolicy;
|
|
|
import com.kym.entity.miniapp.ChargeOrder;
|
|
import com.kym.entity.miniapp.ChargeOrder;
|
|
|
|
|
+import com.kym.entity.miniapp.delay.DelayChargeOrder;
|
|
|
import com.kym.service.admin.EquipmentInfoService;
|
|
import com.kym.service.admin.EquipmentInfoService;
|
|
|
import com.kym.service.admin.EquipmentRelationService;
|
|
import com.kym.service.admin.EquipmentRelationService;
|
|
|
import com.kym.service.enplus.EnPlusService;
|
|
import com.kym.service.enplus.EnPlusService;
|
|
@@ -20,6 +22,8 @@ import com.kym.service.miniapp.ChargeService;
|
|
|
import com.kym.service.miniapp.DelayService;
|
|
import com.kym.service.miniapp.DelayService;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
@@ -49,18 +53,22 @@ public class ChargeServiceImpl implements ChargeService {
|
|
|
|
|
|
|
|
private final EnPlusConfig enPlusConfig;
|
|
private final EnPlusConfig enPlusConfig;
|
|
|
|
|
|
|
|
- private final DelayService<ChargeOrder> delayService;
|
|
|
|
|
|
|
+ private final DelayService<DelayChargeOrder> startDelayService;
|
|
|
|
|
+ private final DelayService<DelayChargeOrder> stopDelayService;
|
|
|
|
|
|
|
|
public ChargeServiceImpl(EquipmentRelationService equipmentRelationService, EquipmentInfoService equipmentInfoService,
|
|
public ChargeServiceImpl(EquipmentRelationService equipmentRelationService, EquipmentInfoService equipmentInfoService,
|
|
|
ChargeOrderService chargeOrderService, AccountService accountService,
|
|
ChargeOrderService chargeOrderService, AccountService accountService,
|
|
|
- EnPlusService enPlusService, EnPlusConfig enPlusConfig, @Lazy DelayService<ChargeOrder> delayService) {
|
|
|
|
|
|
|
+ EnPlusService enPlusService, EnPlusConfig enPlusConfig,
|
|
|
|
|
+ @Qualifier("startDelayServiceImpl") @Lazy DelayService<DelayChargeOrder> startDelayService,
|
|
|
|
|
+ @Qualifier("stopDelayServiceImpl") @Lazy DelayService<DelayChargeOrder> stopDelayService) {
|
|
|
this.equipmentRelationService = equipmentRelationService;
|
|
this.equipmentRelationService = equipmentRelationService;
|
|
|
this.equipmentInfoService = equipmentInfoService;
|
|
this.equipmentInfoService = equipmentInfoService;
|
|
|
this.chargeOrderService = chargeOrderService;
|
|
this.chargeOrderService = chargeOrderService;
|
|
|
this.accountService = accountService;
|
|
this.accountService = accountService;
|
|
|
this.enPlusService = enPlusService;
|
|
this.enPlusService = enPlusService;
|
|
|
this.enPlusConfig = enPlusConfig;
|
|
this.enPlusConfig = enPlusConfig;
|
|
|
- this.delayService = delayService;
|
|
|
|
|
|
|
+ this.startDelayService = startDelayService;
|
|
|
|
|
+ this.stopDelayService = stopDelayService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -74,11 +82,18 @@ public class ChargeServiceImpl implements ChargeService {
|
|
|
public Map<String, String> immediatelyCharge(String connectorId) {
|
|
public Map<String, String> immediatelyCharge(String connectorId) {
|
|
|
var userId = StpUtil.getLoginIdAsLong();
|
|
var userId = StpUtil.getLoginIdAsLong();
|
|
|
// 修改订单状态,取消预约
|
|
// 修改订单状态,取消预约
|
|
|
- chargeOrderService.lambdaUpdate()
|
|
|
|
|
- .set(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_未知)
|
|
|
|
|
|
|
+ var chargeOrder = chargeOrderService.lambdaQuery()
|
|
|
|
|
+// .set(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_未知)
|
|
|
.eq(ChargeOrder::getConnectorId, connectorId)
|
|
.eq(ChargeOrder::getConnectorId, connectorId)
|
|
|
.eq(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_预约中)
|
|
.eq(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_预约中)
|
|
|
- .update();
|
|
|
|
|
|
|
+ .one();
|
|
|
|
|
+ // TODO 预约充电启动和停止队列删除数据
|
|
|
|
|
+ var delayOrder = new DelayChargeOrder();
|
|
|
|
|
+ BeanUtils.copyProperties(chargeOrder, delayOrder);
|
|
|
|
|
+ startDelayService.removeFromOrderDelayQueue(delayOrder);
|
|
|
|
|
+ if (delayOrder.getEndTime() != null) {
|
|
|
|
|
+ stopDelayService.removeFromOrderDelayQueue(delayOrder);
|
|
|
|
|
+ }
|
|
|
return queryStartCharge(userId, connectorId, false, null);
|
|
return queryStartCharge(userId, connectorId, false, null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -92,8 +107,12 @@ public class ChargeServiceImpl implements ChargeService {
|
|
|
@Override
|
|
@Override
|
|
|
public void modifyBookingTime(String startChargeSeq, LocalDateTime startTime) {
|
|
public void modifyBookingTime(String startChargeSeq, LocalDateTime startTime) {
|
|
|
// 预约充电队列更新
|
|
// 预约充电队列更新
|
|
|
- var chargeOrder = chargeOrderService.getChargingOrderByStartChargeSeq(startChargeSeq);
|
|
|
|
|
- boolean success = delayService.removeToOrderDelayQueue(chargeOrder);
|
|
|
|
|
|
|
+ var chargeOrder = chargeOrderService.lambdaQuery().eq(ChargeOrder::getStartChargeSeq, startChargeSeq)
|
|
|
|
|
+ .eq(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_预约中).one();
|
|
|
|
|
+ var delayChargeOrder = new DelayChargeOrder();
|
|
|
|
|
+ BeanUtils.copyProperties(chargeOrder, delayChargeOrder);
|
|
|
|
|
+ boolean success = CommUtil.isNotEmptyAndNull(chargeOrder.getEndTime()) ?
|
|
|
|
|
+ startDelayService.removeFromOrderDelayQueue(delayChargeOrder) : stopDelayService.removeFromOrderDelayQueue(delayChargeOrder);
|
|
|
if (!success) {
|
|
if (!success) {
|
|
|
throw new BusinessException("修改预约时间失败");
|
|
throw new BusinessException("修改预约时间失败");
|
|
|
}
|
|
}
|
|
@@ -170,15 +189,26 @@ public class ChargeServiceImpl implements ChargeService {
|
|
|
// 如果是预约订单,则将订单放入预约充电延迟队列
|
|
// 如果是预约订单,则将订单放入预约充电延迟队列
|
|
|
if (isBooking) {
|
|
if (isBooking) {
|
|
|
order = order.setStartTime(startTime).setChargeStatus(ChargeOrder.CHARGE_STATUS_预约中);
|
|
order = order.setStartTime(startTime).setChargeStatus(ChargeOrder.CHARGE_STATUS_预约中);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO: 2023-10-21 如果有设置结束时间,取消时记得删
|
|
|
|
|
+ var endTime = LocalDateTime.now();
|
|
|
|
|
+ order.setEndTime(endTime);
|
|
|
|
|
+
|
|
|
chargeOrderService.lambdaUpdate()
|
|
chargeOrderService.lambdaUpdate()
|
|
|
.set(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_预约中)
|
|
.set(ChargeOrder::getChargeStatus, ChargeOrder.CHARGE_STATUS_预约中)
|
|
|
.set(ChargeOrder::getStartTime, startTime)
|
|
.set(ChargeOrder::getStartTime, startTime)
|
|
|
|
|
+ .set(CommUtil.isNotEmptyAndNull(endTime), ChargeOrder::getEndTime, endTime)
|
|
|
.eq(ChargeOrder::getStartChargeSeq, order.getStartChargeSeq())
|
|
.eq(ChargeOrder::getStartChargeSeq, order.getStartChargeSeq())
|
|
|
.update();
|
|
.update();
|
|
|
- var flag = delayService.addToDelayQueue(order.setStartTime(startTime));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ var delayChargeOrder = new DelayChargeOrder();
|
|
|
|
|
+ BeanUtils.copyProperties(order, delayChargeOrder);
|
|
|
|
|
+
|
|
|
|
|
+ var flag = startDelayService.addToDelayQueue(delayChargeOrder.setStartTime(startTime));
|
|
|
if (flag) {
|
|
if (flag) {
|
|
|
- // 修改设备状态为预约中
|
|
|
|
|
- // 切换数据源
|
|
|
|
|
|
|
+ // 如果有结束时间,将订单放入结束充电延迟队列中
|
|
|
|
|
+ stopDelayService.addToDelayQueue(delayChargeOrder.setEndTime(endTime));
|
|
|
|
|
+ // 切换数据源,修改设备状态为预约中
|
|
|
updateEquipmentStatus(connectorId);
|
|
updateEquipmentStatus(connectorId);
|
|
|
LOGGER.info("预约充电成功,用户:{},订单号:{}", userId, order.getStartChargeSeq());
|
|
LOGGER.info("预约充电成功,用户:{},订单号:{}", userId, order.getStartChargeSeq());
|
|
|
return Map.of("startChargeSeq", order.getStartChargeSeq());
|
|
return Map.of("startChargeSeq", order.getStartChargeSeq());
|