檀树岗雨情数据同步修复

master
cxw 2024-09-23 17:30:37 +08:00
parent f079928d65
commit f5498b934e
2 changed files with 16 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package com.gunshi.project.xyt.timetask;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@ -34,6 +35,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@ -51,13 +53,16 @@ import java.util.stream.Collectors;
@EnableScheduling//开启定时任务
@Component
@Slf4j
@Profile("prod")
@Profile("dev")
public class DataTaskTSG {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static SimpleDateFormat sdfD = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat sdfEight = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
@Value("${jcskPath}")
private String jcskPath;// 荆楚水库同步地址
@ -169,23 +174,19 @@ public class DataTaskTSG {
stPptnRRealService.updatePptnRReal(rlist.get(0).getStcd());
// 整编降雨量天表数据
StPptnRD maxDataD = stPptnRDService.getMaxData(stPptnR.getStcd());
Date tmMax = maxDataD.getTm();
maxDataD.setTm(sdf.parse(sdfEight.format(tmMax)));
List<StPptnRD> listD = stPptnRDService.reorganizePptnRDData(stPptnR.getStcd(), maxDataD);
if (CollectionUtils.isNotEmpty(listD)) {
StPptnRD LastData = listD.get(0);
if (LastData.getTm().equals(maxDataD.getTm())) {
listD.remove(0);
UpdateWrapper<StPptnRD> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("stcd", LastData.getStcd()).eq("tm", LastData.getTm());
LastData.setDrp(LastData.getDrp());
LastData.setYear(Integer.valueOf(sdfD.format(LastData.getTm()).substring(0, 4)));
stPptnRDService.saveOrUpdate(LastData, updateWrapper);
}
if (listD.size() > 0) {
listD = listD.stream()
.map(user -> {
user.setYear(Integer.valueOf(sdfD.format(user.getTm()).substring(0, 4))); // 修改属性值
return user;
}).collect(Collectors.toList());
QueryWrapper<StPptnRD> deleteWrapper = new QueryWrapper<>();
deleteWrapper.eq("stcd", stcd).ge("tm", tmMax);
stPptnRDService.remove(deleteWrapper);
stPptnRDService.saveBatch(listD);
}
}
@ -212,6 +213,8 @@ public class DataTaskTSG {
}
} catch (IOException e) {
log.error("荆楚水库雨情定时任务失败:", e.getMessage());
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
@ -293,6 +296,7 @@ public class DataTaskTSG {
UpdateWrapper<StRsvrRReal> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("stcd", stRsvrRLast.getStcd()).eq("tm", stRsvrRLast.getTm());
BeanUtils.copyProperties(stRsvrRLast, stRsvrRReal);
stRsvrRReal.setChtm(new Date());
stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper);
}
}

View File

@ -14,7 +14,7 @@
</select>
<select id="getMaxData" resultType="com.gunshi.project.xyt.model.StPptnRD">
SELECT #{stcd} stcd, COALESCE(max(tm), '2021-01-01 00:00:00') tm FROM st_pptn_r_d
SELECT #{stcd} stcd, COALESCE(max(tm), '2021-01-01 00:00:00') tm FROM st_pptn_r_d WHERE stcd = #{stcd}
</select>
<select id="reorganizePptnRDData" resultType="com.gunshi.project.xyt.model.StPptnRD">
@ -24,7 +24,7 @@
DATE_TRUNC('day', tm - INTERVAL '8 hour' - INTERVAL '1 second') + INTERVAL '8 hour' AS day_date, sum (drp) AS drp
FROM
st_pptn_r
WHERE stcd = #{stcd} AND tm >= #{maxData.tm}
WHERE stcd = #{stcd} AND tm > #{maxData.tm}
GROUP BY
day_date, stcd
ORDER BY