From 74233dffc8fa0e374cb959a81d471ea44bbd50f4 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 24 九月 2026 09:10:52 +0800
Subject: [PATCH] 新增加功能

---
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TBillingTemplateServiceImpl.java |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TBillingTemplateServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TBillingTemplateServiceImpl.java
index 256a5d0..c04f6e1 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TBillingTemplateServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TBillingTemplateServiceImpl.java
@@ -20,11 +20,9 @@
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -120,6 +118,12 @@
             d.setId(null);
             d.setTemplateId(templateId);
             d.setDelFlag(false);
+            if (d.getStartTime() == null) {
+                d.setStartTime("");
+            }
+            if (d.getEndTime() == null) {
+                d.setEndTime("");
+            }
             detailMapper.insert(d);
         }
     }
@@ -128,34 +132,30 @@
         if (CollectionUtils.isEmpty(details)) {
             throw new IllegalArgumentException("请填写费率明细");
         }
-        // 时间段连续性
-        List<TBillingTemplateDetail> sorted = details.stream()
-                .sorted(Comparator.comparing(TBillingTemplateDetail::getStartTime))
-                .collect(Collectors.toList());
-        boolean firstValid = sorted.isEmpty() || !sorted.get(0).getStartTime().equals(sorted.get(sorted.size() - 1).getEndTime());
-        boolean continuous = sorted.stream()
-                .skip(1)
-                .allMatch(d -> d.getStartTime().equals(sorted.get(sorted.indexOf(d) - 1).getEndTime()));
-        if (firstValid || !continuous) {
-            throw new IllegalArgumentException("计费模板时间设置有误差");
-        }
         // 同阶段价格一致
         Map<Integer, BigDecimal> phaseElectrovalence = new HashMap<>();
         Map<Integer, BigDecimal> phaseServiceFee = new HashMap<>();
         Map<Integer, BigDecimal> phaseCostServiceFee = new HashMap<>();
         for (TBillingTemplateDetail d : details) {
             Integer type = d.getType();
+            BigDecimal electrovalence = defaultZero(d.getElectrovalence());
+            BigDecimal serviceCharge = defaultZero(d.getServiceCharge());
+            BigDecimal costServiceCharge = defaultZero(d.getCostServiceCharge());
             if (phaseElectrovalence.containsKey(type)) {
-                if (phaseElectrovalence.get(type).compareTo(d.getElectrovalence()) != 0
-                        || phaseServiceFee.get(type).compareTo(d.getServiceCharge()) != 0
-                        || phaseCostServiceFee.get(type).compareTo(d.getCostServiceCharge()) != 0) {
+                if (phaseElectrovalence.get(type).compareTo(electrovalence) != 0
+                        || phaseServiceFee.get(type).compareTo(serviceCharge) != 0
+                        || phaseCostServiceFee.get(type).compareTo(costServiceCharge) != 0) {
                     throw new IllegalArgumentException("同阶段费率值需一致");
                 }
             } else {
-                phaseElectrovalence.put(type, d.getElectrovalence());
-                phaseServiceFee.put(type, d.getServiceCharge());
-                phaseCostServiceFee.put(type, d.getCostServiceCharge());
+                phaseElectrovalence.put(type, electrovalence);
+                phaseServiceFee.put(type, serviceCharge);
+                phaseCostServiceFee.put(type, costServiceCharge);
             }
         }
     }
+
+    private BigDecimal defaultZero(BigDecimal value) {
+        return value == null ? BigDecimal.ZERO : value;
+    }
 }
\ No newline at end of file

--
Gitblit v1.7.1