From 528e346c831e838d5cef7730dabbc67880c4c263 Mon Sep 17 00:00:00 2001 From: xlp <384053035@qq.com> Date: Thu, 28 Nov 2024 09:36:27 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=A4=AA=E9=98=B3?= =?UTF-8?q?=E8=83=BD=E8=BE=90=E5=B0=84=E6=A8=A1=E6=8B=9F=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SimulAndPredicController.java | 13 ++++++------- .../solarenergy/service/SolarenergyService.java | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java index 176367f..6054379 100644 --- a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java +++ b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java @@ -13,10 +13,7 @@ import com.cuit.solarenergy.service.DataImportService; import com.cuit.solarenergy.service.GeoServerPubService; import com.cuit.solarenergy.service.SolarenergyService; import com.github.xiaoymin.knife4j.annotations.ApiSupport; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -58,10 +55,12 @@ public class SimulAndPredicController { public RetResult> getSolarSimulation(SolarPredicReq solarReq) { try { log.info("太阳能日总辐射实时模拟"); + // 获取当前日期和时间的 Calendar 对象 + String time = solarReq.getTime(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,"", 0, 2000); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, 0, 2000); //2.发布geoserverter服务并存入数据库 - Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tyn", "EPSG:3857",pathFile, solarReq.getRegionname()); + Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误"); } @@ -95,7 +94,7 @@ public class SimulAndPredicController { //1.辐射出图 String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, time, 0, 2000); //2.发布geoserverter服务并存入数据库 - Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tyn", "EPSG:3857",pathFile, solarReq.getRegionname()); + Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误"); } diff --git a/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java b/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java index a4b2fec..ce13168 100644 --- a/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java +++ b/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java @@ -82,9 +82,9 @@ public class SolarenergyService { * @param cloudcoverof10parts */ public String calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType type, String time, double cloudcoverof10parts, int cellSize) { - //处理时间,如果为空,则为预测当时太阳辐射值,否则为指定日期太阳辐射值 + //处理时间,如果不为空,则为预测指定日期太阳辐射值,否则为计算当前时间太阳辐射值 Calendar calendar = Calendar.getInstance(); - if (StringUtils.isEmpty(time)){ + if (!StringUtils.isEmpty(time) && !time.equals("")){ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { calendar.setTime(simpleDateFormat.parse(time)); From 9a8f61106f99568f66c933bc9392ae849cf356db Mon Sep 17 00:00:00 2001 From: xlp <384053035@qq.com> Date: Thu, 28 Nov 2024 09:53:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=A4=AA=E9=98=B3?= =?UTF-8?q?=E8=83=BD=E8=BE=90=E5=B0=84=E6=A8=A1=E6=8B=9F=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cuit/solarenergy/controller/SimulAndPredicController.java | 4 ++-- .../solarenergy/service/impl/GeoServerPubServiceImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java index 6054379..0377431 100644 --- a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java +++ b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java @@ -58,7 +58,7 @@ public class SimulAndPredicController { // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, 0, 2000); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, 0, 1500); //2.发布geoserverter服务并存入数据库 Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ @@ -92,7 +92,7 @@ public class SimulAndPredicController { // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, time, 0, 2000); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, time, 0, 1500); //2.发布geoserverter服务并存入数据库 Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ diff --git a/src/main/java/com/cuit/solarenergy/service/impl/GeoServerPubServiceImpl.java b/src/main/java/com/cuit/solarenergy/service/impl/GeoServerPubServiceImpl.java index 30a5ec8..9bc2722 100644 --- a/src/main/java/com/cuit/solarenergy/service/impl/GeoServerPubServiceImpl.java +++ b/src/main/java/com/cuit/solarenergy/service/impl/GeoServerPubServiceImpl.java @@ -129,7 +129,7 @@ public class GeoServerPubServiceImpl implements GeoServerPubService { boolean pubFlag = pubGeoServer(layer, srs, defstyles, filePathName); if (pubFlag) { - return save2DB(filePathName, srs, defstyles); + return save2DB(filePathName, srs, defstyles,regionName); } return -1L; } From 430229968a978a2c11edb96caed97db51cf49d0c Mon Sep 17 00:00:00 2001 From: xlp <384053035@qq.com> Date: Thu, 28 Nov 2024 10:28:04 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=A4=AA=E9=98=B3?= =?UTF-8?q?=E8=83=BD=E8=BE=90=E5=B0=84=E6=A8=A1=E6=8B=9F=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SimulAndPredicController.java | 17 +++++++++++++---- .../mapper/TGeoserverinfoMapper.java | 2 ++ .../solarenergy/service/DataImportService.java | 9 +++++++++ .../service/impl/DataImportServiceImpl.java | 11 +++++++++++ .../resources/mapper/TGeoserverinfoMapper.xml | 9 +++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java index 0377431..01f8391 100644 --- a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java +++ b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java @@ -15,6 +15,7 @@ import com.cuit.solarenergy.service.SolarenergyService; import com.github.xiaoymin.knife4j.annotations.ApiSupport; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.RequestMapping; @@ -52,8 +53,12 @@ public class SimulAndPredicController { @ApiResponse(code = 500, message = "服务器内部错误"), @ApiResponse(code = 900, message = "失败") }) - public RetResult> getSolarSimulation(SolarPredicReq solarReq) { + public RetResult getSolarSimulation(SolarPredicReq solarReq) { try { + //检验参数 + if (StringUtils.isEmpty(solarReq.getRegionname()) || solarReq.getRegionname().equals("")){ + throw new ParamsException("区域名称不能为空"); + } log.info("太阳能日总辐射实时模拟"); // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); @@ -66,7 +71,7 @@ public class SimulAndPredicController { } //3.查询tif log.info("Tif查询"); - List regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname()); + TGeoserverinfo regionInfo = dataImportService.getTifByRegionAndTime(solarReq.getRegionname()); return RetResponse.makeOKRsp(regionInfo); }catch (RuntimeException e){ return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage()); @@ -86,8 +91,12 @@ public class SimulAndPredicController { @ApiResponse(code = 500, message = "服务器内部错误"), @ApiResponse(code = 900, message = "失败") }) - public RetResult> getSolarPrediction(SolarPredicReq solarReq) { + public RetResult getSolarPrediction(SolarPredicReq solarReq) { try { + //检验参数 + if (StringUtils.isEmpty(solarReq.getRegionname()) || solarReq.getRegionname().equals("")){ + throw new ParamsException("区域名称不能为空"); + } log.info("太阳能日总辐射预报"); // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); @@ -100,7 +109,7 @@ public class SimulAndPredicController { } //3.查询tif log.info("Tif查询"); - List regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname()); + TGeoserverinfo regionInfo = dataImportService.getTifByRegionAndTime(solarReq.getRegionname()); return RetResponse.makeOKRsp(regionInfo); }catch (RuntimeException e){ return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage()); diff --git a/src/main/java/com/cuit/solarenergy/mapper/TGeoserverinfoMapper.java b/src/main/java/com/cuit/solarenergy/mapper/TGeoserverinfoMapper.java index 0a7655c..8082669 100644 --- a/src/main/java/com/cuit/solarenergy/mapper/TGeoserverinfoMapper.java +++ b/src/main/java/com/cuit/solarenergy/mapper/TGeoserverinfoMapper.java @@ -30,6 +30,8 @@ public interface TGeoserverinfoMapper extends BaseMapper { * @return */ List getTifByRegion(@Param("region") String region); + + TGeoserverinfo getTifByRegionAndTime(@Param("region") String region); } diff --git a/src/main/java/com/cuit/solarenergy/service/DataImportService.java b/src/main/java/com/cuit/solarenergy/service/DataImportService.java index 40e871f..38db575 100644 --- a/src/main/java/com/cuit/solarenergy/service/DataImportService.java +++ b/src/main/java/com/cuit/solarenergy/service/DataImportService.java @@ -79,6 +79,15 @@ public interface DataImportService { */ List getTifByRegion(String region); + + /** + * 根据区域查询tif文件, 得到创建时间最新的一条 + * + * @param region + * @return + */ + TGeoserverinfo getTifByRegionAndTime(String region); + /** * 获取图层信息 * @return diff --git a/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java b/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java index e0326a5..cd18251 100644 --- a/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java +++ b/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java @@ -414,6 +414,17 @@ public class DataImportServiceImpl implements DataImportService { } + @Override + public TGeoserverinfo getTifByRegionAndTime(String region) { + try{ + TGeoserverinfo tGeoserverinfo = new TGeoserverinfo(); + tGeoserverinfo = tGeoserverinfoMapper.getTifByRegionAndTime(region); + return tGeoserverinfo; + }catch (ParamsException e){ + throw new RuntimeException("数据库获取失败", e); + } + } + @Override public List getLayer() { try{ diff --git a/src/main/resources/mapper/TGeoserverinfoMapper.xml b/src/main/resources/mapper/TGeoserverinfoMapper.xml index 72ebf88..faed2ab 100644 --- a/src/main/resources/mapper/TGeoserverinfoMapper.xml +++ b/src/main/resources/mapper/TGeoserverinfoMapper.xml @@ -38,4 +38,13 @@ + From 260d10f90f0393d9879bb704132dcfc7f0f14471 Mon Sep 17 00:00:00 2001 From: xlp <384053035@qq.com> Date: Thu, 28 Nov 2024 10:50:09 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=A4=AA=E9=98=B3?= =?UTF-8?q?=E8=83=BD=E8=BE=90=E5=B0=84=E6=A8=A1=E6=8B=9F=E4=B8=8E=E9=A2=84?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solarenergy/controller/SimulAndPredicController.java | 4 ++-- .../com/cuit/solarenergy/entity/vo/req/SolarPredicReq.java | 3 ++- .../com/cuit/solarenergy/service/SolarenergyService.java | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java index 01f8391..3b1bc70 100644 --- a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java +++ b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java @@ -63,7 +63,7 @@ public class SimulAndPredicController { // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, 0, 1500); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, solarReq.getCloudcoverof10parts(), 1500); //2.发布geoserverter服务并存入数据库 Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ @@ -101,7 +101,7 @@ public class SimulAndPredicController { // 获取当前日期和时间的 Calendar 对象 String time = solarReq.getTime(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, time, 0, 1500); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, time, solarReq.getCloudcoverof10parts(), 1500); //2.发布geoserverter服务并存入数据库 Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tynday", "EPSG:3857",pathFile, solarReq.getRegionname()); if (Objects.isNull(aLong)|| aLong == -1){ diff --git a/src/main/java/com/cuit/solarenergy/entity/vo/req/SolarPredicReq.java b/src/main/java/com/cuit/solarenergy/entity/vo/req/SolarPredicReq.java index a75112b..69e7d2d 100644 --- a/src/main/java/com/cuit/solarenergy/entity/vo/req/SolarPredicReq.java +++ b/src/main/java/com/cuit/solarenergy/entity/vo/req/SolarPredicReq.java @@ -19,7 +19,8 @@ public class SolarPredicReq { @ApiModelProperty(value = "预报时间", name = "time", notes = "格式为yyyy-MM-dd") @DateTimeFormat(pattern = DATE_FORMAT) private String time; - + @ApiModelProperty(value = "云量,输入0-10, 默认为0", name = "cloudcoverof10parts") + double cloudcoverof10parts; @ApiModelProperty(value = "地区名称", name = "regionname") private String regionname; diff --git a/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java b/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java index ce13168..7c4cdb3 100644 --- a/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java +++ b/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java @@ -10,6 +10,7 @@ import com.cuit.gis.raster.GeoTiff; import com.cuit.gis.raster.GridCoverageUtil; import com.cuit.solarenergy.utils.TimeUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.geotools.coverage.grid.GridCoverage2D; import org.opengis.referencing.FactoryException; @@ -167,7 +168,9 @@ public class SolarenergyService { */ //RasterSolarRadiationOperation.SolarEadiationAnalysisType type = RasterSolarRadiationOperation.SolarEadiationAnalysisType.MONTH_TOTAL_SOLARRADIATION_AMOUNT; // RasterSolarRadiationOperation.SolarEadiationAnalysisType type = RasterSolarRadiationOperation.SolarEadiationAnalysisType.SUNRISETIME; - + if (ObjectUtils.isEmpty(cloudcoverof10parts)){ + cloudcoverof10parts = 0; + } GridCoverage2D solarRadiationCoverage2D = solarRadiationSpatialAnalysis.calculateSolarRadiation(slopCoverage, aspectCoverage, type, calendar, cloudcoverof10parts); GridCoverageUtil.writeGeoTiff(solarRadiationCoverage2D, outFileName);