diff --git a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java index 176367f..3b1bc70 100644 --- a/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java +++ b/src/main/java/com/cuit/solarenergy/controller/SimulAndPredicController.java @@ -13,11 +13,9 @@ 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.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; @@ -55,19 +53,25 @@ 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(); //1.辐射出图 - String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,"", 0, 2000); + String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,time, solarReq.getCloudcoverof10parts(), 1500); //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("太阳能日总辐射实时模拟服务有误"); } //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()); @@ -87,21 +91,25 @@ 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(); //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, solarReq.getCloudcoverof10parts(), 1500); //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("太阳能日总辐射实时模拟服务有误"); } //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/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/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 4306c93..17c3683 100644 --- a/src/main/java/com/cuit/solarenergy/service/DataImportService.java +++ b/src/main/java/com/cuit/solarenergy/service/DataImportService.java @@ -78,6 +78,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/SolarenergyService.java b/src/main/java/com/cuit/solarenergy/service/SolarenergyService.java index a4b2fec..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; @@ -82,9 +83,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)); @@ -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); 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 1068869..6ade357 100644 --- a/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java +++ b/src/main/java/com/cuit/solarenergy/service/impl/DataImportServiceImpl.java @@ -417,6 +417,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/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; } 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 @@ +