Merge remote-tracking branch 'origin/main'

main
qh 5 months ago
commit 69f15d971a

@ -13,11 +13,9 @@ import com.cuit.solarenergy.service.DataImportService;
import com.cuit.solarenergy.service.GeoServerPubService; import com.cuit.solarenergy.service.GeoServerPubService;
import com.cuit.solarenergy.service.SolarenergyService; import com.cuit.solarenergy.service.SolarenergyService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport; import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api; import io.swagger.annotations.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -55,19 +53,25 @@ public class SimulAndPredicController {
@ApiResponse(code = 500, message = "服务器内部错误"), @ApiResponse(code = 500, message = "服务器内部错误"),
@ApiResponse(code = 900, message = "失败") @ApiResponse(code = 900, message = "失败")
}) })
public RetResult<List<TGeoserverinfo>> getSolarSimulation(SolarPredicReq solarReq) { public RetResult<TGeoserverinfo> getSolarSimulation(SolarPredicReq solarReq) {
try { try {
//检验参数
if (StringUtils.isEmpty(solarReq.getRegionname()) || solarReq.getRegionname().equals("")){
throw new ParamsException("区域名称不能为空");
}
log.info("太阳能日总辐射实时模拟"); log.info("太阳能日总辐射实时模拟");
// 获取当前日期和时间的 Calendar 对象
String time = solarReq.getTime();
//1.辐射出图 //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服务并存入数据库 //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){ if (Objects.isNull(aLong)|| aLong == -1){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误"); return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误");
} }
//3.查询tif //3.查询tif
log.info("Tif查询"); log.info("Tif查询");
List<TGeoserverinfo> regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname()); TGeoserverinfo regionInfo = dataImportService.getTifByRegionAndTime(solarReq.getRegionname());
return RetResponse.makeOKRsp(regionInfo); return RetResponse.makeOKRsp(regionInfo);
}catch (RuntimeException e){ }catch (RuntimeException e){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage()); return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage());
@ -87,21 +91,25 @@ public class SimulAndPredicController {
@ApiResponse(code = 500, message = "服务器内部错误"), @ApiResponse(code = 500, message = "服务器内部错误"),
@ApiResponse(code = 900, message = "失败") @ApiResponse(code = 900, message = "失败")
}) })
public RetResult<List<TGeoserverinfo>> getSolarPrediction(SolarPredicReq solarReq) { public RetResult<TGeoserverinfo> getSolarPrediction(SolarPredicReq solarReq) {
try { try {
//检验参数
if (StringUtils.isEmpty(solarReq.getRegionname()) || solarReq.getRegionname().equals("")){
throw new ParamsException("区域名称不能为空");
}
log.info("太阳能日总辐射预报"); log.info("太阳能日总辐射预报");
// 获取当前日期和时间的 Calendar 对象 // 获取当前日期和时间的 Calendar 对象
String time = solarReq.getTime(); String time = solarReq.getTime();
//1.辐射出图 //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服务并存入数据库 //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){ if (Objects.isNull(aLong)|| aLong == -1){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误"); return RetResponse.makeErrRsp("太阳能日总辐射实时模拟服务有误");
} }
//3.查询tif //3.查询tif
log.info("Tif查询"); log.info("Tif查询");
List<TGeoserverinfo> regionInfo = dataImportService.getTifByRegion(solarReq.getRegionname()); TGeoserverinfo regionInfo = dataImportService.getTifByRegionAndTime(solarReq.getRegionname());
return RetResponse.makeOKRsp(regionInfo); return RetResponse.makeOKRsp(regionInfo);
}catch (RuntimeException e){ }catch (RuntimeException e){
return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage()); return RetResponse.makeErrRsp("太阳能日总辐射实时模拟有误!"+e.getMessage());

@ -19,7 +19,8 @@ public class SolarPredicReq {
@ApiModelProperty(value = "预报时间", name = "time", notes = "格式为yyyy-MM-dd") @ApiModelProperty(value = "预报时间", name = "time", notes = "格式为yyyy-MM-dd")
@DateTimeFormat(pattern = DATE_FORMAT) @DateTimeFormat(pattern = DATE_FORMAT)
private String time; private String time;
@ApiModelProperty(value = "云量,输入0-10, 默认为0", name = "cloudcoverof10parts")
double cloudcoverof10parts;
@ApiModelProperty(value = "地区名称", name = "regionname") @ApiModelProperty(value = "地区名称", name = "regionname")
private String regionname; private String regionname;

@ -30,6 +30,8 @@ public interface TGeoserverinfoMapper extends BaseMapper<TGeoserverinfo> {
* @return * @return
*/ */
List<TGeoserverinfo> getTifByRegion(@Param("region") String region); List<TGeoserverinfo> getTifByRegion(@Param("region") String region);
TGeoserverinfo getTifByRegionAndTime(@Param("region") String region);
} }

@ -78,6 +78,15 @@ public interface DataImportService {
*/ */
List<TGeoserverinfo> getTifByRegion(String region); List<TGeoserverinfo> getTifByRegion(String region);
/**
* tif,
*
* @param region
* @return
*/
TGeoserverinfo getTifByRegionAndTime(String region);
/** /**
* *
* @return * @return

@ -10,6 +10,7 @@ import com.cuit.gis.raster.GeoTiff;
import com.cuit.gis.raster.GridCoverageUtil; import com.cuit.gis.raster.GridCoverageUtil;
import com.cuit.solarenergy.utils.TimeUtil; import com.cuit.solarenergy.utils.TimeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverage2D;
import org.opengis.referencing.FactoryException; import org.opengis.referencing.FactoryException;
@ -82,9 +83,9 @@ public class SolarenergyService {
* @param cloudcoverof10parts * @param cloudcoverof10parts
*/ */
public String calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType type, String time, double cloudcoverof10parts, int cellSize) { public String calSolarRadiation(RasterSolarRadiationOperation.SolarEadiationAnalysisType type, String time, double cloudcoverof10parts, int cellSize) {
//处理时间,如果为空,则为预测当时太阳辐射值,否则为指定日期太阳辐射值 //处理时间,如果不为空,则为预测指定日期太阳辐射值,否则为计算当前时间太阳辐射值
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
if (StringUtils.isEmpty(time)){ if (!StringUtils.isEmpty(time) && !time.equals("")){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try { try {
calendar.setTime(simpleDateFormat.parse(time)); 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.MONTH_TOTAL_SOLARRADIATION_AMOUNT;
// RasterSolarRadiationOperation.SolarEadiationAnalysisType type = RasterSolarRadiationOperation.SolarEadiationAnalysisType.SUNRISETIME; // RasterSolarRadiationOperation.SolarEadiationAnalysisType type = RasterSolarRadiationOperation.SolarEadiationAnalysisType.SUNRISETIME;
if (ObjectUtils.isEmpty(cloudcoverof10parts)){
cloudcoverof10parts = 0;
}
GridCoverage2D solarRadiationCoverage2D = solarRadiationSpatialAnalysis.calculateSolarRadiation(slopCoverage, aspectCoverage, type, calendar, cloudcoverof10parts); GridCoverage2D solarRadiationCoverage2D = solarRadiationSpatialAnalysis.calculateSolarRadiation(slopCoverage, aspectCoverage, type, calendar, cloudcoverof10parts);
GridCoverageUtil.writeGeoTiff(solarRadiationCoverage2D, outFileName); GridCoverageUtil.writeGeoTiff(solarRadiationCoverage2D, outFileName);

@ -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 @Override
public List<String> getLayer() { public List<String> getLayer() {
try{ try{

@ -129,7 +129,7 @@ public class GeoServerPubServiceImpl implements GeoServerPubService {
boolean pubFlag = pubGeoServer(layer, srs, defstyles, filePathName); boolean pubFlag = pubGeoServer(layer, srs, defstyles, filePathName);
if (pubFlag) { if (pubFlag) {
return save2DB(filePathName, srs, defstyles); return save2DB(filePathName, srs, defstyles,regionName);
} }
return -1L; return -1L;
} }

@ -38,4 +38,13 @@
</where> </where>
</select> </select>
<select id="getTifByRegionAndTime" resultType="com.cuit.solarenergy.entity.TGeoserverinfo">
select
<include refid="Base_Column_List"/>
from t_geoserverinfo
where
regionname = #{region}
order by createdate desc
limit 1
</select>
</mapper> </mapper>

Loading…
Cancel
Save