Quellcode durchsuchen

fix(pricing): 优化平台与企业价格计算逻辑

- 新增查询平台价格(salesType=0)用于普通用户价格计算
- 企业价格计算改为直接取综合销售费,无需累加电费等项
- 充电价合计改为显示平台综合销售费
- 服务费改为原服务费加上平台运营费
- 更新价格列表构建逻辑,区分平台与企业价格来源
- 调整相关字段注释,明确价格含义和计算依据
SheepHy vor 2 Tagen
Ursprung
Commit
7fcfdace85

+ 2 - 2
src/main/java/com/zsElectric/boot/business/model/vo/AppletStationPriceListVO.java

@@ -64,10 +64,10 @@ public class AppletStationPriceListVO implements Serializable {
         @Schema(description = "服务费(元/度)")
         private BigDecimal servicePrice;
 
-        @Schema(description = "合计充电价(元/度)= 电费 + 服务费")
+        @Schema(description = "合计充电价(元/度)= c_policy_fee.综合销售费")
         private BigDecimal totalPrice;
 
-        @Schema(description = "企业价格(元/度)= 电费 + 服务费 + 运营费 + 综合销售费")
+        @Schema(description = "企业价格(元/度)= c_policy_fee.综合销售费(sales_type=1)")
         private BigDecimal enterprisePrice;
 
         @Schema(description = "是否当前时段")

+ 39 - 27
src/main/java/com/zsElectric/boot/business/service/impl/AppletHomeServiceImpl.java

@@ -467,7 +467,20 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             return result;
         }
         
-        // 4. 如果是企业用户,查询企业价格
+        // 4. 查询平台价格(salesType=0),用于普通用户的价格计算
+        Map<Integer, PolicyFee> platformPriceMap = new HashMap<>();
+        List<PolicyFee> platformPolicyFeeList = policyFeeMapper.selectList(
+                new LambdaQueryWrapper<PolicyFee>()
+                        .eq(PolicyFee::getStationInfoId, stationId)
+                        .eq(PolicyFee::getSalesType, 0) // 0-平台
+                        .eq(PolicyFee::getIsDeleted, 0)
+        );
+        log.info("查询平台价格记录数: {}, stationInfoId: {}", platformPolicyFeeList.size(), stationId);
+        for (PolicyFee policyFee : platformPolicyFeeList) {
+            platformPriceMap.put(policyFee.getPeriodFlag(), policyFee);
+        }
+        
+        // 5. 如果是企业用户,查询企业价格
         Map<Integer, BigDecimal> enterprisePriceMap = new HashMap<>();
         boolean hasEnterprisePrice = false;
         if (firmId != null) {
@@ -489,26 +502,11 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             
             // 构建企业价格映射 (periodFlag -> enterprisePrice)
             for (PolicyFee policyFee : policyFeeList) {
-                // 查找对应的时段价格信息(通过periodFlag匹配)
-                ThirdPartyPolicyInfo matchedPolicyInfo = policyInfoList.stream()
-                        .filter(info -> info.getPeriodFlag() != null && info.getPeriodFlag().equals(policyFee.getPeriodFlag()))
-                        .findFirst()
-                        .orElse(null);
-                
-                if (matchedPolicyInfo != null) {
-                    // 企业价格 = 电费 + 服务费 + 运营费 + 综合销售费
-                    BigDecimal elecPrice = matchedPolicyInfo.getElecPrice() != null ? matchedPolicyInfo.getElecPrice() : BigDecimal.ZERO;
-                    BigDecimal servicePrice = matchedPolicyInfo.getServicePrice() != null ? matchedPolicyInfo.getServicePrice() : BigDecimal.ZERO;
-                    BigDecimal opFee = policyFee.getOpFee() != null ? policyFee.getOpFee() : BigDecimal.ZERO;
-                    BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
-                    
-                    BigDecimal enterprisePrice = elecPrice.add(servicePrice).add(opFee).add(compSalesFee);
-                    enterprisePriceMap.put(policyFee.getPeriodFlag(), enterprisePrice);
-                    log.debug("企业价格计算 - periodFlag: {}, 电费: {}, 服务费: {}, 运营费: {}, 综合销售费: {}, 企业价: {}",
-                            policyFee.getPeriodFlag(), elecPrice, servicePrice, opFee, compSalesFee, enterprisePrice);
-                } else {
-                    log.warn("未找到匹配的价格策略明细,periodFlag: {}", policyFee.getPeriodFlag());
-                }
+                // 企业价格 = 综合销售费(直接取c_policy_fee.comp_sales_fee)
+                BigDecimal compSalesFee = policyFee.getCompSalesFee() != null ? policyFee.getCompSalesFee() : BigDecimal.ZERO;
+                enterprisePriceMap.put(policyFee.getPeriodFlag(), compSalesFee);
+                log.debug("企业价格计算 - periodFlag: {}, 综合销售费(企业价): {}",
+                        policyFee.getPeriodFlag(), compSalesFee);
             }
         }
         
@@ -516,7 +514,7 @@ public class AppletHomeServiceImpl implements AppletHomeService {
         result.setHasEnterprisePrice(hasEnterprisePrice);
         log.info("是否有企业价格: {}", hasEnterprisePrice);
         
-        // 5. 构建价格列表
+        // 6. 构建价格列表
         List<AppletStationPriceListVO.PriceItemVO> priceList = new ArrayList<>();
         for (int i = 0; i < policyInfoList.size(); i++) {
             ThirdPartyPolicyInfo policyInfo = policyInfoList.get(i);
@@ -533,12 +531,26 @@ public class AppletHomeServiceImpl implements AppletHomeService {
             priceItem.setPeriodFlag(policyInfo.getPeriodFlag());
             priceItem.setPeriodFlagName(getPeriodFlagName(policyInfo.getPeriodFlag()));
             priceItem.setElecPrice(policyInfo.getElecPrice());
-            priceItem.setServicePrice(policyInfo.getServicePrice());
             
-            // 合计充电价 = 电费 + 服务费
-            BigDecimal elecPrice = policyInfo.getElecPrice() != null ? policyInfo.getElecPrice() : BigDecimal.ZERO;
-            BigDecimal servicePrice = policyInfo.getServicePrice() != null ? policyInfo.getServicePrice() : BigDecimal.ZERO;
-            priceItem.setTotalPrice(elecPrice.add(servicePrice));
+            // 从平台价格映射中获取运营费和综合销售费
+            BigDecimal originalServicePrice = policyInfo.getServicePrice() != null ? policyInfo.getServicePrice() : BigDecimal.ZERO;
+            BigDecimal platformOpFee = BigDecimal.ZERO;
+            BigDecimal platformCompSalesFee = BigDecimal.ZERO;
+            
+            PolicyFee platformPolicyFee = platformPriceMap.get(policyInfo.getPeriodFlag());
+            if (platformPolicyFee != null) {
+                platformOpFee = platformPolicyFee.getOpFee() != null ? platformPolicyFee.getOpFee() : BigDecimal.ZERO;
+                platformCompSalesFee = platformPolicyFee.getCompSalesFee() != null ? platformPolicyFee.getCompSalesFee() : BigDecimal.ZERO;
+            }
+            
+            // 服务费 = 原服务费 + 运营费
+            BigDecimal servicePrice = originalServicePrice.add(platformOpFee);
+            priceItem.setServicePrice(servicePrice);
+            
+            // 合计充电价 = 综合销售费(直接取c_policy_fee.comp_sales_fee)
+            priceItem.setTotalPrice(platformCompSalesFee);
+            log.debug("平台价格计算 - periodFlag: {}, 电费: {}, 原服务费: {}, 运营费: {}, 服务费(含运营): {}, 综合销售费(totalPrice): {}",
+                    policyInfo.getPeriodFlag(), policyInfo.getElecPrice(), originalServicePrice, platformOpFee, servicePrice, platformCompSalesFee);
             
             // 设置企业价格(如果有)- 通过periodFlag匹配
             BigDecimal enterprisePrice = enterprisePriceMap.get(policyInfo.getPeriodFlag());