出入库流量

master
yangzhe123 2026-01-26 13:11:07 +08:00
parent 8301533a10
commit 7153841cf1
5 changed files with 125 additions and 115 deletions

View File

@ -38,13 +38,13 @@ public class ReservoirDemarcationInfoController extends AbstractCommonFileContro
public R<ReservoirDemarcationInfo> get(){ public R<ReservoirDemarcationInfo> get(){
ReservoirDemarcationInfo query = service.list().get(0); ReservoirDemarcationInfo query = service.list().get(0);
//获取资料 //获取资料
List<FileAssociations> managementScopeAreaFile = fileService.getFiles(managementScopeArea, query.getId().toString()); List<FileAssociations> managementScopeAreaFile = fileService.getFiles2(managementScopeArea, query.getId().toString());
List<FileAssociations> protectionScopeAreaFile = fileService.getFiles(protectionScopeArea, query.getId().toString()); List<FileAssociations> protectionScopeAreaFile = fileService.getFiles2(protectionScopeArea, query.getId().toString());
List<FileAssociations> propertyCertificateAreaFile = fileService.getFiles(propertyCertificateArea, query.getId().toString()); List<FileAssociations> propertyCertificateAreaFile = fileService.getFiles2(propertyCertificateArea, query.getId().toString());
List<FileAssociations> totalUseAreaFile = fileService.getFiles(totalUseArea, query.getId().toString()); List<FileAssociations> totalUseAreaFile = fileService.getFiles2(totalUseArea, query.getId().toString());
query.setManagementScopeAreaFiles(managementScopeAreaFile); query.setManagementScopeAreaFiles(managementScopeAreaFile);
query.setProtectionScopeFiles(protectionScopeAreaFile); query.setProtectionScopeFiles(protectionScopeAreaFile);

View File

@ -4,27 +4,24 @@ package com.gunshi.project.ss.entity.vo;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data @Data
public class StFlowLowerDataCheckVo { public class StFlowLowerDataCheckVo {
/** /**
* 1 *
*/ */
private BigDecimal max1hoursQ; private BigDecimal maxQ;
/** /**
* 6 *
*/ */
private BigDecimal max6hoursQ; private LocalDateTime maxQTm;
/** /**
* 1 *
*/ */
private String max1hoursTm; private BigDecimal totalWater;
/**
* 6
*/
private String max6hoursTm;
} }

View File

@ -26,22 +26,10 @@ public class StFlowRListVo {
/** /**
* 24h * m³
*/ */
@TableField(exist = false) @TableField(exist = false)
private BigDecimal avg24Q; private BigDecimal totalWater;
/**
* 24h
*/
@TableField(exist = false)
private BigDecimal change24Q;
/**
* 24m³
*/
@TableField(exist = false)
private BigDecimal total24V;
private BigDecimal lgtd; private BigDecimal lgtd;

View File

@ -654,4 +654,24 @@ public class AttResBase implements Serializable {
private String managementUnitPerson; 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;
} }

View File

@ -29,6 +29,7 @@ import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
@Service @Service
@ -100,47 +101,12 @@ public class StFlowRService extends ServiceImpl<StFlowRMapper, StFlowR> {
stFlowR.setStatus(1); stFlowR.setStatus(1);
} }
// 计算统计值 // 计算统计值
calculateTotalVolume(list, stFlowR);
res.add(stFlowR); res.add(stFlowR);
} }
return res; return res;
} }
// 替代的累计水量计算方法(使用梯形法,更精确)
private void calculateTotalVolume(List<StFlowR> 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<StFlowRListVo> upperDataCheck(StFlowDataCheckDto dto) { public List<StFlowRListVo> upperDataCheck(StFlowDataCheckDto dto) {
List<StFlowRListVo> res = new ArrayList<>(); List<StFlowRListVo> res = new ArrayList<>();
@ -148,12 +114,12 @@ public class StFlowRService extends ServiceImpl<StFlowRMapper, StFlowR> {
.eq(StFlowR::getStcd, dto.getStcd()) .eq(StFlowR::getStcd, dto.getStcd())
.ge(StFlowR::getTm, dto.getDateTimeRangeSo().getStart()) .ge(StFlowR::getTm, dto.getDateTimeRangeSo().getStart())
.le(StFlowR::getTm, dto.getDateTimeRangeSo().getEnd()) .le(StFlowR::getTm, dto.getDateTimeRangeSo().getEnd())
.orderByDesc(StFlowR::getTm) .orderByAsc(StFlowR::getTm)
.list(); .list();
if(list.isEmpty()){ if(list.isEmpty()){
return res; return res;
} }
if(dto.getType() == 0){
for (StFlowR stFlowR : list) { for (StFlowR stFlowR : list) {
StFlowRListVo stFlowRListVo = new StFlowRListVo(); StFlowRListVo stFlowRListVo = new StFlowRListVo();
stFlowRListVo.setStcd(stFlowR.getStcd()); stFlowRListVo.setStcd(stFlowR.getStcd());
@ -161,54 +127,93 @@ public class StFlowRService extends ServiceImpl<StFlowRMapper, StFlowR> {
stFlowRListVo.setTm(stFlowR.getTm()); stFlowRListVo.setTm(stFlowR.getTm());
res.add(stFlowRListVo); res.add(stFlowRListVo);
} }
}else{
// 使用Map按日期分组
Map<LocalDate, List<StFlowR>> dailyMap = new LinkedHashMap<>();
for (StFlowR flow : list) { // 3. 计算累计水量
LocalDate date = flow.getTm().toLocalDate(); // 设置第一个时间点的累计水量为0
dailyMap.computeIfAbsent(date, k -> new ArrayList<>()).add(flow); 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³
for (Map.Entry<LocalDate, List<StFlowR>> entry : dailyMap.entrySet()) { BigDecimal waterVolume = previousFlow
LocalDate date = entry.getKey(); .multiply(BigDecimal.valueOf(seconds)) // m³
List<StFlowR> dayList = entry.getValue(); .divide(BigDecimal.valueOf(10000), 10, RoundingMode.HALF_UP); // 万m³
if (!dayList.isEmpty()) { // 累计水量 = 上一个累计水量 + 当前时段水量
StFlowR sample = dayList.get(0); BigDecimal totalWater = previous.getTotalWater().add(waterVolume);
BigDecimal totalQ = BigDecimal.ZERO;
int count = 0;
// 计算当日流量总和 current.setTotalWater(totalWater);
for (StFlowR flow : dayList) {
if (flow.getQ() != null) {
totalQ = totalQ.add(flow.getQ());
count++;
}
} }
// 创建结果对象 // 3. 将结果按时间降序排列(最新的时间在前面)
StFlowRListVo vo = new StFlowRListVo(); res.sort(Comparator.comparing(StFlowRListVo::getTm).reversed());
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);
}
}
}
return res; return res;
} }
public StFlowLowerDataCheckVo lowerDataCheckVoR(StFlowDataCheckDto dto) { public StFlowLowerDataCheckVo lowerDataCheckVoR(StFlowDataCheckDto dto) {
return null; StFlowLowerDataCheckVo res = new StFlowLowerDataCheckVo();
List<StFlowR> 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<StFlowR> getByStcd(StFlowDataCheckDto dto) { public List<StFlowR> getByStcd(StFlowDataCheckDto dto) {