From 7081e6ea2057e2c9d2949e6d21fd5361172c55a8 Mon Sep 17 00:00:00 2001 From: Igor I Date: Wed, 8 Jan 2025 17:53:19 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B8=D1=88=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D1=8F=D0=BC=D0=B0=D1=8F,=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=B8=D1=80=D1=83=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- org_ccalm_weather.yml | 12 +-- .../org/ccalm/weather/AirTemperature.java | 91 ++++++++++--------- .../java/org/ccalm/weather/GeoTIFFList.java | 3 +- .../java/org/ccalm/weather/Precipitation.java | 83 ++++++++--------- .../org/ccalm/weather/SoilTmperature.java | 84 ++++++++--------- 5 files changed, 141 insertions(+), 132 deletions(-) diff --git a/org_ccalm_weather.yml b/org_ccalm_weather.yml index de17d0f..23118b4 100644 --- a/org_ccalm_weather.yml +++ b/org_ccalm_weather.yml @@ -13,17 +13,17 @@ spring: #custom.config.db_url=jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=weather&sslmode=require custom: config: - data_dir: O:\\temp\\CCALM\\ - #data_dir: /temp/CCALM/ + #data_dir: O:\\temp\\CCALM\\ + data_dir: /data/ db_all: - url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require - #url: jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require + #url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require + url: jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require #url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require login: postgres password: PasSecrKey1 db_ru: - url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require - #url: jdbc:postgresql://192.168.0.90:5433/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require + #url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require + url: jdbc:postgresql://192.168.0.90:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require #url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require login: postgres password: PasSecrKey1 diff --git a/src/main/java/org/ccalm/weather/AirTemperature.java b/src/main/java/org/ccalm/weather/AirTemperature.java index b448105..2700121 100644 --- a/src/main/java/org/ccalm/weather/AirTemperature.java +++ b/src/main/java/org/ccalm/weather/AirTemperature.java @@ -319,52 +319,53 @@ public class AirTemperature implements ServletContextAware { if(country_id!=null && !country_id.equals("") && !country_id.equals("null")) { - try { - String sql= """ - insert into main.air_temperature( - val, - country_id, - point_id, - air_temperature_date_id - )values( - ?, - ?, - ?, - main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) - ); - """; - String point_id=null; - if(db_all) { - point_id = DBTools.getPointId(st_all, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + String sql= """ + insert into main.air_temperature( + val, + country_id, + point_id, + air_temperature_date_id + )values( + ?, + ?, + ?, + main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) + ); + """; + String point_id=null; + if(db_all) { + point_id = DBTools.getPointId(st_all, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + //throw new Exception("Failed insert ..."); } } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + } + if(db_ru) { + point_id = DBTools.getPointId(st_ru, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E11:"+ex.getMessage(),ex); + //throw new Exception("Failed insert ..."); } } - } catch (SQLException ex) { - logger.error("N10:"+ex.getMessage(),ex); } } - } } pos++; @@ -373,7 +374,7 @@ public class AirTemperature implements ServletContextAware { //Cut data piece from big country of Russia try { - String sql="delete from main.points where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);"; + String sql="delete from main.points p where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));"; if(st_all!=null) st_all.executeUpdate(sql); if(st_ru!=null) st_ru.executeUpdate(sql); } catch (SQLException ex) { @@ -390,8 +391,12 @@ public class AirTemperature implements ServletContextAware { try { String sql = "END TRANSACTION;"; - if(st_all!=null) st_all.executeUpdate(sql); - if(st_ru!=null) st_ru.executeUpdate(sql); + if(st_all!=null) { + st_all.executeUpdate(sql); + } + if(st_ru!=null) { + st_ru.executeUpdate(sql); + } } catch (SQLException ex) { logger.error("N13:"+ex.getMessage(),ex); } diff --git a/src/main/java/org/ccalm/weather/GeoTIFFList.java b/src/main/java/org/ccalm/weather/GeoTIFFList.java index b8c75cc..27a5a11 100644 --- a/src/main/java/org/ccalm/weather/GeoTIFFList.java +++ b/src/main/java/org/ccalm/weather/GeoTIFFList.java @@ -19,7 +19,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import tctable.Tools; -import javax.servlet.http.HttpServletResponse; +//import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponse; /* * Server buffer for map tiles. */ diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java index df12bfc..18b78b0 100644 --- a/src/main/java/org/ccalm/weather/Precipitation.java +++ b/src/main/java/org/ccalm/weather/Precipitation.java @@ -339,50 +339,51 @@ public class Precipitation implements ServletContextAware { if(country_id!=null && !country_id.equals("") && !country_id.equals("null")) { - try { - String sql= """ - insert into main.precipitation( - val, - country_id, - point_id, - air_temperature_date_id - )values( - ?, - ?, - ?, - main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) - ); - """; - String point_id=null; - if(db_all) { - point_id = DBTools.getPointId(st_all, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + String sql= """ + insert into main.precipitation( + val, + country_id, + point_id, + air_temperature_date_id + )values( + ?, + ?, + ?, + main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) + ); + """; + String point_id=null; + if(db_all) { + point_id = DBTools.getPointId(st_all, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + //throw new Exception("Failed insert precipitation..."); } } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + } + if(db_ru) { + point_id = DBTools.getPointId(st_ru, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + //throw new Exception("Failed insert precipitation..."); } } - } catch (SQLException ex) { - logger.error("N10:"+ex.getMessage(),ex); - throw new Exception("Failed insert precipitation..."); } } @@ -394,7 +395,7 @@ public class Precipitation implements ServletContextAware { //Cut data piece from big country of Russia try { - String sql="delete from main.points where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);"; + String sql="delete from main.points p where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));"; st_all.executeUpdate(sql); st_ru.executeUpdate(sql); } catch (SQLException ex) { diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java index 88d03f7..7859bba 100644 --- a/src/main/java/org/ccalm/weather/SoilTmperature.java +++ b/src/main/java/org/ccalm/weather/SoilTmperature.java @@ -358,50 +358,52 @@ public class SoilTmperature implements ServletContextAware { if(!country_id.isEmpty() && !country_id.equals("null")) { - try { - String sql=""" - insert into main.soil_temperature( - val, - country_id, - point_id, - soil_temperature_date_id - )values( - ?, - ?, - ?, - main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) - ); - """; - String point_id=null; - if(db_all) { - point_id = DBTools.getPointId(st_all, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + + String sql=""" + insert into main.soil_temperature( + val, + country_id, + point_id, + soil_temperature_date_id + )values( + ?, + ?, + ?, + main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) + ); + """; + String point_id=null; + if(db_all) { + point_id = DBTools.getPointId(st_all, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + //throw new Exception("Failed insert soil temperature..."); } } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } + } + if(db_ru) { + point_id = DBTools.getPointId(st_ru, country_id, lon, lat); + if(point_id!=null) { + try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(4, date + " " + time); + pstmt.setInt(5, Integer.valueOf(forecast)); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + //throw new Exception("Failed insert soil temperature..."); } } - } catch (SQLException ex) { - logger.error("N11: "+ex.getMessage(),ex); - throw new Exception("Failed insert soil temperature..."); } } @@ -413,7 +415,7 @@ public class SoilTmperature implements ServletContextAware { //Cut data piece from big country of Russia try { - String sql="delete from main.points where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);"; + String sql="delete from main.points p where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));"; st_all.executeUpdate(sql); st_ru.executeUpdate(sql); } catch (SQLException ex) {