洪水预测相关优化

master
cxw 2024-09-29 16:45:40 +08:00
parent 5a59239d75
commit fab8bfec9c
7 changed files with 218 additions and 130 deletions

View File

@ -33,4 +33,6 @@ public interface StPptnRMapper extends BaseMapper<StPptnR> {
List<StPptnR> getStcdLastPptnData();
List<Map<String, Object>> getPptnRDataList(@Param("stcd") String stcd, @Param("tm") String tm);
List<Map<String, Object>> getPptnRDataListByTask(@Param("resCode") String resCode, @Param("stcd") String stcd, @Param("tm") String tm);
}

View File

@ -0,0 +1,35 @@
package com.gunshi.project.xyt.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gunshi.core.dateformat.DateFormatString;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.Date;
/**
* : -
*/
@Data
public class StPptnRAverage extends StPptnR {
/**
*
*/
@Schema(description="时段降水量")
private String drp;
/**
*
*/
@Schema(description="时间")
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
private Date tm;
public StPptnRAverage(Date tm, String drp) {
this.tm = tm;
this.drp = drp;
}
}

View File

@ -21,6 +21,7 @@ import com.gunshi.project.xyt.model.ForecastTask;
import com.gunshi.project.xyt.model.ForecastU;
import com.gunshi.project.xyt.model.ForecastUseparam;
import com.gunshi.project.xyt.model.StPptnR;
import com.gunshi.project.xyt.model.StPptnRAverage;
import com.gunshi.project.xyt.model.StRsvrR;
import com.gunshi.project.xyt.model.StStbprpB;
import com.gunshi.project.xyt.model.StZqrlB;
@ -125,7 +126,8 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
voList = excuteForecast(forecastTask);
voList.sort(Comparator.comparing(ForecastResultVo::getTm));
} catch (Exception e) {
throw new IllegalArgumentException("数据异常!");
e.printStackTrace();
throw new IllegalArgumentException(e.getMessage());
}
return voList;
}
@ -138,9 +140,19 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
* @date: 2024-08-05, , 17:14:52
*/
private List<ForecastResultVo> excuteForecast(ForecastTask forecastTask) throws Exception {
List<ForecastResultVo> voList = new ArrayList<>();
// 获取配置参数
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
if (CollectionUtils.isEmpty(paramList)) {
throw new IllegalArgumentException("温馨提示:当前洪水预报所依赖的数据尚不完整,请检查入参是否缺失。");
}
// 获取系统当前的水库站编码、汛限水位
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
List<ForecastResultVo> voList = new ArrayList<>();
// 多站点水库面雨量
List<StStbprpB> stbs = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("res_code", attResBase.getResCode()));
if (CollectionUtils.isEmpty(stbs)) {
return voList;
}
Date nowHourTime = forecastTask.getNowTime();
Date startTime = forecastTask.getStartTime();
Date endTime = forecastTask.getEndTime();
@ -149,30 +161,43 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
List<StPptnR> pptnRFutureList = new ArrayList<>();
QueryWrapper<StPptnR> qwExisted = new QueryWrapper<>();
Boolean isHaveFuturePPtn = true;
// 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
if (endTime.compareTo(nowHourTime) <= 0) {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", attResBase.getStcd()).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
} else {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", attResBase.getStcd()).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
try {
// 获取预报数据
pptnRFutureList = getForecastDrpData(nowHourTime, attResBase.getStcd());
} catch (IllegalArgumentException e) {
isHaveFuturePPtn = false;
log.error("该时间无预报数据");
for(StStbprpB b : stbs){
String stcd = b.getStcd();
// 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
if (endTime.compareTo(nowHourTime) <= 0) {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
} else {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
try {
// 获取预报数据
pptnRFutureList = getForecastDrpData(nowHourTime, stcd);
} catch (IllegalArgumentException e) {
if(stcd.equals(attResBase.getStcd())){
isHaveFuturePPtn = false;
}
log.error("该时间无预报数据");
}
}
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
pptnRAllList.addAll(pptnRExistedList);
pptnRAllList.addAll(pptnRFutureList);
}
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
pptnRAllList.addAll(pptnRExistedList);
pptnRAllList.addAll(pptnRFutureList);
if (CollectionUtils.isEmpty(pptnRAllList)) {
return voList;
}
// 获取配置参数
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
if (CollectionUtils.isEmpty(paramList)) {
throw new IllegalArgumentException("温馨提示:当前洪水预报所依赖的数据尚不完整,请检查入参是否缺失。");
}
// 多站点面雨量结果list
List<StPptnR> polyPptnRList = pptnRAllList.stream()
.collect(Collectors.groupingBy(
StPptnR::getTm,
Collectors.mapping(
pptn -> Double.parseDouble(pptn.getDrp()), // 将String转换为double
Collectors.averagingDouble(d -> d) // 计算平均值
)
))
.entrySet().stream()
.map(entry -> new StPptnRAverage(entry.getKey(), String.valueOf(entry.getValue())))
.sorted(Comparator.comparing(StPptnRAverage::getTm))
.collect(Collectors.toList());
double dt = 0.0;
double Wm = 0.0;
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
@ -228,7 +253,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
}
// 根据降雨数据按照△t的颗粒度均分
// 筛选时间段内的降雨数据。不包前但包后
List<StPptnR> filterList = pptnRAllList.stream().filter(e -> e.getTm().compareTo(period[0]) >= 0).filter(e -> e.getTm().compareTo(period[1]) <= 0).collect(Collectors.toList());
List<StPptnR> filterList = polyPptnRList.stream().filter(e -> e.getTm().compareTo(period[0]) >= 0).filter(e -> e.getTm().compareTo(period[1]) <= 0).collect(Collectors.toList());
Map<String, List<StPptnR>> retMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(filterList)) {
retMap = reorganizePptnRData(filterList, dt, period[0], period[1], nowHourTime, isHaveFuturePPtn);

View File

@ -30,6 +30,10 @@ public class StPptnRService extends ServiceImpl<StPptnRMapper, StPptnR>
public List<Map<String, Object>> getPptnRDataList(String stcd, String tm) {
return baseMapper.getPptnRDataList(stcd, tm);
}
public List<Map<String, Object>> getPptnRDataListByTask(String resCode, String stcd, String tm) {
return baseMapper.getPptnRDataListByTask(resCode, stcd, tm);
}
}

View File

@ -4,18 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gunshi.algorithm.RunoffService;
import com.gunshi.project.xyt.model.AttResBase;
import com.gunshi.project.xyt.model.ForecastK;
import com.gunshi.project.xyt.model.ForecastPa;
import com.gunshi.project.xyt.model.ForecastUseparam;
import com.gunshi.project.xyt.model.StPptnR;
import com.gunshi.project.xyt.model.StStbprpB;
import com.gunshi.project.xyt.service.AttResBaseService;
import com.gunshi.project.xyt.service.ForecastKService;
import com.gunshi.project.xyt.service.ForecastPaService;
import com.gunshi.project.xyt.service.ForecastResultsService;
import com.gunshi.project.xyt.service.ForecastUseparamService;
import com.gunshi.project.xyt.service.StPptnRService;
import com.gunshi.project.xyt.service.StStbprpBService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
@ -70,6 +71,9 @@ public class PaDataTask {
@Autowired
private ForecastResultsService forecastResultsService;
@Autowired
private AttResBaseService attResBaseService;
/**
* @description: 830Pa
* @param
@ -79,7 +83,6 @@ public class PaDataTask {
*/
@Async
@Scheduled(cron ="0 30 8 * * ?")
// @PostConstruct
public void PaDataCalc() throws ParseException {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
@ -87,58 +90,60 @@ public class PaDataTask {
// 获取配置参数
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
List<ForecastK> kList = forecastKService.list();
// 查询所有需要统计pa值的站点
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
// 先删除站点当天的pa假如已经存在的话有另一任务提前算了第二天此处为当天
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)));
for (StStbprpB stb : stStbprpBList) {
String stcd = stb.getStcd();
// 获取最新pa
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).orderBy(true, false, "tm").last("limit 1"));
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
calendar2.add(Calendar.DAY_OF_MONTH, -3);
String searchTm = sdfDay.format(calendar2.getTime());
String lastTm = forecastPaLast.getTm();
// 获取空缺时间的所有降雨当天8点到第二天8点间的drp和
List<Map<String, Object>> mapList = stPptnRService.getPptnRDataList(stcd, searchTm);
Map<String, Object> pptnrMap;
if (CollectionUtils.isNotEmpty(mapList)) {
pptnrMap = mapList.stream().collect(Collectors.toMap(map -> (String) map.get("tm"), map -> map.get("drp")));
} else {
return;
}
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
// 第一次的pa0是最新一条的pa
List<ForecastPa> list = new ArrayList<>();
ForecastPa forecastPa = null;
while (!lastTm.equals(sdfDay.format(nowTime))) {
double lastPa0 = forecastPaLast.getPa().doubleValue();
double lastPt0 = Double.valueOf(ObjectUtils.isEmpty(pptnrMap.get(lastTm)) ? "0.0" : pptnrMap.get(lastTm).toString());
forecastPa = new ForecastPa();
// 最新加1天
calendar.setTime(sdfDay.parse(lastTm));
calendar.add(Calendar.DAY_OF_MONTH, 1);
lastTm = sdfDay.format(calendar.getTime());
double k = kMap.get(Integer.valueOf(lastTm.substring(5, 7))).doubleValue();
double pa = RunoffService.PaCaculate(k, lastPa0, lastPt0, Im);
forecastPa.setStcd(stcd);
forecastPa.setTm(lastTm);
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa0(new BigDecimal(lastPa0));
forecastPa.setIm(new BigDecimal(Im));
forecastPa.setPt0(new BigDecimal(lastPt0).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa(new BigDecimal(pa));
list.add(forecastPa);
forecastPaLast = forecastPa;
}
if (CollectionUtils.isNotEmpty(list)) {
forecastPaService.saveBatch(list);
}
if (CollectionUtils.isEmpty(paramList) || CollectionUtils.isEmpty(kList)) {
return;
}
// 檀树岗使用多个站点的均值作为水库的降雨
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
if (ObjectUtils.isNotEmpty(attResBase)) {
String resCode = attResBase.getResCode();
String skStcd = attResBase.getStcd();
// 先删除水库当天的pa假如已经存在的话有另一任务提前算了第二天此处为当天
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)).eq("stcd", attResBase.getResCode()));
// 获取最新pa
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).orderBy(true, false, "tm").last("limit 1"));
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
calendar2.add(Calendar.DAY_OF_MONTH, -3);
String searchTm = sdfDay.format(calendar2.getTime());
String lastTm = forecastPaLast.getTm();
// 获取空缺时间的所有降雨当天8点到第二天8点间的drp和
List<Map<String, Object>> mapList = stPptnRService.getPptnRDataListByTask(resCode, skStcd, searchTm);
Map<String, Object> pptnrMap;
if (CollectionUtils.isNotEmpty(mapList)) {
pptnrMap = mapList.stream().collect(Collectors.toMap(map -> (String) map.get("tm"), map -> map.get("drp")));
} else {
return;
}
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
// 第一次的pa0是最新一条的pa
List<ForecastPa> list = new ArrayList<>();
ForecastPa forecastPa = null;
while (!lastTm.equals(sdfDay.format(nowTime))) {
double lastPa0 = forecastPaLast.getPa().doubleValue();
double lastPt0 = Double.valueOf(ObjectUtils.isEmpty(pptnrMap.get(lastTm)) ? "0.0" : pptnrMap.get(lastTm).toString());
forecastPa = new ForecastPa();
// 最新加1天
calendar.setTime(sdfDay.parse(lastTm));
calendar.add(Calendar.DAY_OF_MONTH, 1);
lastTm = sdfDay.format(calendar.getTime());
double k = kMap.get(Integer.valueOf(lastTm.substring(5, 7))).doubleValue();
double pa = RunoffService.PaCaculate(k, lastPa0, lastPt0, Im);
forecastPa.setStcd(skStcd);
forecastPa.setTm(lastTm);
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa0(new BigDecimal(lastPa0));
forecastPa.setIm(new BigDecimal(Im));
forecastPa.setPt0(new BigDecimal(lastPt0).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa(new BigDecimal(pa));
list.add(forecastPa);
forecastPaLast = forecastPa;
}
if (CollectionUtils.isNotEmpty(list)) {
forecastPaService.saveBatch(list);
}
}
}
@ -155,48 +160,58 @@ public class PaDataTask {
@Scheduled(cron ="0 0/5 20-23 * * ?")
public void PaNextDataCalc() throws ParseException {
Date nowTime = new Date();
// 查询所有需要统计pa值的站点
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
// 檀树岗使用多个站点的均值作为水库的降雨
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
if (ObjectUtils.isNotEmpty(attResBase)) {
// 查询所有需要统计pa值的站点
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("res_code", attResBase.getResCode()));
if(CollectionUtils.isEmpty(stStbprpBList)){
return;
}
// 获取配置参数
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
List<ForecastK> kList = forecastKService.list();
for (StStbprpB stb : stStbprpBList) {
String stcd = stb.getStcd();
// 查询第二天的是否已经生成了
Calendar calendarNext = Calendar.getInstance();
calendarNext.setTime(nowTime);
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
String nextTimeStr = sdfDay.format(calendarNext.getTime());
ForecastPa hasPa = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", nextTimeStr));
if(ObjectUtils.isNotEmpty(hasPa)){
return;
}
// 获取最新pa当天
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", sdfDay.format(nowTime)).last("limit 1"));
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast)) {
if (CollectionUtils.isEmpty(paramList) || CollectionUtils.isEmpty(kList)) {
return;
}
String skStcd = attResBase.getResCode();
// 查询第二天的是否已经生成了
Calendar calendarNext = Calendar.getInstance();
calendarNext.setTime(nowTime);
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
String nextTimeStr = sdfDay.format(calendarNext.getTime());
ForecastPa hasPa = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).eq("tm", nextTimeStr));
if (ObjectUtils.isNotEmpty(hasPa)) {
return;
}
// 获取最新pa当天
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).eq("tm", sdfDay.format(nowTime)).last("limit 1"));
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast)) {
List<StPptnR> listAll = new ArrayList<>();
for (StStbprpB stb : stStbprpBList) {
String stcd = stb.getStcd();
// 获取当天大于08点到执行时间的真实降雨
List<StPptnR> qwExisted = stPptnRService.list(new QueryWrapper<StPptnR>().eq("stcd", stcd).gt("tm", sdf.parse(eightSdf.format(nowTime))).le("tm", nowTime).orderBy(true, true, "tm"));
List<StPptnR> qwExistedStcd = stPptnRService.list(new QueryWrapper<StPptnR>().eq("stcd", stcd).gt("tm", sdf.parse(eightSdf.format(nowTime))).le("tm", nowTime).orderBy(true, true, "tm"));
// 获取当天的预测降雨
List<StPptnR> pptnRFutureList = forecastResultsService.getForecastDrpData(nowTime, stcd);
qwExisted.addAll(pptnRFutureList);
Double totalDrp = qwExisted.stream().mapToDouble(x -> Double.valueOf(x.getDrp())).sum();
ForecastPa forecastPa = new ForecastPa();
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
double k = kMap.get(Integer.valueOf(nextTimeStr.substring(5, 7))).doubleValue();
double pa = RunoffService.PaCaculate(k, Double.parseDouble(forecastPaLast.getPa().toString()), totalDrp, Im);
forecastPa.setStcd(stcd);
forecastPa.setTm(nextTimeStr);
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa0(forecastPaLast.getPa());
forecastPa.setIm(new BigDecimal(Im));
forecastPa.setPt0(new BigDecimal(totalDrp).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa(new BigDecimal(pa));
forecastPaService.save(forecastPa);
List<StPptnR> pptnRFutureListStcd = forecastResultsService.getForecastDrpData(nowTime, stcd);
listAll.addAll(qwExistedStcd);
listAll.addAll(pptnRFutureListStcd);
}
Double totalDrp = listAll.stream().mapToDouble(x -> Double.valueOf(x.getDrp())).sum();
ForecastPa forecastPa = new ForecastPa();
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
double k = kMap.get(Integer.valueOf(nextTimeStr.substring(5, 7))).doubleValue();
double pa = RunoffService.PaCaculate(k, Double.parseDouble(forecastPaLast.getPa().toString()), totalDrp, Im);
forecastPa.setStcd(skStcd);
forecastPa.setTm(nextTimeStr);
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa0(forecastPaLast.getPa());
forecastPa.setIm(new BigDecimal(Im));
forecastPa.setPt0(new BigDecimal(totalDrp).setScale(2, BigDecimal.ROUND_HALF_UP));
forecastPa.setPa(new BigDecimal(pa));
forecastPaService.save(forecastPa);
}
}
}

View File

@ -15,22 +15,29 @@
</select>
<select id="getPptnRDataList" resultType="java.util.Map">
SELECT
to_char( tm_start, 'YYYY-MM-DD' ) tm,
drp
FROM
(
SELECT
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '9 hours' ) + INTERVAL '9 hours' AS tm_start,
SUM ( drp ) AS drp
FROM
st_pptn_r
WHERE
stcd = #{stcd} AND tm >= #{tm}
GROUP BY
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '9 hours' ) + INTERVAL '9 hours'
ORDER BY
tm_start ASC
) t
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
drp
FROM (SELECT date_trunc('day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours' AS tm_start, SUM ( drp ) AS drp
FROM
st_pptn_r
WHERE
stcd = #{stcd}
AND tm >= #{tm}
GROUP BY
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours'
ORDER BY
tm_start ASC) t
</select>
<select id="getPptnRDataListByTask" resultType="java.util.Map">
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
drp
FROM (SELECT date_trunc('day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours' AS tm_start, SUM ( drp ) AS drp
FROM
(SELECT tm, ROUND(AVG (drp), 1) drp FROM st_pptn_r WHERE tm >= #{tm} AND stcd IN (SELECT stcd FROM st_stbprp_b WHERE res_code = #{resCode}) GROUP BY tm) a
GROUP BY
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours'
ORDER BY
tm_start ASC) T
</select>
</mapper>

View File

@ -4,7 +4,7 @@
<select id="getStcdLastRsvrData" resultType="com.gunshi.project.xyt.model.StRsvrR">
SELECT stb.stcd,
case UPPER(stb.sttp) when 'RR' then r2.tm when 'ZZ' then r.tm end stm,
case UPPER(stb.sttp) when 'RR' then r.tm when 'ZZ' then r2.tm end stm,
stb.source,
stb.sttp
FROM public.st_stbprp_b stb