diff --git a/org_ccalm_weather.yml b/org_ccalm_weather.yml
index 339559f..b7e913c 100644
--- a/org_ccalm_weather.yml
+++ b/org_ccalm_weather.yml
@@ -10,19 +10,21 @@ spring:
cache:
type: none
-#custom.config.db_url=jdbc:postgresql://192.168.0.90:5432/weather
+#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/
db_all:
- #url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather
- url: jdbc:postgresql://92.46.48.43:5433/weather?ApplicationName=kz_mcp_weather
+ 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
+ #url: jdbc:postgresql://92.46.48.43:5433/weather?ApplicationName=kz_mcp_weather&sslmode=require
login: postgres
- password: PasSecrKey10
+ password: PasSecrKey1
db_ru:
- #url: jdbc:postgresql://92.46.48.43:5433/weather_ru?ApplicationName=kz_mcp_weather
- url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather
+ url: jdbc:postgresql://192.168.0.90:5433/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
+ #url: jdbc:postgresql://92.46.48.43:5433/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/pom.xml b/pom.xml
index aeaf629..1b10231 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,10 +12,9 @@
weather
0.0.7-SNAPSHOT
weather
- Demo project for Spring Boot
+ Weather APP
- 17
- org.ccalm.weather.WeatherApplication
+ 21
@@ -24,11 +23,6 @@
Unidata UCAR Repository
https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases/
-
@@ -36,7 +30,6 @@
org.springframework.boot
spring-boot-starter-web
-
org.postgresql
postgresql
@@ -47,22 +40,12 @@
spring-boot-starter-test
test
-
net.logstash.logback
logstash-logback-encoder
6.6
-
-
-
edu.ucar
@@ -85,7 +68,7 @@
-
+
org.apache.maven.plugins
@@ -100,5 +83,4 @@
-
diff --git a/src/main/java/org/ccalm/weather/AirTemperature.java b/src/main/java/org/ccalm/weather/AirTemperature.java
index ba8dab8..68eece2 100644
--- a/src/main/java/org/ccalm/weather/AirTemperature.java
+++ b/src/main/java/org/ccalm/weather/AirTemperature.java
@@ -17,23 +17,20 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
+//import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.ServletContextAware;
import org.w3c.dom.Document;
@@ -75,58 +72,7 @@ public class AirTemperature implements ServletContextAware {
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
this.context = servletContext;
}
- //---------------------------------------------------------------------------
- public String getCountryId(Statement st,double lon,double lat) {
- String country_id = "";
- try {
- String sql = "select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1";
- try (ResultSet rs = st.executeQuery(sql)) {
- if (rs.next()) {
- country_id = rs.getString(1);
- }
- }
- } catch (SQLException ex) {
- logger.error("N9: " + ex.getMessage(), ex);
- }
- return country_id;
- }
- //---------------------------------------------------------------------------
- public String getPointId(Statement st, String country_id, double lon, double lat) {
- String point_id = "";
- PreparedStatement pstmt = null;
- try {
- String sql = "SELECT id FROM main.points WHERE lon = ? AND lat = ? LIMIT 1";
- pstmt = st.getConnection().prepareStatement(sql);
- pstmt.setDouble(1, lon);
- pstmt.setDouble(2, lat);
- try (ResultSet rs = pstmt.executeQuery()) {
- if (rs.next()) {
- point_id = rs.getString(1);
- }
- }
- } catch (SQLException ex) {
- logger.error("N9: " + ex.getMessage(), ex);
- }
- if(point_id.isEmpty()){
- try {
- String sql = "insert into main.points(country_id,geom,lon,lat)values(?,ST_SetSRID(st_makepoint(?,?),4326),?,?) RETURNING id";
- pstmt = st.getConnection().prepareStatement(sql);
- pstmt.setLong(1, Long.valueOf(country_id));
- pstmt.setDouble(2, lon);
- pstmt.setDouble(3, lat);
- pstmt.setDouble(4, lon);
- pstmt.setDouble(5, lat);
- try (ResultSet rs = pstmt.executeQuery()) {
- if (rs.next()) {
- point_id = rs.getString(1); // Получаем ID, возвращаемый SQL-запросом
- }
- }
- } catch (SQLException ex) {
- logger.error("N11: " + ex.getMessage(), ex);
- }
- }
- return point_id;
- }
+
//---------------------------------------------------------------------------
public Connection getConn(String url, String login,String password){
Connection conn = null;
@@ -182,7 +128,7 @@ public class AirTemperature implements ServletContextAware {
System.out.println("Failed to delete the file \"air_text.idx\".");
}
}
-
+
WeatherDownload wd = new WeatherDownload();
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"air_text.idx", "0", ""))
{
@@ -363,27 +309,52 @@ public class AirTemperature implements ServletContextAware {
String country_id="";
boolean db_all=false,db_ru=false;
if(st_all!=null && country_id.isEmpty()) {
- country_id = getCountryId(st_all, lon, lat);
+ country_id = DBTools.getCountryId(st_all, lon, lat);
if(!country_id.isEmpty()) db_all=true;
}
if(st_ru!=null && country_id.isEmpty()) {
- country_id = getCountryId(st_ru, lon, lat);
+ country_id = DBTools.getCountryId(st_ru, lon, lat);
if(!country_id.isEmpty()) db_ru=true;
}
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="";
if(db_all) {
- point_id = getPointId(st_all, country_id, lon, lat);
- String sql="insert into main.air_temperature(val,point_id,country_id,air_temperature_date_id)values("+dataArrayTmp.getFloat(pos)+","+point_id+","+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
- st_all.executeUpdate(sql);
+ point_id = DBTools.getPointId(st_all, country_id, lon, lat);
+ 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();
+ }
}
if(db_ru) {
- point_id = getPointId(st_ru, country_id, lon, lat);
- String sql="insert into main.air_temperature(val,point_id,country_id,air_temperature_date_id)values("+dataArrayTmp.getFloat(pos)+","+point_id+","+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
- st_ru.executeUpdate(sql);
+ point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
+ 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("N10:"+ex.getMessage(),ex);
@@ -398,14 +369,13 @@ public class AirTemperature implements ServletContextAware {
//Cut data piece from big country of Russia
try {
- String sql="update main.points w set country_id=null 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 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);";
if(st_all!=null) st_all.executeUpdate(sql);
if(st_ru!=null) st_ru.executeUpdate(sql);
} catch (SQLException ex) {
logger.error("N11:"+ex.getMessage(),ex);
}
- //Delete values where country_id is null
try {
String sql="delete from main.points where country_id is null;";
if(st_all!=null) st_all.executeUpdate(sql);
@@ -451,21 +421,34 @@ public class AirTemperature implements ServletContextAware {
return result;
}
//---------------------------------------------------------------------------
+ //@Autowired
+ @GetMapping("/geodatalist/AirTemperatureDates0")
+ @ResponseBody
+ public String getGeoDataList0(HttpServletResponse response) {
+ String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
+ response.addHeader("Cache-Control", headerValue);
+
+ String html="";
+ html+="AirTemperatureDates
";
+ html+="PrecipitationDates
";
+ html+="SoilDates
";
+ return html;
+ }
+ //---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON
//@CacheControl(maxAge = 300)
@CrossOrigin
- @RequestMapping(value = "/geodatalist/AirTemperatureDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
+ @RequestMapping(value = "/geodatalist/AirTemperatureDates",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
@ResponseBody
public Object ajaxAirDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
- boolean error=false;
String result="";
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
- if(!error)
+ if(conn_all!=null)
{
Statement st_all;
try {
diff --git a/src/main/java/org/ccalm/weather/DBTools.java b/src/main/java/org/ccalm/weather/DBTools.java
new file mode 100644
index 0000000..6445906
--- /dev/null
+++ b/src/main/java/org/ccalm/weather/DBTools.java
@@ -0,0 +1,64 @@
+package org.ccalm.weather;
+
+import org.slf4j.LoggerFactory;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class DBTools {
+ private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DBTools.class);
+ //---------------------------------------------------------------------------
+ public static String getCountryId(Statement st,double lon,double lat) {
+ String country_id = "";
+ try {
+ String sql = "select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1";
+ try (ResultSet rs = st.executeQuery(sql)) {
+ if (rs.next()) {
+ country_id = rs.getString(1);
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N9: " + ex.getMessage(), ex);
+ }
+ return country_id;
+ }
+ //---------------------------------------------------------------------------
+ public static String getPointId(Statement st, String country_id, double lon, double lat) {
+ String point_id = "";
+ PreparedStatement pstmt = null;
+ try {
+ String sql = "SELECT id FROM main.points WHERE lon = ? AND lat = ? LIMIT 1";
+ pstmt = st.getConnection().prepareStatement(sql);
+ pstmt.setDouble(1, lon);
+ pstmt.setDouble(2, lat);
+ try (ResultSet rs = pstmt.executeQuery()) {
+ if (rs.next()) {
+ point_id = rs.getString(1);
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N9: " + ex.getMessage(), ex);
+ }
+ if(point_id.isEmpty()){
+ try {
+ String sql = "insert into main.points(country_id,geom,lon,lat)values(?,ST_SetSRID(st_makepoint(?,?),4326),?,?) RETURNING id";
+ pstmt = st.getConnection().prepareStatement(sql);
+ pstmt.setLong(1, Long.valueOf(country_id));
+ pstmt.setDouble(2, lon);
+ pstmt.setDouble(3, lat);
+ pstmt.setDouble(4, lon);
+ pstmt.setDouble(5, lat);
+ try (ResultSet rs = pstmt.executeQuery()) {
+ if (rs.next()) {
+ point_id = rs.getString(1); // Получаем ID, возвращаемый SQL-запросом
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N11: " + ex.getMessage(), ex);
+ }
+ }
+ return point_id;
+ }
+}
diff --git a/src/main/java/org/ccalm/weather/MainController.java b/src/main/java/org/ccalm/weather/MainController.java
index 761914f..a00b8d1 100644
--- a/src/main/java/org/ccalm/weather/MainController.java
+++ b/src/main/java/org/ccalm/weather/MainController.java
@@ -16,7 +16,7 @@ public class MainController {
@GetMapping("/")
@ResponseBody
public String getIndex(Model model) {
- return "The weather list is working!
/geodatalist/";
+ return "The weather list is working!
/geodatalist";
}
@CrossOrigin
@@ -24,9 +24,9 @@ public class MainController {
@ResponseBody
public String getGeoDataList(Model model) {
String html="";
- html+="AirTemperatureDates
";
- html+="PrecipitationDates
";
- html+="SoilDates
";
+ html+="AirTemperatureDates
";
+ html+="PrecipitationDates
";
+ html+="SoilDates
";
return html;
}
diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java
index 49355ef..8015cd1 100644
--- a/src/main/java/org/ccalm/weather/Precipitation.java
+++ b/src/main/java/org/ccalm/weather/Precipitation.java
@@ -5,11 +5,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -20,7 +16,8 @@ import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
+//import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -98,26 +95,6 @@ public class Precipitation implements ServletContextAware {
return result;
}
//---------------------------------------------------------------------------
- public String getCountryId(Statement st,double lon,double lat) {
- String country_id = "";
- ResultSet rs = null;
- try {
- rs = st.executeQuery("select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1");
- } catch (SQLException ex) {
- logger.error("N9: " + ex.getMessage(), ex);
- }
- if (rs != null) {
- try {
- if (rs.next())
- country_id = rs.getString(1);
- rs.close();
- } catch (SQLException ex) {
- logger.error("N10: " + ex.getMessage(), ex);
- }
- }
- return country_id;
- }
- //---------------------------------------------------------------------------
public Connection getConn(String url, String login,String password){
Connection conn = null;
try{
@@ -352,23 +329,53 @@ public class Precipitation implements ServletContextAware {
String country_id="";
boolean db_all=false,db_ru=false;
if(country_id.isEmpty()) {
- country_id = getCountryId(st_all, lon, lat);
+ country_id = DBTools.getCountryId(st_all, lon, lat);
if(!country_id.isEmpty()) db_all=true;
}
if(country_id.isEmpty()) {
- country_id = getCountryId(st_ru, lon, lat);
+ country_id = DBTools.getCountryId(st_ru, lon, lat);
if(!country_id.isEmpty()) db_ru=true;
}
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
{
- //logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
- 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+"));";
- if(db_all)
- st_all.executeUpdate(sql);
- if(db_ru)
- st_ru.executeUpdate(sql);
+ 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="";
+ if(db_all) {
+ point_id = DBTools.getPointId(st_all, country_id, lon, lat);
+ 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();
+ }
+ }
+ if(db_ru) {
+ point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
+ 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("N10:"+ex.getMessage(),ex);
throw new Exception("Failed insert precipitation...");
@@ -383,16 +390,15 @@ public class Precipitation implements ServletContextAware {
//Cut data piece from big country of Russia
try {
- String sql="update main.precipitation w set country_id=null 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 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);";
st_all.executeUpdate(sql);
st_ru.executeUpdate(sql);
} catch (SQLException ex) {
logger.error("N11:"+ex.getMessage(),ex);
}
- //Delete values where country_id is null
try {
- String sql="delete from main.precipitation where country_id is null;";
+ String sql="delete from main.points where country_id is null;";
st_all.executeUpdate(sql);
st_ru.executeUpdate(sql);
} catch (SQLException ex) {
@@ -423,19 +429,18 @@ public class Precipitation implements ServletContextAware {
//---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON
@CrossOrigin
- @RequestMapping(value = "/geodatalist/PrecipitationDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
+ @RequestMapping(value = "/geodatalist/PrecipitationDates",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
@ResponseBody
public Object ajaxAirDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
- boolean error=false;
String result="";
//Load DB configuration from "config.xml"
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
- if(!error)
+ if(conn_all!=null)
{
Statement st_all=null;
try {
diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java
index 241d53d..0c1bb5c 100644
--- a/src/main/java/org/ccalm/weather/SoilTmperature.java
+++ b/src/main/java/org/ccalm/weather/SoilTmperature.java
@@ -5,6 +5,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.Type;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -17,7 +18,8 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
+//import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -89,26 +91,6 @@ public class SoilTmperature implements ServletContextAware {
return conn;
}
//---------------------------------------------------------------------------
- public String getCountryId(Statement st,double lon,double lat) {
- String country_id = "";
- ResultSet rs = null;
- try {
- rs = st.executeQuery("select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1");
- } catch (SQLException ex) {
- logger.error("N9: " + ex.getMessage(), ex);
- }
- if (rs != null) {
- try {
- if (rs.next())
- country_id = rs.getString(1);
- rs.close();
- } catch (SQLException ex) {
- logger.error("N10: " + ex.getMessage(), ex);
- }
- }
- return country_id;
- }
- //---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
@@ -366,18 +348,17 @@ public class SoilTmperature implements ServletContextAware {
String country_id="";
boolean db_all=false,db_ru=false;
if(country_id.isEmpty()) {
- country_id = getCountryId(st_all, lon, lat);
+ country_id = DBTools.getCountryId(st_all, lon, lat);
if(!country_id.isEmpty()) db_all=true;
}
if(country_id.isEmpty()) {
- country_id = getCountryId(st_ru, lon, lat);
+ country_id = DBTools.getCountryId(st_ru, lon, lat);
if(!country_id.isEmpty()) db_ru=true;
}
if(!country_id.isEmpty() && !country_id.equals("null"))
{
try {
-+++++++
String sql="""
insert into main.soil_temperature(
val,
@@ -387,29 +368,32 @@ public class SoilTmperature implements ServletContextAware {
)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+")
+ ?,
+ main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
);
""";
+ String point_id="";
if(db_all) {
+ point_id = DBTools.getPointId(st_all, country_id, lon, lat);
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.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) {
- st_ru.executeUpdate(sql);
+ point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
+ 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("N11: "+ex.getMessage(),ex);
@@ -425,16 +409,15 @@ public class SoilTmperature implements ServletContextAware {
//Cut data piece from big country of Russia
try {
- String sql="update main.soil_temperature w set country_id=null 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 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);";
st_all.executeUpdate(sql);
st_ru.executeUpdate(sql);
} catch (SQLException ex) {
logger.error("N12: "+ex.getMessage(),ex);
}
- //Delete values where country_id is null
try {
- String sql="delete from main.soil_temperature where country_id is null;";
+ String sql="delete from main.points where country_id is null;";
st_all.executeUpdate(sql);
st_ru.executeUpdate(sql);
} catch (SQLException ex) {
@@ -465,19 +448,17 @@ public class SoilTmperature implements ServletContextAware {
//---------------------------------------------------------------------------
//List of "Soil temperature" dates from database in JSON
@CrossOrigin
- @RequestMapping(value = "/geodatalist/SoilDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
+ @RequestMapping(value = "/geodatalist/SoilDates",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
@ResponseBody
public Object ajaxSoilDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
- boolean error=false;
String result="";
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
- //Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
- if(!error)
+ if(conn_all!=null)
{
Statement st;
try {