diff --git a/src/main/java/com/gunshi/project/ss/controller/ReservoirDemarcationInfoController.java b/src/main/java/com/gunshi/project/ss/controller/ReservoirDemarcationInfoController.java index 55e4f28..3431755 100644 --- a/src/main/java/com/gunshi/project/ss/controller/ReservoirDemarcationInfoController.java +++ b/src/main/java/com/gunshi/project/ss/controller/ReservoirDemarcationInfoController.java @@ -38,13 +38,13 @@ public class ReservoirDemarcationInfoController extends AbstractCommonFileContro public R get(){ ReservoirDemarcationInfo query = service.list().get(0); //获取资料 - List managementScopeAreaFile = fileService.getFiles(managementScopeArea, query.getId().toString()); + List managementScopeAreaFile = fileService.getFiles2(managementScopeArea, query.getId().toString()); - List protectionScopeAreaFile = fileService.getFiles(protectionScopeArea, query.getId().toString()); + List protectionScopeAreaFile = fileService.getFiles2(protectionScopeArea, query.getId().toString()); - List propertyCertificateAreaFile = fileService.getFiles(propertyCertificateArea, query.getId().toString()); + List propertyCertificateAreaFile = fileService.getFiles2(propertyCertificateArea, query.getId().toString()); - List totalUseAreaFile = fileService.getFiles(totalUseArea, query.getId().toString()); + List totalUseAreaFile = fileService.getFiles2(totalUseArea, query.getId().toString()); query.setManagementScopeAreaFiles(managementScopeAreaFile); query.setProtectionScopeFiles(protectionScopeAreaFile); diff --git a/src/main/java/com/gunshi/project/ss/entity/vo/StFlowLowerDataCheckVo.java b/src/main/java/com/gunshi/project/ss/entity/vo/StFlowLowerDataCheckVo.java index 0036ed3..bb5abd9 100644 --- a/src/main/java/com/gunshi/project/ss/entity/vo/StFlowLowerDataCheckVo.java +++ b/src/main/java/com/gunshi/project/ss/entity/vo/StFlowLowerDataCheckVo.java @@ -4,27 +4,24 @@ package com.gunshi.project.ss.entity.vo; import lombok.Data; import java.math.BigDecimal; +import java.time.LocalDateTime; @Data public class StFlowLowerDataCheckVo { /** - * 最大1小时流量 + * 最大瞬时流量 */ - private BigDecimal max1hoursQ; + private BigDecimal maxQ; /** - * 最大6小时流量 + * 最大瞬时流量时间 */ - private BigDecimal max6hoursQ; + private LocalDateTime maxQTm; + /** - * 最大1小时时间 + * 累计水量 */ - private String max1hoursTm; - - /** - * 最大6小时时间 - */ - private String max6hoursTm; + private BigDecimal totalWater; } diff --git a/src/main/java/com/gunshi/project/ss/entity/vo/StFlowRListVo.java b/src/main/java/com/gunshi/project/ss/entity/vo/StFlowRListVo.java index b9a80a7..4d832af 100644 --- a/src/main/java/com/gunshi/project/ss/entity/vo/StFlowRListVo.java +++ b/src/main/java/com/gunshi/project/ss/entity/vo/StFlowRListVo.java @@ -26,22 +26,10 @@ public class StFlowRListVo { /** - * 近24h平均流量 + * 累计水量单位万m³ */ @TableField(exist = false) - private BigDecimal avg24Q; - - /** - * 近24h变幅 - */ - @TableField(exist = false) - private BigDecimal change24Q; - - /** - * 近24小时累计水量单位万m³ - */ - @TableField(exist = false) - private BigDecimal total24V; + private BigDecimal totalWater; private BigDecimal lgtd; diff --git a/src/main/java/com/gunshi/project/ss/model/AttResBase.java b/src/main/java/com/gunshi/project/ss/model/AttResBase.java index 97f0ad7..6ddb5f1 100644 --- a/src/main/java/com/gunshi/project/ss/model/AttResBase.java +++ b/src/main/java/com/gunshi/project/ss/model/AttResBase.java @@ -654,4 +654,24 @@ public class AttResBase implements Serializable { private String managementUnitPerson; + @TableField("total_catchment_area") + @Schema(description = "承雨面积") + private BigDecimal totalCatchmentArea; + + @TableField("direct_catchment_area") + @Schema(description = "水库直接承雨面积") + private BigDecimal directCatchmentArea; + + @TableField("reservoir_water_surface_area") + @Schema(description = "库区内水库承雨面积") + private BigDecimal reservoirWaterSurfaceArea; + + @TableField("haiyuan_tunnel_diversion_area") + @Schema(description = "海源隧洞引区面积") + private BigDecimal haiyuanTunnelDiversionArea; + + @TableField("main_dam_type") + @Schema(description = "主坝坝型") + private String mainDamType; + } diff --git a/src/main/java/com/gunshi/project/ss/service/StFlowRService.java b/src/main/java/com/gunshi/project/ss/service/StFlowRService.java index 09cc402..b8257d6 100644 --- a/src/main/java/com/gunshi/project/ss/service/StFlowRService.java +++ b/src/main/java/com/gunshi/project/ss/service/StFlowRService.java @@ -29,6 +29,7 @@ import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.*; @Service @@ -100,47 +101,12 @@ public class StFlowRService extends ServiceImpl { stFlowR.setStatus(1); } // 计算统计值 - calculateTotalVolume(list, stFlowR); res.add(stFlowR); } return res; } - // 替代的累计水量计算方法(使用梯形法,更精确) - private void calculateTotalVolume(List flowList, StFlowRListVo vo) { - if (flowList == null || flowList.size() < 2) { - vo.setTotal24V(BigDecimal.ZERO); - return; - } - - BigDecimal totalVolume = BigDecimal.ZERO; - - for (int i = 0; i < flowList.size() - 1; i++) { - StFlowR current = flowList.get(i); - StFlowR next = flowList.get(i + 1); - - if (current.getQ() != null && next.getQ() != null && - current.getTm() != null && next.getTm() != null) { - - // 计算时间间隔(秒) - long seconds = Duration.between(current.getTm(), next.getTm()).getSeconds(); - - // 使用梯形法计算水量:(当前流量 + 下一流量) / 2 × 时间间隔 - BigDecimal avgQ = current.getQ().add(next.getQ()) - .divide(BigDecimal.valueOf(2), 4, RoundingMode.HALF_UP); - - // 水量 = 平均流量(m³/s) × 时间(秒) - BigDecimal volume = avgQ.multiply(BigDecimal.valueOf(seconds)); - - totalVolume = totalVolume.add(volume); - } - } - - // 转换为万立方米(1万立方米 = 10000立方米) - totalVolume = totalVolume.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_UP); - vo.setTotal24V(totalVolume); - } public List upperDataCheck(StFlowDataCheckDto dto) { List res = new ArrayList<>(); @@ -148,67 +114,106 @@ public class StFlowRService extends ServiceImpl { .eq(StFlowR::getStcd, dto.getStcd()) .ge(StFlowR::getTm, dto.getDateTimeRangeSo().getStart()) .le(StFlowR::getTm, dto.getDateTimeRangeSo().getEnd()) - .orderByDesc(StFlowR::getTm) + .orderByAsc(StFlowR::getTm) .list(); if(list.isEmpty()){ return res; } - if(dto.getType() == 0){ - for (StFlowR stFlowR : list) { - StFlowRListVo stFlowRListVo = new StFlowRListVo(); - stFlowRListVo.setStcd(stFlowR.getStcd()); - stFlowRListVo.setQ(stFlowR.getQ()); - stFlowRListVo.setTm(stFlowR.getTm()); - res.add(stFlowRListVo); - } - }else{ - // 使用Map按日期分组 - Map> dailyMap = new LinkedHashMap<>(); - for (StFlowR flow : list) { - LocalDate date = flow.getTm().toLocalDate(); - dailyMap.computeIfAbsent(date, k -> new ArrayList<>()).add(flow); - } - - // 计算每天的平均流量 - for (Map.Entry> entry : dailyMap.entrySet()) { - LocalDate date = entry.getKey(); - List dayList = entry.getValue(); - - if (!dayList.isEmpty()) { - StFlowR sample = dayList.get(0); - BigDecimal totalQ = BigDecimal.ZERO; - int count = 0; - - // 计算当日流量总和 - for (StFlowR flow : dayList) { - if (flow.getQ() != null) { - totalQ = totalQ.add(flow.getQ()); - count++; - } - } - - // 创建结果对象 - StFlowRListVo vo = new StFlowRListVo(); - vo.setStcd(sample.getStcd()); - - // 计算平均值并保留2位小数 - if (count > 0) { - BigDecimal avgQ = totalQ.divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP); - vo.setQ(avgQ); - } - - // 设置时间为当天的开始时间(00:00:00) - vo.setTm(date.atStartOfDay()); - res.add(vo); - } - } + for (StFlowR stFlowR : list) { + StFlowRListVo stFlowRListVo = new StFlowRListVo(); + stFlowRListVo.setStcd(stFlowR.getStcd()); + stFlowRListVo.setQ(stFlowR.getQ()); + stFlowRListVo.setTm(stFlowR.getTm()); + res.add(stFlowRListVo); } + + // 3. 计算累计水量 + // 设置第一个时间点的累计水量为0 + res.get(0).setTotalWater(BigDecimal.ZERO); + + // 从第二个开始计算累计水量 + for (int i = 1; i < res.size(); i++) { + StFlowRListVo current = res.get(i); + StFlowRListVo previous = res.get(i - 1); + + // 计算时间间隔(秒) + long seconds = ChronoUnit.SECONDS.between(previous.getTm(), current.getTm()); + // 使用前一个时间的流量计算水量 + BigDecimal previousFlow = previous.getQ(); + if (previousFlow == null) { + previousFlow = BigDecimal.ZERO; + } + + // 水量 = 流量 × 时间间隔(m³/s × s = m³,再除以10000转换为万m³) + BigDecimal waterVolume = previousFlow + .multiply(BigDecimal.valueOf(seconds)) // m³ + .divide(BigDecimal.valueOf(10000), 10, RoundingMode.HALF_UP); // 万m³ + + // 累计水量 = 上一个累计水量 + 当前时段水量 + BigDecimal totalWater = previous.getTotalWater().add(waterVolume); + + current.setTotalWater(totalWater); + } + + // 3. 将结果按时间降序排列(最新的时间在前面) + res.sort(Comparator.comparing(StFlowRListVo::getTm).reversed()); return res; } public StFlowLowerDataCheckVo lowerDataCheckVoR(StFlowDataCheckDto dto) { - return null; + StFlowLowerDataCheckVo res = new StFlowLowerDataCheckVo(); + List list = lambdaQuery() + .eq(StFlowR::getStcd, dto.getStcd()) + .ge(StFlowR::getTm, dto.getDateTimeRangeSo().getStart()) + .le(StFlowR::getTm, dto.getDateTimeRangeSo().getEnd()) + .orderByAsc(StFlowR::getTm) + .list(); + if(list.isEmpty()){ + return res; + } + // 1. 找出最大瞬时流量及其时间(此时res是按时间升序的) + BigDecimal maxQ = list.get(0).getQ(); + LocalDateTime maxQTm = list.get(0).getTm(); + + for (StFlowR vo : list) { + if (vo.getQ() != null && vo.getQ().compareTo(maxQ) > 0) { + maxQ = vo.getQ(); + maxQTm = vo.getTm(); + } + } + + BigDecimal totalWater = BigDecimal.ZERO; + + // 2. 计算累计水量 + // 第一个时间点累计水量为0 + // 从第二个开始计算:上一个累计水量 + 流量 × 时间间隔 + for (int i = 1; i < list.size(); i++) { + StFlowR current = list.get(i); + StFlowR previous = list.get(i - 1); + + // 计算时间间隔(秒) + long seconds = ChronoUnit.SECONDS.between(previous.getTm(), current.getTm()); + + // 使用当前时间点的流量(矩形法) + // 注意:这里使用的是上一个时间点的流量,不是当前时间点的 + // 也可以根据需求改为使用 current.getQ() + BigDecimal previousFlow = previous.getQ() != null ? previous.getQ() : BigDecimal.ZERO; + + // 计算当前时段的水量:流量 × 时间间隔 + // 注意单位转换:流量 m³/s,时间 s,结果 m³,再转万m³ + BigDecimal waterVolume = previousFlow + .multiply(BigDecimal.valueOf(seconds)) // m³ + .divide(BigDecimal.valueOf(10000), 10, RoundingMode.HALF_UP); // 万m³ + + // 累加到总水量 + totalWater = totalWater.add(waterVolume); + } + // 3. 设置返回结果 + res.setMaxQ(maxQ); + res.setMaxQTm(maxQTm); + res.setTotalWater(totalWater); + return res; } public List getByStcd(StFlowDataCheckDto dto) {