yanderong
4 天以前 7617d46abee2950b7336e3379f8c7a564939cb54
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TVinChargingOrderServiceImpl.java
@@ -251,10 +251,10 @@
            page.setRecords(Collections.emptyList());
            return page;
        }
        long total = baseMapper.countAppletOrders(vinIds);
        long total = baseMapper.countAppletOrders(appUserId, vinIds);
        page.setTotal(total);
        List<MyVinChargingOrderList> records = total == 0 ? Collections.emptyList()
                : baseMapper.pageAppletOrders(vinIds, (long) (current - 1) * size, size);
                : baseMapper.pageAppletOrders(appUserId, vinIds, (long) (current - 1) * size, size);
        fillAppletExtra(records);
        page.setRecords(records);
        return page;
@@ -482,7 +482,9 @@
                tokenService.getLoginUserApplet().getUserId());
        List<Long> vinIds = response == null ? Collections.emptyList()
                : Optional.ofNullable(response.getData()).orElse(Collections.emptyList());
        return vinIds.contains(order.getVinId()) ? order : null;
        // VIN 可换绑:除校验 VIN 当前归属外,还必须校验订单下单用户与当前登录用户一致,防止新绑定用户查看他人历史订单
        Long appUserId = tokenService.getLoginUserApplet().getUserId();
        return vinIds.contains(order.getVinId()) && appUserId.equals(order.getAppUserId()) ? order : null;
    }
    private Long toEpochMilli(LocalDateTime time) {
@@ -901,6 +903,8 @@
                accountUpdate.setAccountMode(chargeContext.getAccountMode());
                accountUpdate.setLockedAmount(chargeContext.getDispatchAmount());
                accountUpdate.setMaxEndTime(chargeContext.getMaxEndTime());
                // 企业优惠快照落库(建单时固化,结算/补偿优先读快照,抵抗公司优惠设置后续变更)
                chargeAccountSupport.fillPreferentialSnapshot(accountUpdate, vinRecord.getCompanyId());
                updateById(accountUpdate);
                // 同步内存对象,保证后续失败回滚能按账户模式/锁定额释放额度
                order.setAccountMode(chargeContext.getAccountMode());
@@ -1150,20 +1154,6 @@
    private PeriodTypeWindow findCurrentPeriodType(Integer strategyId, LocalTime current) {
        ChargeAccountSupport.PeriodTypeWindow period = chargeAccountSupport.findCurrentPeriodType(strategyId, current);
        return period == null ? null : new PeriodTypeWindow(period.getType(), period.getEndTime());
    }
    /**
     * 查询企业优惠设置(失败或未配置返回 null,按不优惠结算;实现见公共支持类)
     */
    private CompanyPreferentialDTO loadCompanyPreferential(Integer companyId) {
        return chargeAccountSupport.loadCompanyPreferential(companyId);
    }
    /**
     * 按优惠方式加载计费模板(仅方式3需要,取不到时该段按原价结算;实现见公共支持类)
     */
    private TBillingTemplateDTO loadBillingTemplate(CompanyPreferentialDTO preferential) {
        return chargeAccountSupport.loadBillingTemplate(preferential);
    }
    /**
@@ -1528,9 +1518,10 @@
        snapshots.sort(Comparator.comparing(TVinAccountingStrategyDetailOrder::getStartTime,
                Comparator.nullsLast(String::compareTo)));
        // 企业优惠设置与计费模板(1=不优惠,2=服务费按比例优惠,3=按计费模板优惠单价收费)
        CompanyPreferentialDTO preferential = loadCompanyPreferential(order.getCompanyId());
        TBillingTemplateDTO billingTemplate = loadBillingTemplate(preferential);
        // 企业优惠设置与计费模板(1=不优惠,2=服务费按比例优惠,3=按计费模板优惠单价收费):
        // 订单快照优先(建单时固化,策略后续变更不影响本单结算口径),快照为空的历史订单实时查询并在本事务回填
        ChargeAccountSupport.PreferentialSnapshot preferential = chargeAccountSupport.resolvePreferential(order);
        TBillingTemplateDTO billingTemplate = preferential == null ? null : preferential.getTemplate();
        BigDecimal electrovalenceTotal = BigDecimal.ZERO;
        BigDecimal serviceChargeTotal = BigDecimal.ZERO;
@@ -1630,6 +1621,8 @@
        final BigDecimal discountSvcTotal = discountServiceTotal;
        final BigDecimal startSoc = getMonitoringSocQuietly(code, "asc");
        final BigDecimal endSoc = getMonitoringSocQuietly(code, "desc");
        final ChargeAccountSupport.PreferentialSnapshot preferentialSnapshot = preferential;
        final boolean preferentialBackfill = preferentialSnapshot != null && preferentialSnapshot.needBackfill();
        // 本地事务:写计费明细 + 更新订单(状态5;账户结算在事务外执行,避免长事务占用链接)
        transactionTemplate.execute(status -> {
@@ -1663,6 +1656,15 @@
            if (order.getEndMode() == null) {
                update.setEndMode(1);
            }
            if (preferentialBackfill) {
                // 历史订单(快照为空)实时查询结果回填订单快照列,保证后续补偿重算口径一致
                update.setPreferentialType(preferentialSnapshot.getPreferentialType());
                update.setServiceDiscountRate(preferentialSnapshot.getServiceDiscountRate());
                update.setBillingTemplateId(preferentialSnapshot.getBillingTemplateId());
                update.setBillingTemplateSnapshot(
                        ChargeAccountSupport.serializeTemplateSnapshot(preferentialSnapshot.getTemplate()));
                update.setPreferentialSnapshotTime(LocalDateTime.now());
            }
            updateById(update);
            return true;
        });