From f4d59ed1e007e20be8148d51e429253470231dd3 Mon Sep 17 00:00:00 2001 From: yangzhe123 <2824096059@qq.com> Date: Fri, 5 Dec 2025 16:56:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A1=E7=AE=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/RiceSupportBalanceService.java | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/gunshi/project/hsz/service/RiceSupportBalanceService.java b/src/main/java/com/gunshi/project/hsz/service/RiceSupportBalanceService.java index 909b4c8..b4fc982 100644 --- a/src/main/java/com/gunshi/project/hsz/service/RiceSupportBalanceService.java +++ b/src/main/java/com/gunshi/project/hsz/service/RiceSupportBalanceService.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -61,7 +62,7 @@ public class RiceSupportBalanceService extends ServiceImpl allDaysByStartAndEndTime = LocalDateTimeUtils.getAllDaysByStartAndEndTime(dto.getStartTime(), dto.getEndTime()); LocalDateTime today = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0); BigDecimal totalIcWater = BigDecimal.ZERO;//总来水量 @@ -101,7 +102,7 @@ public class RiceSupportBalanceService extends ServiceImpl 0){ @@ -138,6 +139,8 @@ public class RiceSupportBalanceService extends ServiceImpl=0?totalNeedWater:totalPlan; } /** * 需要优先保障每日生态供水 @@ -156,32 +159,23 @@ public class RiceSupportBalanceService extends ServiceImpl= 0) { - // 充足,完全满足 - totalWaterForIrrigation = totalIrrigationNeed; - }else { - // 不足,优先保障生态用水,剩余给灌溉 - if (totalPlan.compareTo(totalWaterForEco) >= 0) { - // 生态用水能完全满足,剩余给灌溉 - totalWaterForIrrigation = totalPlan.subtract(totalWaterForEco); - } else { - // 连生态用水都不能完全满足 - totalWaterForIrrigation = BigDecimal.ZERO; + // 如果来水量不足够供应所有生态用水和灌溉用水 + if(totalPlan.compareTo(totalNeedWater) <0){ + //如果生态用水都满足不了 + if(totalPlan.compareTo(totalWaterForEco) < 0){ + //调整生态用水量 totalWaterForEco = totalPlan; // 实际生态供水量调整为可用的总量 dailyEcoWaterUse = totalWaterForEco.divide( - new BigDecimal(allDaysByStartAndEndTime.size()), 4, BigDecimal.ROUND_HALF_UP - ); + new BigDecimal(allDaysByStartAndEndTime.size()),10,RoundingMode.HALF_UP); } } - // 计算灌溉用水的缩放比例 BigDecimal irrigationRatio; if (totalIrrigationNeed.compareTo(BigDecimal.ZERO) > 0) { - irrigationRatio = totalIcWater.divide(totalNeedWater, 4, BigDecimal.ROUND_HALF_UP); + //总计划供水/总需水 + irrigationRatio = totalPlan.divide(totalNeedWater,3,RoundingMode.DOWN); } else { irrigationRatio = BigDecimal.ZERO; } @@ -192,8 +186,8 @@ public class RiceSupportBalanceService extends ServiceImpl 0 && caculate.getIrrigationUse() != null) { // 该生长周期每天的灌溉需水量 dailyIrrigationNeed = caculate.getIrrigationUse() - .divide(new BigDecimal(daysInCycle), 2, BigDecimal.ROUND_HALF_UP); + .divide(new BigDecimal(daysInCycle),2,RoundingMode.DOWN); } break; } @@ -265,7 +259,7 @@ public class RiceSupportBalanceService extends ServiceImpl matchingCycle = riceWaterForecastCycles.stream() .filter(cycle -> cycle.getRiceGrowStage().equals(riceWaterKi.getRiceGrowStage())) .findFirst(); - // 根据是否找到匹配设置灌溉用水 if (matchingCycle.isPresent()) { - // 假设RiceWaterForecastCycle中有getIrrigationUse方法 entity.setIrrigationUse(matchingCycle.get().getIrrigationUse()); } else { - // 如果没有匹配的,设置默认值或null - entity.setIrrigationUse(BigDecimal.ZERO); // 或者BigDecimal.ZERO等默认值 + entity.setIrrigationUse(BigDecimal.ZERO); } res.add(entity); }