+Таблица даты

This commit is contained in:
2024-05-01 17:34:52 +05:00
parent 18d7a228f9
commit 6bdcabc5d1
5 changed files with 97 additions and 22 deletions

22
pom.xml
View File

@ -10,13 +10,20 @@
</parent>
<groupId>org.ccalm</groupId>
<artifactId>weather</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.4-SNAPSHOT</version>
<name>weather</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<java.version>17</java.version>
<start-class>org.ccalm.weather.WeatherApplication</start-class>
</properties>
<!--repositories>
<repository>
<id>boundless</id>
<name>Boundless Repository</name>
<url>https://repo.boundlessgeo.com/main/</url>
</repository>
</repositories-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -48,12 +55,11 @@
<groupId>edu.ucar</groupId>
<artifactId>netcdfAll</artifactId>
<version>5.3.1</version>
<!-- Look: https://newbedev.com/how-to-include-system-dependencies-in-war-built-using-maven
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/lib/netcdfAll-5.3.1.jar</systemPath>
-->
<systemPath>O:/projects/Workspace_Java/CCALM_weather/src/main/lib/netcdfAll-5.3.1.jar</systemPath>
</dependency>
</dependencies>
<build>
@ -63,7 +69,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<!--plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
@ -71,7 +77,7 @@
<id>install-external</id>
<phase>clean</phase>
<configuration>
<file>${basedir}/src/main/lib/netcdfAll-5.3.1.jar</file>
<file>O:/projects/Workspace_Java/CCALM_weather/src/main/lib/netcdfAll-5.3.1.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>edu.ucar</groupId>
<artifactId>netcdfAll</artifactId>
@ -84,7 +90,7 @@
</goals>
</execution>
</executions>
</plugin>
</plugin-->
</plugins>

View File

@ -248,15 +248,20 @@ public class AirTemperature implements ServletContextAware {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.air_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 3");
try {
String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
int pos=0;
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
{
@ -289,11 +294,12 @@ public class AirTemperature implements ServletContextAware {
logger.info(ex.getMessage());
}
}
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
String sql="insert into main.air_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
String sql="insert into main.air_temperature(date,hours,val,geom,country_id,air_temperature_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
@ -395,7 +401,17 @@ public class AirTemperature implements ServletContextAware {
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
String sql = """
SELECT
to_char(date, 'YYYY-MM-DD') as date,
hours as hour,
EXTRACT(DAY FROM CURRENT_DATE-date) as day
FROM
main.air_temperature_dates
group by date,hours
order by date,hours
""";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{

View File

@ -63,7 +63,7 @@ public class Precipitation implements ServletContextAware {
@Value("${custom.config.data_dir}")
private String data_dir;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Precipitation.class);
private ServletContext context;
@ -250,6 +250,13 @@ public class Precipitation implements ServletContextAware {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 3");
try {
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
@ -294,7 +301,7 @@ public class Precipitation implements ServletContextAware {
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
String sql="insert into main.precipitation(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
String sql="insert into main.precipitation(date,hours,val,geom,country_id,precipitation_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_precipitation_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
@ -396,7 +403,19 @@ public class Precipitation implements ServletContextAware {
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
String sql = """
SELECT
to_char(date, 'YYYY-MM-DD') as date,
hours as hour,
DATE_PART('doy',date)-1 as day
FROM
main.precipitation_dates
group by
date,
hours
order by date,hours
""";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{

View File

@ -266,6 +266,13 @@ public class SoilTmperature implements ServletContextAware {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.soil_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 3");
try {
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
@ -273,7 +280,7 @@ public class SoilTmperature implements ServletContextAware {
logger.info(ex.getMessage());
}
if(Integer.parseInt(forecast)!=0) {
System.out.println("Delete old data 3");
System.out.println("Delete old data 4");
try {
String sql="delete from main.soil_temperature where hours="+forecast;
st.executeUpdate(sql);
@ -317,9 +324,7 @@ public class SoilTmperature implements ServletContextAware {
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326));";
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom,country_id)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),(select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1));";
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id,soil_temperature_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_soil_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
@ -420,8 +425,18 @@ public class SoilTmperature implements ServletContextAware {
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
String sql = """
SELECT
to_char(date, 'YYYY-MM-DD') as date,
hours as hour,
EXTRACT(DAY FROM CURRENT_DATE-date) as day
FROM
main.soil_temperature_dates
group by date,hours
order by date,hours
""";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<!-- Ротирующий файловый аппендер -->
<RollingFile name="RollingFile" fileName="logs/application.log"
filePattern="logs/application-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="ALL">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>