parent
6e3d2f799f
commit
0a8e44f15b
|
|
@ -49,27 +49,49 @@ public interface StPptnRMapper extends BaseMapper<StPptnR> {
|
|||
/**
|
||||
* 根据stcd查询24小时总降水量
|
||||
*/
|
||||
// @Select("""
|
||||
// select SUM(drp) from public.st_pptn_r
|
||||
// where stcd=#{stcd} and tm >= now() - interval '24 hours'
|
||||
// """)
|
||||
@Select("""
|
||||
select SUM(drp) from public.st_pptn_r
|
||||
where stcd=#{stcd} and tm >= now() - interval '24 hours'
|
||||
""")
|
||||
SELECT SUM(drp)
|
||||
FROM public.st_pptn_r
|
||||
WHERE stcd = #{stcd}
|
||||
AND tm > DATE_TRUNC('day', NOW() - INTERVAL '1 day') + INTERVAL '8 hours'
|
||||
AND tm <= DATE_TRUNC('day', NOW()) + INTERVAL '8 hours'
|
||||
""")
|
||||
BigDecimal getdrp24SumByStcd(String stcd);
|
||||
|
||||
/**
|
||||
* 根据stcd查询24小时内最大降水量
|
||||
*/
|
||||
// @Select("""
|
||||
// SELECT *
|
||||
// FROM public.st_pptn_r
|
||||
// WHERE stcd = #{stcd}
|
||||
// AND drp = (
|
||||
// SELECT MAX(drp)
|
||||
// FROM public.st_pptn_r
|
||||
// WHERE stcd = #{stcd}
|
||||
// AND tm >= NOW() - INTERVAL '24 hours'
|
||||
// )
|
||||
// AND tm >= NOW() - INTERVAL '24 hours'
|
||||
// LIMIT 1
|
||||
// """)
|
||||
@Select("""
|
||||
SELECT *
|
||||
FROM public.st_pptn_r
|
||||
WHERE stcd = #{stcd}
|
||||
AND drp = (
|
||||
SELECT MAX(drp)
|
||||
FROM public.st_pptn_r
|
||||
WHERE stcd = #{stcd}
|
||||
AND tm >= NOW() - INTERVAL '24 hours'
|
||||
)
|
||||
AND tm >= NOW() - INTERVAL '24 hours'
|
||||
LIMIT 1
|
||||
""")
|
||||
SELECT *
|
||||
FROM public.st_pptn_r
|
||||
WHERE stcd = #{stcd}
|
||||
AND drp = (
|
||||
SELECT MAX(drp)
|
||||
FROM public.st_pptn_r
|
||||
WHERE stcd = #{stcd}
|
||||
AND tm > DATE_TRUNC('day', NOW() - INTERVAL '1 day') + INTERVAL '8 hours'
|
||||
AND tm <= DATE_TRUNC('day', NOW()) + INTERVAL '8 hours'
|
||||
)
|
||||
AND tm > DATE_TRUNC('day', NOW() - INTERVAL '1 day') + INTERVAL '8 hours'
|
||||
AND tm <= DATE_TRUNC('day', NOW()) + INTERVAL '8 hours'
|
||||
LIMIT 1
|
||||
""")
|
||||
StPptnR getdrp24MaxByStcd(String stcd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,9 @@ public class ResBriefController {
|
|||
}
|
||||
return R.ok(resBriefRService.getResBriefList(startDate, endDate));
|
||||
}
|
||||
|
||||
@GetMapping("/execute")
|
||||
public void executeSyncData(){
|
||||
resBriefRService.scheduledScan();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,6 @@ public class RsvrComplexVo {
|
|||
* 水位查表库容
|
||||
*/
|
||||
public BigDecimal w;
|
||||
|
||||
public BigDecimal totalSv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,12 +184,7 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
vo.setQtotal(BigDecimal.ZERO);
|
||||
} else {
|
||||
StZqrlBVo voPrev = ret.get(i - 1);
|
||||
//累计溢洪量 = 上一条数据累计溢洪量 + 本条溢洪流量 * 2条数据之间的间隔
|
||||
Instant curInstant = vo.getTm().toInstant();
|
||||
Instant preInstant = voPrev.getTm().toInstant();
|
||||
long timeDiffSeconds = Duration.between(preInstant, curInstant).getSeconds();
|
||||
//TODO 或者改成60 * 60 .multiply(BigDecimal.valueOf(60 * 60))
|
||||
BigDecimal qTotal = voPrev.getQtotal().add(vo.getFlowNum().multiply(BigDecimal.valueOf(timeDiffSeconds)));
|
||||
BigDecimal qTotal = voPrev.getQtotal().add(vo.getFlowNum().multiply(BigDecimal.valueOf(60 * 60)));
|
||||
vo.setQtotal(qTotal);
|
||||
}
|
||||
|
||||
|
|
@ -245,8 +240,13 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
zqrlList.sort(Comparator.comparing(StZqrlB::getZ));
|
||||
|
||||
List<RsvrComplexVo> complexList = new ArrayList<>();
|
||||
BigDecimal maxYearSv = BigDecimal.ZERO;
|
||||
Date maxQStartTime = null;
|
||||
Date maxQEndTime = null;
|
||||
boolean inMaxQPeriod = false;
|
||||
int idx = 0;
|
||||
for (StRsvrR rsvr : rsvrList) {
|
||||
for (int i =0;i<rsvrList.size();i++) {
|
||||
StRsvrR rsvr = rsvrList.get(i);
|
||||
RsvrComplexVo complex = new RsvrComplexVo();
|
||||
BigDecimal rz = new BigDecimal(rsvr.getRz());
|
||||
complex.setRz(rz);
|
||||
|
|
@ -257,17 +257,53 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
BigDecimal q = stZqrlBService.getQByZqrl(zqrlList, rz);
|
||||
complex.setQ(q);
|
||||
// complex.setSv(complex.getQ());
|
||||
if (idx == 0) {
|
||||
complex.setSv(BigDecimal.ZERO);
|
||||
} else {
|
||||
//计算溢洪量
|
||||
RsvrComplexVo complexPrev = complexList.get(idx - 1);
|
||||
complex.setSv(complexPrev.getSv().add(complex.getQ().multiply(BigDecimal.valueOf(60 * 60))));
|
||||
complex.setSv(complex.getQ().multiply(BigDecimal.valueOf(60 * 60)));
|
||||
if(i == 0){
|
||||
complex.setTotalSv(BigDecimal.ZERO);
|
||||
}else{
|
||||
RsvrComplexVo pre = complexList.get(i - 1);
|
||||
complex.setTotalSv(pre.getTotalSv().add(complex.getQ().multiply(BigDecimal.valueOf(60 * 60))));
|
||||
}
|
||||
if(complex.getSv().compareTo(BigDecimal.ZERO) > 0){
|
||||
int compare = complex.getSv().compareTo(maxYearSv);
|
||||
if(compare > 0){
|
||||
//发现更大的溢洪流量
|
||||
maxYearSv = complex.getSv();
|
||||
maxQStartTime = rsvr.getTm();
|
||||
maxQEndTime = null;
|
||||
inMaxQPeriod = true;
|
||||
}else if(compare == 0 && inMaxQPeriod){
|
||||
// 连续的最大Q值,更新结束时间
|
||||
// 如果是最后一条数据,使用当前时间作为结束时间
|
||||
if (i == rsvrList.size() - 1) {
|
||||
maxQEndTime = now;
|
||||
} else {
|
||||
maxQEndTime = rsvrList.get(i + 1).getTm();
|
||||
}
|
||||
}else{
|
||||
// Q值变小,结束当前最大Q值期间
|
||||
inMaxQPeriod = false;
|
||||
}
|
||||
}
|
||||
|
||||
complexList.add(complex);
|
||||
idx++;
|
||||
}
|
||||
// 设置最大Q值及其时间范围
|
||||
vo.setCurrYearMaxVal(maxYearSv);
|
||||
if (maxQStartTime != null) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
if (maxQEndTime != null) {
|
||||
String period = sdf.format(maxQStartTime) + " ~ " + sdf.format(maxQEndTime);
|
||||
vo.setMaxOverflowPeriod(period);
|
||||
} else {
|
||||
// 如果最大Q值只出现在一个时间点,时间范围就是这个时间点
|
||||
String period = sdf.format(maxQStartTime);
|
||||
vo.setMaxOverflowPeriod(period);
|
||||
}
|
||||
} else {
|
||||
vo.setMaxOverflowPeriod("无溢洪记录");
|
||||
}
|
||||
|
||||
//当前流量
|
||||
vo.setVal(complexList.getLast().getQ());
|
||||
|
|
@ -287,39 +323,19 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
|
||||
|
||||
// 当年累计溢洪量
|
||||
BigDecimal sumYear = stZqrlBService.getFlowQSum(complexList);
|
||||
|
||||
BigDecimal sumYear = complexList.getLast().getTotalSv();
|
||||
vo.setCurrYearSum(sumYear);
|
||||
|
||||
|
||||
// //今日sv的和
|
||||
// BigDecimal sumToday = complexList.stream().filter(complex -> complex.getTm().after(dayStart))
|
||||
// .map(RsvrComplexVo::getSv)
|
||||
// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// vo.setCurrDayValSum(sumToday);
|
||||
//
|
||||
// // 当月溢洪量总和(筛选本月数据)
|
||||
// BigDecimal sumMonth = complexList.stream()
|
||||
// .filter(complex -> (complex.getTm().after(monthStart) || complex.getTm().equals(monthStart))
|
||||
// && complex.getTm().before(now) || complex.getTm().equals(now))
|
||||
// .map(RsvrComplexVo::getSv)
|
||||
// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// vo.setCurrMonthSum(sumMonth);
|
||||
//
|
||||
// // 当年溢洪量总和(所有数据都是当年的,直接求和)
|
||||
// BigDecimal sumYear = complexList.stream()
|
||||
// .map(RsvrComplexVo::getSv)
|
||||
// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
// vo.setCurrYearSum(sumYear);
|
||||
|
||||
|
||||
//计算溢洪次数
|
||||
// 0 0 0 1 1 0 1 0 1
|
||||
int overFlowCount = 0;
|
||||
boolean isOverFlow = false;
|
||||
//连续的sv > 0 才算一次 溢洪
|
||||
for (int i = 0; i < complexList.size(); i++) {
|
||||
BigDecimal sv = complexList.get(i).getSv();
|
||||
if (sv.compareTo(BigDecimal.ZERO) > 0) {
|
||||
//BigDecimal sv = complexList.get(i).getSv();
|
||||
BigDecimal q = complexList.get(i).getQ();
|
||||
if (q != null && q.compareTo(BigDecimal.ZERO) > 0) {
|
||||
if (!isOverFlow) {
|
||||
overFlowCount++;
|
||||
isOverFlow = true;
|
||||
|
|
@ -329,29 +345,6 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
}
|
||||
}
|
||||
vo.setCurrYearCount(Long.valueOf(overFlowCount));
|
||||
// 本年单次最大溢洪量
|
||||
Optional<RsvrComplexVo> maxOverflowComplex = complexList.stream()
|
||||
.max(Comparator.comparing(RsvrComplexVo::getSv));
|
||||
if (maxOverflowComplex.isPresent()) {
|
||||
RsvrComplexVo maxComplex = maxOverflowComplex.get();
|
||||
vo.setCurrYearMaxVal(maxComplex.getSv());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss");
|
||||
int maxIndex = complexList.indexOf(maxComplex);
|
||||
if (maxIndex < complexList.size() - 1) {
|
||||
// 可以取前后时间点作为时间段的参考
|
||||
Date startTime = complexList.get(maxIndex).getTm();
|
||||
Date endTime = complexList.get(maxIndex + 1).getTm();
|
||||
String period = sdf.format(startTime) + " ~ " + sdf.format(endTime);
|
||||
vo.setMaxOverflowPeriod(period);
|
||||
} else {
|
||||
Date startTime = complexList.get(maxIndex).getTm();
|
||||
String period = sdf.format(startTime) + " ~ " + sdf.format(now);
|
||||
vo.setMaxOverflowPeriod(period);
|
||||
}
|
||||
} else {
|
||||
vo.setCurrYearMaxVal(BigDecimal.ZERO);
|
||||
vo.setMaxOverflowPeriod("无溢洪记录");
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
|
@ -378,8 +371,7 @@ public class StStbprpBService extends ServiceImpl<StStbprpBMapper, StStbprpB> {
|
|||
List<StRsvrR> rsvrList = rsvrRService.lambdaQuery().ge(StRsvrR::getTm, before24).le(StRsvrR::getTm, now).orderByAsc(StRsvrR::getTm).list();
|
||||
//TODO 这个溢洪流量汇总的计算也需要进行公式计算
|
||||
List<RsvrComplexVo> rsvrComplexVos = stZqrlBService.calculateSpilledVolumeList(rsvrList);
|
||||
BigDecimal totalSv = rsvrComplexVos.stream().map(RsvrComplexVo::getSv).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
vo.setSum24(totalSv);
|
||||
vo.setSum24(rsvrComplexVos.getLast().getTotalSv());
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,25 +59,26 @@ public class StZqrlBService extends ServiceImpl<StZqrlBMapper, StZqrlB> {
|
|||
* @author lyf
|
||||
*/
|
||||
public List<RsvrComplexVo> calculateSpilledVolumeList(List<StRsvrR> rsvrList, List<StZqrlB> zqrlList) {
|
||||
rsvrList.sort(Comparator.comparing(StRsvrR::getTm).reversed());
|
||||
rsvrList.sort(Comparator.comparing(StRsvrR::getTm));
|
||||
List<RsvrComplexVo> ret = new ArrayList<>();
|
||||
BigDecimal sum = BigDecimal.ZERO;
|
||||
for (int i = 0; i < rsvrList.size(); i++) {
|
||||
StRsvrR rsvr = rsvrList.get(i);
|
||||
BigDecimal rz = new BigDecimal(rsvr.getRz());
|
||||
Date tm = rsvr.getTm();
|
||||
RsvrComplexVo vo = RsvrComplexVo.of(rz, tm);
|
||||
BigDecimal q = getQFromZqrl(rz, zqrlList);
|
||||
BigDecimal q = getQByZqrl(zqrlList,rz);
|
||||
//TODO 这个需要公式进行对水位->流量的转换
|
||||
vo.setQ(q);
|
||||
if (i == 0) {
|
||||
vo.setQ(getQFromZqrl(rz, zqrlList));
|
||||
vo.setSv(BigDecimal.ZERO);
|
||||
vo.setTotalSv(BigDecimal.ZERO);
|
||||
sum = BigDecimal.ZERO;
|
||||
} else {
|
||||
StRsvrR rsvrPrev = rsvrList.get(i - 1);
|
||||
Date tmPrev = rsvrPrev.getTm();
|
||||
long seconds = tm.getTime() - tmPrev.getTime();
|
||||
vo.setQ(getQFromZqrl(rz, zqrlList));
|
||||
//TODO 这里有个函数调用,记得到时候也替换一下计算公式
|
||||
vo.setSv(calculateSpilledVolume(rz, seconds));
|
||||
sum = sum.add(vo.getQ().multiply(BigDecimal.valueOf(60 * 60)));
|
||||
vo.setTotalSv(sum);
|
||||
}
|
||||
ret.add(vo);
|
||||
}
|
||||
|
|
@ -233,20 +234,9 @@ public class StZqrlBService extends ServiceImpl<StZqrlBMapper, StZqrlB> {
|
|||
// 第一条数据,累计量为0
|
||||
sum = BigDecimal.ZERO;
|
||||
} else {
|
||||
RsvrComplexVo previous = complexList.get(i - 1);
|
||||
|
||||
// 计算时间间隔(秒)
|
||||
long timeDiffSeconds = Duration.between(previous.getTm().toInstant(),
|
||||
current.getTm().toInstant()).getSeconds();
|
||||
|
||||
if (timeDiffSeconds > 0) {
|
||||
// 使用梯形法则计算这段时间内的溢洪量:(上一个流量 + 当前流量) / 2 * 时间间隔
|
||||
BigDecimal avgFlow = previous.getSv().add(current.getSv())
|
||||
.divide(BigDecimal.valueOf(2), 10, RoundingMode.HALF_UP);
|
||||
BigDecimal increment = avgFlow.multiply(BigDecimal.valueOf(timeDiffSeconds));
|
||||
sum = sum.add(increment);
|
||||
BigDecimal multiply = current.getQ().multiply(new BigDecimal(60 * 60));
|
||||
sum = sum.add(multiply);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class AlarmTask {
|
|||
private StRiverRRealService stRiverRRealService;
|
||||
|
||||
@Async
|
||||
@Scheduled(fixedRate = 10, timeUnit = TimeUnit.MINUTES)
|
||||
@Scheduled(cron = "0 7 * * * *")
|
||||
public void updateAlarmSet(){
|
||||
//查询告警设置中所有的配置的站点
|
||||
List<AlarmSet> alarmSets = alarmSetMapper.selectList(null);
|
||||
|
|
@ -57,7 +57,7 @@ public class AlarmTask {
|
|||
}
|
||||
|
||||
@Async
|
||||
@Scheduled(fixedRate = 10, timeUnit = TimeUnit.MINUTES)
|
||||
@Scheduled(cron = "0 7 * * * *")
|
||||
public void updateWaterAlarm(){
|
||||
List<AttResBaseVo> attResBaseVos = attResBaseMapper.queryList();
|
||||
AttResBaseVo attResBaseVo = attResBaseVos.get(0);
|
||||
|
|
@ -70,7 +70,18 @@ public class AlarmTask {
|
|||
Integer desState = entity.getDesState();//是否超设计
|
||||
|
||||
Integer flState = entity.getFlState();//是否超汛限
|
||||
|
||||
WaterAlarm waterAlarmNew = waterAlarmService.getBaseMapper().selectByStcdNew(entity.getStcd());
|
||||
if(waterAlarmNew != null){
|
||||
//判断最新的时间是否大于
|
||||
//最新数据时间
|
||||
Instant newDataInstant = entity.getTm().toInstant();
|
||||
//老数据告警时间
|
||||
Instant currentDataInstant = waterAlarmNew.getAlarmTime().toInstant();
|
||||
if(newDataInstant.compareTo(currentDataInstant) <= 0){
|
||||
//如果不是最新数据,直接结束
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(calState > 0){
|
||||
Integer level = AlarmTypeEnum.RESERVOIR_OVER_CHECK.getLevel();
|
||||
WaterAlarm waterAlarm = new WaterAlarm();
|
||||
|
|
@ -120,12 +131,13 @@ public class AlarmTask {
|
|||
//该站点,真实河道水位的最新数据的时间
|
||||
Instant newDateInstant = stRiverRReal.getTm().toInstant();
|
||||
//告警表中,该站点的最新数据的时间
|
||||
Instant curDateInstant = waterAlarmNew.getAlarmTime().toInstant();
|
||||
if(newDateInstant.compareTo(curDateInstant) <= 0){
|
||||
//如果要插入数据的时间与当前告警表中数据相同,则直接跳过本条数据
|
||||
return;
|
||||
if(waterAlarmNew != null){
|
||||
Instant curDateInstant = waterAlarmNew.getAlarmTime().toInstant();
|
||||
if(newDateInstant.compareTo(curDateInstant) <= 0){
|
||||
//如果要插入数据的时间与当前告警表中数据相同,则直接跳过本条数据
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
AlarmSet alarmSet = alarmSetMapper.queryByStcd(stcd);
|
||||
//警告水位
|
||||
BigDecimal warnWaterLevel = alarmSet.getWarnWaterLevel();
|
||||
|
|
|
|||
Loading…
Reference in New Issue