diff --git a/src/main/java/org/ccalm/main/GeoGSON.java b/src/main/java/org/ccalm/main/GeoGSON.java index 6c14133..9005dd8 100644 --- a/src/main/java/org/ccalm/main/GeoGSON.java +++ b/src/main/java/org/ccalm/main/GeoGSON.java @@ -2,12 +2,7 @@ package org.ccalm.main; import java.io.*; import java.nio.charset.StandardCharsets; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; @@ -263,6 +258,8 @@ public class GeoGSON implements ServletContextAware { @ResponseBody public ResponseEntity podsDensity( @RequestParam(required = false, name = "country_id", defaultValue = "5") Integer countryId, + @RequestParam(required = false, name = "region_id") Long regionId, + @RequestParam(required = false, name = "locust_type_id") Long locustTypeId, @RequestParam(required = false, name = "date_start", defaultValue = "1750227418") Long dateStartUnix, @RequestParam(required = false, name = "date_end", defaultValue = "1758010618") Long dateEndUnix, @CookieValue(value = "lng", defaultValue = "1") String language_id, @@ -276,16 +273,21 @@ public class GeoGSON implements ServletContextAware { ST_AsGeoJSON(st_setsrid(st_makepoint(fl.lon_center, fl.lat_center), 4326)) AS geometry FROM main.frmlocust fl WHERE 1=1 - AND geom IS NOT NULL + AND fl.lon_center IS NOT NULL + AND fl.lat_center IS NOT NULL AND (:countryId IS NULL OR fl.country_id = :countryId) + AND (:regionId IS NULL OR fl.region_id = :regionId) + AND (:locustTypeId IS NULL OR fl.locust_type_id = :locustTypeId) AND (:dateFrom IS NULL OR fl.date >= to_timestamp(:dateFrom)) AND (:dateTo IS NULL OR fl.date <= to_timestamp(:dateTo)) """; MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("countryId", countryId); - params.addValue("dateFrom", dateStartUnix); - params.addValue("dateTo", dateEndUnix); + params.addValue("countryId", countryId, Types.BIGINT); + params.addValue("regionId", regionId, Types.BIGINT); + params.addValue("locustTypeId", locustTypeId, Types.BIGINT); + params.addValue("dateFrom", dateStartUnix, Types.BIGINT); + params.addValue("dateTo", dateEndUnix, Types.BIGINT); List> rows = jdbcTemplate.queryForList(sql, params); diff --git a/src/main/java/org/ccalm/main/QGIS.java b/src/main/java/org/ccalm/main/QGIS.java index 24ef0df..de0a26f 100644 --- a/src/main/java/org/ccalm/main/QGIS.java +++ b/src/main/java/org/ccalm/main/QGIS.java @@ -141,6 +141,10 @@ public class QGIS implements ServletContextAware { sql2+="&country_id="+country_id; } } + if(region_id!=null && !region_id.isEmpty()) + { + sql+="&region_id="+region_id; + } if(locust_type_id!=null && !locust_type_id.isEmpty()) { sql+="&locust_type_id="+locust_type_id; @@ -155,7 +159,7 @@ public class QGIS implements ServletContextAware { if(date_end!=null && !date_end.isEmpty()) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime localDateTime = LocalDateTime.parse(date_start, formatter); + LocalDateTime localDateTime = LocalDateTime.parse(date_end, formatter); long epochSeconds = localDateTime.toEpochSecond(ZoneOffset.UTC); sql+="&date_end="+epochSeconds; } diff --git a/src/main/resources/static/resources/engine/index.js b/src/main/resources/static/resources/engine/index.js index 02b10e4..a280f43 100644 --- a/src/main/resources/static/resources/engine/index.js +++ b/src/main/resources/static/resources/engine/index.js @@ -195,6 +195,7 @@ function downloadQGISFile(product) if(product=='frmlocust') { let country_id=''; + let region_id=''; let locust_type_id=''; let date_start=''; let date_end=''; @@ -204,6 +205,8 @@ function downloadQGISFile(product) let input = null; input = document.getElementById('filter_X1_country_id'); if(input!=null) country_id=input.value; + input = document.getElementById('filter_X1_region_id'); + if(input!=null) region_id=input.value; input = document.getElementById('filter_X1_locust_type_id'); if(input!=null) locust_type_id=input.value; input = document.getElementById('filter_X1_date_start'); @@ -217,15 +220,15 @@ function downloadQGISFile(product) let url=''; if(indicator==1) - url='/api/locust/v01/QGIS?name=frmlocust_pods_density&country_id='+country_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; + url='/api/locust/v01/QGIS?name=frmlocust_pods_density&country_id='+country_id+'®ion_id='+region_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; if(indicator==2) - url='/api/locust/v01/QGIS?name=frmlocust_hoppers_density&country_id='+country_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; + url='/api/locust/v01/QGIS?name=frmlocust_hoppers_density&country_id='+country_id+'®ion_id='+region_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; if(indicator==3) - url='/api/locust/v01/QGIS?name=frmlocust_bands&country_id='+country_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; + url='/api/locust/v01/QGIS?name=frmlocust_bands&country_id='+country_id+'®ion_id='+region_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; if(indicator==4) - url='/api/locust/v01/QGIS?name=frmlocust_adults_density&country_id='+country_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; + url='/api/locust/v01/QGIS?name=frmlocust_adults_density&country_id='+country_id+'®ion_id='+region_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; if(indicator==5) - url='/api/locust/v01/QGIS?name=frmlocust_swarms&country_id='+country_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; + url='/api/locust/v01/QGIS?name=frmlocust_swarms&country_id='+country_id+'®ion_id='+region_id+'&locust_type_id='+locust_type_id+'&date_start='+date_start+'&date_end='+date_end+'®istered='+registered+''; window.open(url,'_blank'); diff --git a/src/main/resources/templates/engine/index.html b/src/main/resources/templates/engine/index.html index 9810fd7..bf5f256 100644 --- a/src/main/resources/templates/engine/index.html +++ b/src/main/resources/templates/engine/index.html @@ -40,7 +40,7 @@ - +