fix:修改太阳能辐射模拟与预报

main
xlp 5 months ago
parent 3bf80087d6
commit 5f519603a2

@ -4,9 +4,13 @@ package com.cuit.solarenergy.controller;
import com.cuit.gis.analysis.solarradiation.RasterSolarRadiationOperation;
import com.cuit.solarenergy.base.annotation.AopLog;
import com.cuit.solarenergy.base.annotation.AuthToken;
import com.cuit.solarenergy.entity.TGeoserverinfo;
import com.cuit.solarenergy.entity.vo.req.SolarPredicReq;
import com.cuit.solarenergy.entity.vo.ret.RetResponse;
import com.cuit.solarenergy.entity.vo.ret.RetResult;
import com.cuit.solarenergy.exception.ParamsException;
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;
@ -20,8 +24,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
@Api(tags = "3、实时模拟与预报")
@ApiSupport(order = 3)
@ -31,12 +37,16 @@ public class SimulAndPredicController {
@Autowired
SolarenergyService solarenergyService;
@Autowired
GeoServerPubService geoServerPubService;
@Autowired
private DataImportService dataImportService;
@AopLog
@AuthToken
@ApiOperation("1、辐射实时模拟")
@PreAuthorize("hasAuthority('minio:upload')")
@RequestMapping(value = "/solarenergy/getSolarSimulation", method = {RequestMethod.GET})
@RequestMapping(value = "/solarenergy/getSolarSimulation", method = {RequestMethod.POST})
@ApiResponses({
@ApiResponse(code = 200, message = "成功"),
@ApiResponse(code = 401, message = "访问未经授权"),
@ -45,11 +55,20 @@ public class SimulAndPredicController {
@ApiResponse(code = 500, message = "服务器内部错误"),
@ApiResponse(code = 900, message = "失败")
})
public RetResult<String> getSolarSimulation() {
public RetResult<List<TGeoserverinfo>> getSolarSimulation(SolarPredicReq solarReq) {
try {
log.info("太阳能日总辐射实时模拟");
String s = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, Calendar.getInstance(), 0, 2000);
return RetResponse.makeOKRsp(s);
//1.辐射出图
String pathFile = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT,"", 0, 2000);
//2.发布geoserverter服务并存入数据库
Long aLong = geoServerPubService.pubGeoServerAndSavetoDB("style_tyn", "EPSG:3857",pathFile, solarReq.getRegionname());
if (Objects.isNull(aLong)|| aLong == -1){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误");
}
//3.查询tif
log.info("Tif查询");
List<TGeoserverinfo> regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname());
return RetResponse.makeOKRsp(regionInfo);
}catch (RuntimeException e){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage());
}
@ -59,7 +78,7 @@ public class SimulAndPredicController {
@AuthToken
@ApiOperation("2、辐射预报")
@PreAuthorize("hasAuthority('minio:upload')")
@RequestMapping(value = "/solarenergy/getSolarPrediction", method = {RequestMethod.GET})
@RequestMapping(value = "/solarenergy/getSolarPrediction", method = {RequestMethod.POST})
@ApiResponses({
@ApiResponse(code = 200, message = "成功"),
@ApiResponse(code = 401, message = "访问未经授权"),
@ -68,15 +87,22 @@ public class SimulAndPredicController {
@ApiResponse(code = 500, message = "服务器内部错误"),
@ApiResponse(code = 900, message = "失败")
})
public RetResult<String> getSolarPrediction() {
public RetResult<List<TGeoserverinfo>> getSolarPrediction(SolarPredicReq solarReq) {
try {
log.info("太阳能日总辐射预报");
// 获取当前日期和时间的 Calendar 对象
Calendar calendar = Calendar.getInstance();
// 给当前日期加3天
calendar.add(Calendar.DATE, 3);
String s = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, calendar, 0, 2000);
return RetResponse.makeOKRsp(s);
String time = solarReq.getTime();
//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());
if (Objects.isNull(aLong)|| aLong == -1){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误");
}
//3.查询tif
log.info("Tif查询");
List<TGeoserverinfo> regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname());
return RetResponse.makeOKRsp(regionInfo);
}catch (RuntimeException e){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage());
}

@ -1,5 +1,6 @@
package com.cuit.solarenergy.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

@ -0,0 +1,26 @@
package com.cuit.solarenergy.entity.vo.req;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import static com.cuit.solarenergy.utils.DateUtil.DATE_FORMAT;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "太阳辐射预测请求类")
public class SolarPredicReq {
@ApiModelProperty(value = "预报时间", name = "time", notes = "格式为yyyy-MM-dd")
@DateTimeFormat(pattern = DATE_FORMAT)
private String time;
@ApiModelProperty(value = "地区名称", name = "regionname")
private String regionname;
}

@ -1,7 +1,8 @@
package com.cuit.solarenergy.mapper;
import generator.domain.radi_chn_mul_hor;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import generator.domain.radi_chn_mul_hor;
import org.apache.ibatis.annotations.Mapper;
/**

@ -38,6 +38,16 @@ public interface GeoServerPubService {
*/
public Long pubGeoServerAndSavetoDB(String defstyles, String srs, String filePathName);
/**
* ,Tif GeoServeret_geoserverinfo
* @param defstyles
* @param srs
* @param filePathName
* @param regionName
* @return
*/
public Long pubGeoServerAndSavetoDB(String defstyles, String srs, String filePathName, String regionName);
/**
* geoinfoIDURL
* @param pubinfoID ID

@ -8,7 +8,9 @@ import com.cuit.gis.exception.SAException;
import com.cuit.gis.projections.CoordinateUtil;
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.StringUtils;
import org.geotools.coverage.grid.GridCoverage2D;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
@ -16,6 +18,7 @@ import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.UUID;
@ -76,10 +79,20 @@ public class SolarenergyService {
* MONTH_POSSIBLE_SUNSHINE_DURATION
*
* YEAR_POSSIBLE_SUNSHINE_DURATION
* @param calendar
* @param cloudcoverof10parts
*/
public String calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType type, Calendar calendar, double cloudcoverof10parts, int cellSize) {
public String calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType type, String time, double cloudcoverof10parts, int cellSize) {
//处理时间,如果为空,则为预测当时太阳辐射值,否则为指定日期太阳辐射值
Calendar calendar = Calendar.getInstance();
if (StringUtils.isEmpty(time)){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
calendar.setTime(simpleDateFormat.parse(time));
} catch (Exception e) {
log.error("时间格式化出错!" + e.getMessage());
throw new RuntimeException(e);
}
}
String workSpacePath = System.getProperty("user.dir");
String path = workSpacePath + File.separator + "data" + File.separator;
CoordinateReferenceSystem crs = null;

@ -19,10 +19,8 @@ import com.cuit.mete.geoserver.wms.WMSGetFeatureInfo;
import com.cuit.solarenergy.config.MyGeoServerConfig;
import com.cuit.solarenergy.entity.Geoserverinfo;
import com.cuit.solarenergy.entity.GeoserverinfoBase;
import com.cuit.solarenergy.service.GeoServerPubService;
import com.cuit.solarenergy.service.GeoserverinfoBaseService;
import com.cuit.solarenergy.service.GeoserverinfoService;
import com.cuit.solarenergy.service.SequenceService;
import com.cuit.solarenergy.entity.TGeoserverinfo;
import com.cuit.solarenergy.service.*;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import lombok.extern.slf4j.Slf4j;
@ -60,6 +58,9 @@ public class GeoServerPubServiceImpl implements GeoServerPubService {
@Autowired
GeoserverinfoBaseService geoserverinfoBaseService;
@Autowired
TGeoserverinfoService tGeoserverinfoService;
@Override
public Long pubGeoServerAndSavetoDB(String filePathName) {
String layer = FilenameUtils.getBaseName(filePathName);
@ -114,6 +115,25 @@ public class GeoServerPubServiceImpl implements GeoServerPubService {
return -1L;
}
/**
* GeoServer
* @param defstyles
* @param srs
* @param filePathName
* @param regionName
* @return
*/
@Override
public Long pubGeoServerAndSavetoDB(String defstyles, String srs, String filePathName, String regionName) {
String layer = FilenameUtils.getBaseName(filePathName);
boolean pubFlag = pubGeoServer(layer, srs, defstyles, filePathName);
if (pubFlag) {
return save2DB(filePathName, srs, defstyles);
}
return -1L;
}
@Override
public String getRasterWmsUrl(Long pubinfoID) {
//pubGeoServerConfig
@ -628,6 +648,48 @@ public class GeoServerPubServiceImpl implements GeoServerPubService {
return geoserverpubid;
}
/**
* t_geoserverinfo
* @param filePathName geotiff()
* @param styles
* @return
*/
private Long save2DB(String filePathName, String srs, String styles, String regionName) {
String layer = FilenameUtils.getBaseName(filePathName);
String geoserverUrl = myGeoServerConfig.getGeoserverurl();
String username = myGeoServerConfig.getUsername();
String password = myGeoServerConfig.getPassword();
String workspaces = myGeoServerConfig.getWorkspaces();
String bbox = "";
String latlonbbox = "";
LayerSRSbbox coverageNativeBoundingBox = GeoServerPublishUtil.getCoverageNativeBoundingBox(geoserverUrl, username, password, workspaces, layer);
LayerSRSbbox coverageSRS = GeoServerPublishUtil.getCoverageBoundingBox(geoserverUrl, username, password, workspaces, layer);
bbox = ""+coverageNativeBoundingBox.getMinx() + "," + coverageNativeBoundingBox.getMiny() + "," + coverageNativeBoundingBox.getMaxx() + "," + coverageNativeBoundingBox.getMaxy();
LayerSRSbbox coverageLatLonBoundingBox = GeoServerPublishUtil.getCoverageLatLonBoundingBox(geoserverUrl, username, password, workspaces, layer);
latlonbbox = ""+coverageLatLonBoundingBox.getMinx() + "," + coverageLatLonBoundingBox.getMiny() + "," + coverageLatLonBoundingBox.getMaxx() + "," + coverageLatLonBoundingBox.getMaxy();
//坐标系与bbox对应
String srsNative = coverageSRS.getSrs();
//保存数据
Long geoserverpubid = sequenceService.getNextval();
// Geoserverinfo geoserverinfo = new Geoserverinfo();
TGeoserverinfo geoserverinfo = new TGeoserverinfo();
geoserverinfo.setId(geoserverpubid);
geoserverinfo.setGeoserverworkspaces(workspaces);
geoserverinfo.setUrl(geoserverUrl);
geoserverinfo.setSrs(srs);
geoserverinfo.setBbox(bbox);
geoserverinfo.setLatlonbbox(latlonbbox);
geoserverinfo.setGeoserverlayers(layer);
geoserverinfo.setGeoserverstyles(styles);
geoserverinfo.setRegionname(regionName);
tGeoserverinfoService.save(geoserverinfo);
return geoserverpubid;
}
/**
* t_geoserverinfo

@ -38,7 +38,8 @@ class SolarenergyApplicationTests {
@Test
public void cal(){
String s = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, Calendar.getInstance(), 0, 1000);
//时间设为空,即为得到当天辐射量值
String s = solarenergyService.calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType.DAY_TOTAL_SOLARRADIATION_AMOUNT, "", 0, 1000);
System.out.println(s);
}

Loading…
Cancel
Save