优化荆楚水库雨量实时表
parent
87a80f07f1
commit
8d71acb67e
|
|
@ -3,6 +3,7 @@ package com.gunshi.project.xyt.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.xyt.model.StPptnRReal;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 描述: 降水量历史表
|
||||
|
|
@ -12,4 +13,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface StPptnRRealMapper extends BaseMapper<StPptnRReal> {
|
||||
|
||||
}
|
||||
int updatePptnRReal(@Param("stcd") String stcd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 描述: 降水量历史表
|
||||
* author: xusan
|
||||
|
|
@ -20,6 +18,9 @@ import java.util.Date;
|
|||
public class StPptnRRealService extends ServiceImpl<StPptnRRealMapper, StPptnRReal>
|
||||
{
|
||||
|
||||
public int updatePptnRReal(String stcd) {
|
||||
return baseMapper.updatePptnRReal(stcd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -286,16 +286,8 @@ public class DataTask {
|
|||
(existing, replacement) -> existing // 如果有冲突,保留现有的
|
||||
)).values().stream().collect(Collectors.toList());
|
||||
stPptnRService.saveBatch(rlist);
|
||||
// 获取时间最大的一条更新到实时数据表
|
||||
StPptnR stPptnR1 = rlist.stream().max(Comparator.comparing(StPptnR::getTm)).get();
|
||||
StPptnRReal stPptnRReal = new StPptnRReal();
|
||||
stPptnRReal.setStcd(stPptnR1.getStcd());
|
||||
stPptnRReal.setTm(stPptnR1.getTm());
|
||||
stPptnRReal.setDrp(stPptnR1.getDrp());
|
||||
stPptnRReal.setChtm(new Date());
|
||||
UpdateWrapper<StPptnRReal> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("stcd", stPptnRReal.getStcd());
|
||||
stPptnRRealService.saveOrUpdate(stPptnRReal, updateWrapper);
|
||||
// 更新到实时数据表
|
||||
stPptnRRealService.updatePptnRReal(stPptnR.getStcd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,22 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gunshi.project.xyt.mapper.StPptnRRealMapper">
|
||||
|
||||
<update id="updatePptnRReal">
|
||||
with m1 as (select stcd,max(tm) as tmx from st_pptn_r where stcd = #{stcd}
|
||||
GROUP BY stcd),
|
||||
m2 as (
|
||||
select t1.stcd,t1.tm,t1.drp,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN (date_trunc('day', t1.tm) + interval '8 hour') AND (date_trunc('day', t1.tm) + interval '1 day' - interval '1 second')) today,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN t1.tm - interval '10 min' and t1.tm) m10,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN t1.tm - interval '30 min' and t1.tm) m30,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN t1.tm - interval '1 hour' and t1.tm) h1,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN t1.tm - interval '3 hour' and t1.tm) h3,
|
||||
(select sum(t3.drp) from st_pptn_r t3 where t3.stcd=t1.stcd and t3.tm BETWEEN t1.tm - interval '6 hour' and t1.tm) h6,
|
||||
CURRENT_TIMESTAMP chtm
|
||||
from st_pptn_r t1 where exists(select 1 from m1 t2 where t2.stcd=t1.stcd and t2.tmx=t1.tm) and stcd = #{stcd}
|
||||
)
|
||||
insert into st_pptn_r_real select * from m2 on conflict (stcd) do update
|
||||
set tm=excluded.tm,today=excluded.today,m10=excluded.m10,m30=excluded.m30,
|
||||
h1=excluded.h1,h3=excluded.h3,h6=excluded.h6,h12=excluded.h12,h24=excluded.h24,h48=excluded.h48,chtm=CURRENT_TIMESTAMP
|
||||
</update>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue