Дома поработал

This commit is contained in:
2025-01-08 07:20:54 +05:00
parent 7cf3d879e4
commit d7fa8eea7a
6 changed files with 73 additions and 77 deletions

View File

@ -6,7 +6,7 @@ server:
spring: spring:
application: application:
name: kz_mcp_weather name: kz_ccalm_weather
cache: cache:
type: none type: none
@ -16,14 +16,14 @@ custom:
data_dir: O:\\temp\\CCALM\\ data_dir: O:\\temp\\CCALM\\
#data_dir: /temp/CCALM/ #data_dir: /temp/CCALM/
db_all: db_all:
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 #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 login: postgres
password: PasSecrKey1 password: PasSecrKey1
db_ru: db_ru:
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://92.46.48.43:5433/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://127.0.0.1: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 login: postgres
password: PasSecrKey1 password: PasSecrKey1

View File

@ -154,7 +154,7 @@ public class AirTemperature implements ServletContextAware {
logger.error("N2:"+ex.getMessage(),ex); logger.error("N2:"+ex.getMessage(),ex);
result+=ex.getMessage()+"<br>"; result+=ex.getMessage()+"<br>";
} }
if(!strPos1.equals("")) if(!strPos1.isEmpty())
{ {
StringBuffer answer1=new StringBuffer(strPos1); StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":"); CutBeforeFirst(answer1,":");
@ -333,9 +333,10 @@ public class AirTemperature implements ServletContextAware {
main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
); );
"""; """;
String point_id=""; String point_id=null;
if(db_all) { if(db_all) {
point_id = DBTools.getPointId(st_all, country_id, lon, lat); point_id = DBTools.getPointId(st_all, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -345,8 +346,10 @@ public class AirTemperature implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
if(db_ru) { if(db_ru) {
point_id = DBTools.getPointId(st_ru, country_id, lon, lat); point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -356,6 +359,7 @@ public class AirTemperature implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N10:"+ex.getMessage(),ex); logger.error("N10:"+ex.getMessage(),ex);
} }
@ -421,20 +425,6 @@ public class AirTemperature implements ServletContextAware {
return result; 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+="<a href=\"./geodatalist/AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
html+="<a href=\"./geodatalist/PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
html+="<a href=\"./geodatalist/SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
return html;
}
//---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON //List of "Air temperature" dates from database in JSON
//@CacheControl(maxAge = 300) //@CacheControl(maxAge = 300)
@CrossOrigin @CrossOrigin

View File

@ -26,7 +26,7 @@ public class DBTools {
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
public static String getPointId(Statement st, String country_id, double lon, double lat) { public static String getPointId(Statement st, String country_id, double lon, double lat) {
String point_id = ""; String point_id = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
String sql = "SELECT id FROM main.points WHERE lon = ? AND lat = ? LIMIT 1"; String sql = "SELECT id FROM main.points WHERE lon = ? AND lat = ? LIMIT 1";
@ -41,15 +41,13 @@ public class DBTools {
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N9: " + ex.getMessage(), ex); logger.error("N9: " + ex.getMessage(), ex);
} }
if(point_id.isEmpty()){ if(point_id==null){
try { try {
String sql = "insert into main.points(country_id,geom,lon,lat)values(?,ST_SetSRID(st_makepoint(?,?),4326),?,?) RETURNING id"; String sql = "insert into main.points(country_id,lon,lat)values(?,?,?) RETURNING id";
pstmt = st.getConnection().prepareStatement(sql); pstmt = st.getConnection().prepareStatement(sql);
pstmt.setLong(1, Long.valueOf(country_id)); pstmt.setLong(1, Long.valueOf(country_id));
pstmt.setDouble(2, lon); pstmt.setDouble(2, lon);
pstmt.setDouble(3, lat); pstmt.setDouble(3, lat);
pstmt.setDouble(4, lon);
pstmt.setDouble(5, lat);
try (ResultSet rs = pstmt.executeQuery()) { try (ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) { if (rs.next()) {
point_id = rs.getString(1); // Получаем ID, возвращаемый SQL-запросом point_id = rs.getString(1); // Получаем ID, возвращаемый SQL-запросом

View File

@ -23,11 +23,11 @@ public class MainController {
@GetMapping("/geodatalist") @GetMapping("/geodatalist")
@ResponseBody @ResponseBody
public String getGeoDataList(Model model) { public String getGeoDataList(Model model) {
String html=""; return """
html+="<a href=\"/geodatalist/AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20240420\"><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>
html+="<a href=\"/geodatalist/PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><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>
html+="<a href=\"/geodatalist/SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><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>
return html; """;
} }
} }

View File

@ -178,7 +178,7 @@ public class Precipitation implements ServletContextAware {
logger.error("N2:"+ex.getMessage(),ex); logger.error("N2:"+ex.getMessage(),ex);
result+=ex.getMessage()+"<br>"; result+=ex.getMessage()+"<br>";
} }
if(!strPos1.equals("")) if(!strPos1.isEmpty())
{ {
StringBuffer answer1=new StringBuffer(strPos1); StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":"); CutBeforeFirst(answer1,":");
@ -353,9 +353,10 @@ public class Precipitation implements ServletContextAware {
main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
); );
"""; """;
String point_id=""; String point_id=null;
if(db_all) { if(db_all) {
point_id = DBTools.getPointId(st_all, country_id, lon, lat); point_id = DBTools.getPointId(st_all, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -365,8 +366,10 @@ public class Precipitation implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
if(db_ru) { if(db_ru) {
point_id = DBTools.getPointId(st_ru, country_id, lon, lat); point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -376,6 +379,7 @@ public class Precipitation implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
} catch (SQLException ex) { } catch (SQLException ex) {
logger.error("N10:"+ex.getMessage(),ex); logger.error("N10:"+ex.getMessage(),ex);
throw new Exception("Failed insert precipitation..."); throw new Exception("Failed insert precipitation...");

View File

@ -188,7 +188,7 @@ public class SoilTmperature implements ServletContextAware {
logger.error("N2: "+ex.getMessage(),ex); logger.error("N2: "+ex.getMessage(),ex);
result+=ex.getMessage()+"<br>"; result+=ex.getMessage()+"<br>";
} }
if(!strPos1.equals("")) if(!strPos1.isEmpty())
{ {
//String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:" //String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:"
StringBuffer answer1=new StringBuffer(strPos1); StringBuffer answer1=new StringBuffer(strPos1);
@ -372,9 +372,10 @@ public class SoilTmperature implements ServletContextAware {
main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
); );
"""; """;
String point_id=""; String point_id=null;
if(db_all) { if(db_all) {
point_id = DBTools.getPointId(st_all, country_id, lon, lat); point_id = DBTools.getPointId(st_all, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -384,8 +385,10 @@ public class SoilTmperature implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
if(db_ru) { if(db_ru) {
point_id = DBTools.getPointId(st_ru, country_id, lon, lat); point_id = DBTools.getPointId(st_ru, country_id, lon, lat);
if(point_id!=null) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); pstmt.setFloat(1, dataArrayTmp.getFloat(pos));
pstmt.setLong(2, Long.valueOf(country_id)); pstmt.setLong(2, Long.valueOf(country_id));
@ -395,6 +398,7 @@ public class SoilTmperature implements ServletContextAware {
pstmt.executeUpdate(); pstmt.executeUpdate();
} }
} }
}
} 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...");