| | |
| | | final BigDecimal totalElec = totalElectricity; |
| | | final BigDecimal elecTotal = electrovalenceTotal; |
| | | final BigDecimal svcTotal = serviceChargeTotal; |
| | | final BigDecimal startSoc = getMonitoringSocQuietly(code, "asc"); |
| | | final BigDecimal endSoc = getMonitoringSocQuietly(code, "desc"); |
| | | |
| | | // 本地事务:写计费明细 + 更新订单(状态5;VD后付记账模式,不做账户扣款) |
| | | transactionTemplate.execute(status -> { |
| | |
| | | update.setServiceCharge(svcTotal); |
| | | update.setOrderAmount(orderAmount); |
| | | update.setPaymentAmount(orderAmount); |
| | | if (startSoc != null) { |
| | | update.setStartSoc(startSoc); |
| | | } |
| | | if (endSoc != null) { |
| | | update.setEndSoc(endSoc); |
| | | } |
| | | update.setEndTime(parseDeviceTime(vo.getEnd_time(), LocalDateTime.now())); |
| | | if (order.getStartTime() == null) { |
| | | update.setStartTime(parseDeviceTime(vo.getStart_time(), null)); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 容错读取订单最早/最新监控记录的 SOC;Mongo 数据缺失或查询异常不阻断主结算流程。 |
| | | */ |
| | | private BigDecimal getMonitoringSocQuietly(String code, String sort) { |
| | | if (monitoringDataService == null) { |
| | | return null; |
| | | } |
| | | try { |
| | | UploadRealTimeMonitoringData monitoringData = monitoringDataService.getDataByOrderCode(code, sort); |
| | | return monitoringData == null || monitoringData.getSoc() == null |
| | | ? null : BigDecimal.valueOf(monitoringData.getSoc().longValue()); |
| | | } catch (Exception ex) { |
| | | log.error("[VD结算] 查询监控SOC失败 code={} sort={}", code, sort, ex); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private LocalDateTime parseDeviceTime(String value, LocalDateTime fallback) { |
| | | if (StringUtils.isEmpty(value)) { |
| | | return fallback; |