начал править код
This commit is contained in:
@ -306,14 +306,6 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//Delete old data
|
||||||
/*logger.info("Delete old data 1");
|
|
||||||
try {
|
|
||||||
String sql="delete from main.air_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
|
||||||
if(st_all!=null) st_all.executeUpdate(sql);
|
|
||||||
if(st_ru!=null) st_ru.executeUpdate(sql);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N5:"+ex.getMessage(),ex);
|
|
||||||
}*/
|
|
||||||
logger.info("Delete old data 2");
|
logger.info("Delete old data 2");
|
||||||
try {
|
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;
|
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;
|
||||||
@ -324,14 +316,22 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
logger.info("Delete old data 3");
|
logger.info("Delete old data 3");
|
||||||
try {
|
try {
|
||||||
//String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
|
||||||
String sql="delete from main.air_temperature_dates where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
String sql="delete from main.air_temperature_dates where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
if(st_all!=null) st_all.executeUpdate(sql);
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
if(st_ru!=null) st_ru.executeUpdate(sql);
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7:"+ex.getMessage(),ex);
|
logger.error("N7:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
if(Integer.parseInt(forecast)!=0) {
|
||||||
|
logger.info("Delete all old forecasts");
|
||||||
|
try {
|
||||||
|
String sql="delete from main.air_temperature_dates where hours="+forecast;
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N8: "+ex.getMessage(),ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if(st_all!=null) st_all.executeUpdate("END TRANSACTION;");
|
if(st_all!=null) st_all.executeUpdate("END TRANSACTION;");
|
||||||
if(st_ru!=null) st_ru.executeUpdate("END TRANSACTION;");
|
if(st_ru!=null) st_ru.executeUpdate("END TRANSACTION;");
|
||||||
|
|||||||
@ -294,47 +294,33 @@ public class Precipitation implements ServletContextAware {
|
|||||||
|
|
||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//If repeat download, delete old data
|
||||||
logger.info("Delete old data 1");
|
logger.info("Delete old data 1");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.precipitation where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
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_all.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N5:"+ex.getMessage(),ex);
|
logger.error("N5:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
logger.info("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_all.executeUpdate(sql);
|
|
||||||
st_ru.executeUpdate(sql);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N6:"+ex.getMessage(),ex);
|
|
||||||
}
|
|
||||||
logger.info("Delete old data 3");
|
logger.info("Delete old data 3");
|
||||||
try {
|
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;
|
String sql="delete from main.precipitation_dates where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
st_all.executeUpdate(sql);
|
|
||||||
st_ru.executeUpdate(sql);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
|
||||||
System.out.println("Delete old data 3");
|
|
||||||
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.error("N6:"+ex.getMessage(),ex);
|
|
||||||
}
|
|
||||||
logger.info("Delete old data 3");
|
|
||||||
try {
|
|
||||||
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
|
||||||
st_all.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7:"+ex.getMessage(),ex);
|
logger.error("N7:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
if(Integer.parseInt(forecast)!=0) {
|
||||||
|
logger.info("Delete all old forecasts");
|
||||||
|
try {
|
||||||
|
String sql="delete from main.precipitation_dates where hours="+forecast;
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N8: "+ex.getMessage(),ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
st_all.executeUpdate("END TRANSACTION;");
|
st_all.executeUpdate("END TRANSACTION;");
|
||||||
st_ru.executeUpdate("END TRANSACTION;");
|
st_ru.executeUpdate("END TRANSACTION;");
|
||||||
|
|||||||
@ -5,11 +5,7 @@ import java.io.File;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -311,10 +307,10 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
|
|
||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//If repeat download, delete old data
|
||||||
logger.info("Delete old data 1");
|
logger.info("Delete old data 1");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
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_all.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
@ -322,24 +318,16 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
logger.info("Delete old data 2");
|
logger.info("Delete old data 2");
|
||||||
try {
|
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;
|
String sql="delete from main.soil_temperature_dates where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
st_all.executeUpdate(sql);
|
|
||||||
st_ru.executeUpdate(sql);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N6: "+ex.getMessage(),ex);
|
|
||||||
}
|
|
||||||
logger.info("Delete old data 3");
|
|
||||||
try {
|
|
||||||
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
|
||||||
st_all.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7: "+ex.getMessage(),ex);
|
logger.error("N7: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
if(Integer.parseInt(forecast)!=0) {
|
if(Integer.parseInt(forecast)!=0) {
|
||||||
logger.info("Delete old data 4");
|
logger.info("Delete all old forecasts");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature where hours="+forecast;
|
String sql="delete from main.soil_temperature_dates where hours="+forecast;
|
||||||
st_all.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
@ -389,11 +377,40 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
if(!country_id.isEmpty() && !country_id.equals("null"))
|
if(!country_id.isEmpty() && !country_id.equals("null"))
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
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+"));";
|
+++++++
|
||||||
if(db_all)
|
String sql="""
|
||||||
st_all.executeUpdate(sql);
|
insert into main.soil_temperature(
|
||||||
if(db_ru)
|
val,
|
||||||
|
country_id,
|
||||||
|
point_id,
|
||||||
|
soil_temperature_date_id
|
||||||
|
)values(
|
||||||
|
?,
|
||||||
|
?,
|
||||||
|
main.get_point_id(?,?,?),
|
||||||
|
"+country_id+",
|
||||||
|
main.get_soil_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+")
|
||||||
|
);
|
||||||
|
""";
|
||||||
|
if(db_all) {
|
||||||
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
|
// Устанавливаем параметры в PreparedStatement
|
||||||
|
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); // val
|
||||||
|
pstmt.setLong(2, country_id); // country_id
|
||||||
|
|
||||||
|
pstmt.setString(2, lon); // lon
|
||||||
|
pstmt.setString(3, lat); // lat
|
||||||
|
|
||||||
|
pstmt.setString(5, date); // date
|
||||||
|
pstmt.setString(6, time); // time
|
||||||
|
pstmt.setInt(7, forecast); // forecast
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(db_ru) {
|
||||||
st_ru.executeUpdate(sql);
|
st_ru.executeUpdate(sql);
|
||||||
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N11: "+ex.getMessage(),ex);
|
logger.error("N11: "+ex.getMessage(),ex);
|
||||||
throw new Exception("Failed insert soil temperature...");
|
throw new Exception("Failed insert soil temperature...");
|
||||||
@ -465,7 +482,6 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
Statement st;
|
Statement st;
|
||||||
try {
|
try {
|
||||||
st = conn_all.createStatement();
|
st = conn_all.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 = """
|
String sql = """
|
||||||
SELECT
|
SELECT
|
||||||
to_char(date, 'YYYY-MM-DD') as date,
|
to_char(date, 'YYYY-MM-DD') as date,
|
||||||
|
|||||||
Reference in New Issue
Block a user