| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | * |
| | | * @param c3Mac |
| | | */ |
| | | public String finishCharging(String c3Mac) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public String finishCharging(String c3Mac, String openId) { |
| | | //查询 |
| | | if (openId.isEmpty()) { |
| | | throw new BusinessException("openId不能为空"); |
| | | } |
| | | //查询该充电桩最近的订单 |
| | | C3mOrder order = SpringContextHolder.getBean(C3mOrderService.class).getOne(Wrappers.lambdaQuery(C3mOrder.class) |
| | | .eq(C3mOrder::getC3Mac, c3Mac).eq(C3mOrder::getChargingStates, 0).last("limit 1")); |
| | | |
| | | if (order == null) { |
| | | throw new BusinessException("充电桩没有进行中的订单"); |
| | | } |
| | | if (!openId.equals(order.getOrderId())) { |
| | | throw new BusinessException("不能操作不属于您的订单"); |
| | | } |
| | | |
| | | C3FinishChargingReqInnerFrame c3FinishChargingReqInnerFrame = |
| | | new C3FinishChargingReqInnerFrame(c3Mac); |
| | |
| | | //结束充电 更改订单状态 |
| | | C3mOrder lastOrderByC3Mac = SpringContextHolder.getBean(C3mOrderService.class).getLastOrderByC3Mac(c3Mac); |
| | | if (lastOrderByC3Mac != null) { |
| | | //设置订单状态为已完成 |
| | | lastOrderByC3Mac.setOrderStatus(OrderStatus.COMPLETE.getStatus()); |
| | | |
| | | BigDecimal actualChargingCapacity = BigDecimal.valueOf(lastOrderByC3Mac.getActualChargingCapacity()); |
| | | BigDecimal actualChargingCapacityHide = BigDecimal.valueOf(lastOrderByC3Mac.getActualChargingCapacityHide()); |
| | | //设置实际充电电量 |
| | | lastOrderByC3Mac.setActualChargingCapacity(actualChargingCapacity.add(actualChargingCapacityHide).doubleValue()); |
| | | //设置订单结束时间 |
| | | lastOrderByC3Mac.setStopChargingTimestamp(System.currentTimeMillis()); |
| | | lastOrderByC3Mac.setActualChargingCapacity(0.00); |
| | | //设置订单状态为充电结束 |
| | | lastOrderByC3Mac.setChargingStates(1); |
| | | SpringContextHolder.getBean(C3mOrderService.class).updateById(lastOrderByC3Mac); |
| | | } |
| | | if (operationReportInnerFrame.isValidate()) { |