Правка в выборке последней даты
This commit is contained in:
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>org.ccalm</groupId>
|
||||
<artifactId>weather</artifactId>
|
||||
<version>0.0.7-SNAPSHOT</version>
|
||||
<version>0.0.8-SNAPSHOT</version>
|
||||
<name>weather</name>
|
||||
<description>Weather APP</description>
|
||||
<properties>
|
||||
|
||||
@ -107,9 +107,33 @@ public class AirTemperature implements ServletContextAware {
|
||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
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);
|
||||
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://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(""))
|
||||
{
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
@ -232,14 +256,6 @@ public class AirTemperature implements ServletContextAware {
|
||||
}
|
||||
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 {
|
||||
String sql = "BEGIN TRANSACTION;";
|
||||
@ -347,7 +363,6 @@ public class AirTemperature implements ServletContextAware {
|
||||
logger.error("E10:"+ex.getMessage(),ex);
|
||||
throw new Exception("Failed insert ...");
|
||||
}
|
||||
|
||||
}
|
||||
if(db_ru) {
|
||||
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
|
||||
@ -374,13 +389,39 @@ public class AirTemperature implements ServletContextAware {
|
||||
logger.error(ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
//Cut data piece from big country of Russia
|
||||
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));";
|
||||
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);
|
||||
//Deleting readings located in northern latitudes since locusts do not live there.
|
||||
{
|
||||
//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.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) {
|
||||
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 {
|
||||
|
||||
@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
|
||||
@ -16,18 +19,61 @@ public class MainController {
|
||||
@GetMapping("/")
|
||||
@ResponseBody
|
||||
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
|
||||
@GetMapping("/geodatalist")
|
||||
@ResponseBody
|
||||
public String getGeoDataList(Model model) {
|
||||
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/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>
|
||||
""";
|
||||
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/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>
|
||||
""";
|
||||
}
|
||||
|
||||
}
|
||||
@ -108,10 +108,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 date
|
||||
* @return
|
||||
* @return HTML string
|
||||
*/
|
||||
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||
@ResponseBody
|
||||
@ -131,8 +131,30 @@ public class Precipitation implements ServletContextAware {
|
||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
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);
|
||||
|
||||
//Example request: http://localhost:8080/Precipitation?date=20210531
|
||||
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);
|
||||
}
|
||||
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(""))
|
||||
{
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
@ -253,14 +275,6 @@ public class Precipitation implements ServletContextAware {
|
||||
}
|
||||
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 {
|
||||
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||
@ -288,16 +302,16 @@ public class Precipitation implements ServletContextAware {
|
||||
} catch (SQLException 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);
|
||||
}
|
||||
}
|
||||
// if(Integer.parseInt(forecast)!=0) {
|
||||
// logger.info("Delete all old forecasts");
|
||||
// try {
|
||||
// String sql="delete from main.precipitation_dates where hours="+forecast; у меня всё 24 часа вот и всё и удалит..... не раскоментировать!
|
||||
// st_all.executeUpdate(sql);
|
||||
// st_ru.executeUpdate(sql);
|
||||
// } catch (SQLException ex) {
|
||||
// logger.error("N8: "+ex.getMessage(),ex);
|
||||
// }
|
||||
// }
|
||||
try {
|
||||
st_all.executeUpdate("END TRANSACTION;");
|
||||
st_ru.executeUpdate("END TRANSACTION;");
|
||||
@ -344,7 +358,7 @@ public class Precipitation implements ServletContextAware {
|
||||
insert into main.precipitation(
|
||||
val,
|
||||
country_id,
|
||||
air_temperature_date_id,
|
||||
precipitation_date_id,
|
||||
point_id
|
||||
)values(
|
||||
?,
|
||||
@ -393,13 +407,39 @@ public class Precipitation implements ServletContextAware {
|
||||
} catch (Exception ex) {
|
||||
logger.error(ex.getMessage(),ex);
|
||||
}
|
||||
//Cut data piece from big country of Russia
|
||||
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));";
|
||||
st_all.executeUpdate(sql);
|
||||
st_ru.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N11:"+ex.getMessage(),ex);
|
||||
//Deleting readings located in northern latitudes since locusts do not live there.
|
||||
{
|
||||
//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.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) {
|
||||
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 {
|
||||
|
||||
@ -112,7 +112,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
* @param response
|
||||
* @param forecast
|
||||
* @param date
|
||||
* @return
|
||||
* @return HTML string
|
||||
*/
|
||||
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||
@ResponseBody
|
||||
@ -135,11 +135,30 @@ public class SoilTmperature implements ServletContextAware {
|
||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||
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);
|
||||
|
||||
|
||||
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
|
||||
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000
|
||||
//Example request: http://127.0.0.1:8080/CCALM/DownloadWeather?forecast=000
|
||||
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);
|
||||
}
|
||||
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(""))
|
||||
{
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
||||
@ -271,15 +290,6 @@ public class SoilTmperature implements ServletContextAware {
|
||||
}
|
||||
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 {
|
||||
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||
st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||
@ -412,13 +422,39 @@ public class SoilTmperature implements ServletContextAware {
|
||||
logger.error(ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
//Cut data piece from big country of Russia
|
||||
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));";
|
||||
st_all.executeUpdate(sql);
|
||||
st_ru.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N12: "+ex.getMessage(),ex);
|
||||
//Deleting readings located in northern latitudes since locusts do not live there.
|
||||
{
|
||||
//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.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) {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user