# Conflicts:
#	src/main/java/org/ccalm/weather/AirTemperature.java
#	src/main/java/org/ccalm/weather/Precipitation.java
#	src/main/java/org/ccalm/weather/SoilTmperature.java
This commit is contained in:
2025-02-03 07:32:38 +05:00
5 changed files with 239 additions and 76 deletions

View File

@ -10,7 +10,7 @@
</parent> </parent>
<groupId>org.ccalm</groupId> <groupId>org.ccalm</groupId>
<artifactId>weather</artifactId> <artifactId>weather</artifactId>
<version>0.0.7-SNAPSHOT</version> <version>0.0.8-SNAPSHOT</version>
<name>weather</name> <name>weather</name>
<description>Weather APP</description> <description>Weather APP</description>
<properties> <properties>

View File

@ -95,9 +95,33 @@ public class AirTemperature implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath()); //response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all); Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru); Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
Statement st_all=null;
Statement st_ru=null;
try {
if(conn_all!=null) st_all = conn_all.createStatement();
if(conn_ru!=null) st_ru = conn_ru.createStatement();
} catch (SQLException ex) {
logger.error("N3:"+ex.getMessage(),ex);
}
//Example request: http://ccalm.org/AirTemperature?date=20210531 //Example request: http://ccalm.org/AirTemperature?date=20210531
//Example request: http://localhost:8080/AirTemperature?date=20210531 //Example request: http://127.0.0.1:8080/AirTemperature?date=20210531
if(date==null || date.equals(""))
{
//Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.air_temperature_dates where hours=0 and date > now() - '10 days'::interval";
if(st_all!=null) {
try {
try (ResultSet rs = st_all.executeQuery(sql)) {
if (rs.next()) {
date = rs.getString(1);
}
}
} catch (SQLException ex) {
logger.error("N4:"+ex.getMessage(),ex);
}
}
}
if(date==null || date.equals("")) if(date==null || date.equals(""))
{ {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@ -220,14 +244,6 @@ public class AirTemperature implements ServletContextAware {
} }
dimIt = null; dimIt = null;
Statement st_all=null;
Statement st_ru=null;
try {
if(conn_all!=null) st_all = conn_all.createStatement();
if(conn_ru!=null) st_ru = conn_ru.createStatement();
} catch (SQLException ex) {
logger.error("N3:"+ex.getMessage(),ex);
}
try { try {
String sql = "BEGIN TRANSACTION;"; String sql = "BEGIN TRANSACTION;";
@ -335,7 +351,6 @@ public class AirTemperature implements ServletContextAware {
logger.error("E10:"+ex.getMessage(),ex); logger.error("E10:"+ex.getMessage(),ex);
throw new Exception("Failed insert ..."); throw new Exception("Failed insert ...");
} }
} }
if(db_ru) { if(db_ru) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
@ -362,13 +377,39 @@ public class AirTemperature implements ServletContextAware {
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
} }
//Cut data piece from big country of Russia //Deleting readings located in northern latitudes since locusts do not live there.
try { {
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));"; //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); String sql= """
if(st_ru!=null) st_ru.executeUpdate(sql); delete from main.air_temperature where id in
(
select a.id from
main.air_temperature a
join main.points p on p.id=a.point_id
where
a.country_id=7
and a.air_temperature_date_id = main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
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(conn_all!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N11:"+ex.getMessage(),ex); logger.error("E10.1:"+ex.getMessage(),ex);
}
}
if(conn_ru!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) {
logger.error("E11:"+ex.getMessage(),ex);
}
}
} }
try { try {

View File

@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.io.InputStream;
import java.util.Properties;
@Controller @Controller
public class MainController { public class MainController {
@ -16,7 +19,50 @@ public class MainController {
@GetMapping("/") @GetMapping("/")
@ResponseBody @ResponseBody
public String getIndex(Model model) { public String getIndex(Model model) {
return "The weather list is working! <br><a href=\"./geodatalist\">/geodatalist</a>"; String buildDate="";
//String buildVersion="";
try {
InputStream inputStream = MainController.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties");
if (inputStream != null) {
Properties properties = new Properties();
properties.load(inputStream);
buildDate = properties.getProperty("build.time");
//buildVersion = properties.getProperty("build.version");
}
} catch (Exception e) {
e.printStackTrace();
}
String result="buildDate = " + buildDate + "<br><br>";
result+="""
The weather list is working! <br><a href=\"./geodatalist\">/geodatalist</a>
""";
return result;
}
@CrossOrigin
@GetMapping("/geodatalist/")
@ResponseBody
public String getIndex2(Model model) {
String buildDate="";
//String buildVersion="";
try {
InputStream inputStream = MainController.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties");
if (inputStream != null) {
Properties properties = new Properties();
properties.load(inputStream);
buildDate = properties.getProperty("build.time");
//buildVersion = properties.getProperty("build.version");
}
} catch (Exception e) {
e.printStackTrace();
}
String result="buildDate = " + buildDate + "<br><br>";
result+="""
The weather list is working! <br><a href=\"./geodatalist\">/geodatalist</a>
""";
return result;
} }
@CrossOrigin @CrossOrigin
@ -25,8 +71,8 @@ public class MainController {
public String getGeoDataList(Model model) { public String getGeoDataList(Model model) {
return """ return """
<a href="/geodatalist/AirTemperatureDates">AirTemperatureDates</a><br><form action="/geodatalist/AirTemperature" method="get"><label for="fname">Date:</label><input type="text" name="date" value="20250107"><input type="submit" value="Submit"></form><br> <a href="/geodatalist/AirTemperatureDates">AirTemperatureDates</a><br><form action="/geodatalist/AirTemperature" method="get"><label for="fname">Date:</label><input type="text" name="date" value="20250107"><input type="submit" value="Submit"></form><br>
<a href="/geodatalist/PrecipitationDates">PrecipitationDates</a><br><form action="/geodatalist/Precipitation" method="get"><label for="fname">Date:</label><input type="text" name="date" value=""20250107"><input type="submit" value="Submit"></form><br> <a href="/geodatalist/PrecipitationDates">PrecipitationDates</a><br><form action="/geodatalist/Precipitation" method="get"><label for="fname">Date:</label><input type="text" name="date" value="20250107"><input type="submit" value="Submit"></form><br>
<a href="/geodatalist/SoilDates">SoilDates</a><br><form action="/geodatalist/DownloadSoil" method="get"><label for="fname">Date:</label><input type="text" name="date" value=""20250107"><label for="forecast">Forecast:</label><input type="text" name="forecast" value="000"><input type="submit" value="Submit"></form><br> <a href="/geodatalist/SoilDates">SoilDates</a><br><form action="/geodatalist/DownloadSoil" method="get"><label for="fname">Date:</label><input type="text" name="date" value="20250107"><label for="forecast">Forecast:</label><input type="text" name="forecast" value="000"><input type="submit" value="Submit"></form><br>
"""; """;
} }

View File

@ -96,10 +96,10 @@ public class Precipitation implements ServletContextAware {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/** /**
* Example http://127.0.0.1:8080/AirTemperature * Example https://127.0.0.1:8081/geodatalist/Precipitation or https://127.0.0.1:8081/geodatalist/Precipitation?date=20250531
* @param response * @param response
* @param date * @param date
* @return * @return HTML string
*/ */
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8") @RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody @ResponseBody
@ -119,8 +119,30 @@ public class Precipitation implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath()); //response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all); Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru); Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
Statement st_all=null;
//Example request: http://localhost:8080/Precipitation?date=20210531 Statement st_ru=null;
try {
st_all = conn_all.createStatement();
st_ru = conn_ru.createStatement();
} catch (SQLException ex) {
logger.error("N3:"+ex.getMessage(),ex);
}
if(date==null || date.equals(""))
{
//Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.precipitation_dates where hours=0 and date > now() - '10 days'::interval";
if(st_all!=null) {
try {
try (ResultSet rs = st_all.executeQuery(sql)) {
if (rs.next()) {
date = rs.getString(1);
}
}
} catch (SQLException ex) {
logger.error("N4:"+ex.getMessage(),ex);
}
}
}
if(date==null || date.equals("")) if(date==null || date.equals(""))
{ {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@ -241,14 +263,6 @@ public class Precipitation implements ServletContextAware {
} }
dimIt = null; dimIt = null;
Statement st_all=null;
Statement st_ru=null;
try {
st_all = conn_all.createStatement();
st_ru = conn_ru.createStatement();
} catch (SQLException ex) {
logger.error("N3:"+ex.getMessage(),ex);
}
try { try {
st_all.executeUpdate("BEGIN TRANSACTION;"); st_all.executeUpdate("BEGIN TRANSACTION;");
@ -276,16 +290,16 @@ public class Precipitation implements ServletContextAware {
} 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 all old forecasts"); // logger.info("Delete all old forecasts");
try { // try {
String sql="delete from main.precipitation_dates where hours="+forecast; // String sql="delete from main.precipitation_dates where hours="+forecast; у меня всё 24 часа вот и всё и удалит..... не раскоментировать!
st_all.executeUpdate(sql); // st_all.executeUpdate(sql);
st_ru.executeUpdate(sql); // st_ru.executeUpdate(sql);
} catch (SQLException ex) { // } catch (SQLException ex) {
logger.error("N8: "+ex.getMessage(),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;");
@ -332,7 +346,7 @@ public class Precipitation implements ServletContextAware {
insert into main.precipitation( insert into main.precipitation(
val, val,
country_id, country_id,
air_temperature_date_id, precipitation_date_id,
point_id point_id
)values( )values(
?, ?,
@ -381,13 +395,39 @@ public class Precipitation implements ServletContextAware {
} catch (Exception ex) { } catch (Exception ex) {
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
} }
//Cut data piece from big country of Russia //Deleting readings located in northern latitudes since locusts do not live there.
try { {
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));"; //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); String sql= """
st_ru.executeUpdate(sql); delete from main.precipitation where id in
(
select a.id from
main.precipitation a
join main.points p on p.id=a.point_id
where
a.country_id=7
and a.precipitation_date_id = main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
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(conn_all!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N11:"+ex.getMessage(),ex); logger.error("E10.1:"+ex.getMessage(),ex);
}
}
if(conn_ru!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) {
logger.error("E11:"+ex.getMessage(),ex);
}
}
} }
try { try {

View File

@ -100,7 +100,7 @@ public class SoilTmperature implements ServletContextAware {
* @param response * @param response
* @param forecast * @param forecast
* @param date * @param date
* @return * @return HTML string
*/ */
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8") @RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody @ResponseBody
@ -123,11 +123,30 @@ public class SoilTmperature implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath()); //response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all); Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru); Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
Statement st_all=null;
Statement st_ru=null;
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531 try {
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000 st_all = conn_all.createStatement();
//Example request: http://127.0.0.1:8080/CCALM/DownloadWeather?forecast=000 st_ru = conn_ru.createStatement();
} catch (SQLException ex) {
logger.error("N3:"+ex.getMessage(),ex);
}
if(date==null || date.equals(""))
{
//Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.soil_temperature_dates where hours=0 and date > now() - '10 days'::interval";
if(st_all!=null) {
try {
try (ResultSet rs = st_all.executeQuery(sql)) {
if (rs.next()) {
date = rs.getString(1);
}
}
} catch (SQLException ex) {
logger.error("N4:"+ex.getMessage(),ex);
}
}
}
if(date==null || date.equals("")) if(date==null || date.equals(""))
{ {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@ -259,15 +278,6 @@ public class SoilTmperature implements ServletContextAware {
} }
dimIt = null; dimIt = null;
Statement st_all=null;
Statement st_ru=null;
try {
st_all = conn_all.createStatement();
st_ru = conn_all.createStatement();
} catch (SQLException ex) {
logger.error("N3: "+ex.getMessage(),ex);
}
try { try {
st_all.executeUpdate("BEGIN TRANSACTION;"); st_all.executeUpdate("BEGIN TRANSACTION;");
st_ru.executeUpdate("BEGIN TRANSACTION;"); st_ru.executeUpdate("BEGIN TRANSACTION;");
@ -400,13 +410,39 @@ public class SoilTmperature implements ServletContextAware {
logger.error(ex.getMessage(),ex); logger.error(ex.getMessage(),ex);
} }
//Cut data piece from big country of Russia //Deleting readings located in northern latitudes since locusts do not live there.
try { {
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));"; //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); String sql= """
st_ru.executeUpdate(sql); delete from main.soil_temperature where id in
(
select a.id from
main.soil_temperature a
join main.points p on p.id=a.point_id
where
a.country_id=7
and a.soil_temperature_date_id = main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
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(conn_all!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N12: "+ex.getMessage(),ex); logger.error("E10.1:"+ex.getMessage(),ex);
}
}
if(conn_ru!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setString(1, date + " " + time);
pstmt.setInt(2, Integer.valueOf(forecast));
pstmt.executeUpdate();
} catch (SQLException ex) {
logger.error("E11:"+ex.getMessage(),ex);
}
}
} }
try { try {