Commit 87a1a1dc authored by ZWT's avatar ZWT

feat(吉林演示): 松原

1.修改系统首页大屏总览接口,增加区分组织机构逻辑,完成接口冒烟测试;
2.修改系统首页获取井场列表接口,增加区分组织机构逻辑,完成接口冒烟测试;
3.修改系统首页井场功能下钻后提示报错问题,修改用电功率数据获取逻辑,修复报错问题;
4.修改输电线路分页列表查询接口,增加查询条件,在查询父线路列表时只查询10千伏线路,修改线上接口文档同时完成接口冒烟测试;
5.修改系统首页井场实时监控接口,增加区分组织机构逻辑,完成接口冒烟测试;
6.修改系统首页用能分析接口,增加区分组织机构逻辑,完成接口冒烟测试;
7.修改系统首页井场用能分析(双坐标轴)接口,增加区分组织机构逻辑,完成接口冒烟测试;
8.修改系统首页累积用电接口,增加区分组织机构逻辑,完成接口冒烟测试;
9.修改系统首页光伏实时监控接口,增加区分组织机构逻辑,完成接口冒烟测试;
10.修改系统首页井场效果评价接口,增加区分组织机构逻辑,完成接口冒烟测试;
11.修改系统首页先导实验井间开制度接口,增加区分组织机构逻辑,完成接口冒烟测试;
12.修改极短期间开优化模块井口生产情况油井状态接口,增加区分组织机构逻辑,完成接口冒烟测试;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent 8c7f8a2e
...@@ -27,7 +27,6 @@ import pps.cloud.base.service.data.base_wellhead.DynamicQueryBaseWellheadOutput; ...@@ -27,7 +27,6 @@ import pps.cloud.base.service.data.base_wellhead.DynamicQueryBaseWellheadOutput;
import pps.cloud.prediction.service.IPlantPredictedPowerCloudService; import pps.cloud.prediction.service.IPlantPredictedPowerCloudService;
import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerInput; import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerInput;
import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerOutput; import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerOutput;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerInput;
import pps.core.common.constant.BusinessConstant; import pps.core.common.constant.BusinessConstant;
import pps.core.common.entity.BaseModel; import pps.core.common.entity.BaseModel;
import pps.core.common.utils.BaseUtils; import pps.core.common.utils.BaseUtils;
...@@ -689,11 +688,7 @@ public class SpaceOptimizeBaseService { ...@@ -689,11 +688,7 @@ public class SpaceOptimizeBaseService {
case "0": case "0":
this.offGridOptimization(context, wellheadDTOList, durationDTOList, unOptimizeDurationList, this.offGridOptimization(context, wellheadDTOList, durationDTOList, unOptimizeDurationList,
relation.getWellheadsByInstitutionIdIdMap().get(detail.getId()), relation.getStorageAvgMap(), detail, periodId, relation.getWellheadsByInstitutionIdIdMap().get(detail.getId()), relation.getStorageAvgMap(), detail, periodId,
DynamicQueryStoragePredictedPowerInput.builder() powerInput, offset > 1 ? startDate : optimizeDate
.storageIds(relation.getStorageIdsByLineIdMap().get(detail.getLineId()))
.startTime(DateUtil.offsetDay(startDate, -offset).toString(BusinessConstant.DATE_FORMAT_DAY))
.endTime(DateUtil.offsetDay(optimizeDate, -offset).toString(BusinessConstant.DATE_FORMAT_DAY))
.build(), powerInput, offset > 1 ? startDate : optimizeDate
); );
break; break;
default: default:
...@@ -851,14 +846,13 @@ public class SpaceOptimizeBaseService { ...@@ -851,14 +846,13 @@ public class SpaceOptimizeBaseService {
* @param storageAvgMap 存储平均值映射 * @param storageAvgMap 存储平均值映射
* @param detail 细节 * @param detail 细节
* @param periodId 期间id * @param periodId 期间id
* @param input 输入
* @param plantPowerInput 电厂功率输入 * @param plantPowerInput 电厂功率输入
* @param optimizeDate 优化日期 * @param optimizeDate 优化日期
*/ */
public void offGridOptimization(XContext context, List<SpaceOptimizeWellheadDTO> wellheadDTOList, List<SpaceOptimizeDurationDTO> durationDTOList, public void offGridOptimization(XContext context, List<SpaceOptimizeWellheadDTO> wellheadDTOList, List<SpaceOptimizeDurationDTO> durationDTOList,
List<SpaceOptimizeDurationDTO> unOptimizeDurationList, List<SpaceInstitutionWellheadView> spaceWellheadList, List<SpaceOptimizeDurationDTO> unOptimizeDurationList, List<SpaceInstitutionWellheadView> spaceWellheadList,
Map<String, List<DynamicQueryBasePowerLineStorageViewOutput>> storageAvgMap, SpaceInstitutionDetailEnt detail, String periodId, Map<String, List<DynamicQueryBasePowerLineStorageViewOutput>> storageAvgMap, SpaceInstitutionDetailEnt detail, String periodId,
DynamicQueryStoragePredictedPowerInput input, DynamicQueryPlantPredictedPowerInput plantPowerInput, DateTime optimizeDate) { DynamicQueryPlantPredictedPowerInput plantPowerInput, DateTime optimizeDate) {
//获取井口间开时间段 //获取井口间开时间段
Map<String, List<SpaceInstitutionDurationEnt>> durationMap = this.getDurationMap(context, detail.getId()); Map<String, List<SpaceInstitutionDurationEnt>> durationMap = this.getDurationMap(context, detail.getId());
//获取当前制度对应的光伏预测数据列表 //获取当前制度对应的光伏预测数据列表
......
package pps.cloud.prediction.service;
import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerOutput;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerInput;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerOutput;
import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.data.XListResult;
import xstartup.feature.api.annotation.XApiPost;
/**
* 储能预测电量数据Cloud模块(模拟数据测试用)
*
* @author ZWT
* @date 2023/09/20 15:40
*/
@XService
@XText("储能预测Cloud模块")
public interface IStoragePredictedPowerCloudService {
/**
* 储能预测Cloud模块--条件查询时段储能电量平均值
*
* @param context 上下文
* @param input 输入
* @return {@link XListResult}<{@link DynamicQueryPlantPredictedPowerOutput}>
*/
@XText("储能预测Cloud模块--条件查询时段储能电量平均值")
@XApiPost
XListResult<DynamicQueryStoragePredictedPowerOutput> queryAverageEnergyStorageListByParam(XContext context, DynamicQueryStoragePredictedPowerInput input);
}
package pps.cloud.prediction.service.data.storage_predicted_power_data;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xstartup.annotation.XText;
import java.util.List;
/**
* 储能预测电量数据(模拟数据测试用)
*
* @author ZWT
* @date 2023/09/20
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DynamicQueryStoragePredictedPowerInput {
@XText("储能设备id")
private String storageId;
@XText("储能设备ID集合")
private List<String> storageIds;
@XText("年")
private String yearTime;
@XText("月")
private String monthTime;
@XText("开始时间")
private String startTime;
@XText("结束时间")
private String endTime;
}
package pps.cloud.prediction.service.data.storage_predicted_power_data;
import lombok.Data;
import xstartup.annotation.XText;
import java.math.BigDecimal;
/**
* 储能预测电量数据(模拟数据测试用)
*
* @author ZWT
* @date 2023/09/20
*/
@Data
public class DynamicQueryStoragePredictedPowerOutput {
@XText("年")
private String yearTime;
@XText("月")
private String monthTime;
@XText("时")
private String hourTime;
@XText("分")
private String minTime;
@XText("预测功率")
private BigDecimal power;
}
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.common.utils.ExcelUtils; import pps.core.common.utils.ExcelUtils;
import pps.core.common.utils.ExportExcelUtils; import pps.core.common.utils.ExportExcelUtils;
...@@ -17,8 +20,6 @@ import xstartup.annotation.XService; ...@@ -17,8 +20,6 @@ import xstartup.annotation.XService;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import xstartup.base.XContext; import xstartup.base.XContext;
import xstartup.base.tool.XStorageTool; import xstartup.base.tool.XStorageTool;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.data.XFileResult; import xstartup.data.XFileResult;
import xstartup.data.XFileType; import xstartup.data.XFileType;
import xstartup.data.XPageResult; import xstartup.data.XPageResult;
...@@ -40,9 +41,9 @@ public class PlantPowerDataService { ...@@ -40,9 +41,9 @@ public class PlantPowerDataService {
PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class); PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class);
QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>(); QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, input.getPlantId()); queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isNotEmpty(input.getStartTime())) if (CharSequenceUtil.isNotBlank(input.getStartTime()))
queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, input.getStartTime()); queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, input.getStartTime());
if (XStringUtils.isNotEmpty(input.getEndTime())) if (CharSequenceUtil.isNotBlank(input.getEndTime()))
queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, input.getEndTime()); queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, input.getEndTime());
queryWrapper.lambda().orderByDesc(PlantPowerDataEnt::getDataDate); queryWrapper.lambda().orderByDesc(PlantPowerDataEnt::getDataDate);
return XMapperHelper.query(mapper, input, queryWrapper, QueryPlantPowerDataOutput.class); return XMapperHelper.query(mapper, input, queryWrapper, QueryPlantPowerDataOutput.class);
...@@ -51,14 +52,14 @@ public class PlantPowerDataService { ...@@ -51,14 +52,14 @@ public class PlantPowerDataService {
@XText("下载电站实际发电数据导入模板") @XText("下载电站实际发电数据导入模板")
@XApiGet @XApiGet
public XFileResult downloadImportTemplate(XContext context) { public XFileResult downloadImportTemplate(XContext context) {
String fileSavePath = XStorageTool.getAbsolutePath("/temp/excel/导入模板_" + XDateUtils.getString(new Date(), "yyyy-MM-dd") + ".xlsx"); String fileSavePath = XStorageTool.getAbsolutePath("/temp/excel/导入模板_" + DateUtil.formatDate(DateUtil.date()) + ".xlsx");
String templateFilePath = "template/import_plant_data_template.xlsx"; String templateFilePath = "template/import_plant_data_template.xlsx";
InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(templateFilePath); InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(templateFilePath);
byte[] excelContent = ExportExcelUtils.genSingleExcelFileData(templateInputStream, null); byte[] excelContent = ExportExcelUtils.genSingleExcelFileData(templateInputStream, null);
try { try {
ExportExcelUtils.outputFileData(excelContent, fileSavePath); ExportExcelUtils.outputFileData(excelContent, fileSavePath);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); context.getLogger().error(e);
} }
return XFileResult.success(XFileType.APPLICATION_XLSX, fileSavePath); return XFileResult.success(XFileType.APPLICATION_XLSX, fileSavePath);
} }
...@@ -75,8 +76,8 @@ public class PlantPowerDataService { ...@@ -75,8 +76,8 @@ public class PlantPowerDataService {
for (Map<String, Object> objectMap : mapList) { for (Map<String, Object> objectMap : mapList) {
PlantPowerDataView dataView = BeanUtil.toBean(objectMap, PlantPowerDataView.class); PlantPowerDataView dataView = BeanUtil.toBean(objectMap, PlantPowerDataView.class);
dataView.setPlantId(input.getPlantId()); dataView.setPlantId(input.getPlantId());
if (dataView.getDataDate() != null) { if (ObjectUtil.isNotNull(dataView.getDataDate())) {
if (minDate == null) { if (ObjectUtil.isNull(minDate)) {
minDate = dataView.getDataDate(); minDate = dataView.getDataDate();
maxDate = dataView.getDataDate(); maxDate = dataView.getDataDate();
} }
...@@ -88,15 +89,15 @@ public class PlantPowerDataService { ...@@ -88,15 +89,15 @@ public class PlantPowerDataService {
dataList.add(dataView); dataList.add(dataView);
} }
} }
if (minDate == null) { if (ObjectUtil.isNull(minDate)) {
return XServiceResult.error(1000, "日期错误"); return XServiceResult.error(1000, "日期错误");
} }
PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class); PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class);
QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>(); mapper.delete(new QueryWrapper<PlantPowerDataEnt>()
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, input.getPlantId()) .lambda()
.eq(PlantPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPowerDataEnt::getDataDate, minDate) .ge(PlantPowerDataEnt::getDataDate, minDate)
.le(PlantPowerDataEnt::getDataDate, maxDate); .le(PlantPowerDataEnt::getDataDate, maxDate));
mapper.delete(queryWrapper);
PlantPowerDataViewMapper viewMapper = context.getBean(PlantPowerDataViewMapper.class); PlantPowerDataViewMapper viewMapper = context.getBean(PlantPowerDataViewMapper.class);
viewMapper.insertBatch(dataList); viewMapper.insertBatch(dataList);
//进行训练 //进行训练
......
...@@ -11,6 +11,7 @@ import pps.cloud.prediction.service.IPlantPredictedPowerCloudService; ...@@ -11,6 +11,7 @@ import pps.cloud.prediction.service.IPlantPredictedPowerCloudService;
import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerInput; import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerInput;
import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerOutput; import pps.cloud.prediction.service.data.plant_predicted_power_data.DynamicQueryPlantPredictedPowerOutput;
import pps.core.auth.HttpRequestClient; import pps.core.auth.HttpRequestClient;
import pps.core.common.constant.BusinessConstant;
import pps.core.prediction.constant.ThirdPartyApiConstant; import pps.core.prediction.constant.ThirdPartyApiConstant;
import pps.core.prediction.entity.PredictedPowerView; import pps.core.prediction.entity.PredictedPowerView;
import pps.core.prediction.entity.WellheadDailyProductionSituationView; import pps.core.prediction.entity.WellheadDailyProductionSituationView;
...@@ -181,7 +182,7 @@ public class PlantPredictedPowerCloudServiceImpl implements IPlantPredictedPower ...@@ -181,7 +182,7 @@ public class PlantPredictedPowerCloudServiceImpl implements IPlantPredictedPower
String token = ServiceUtil.getToken(context); String token = ServiceUtil.getToken(context);
HttpRequestClient client = new HttpRequestClient(token); HttpRequestClient client = new HttpRequestClient(token);
Map<String, Object> param = new HashMap<>(4); Map<String, Object> param = new HashMap<>(4);
param.put("Calc_Date", DateUtil.yesterday().toString("yyyy-MM-dd")); param.put("Calc_Date", DateUtil.yesterday().toString(BusinessConstant.DATE_FORMAT_DAY));
String url = XStartup.getCurrent().getProperty("third-party.chang-qing.url"); String url = XStartup.getCurrent().getProperty("third-party.chang-qing.url");
url += ThirdPartyApiConstant.CQ_WELL_TECH_DAILY; url += ThirdPartyApiConstant.CQ_WELL_TECH_DAILY;
String resultStr = client.doPostForm(url, param); String resultStr = client.doPostForm(url, param);
......
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.common.constant.BusinessConstant;
import pps.core.prediction.entity.PlantPredictedPowerDataEnt; import pps.core.prediction.entity.PlantPredictedPowerDataEnt;
import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt; import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt;
import pps.core.prediction.mapper.PlantPredictedPowerDataMapper; import pps.core.prediction.mapper.PlantPredictedPowerDataMapper;
...@@ -13,8 +18,6 @@ import xstartup.annotation.XService; ...@@ -13,8 +18,6 @@ import xstartup.annotation.XService;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import xstartup.base.XContext; import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils; import xstartup.base.util.XCopyUtils;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.data.XListResult; import xstartup.data.XListResult;
import xstartup.data.XServiceResult; import xstartup.data.XServiceResult;
import xstartup.feature.api.annotation.XApiGet; import xstartup.feature.api.annotation.XApiGet;
...@@ -36,13 +39,13 @@ public class PlantPredictedPowerDataService { ...@@ -36,13 +39,13 @@ public class PlantPredictedPowerDataService {
Date date = new Date(); Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>(); QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId()); queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isEmpty(input.getStartTime())) { if (CharSequenceUtil.isBlank(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date); queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date)
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addHours(date, 4)); .le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetHour(date, 4));
} else { } else {
String dataDate = XDateUtils.getDateString(new Date()) + " " + input.getStartTime() + ":00"; String dataDate = DateUtil.formatDate(date) + " " + input.getStartTime() + BusinessConstant.INITIALIZATION_SECOND;
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, dataDate); queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, dataDate)
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addHours(XDateUtils.parse(dataDate), 4)); .le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetHour(DateUtil.parseDateTime(dataDate), 4));
} }
queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate); queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate);
List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper); List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper);
...@@ -60,12 +63,12 @@ public class PlantPredictedPowerDataService { ...@@ -60,12 +63,12 @@ public class PlantPredictedPowerDataService {
Date date = new Date(); Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>(); QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId()); queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isEmpty(input.getStartTime())) { if (CharSequenceUtil.isBlank(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date); queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date)
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, 7)); .le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(date, 7));
} else { } else {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, input.getStartTime()); queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, input.getStartTime())
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(XDateUtils.parse(input.getStartTime()), 7)); .le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(DateUtil.parseDateTime(input.getStartTime()), 7));
} }
queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate); queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate);
List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper); List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper);
...@@ -83,31 +86,36 @@ public class PlantPredictedPowerDataService { ...@@ -83,31 +86,36 @@ public class PlantPredictedPowerDataService {
PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class); PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class);
Date date = new Date(); Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>(); QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power"); queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId()); .lambda()
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date); .eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, 7)); .ge(PlantPredictedPowerDataEnt::getDataDate, date)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(date, 7));
PlantPredictedPowerDataEnt currentData = mapper.selectOne(queryWrapper); PlantPredictedPowerDataEnt currentData = mapper.selectOne(queryWrapper);
queryWrapper.clear(); queryWrapper.clear();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power"); DateTime lastYear = DateUtil.offset(date, DateField.YEAR, -1);
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId()); queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -365)); .lambda()
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -358)); .eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPredictedPowerDataEnt::getDataDate, lastYear)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(lastYear, 7));
PlantPredictedPowerDataEnt lastData = mapper.selectOne(queryWrapper); PlantPredictedPowerDataEnt lastData = mapper.selectOne(queryWrapper);
BigDecimal compare = new BigDecimal(1); BigDecimal compare = new BigDecimal(1);
if (lastData.getPower().compareTo(BigDecimal.ZERO) > 0) if (lastData.getPower().compareTo(BigDecimal.ZERO) > 0) {
compare = currentData.getPower().divide(lastData.getPower(), 6, BigDecimal.ROUND_HALF_UP); compare = currentData.getPower().divide(lastData.getPower(), 6, BigDecimal.ROUND_HALF_UP);
}
queryWrapper.clear(); queryWrapper.clear();
queryWrapper.select(" data_date , power "); queryWrapper.select("data_date, power")
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId()); .lambda()
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -365)); .eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -335)); .ge(PlantPredictedPowerDataEnt::getDataDate, lastYear)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(lastYear, 30));
List<PlantPredictedPowerDataEnt> lastList = mapper.selectList(queryWrapper); List<PlantPredictedPowerDataEnt> lastList = mapper.selectList(queryWrapper);
//获取去年30天的数据,预测今年30天的数据 //获取去年30天的数据,预测今年30天的数据
List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(lastList, GetPlantPredictedPowerDataOutput.class); List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(lastList, GetPlantPredictedPowerDataOutput.class);
for (GetPlantPredictedPowerDataOutput item : outputs) { for (GetPlantPredictedPowerDataOutput item : outputs) {
item.setPredictedPower(item.getPower().multiply(compare)); item.setPredictedPower(item.getPower().multiply(compare));
item.setDataDate(XDateUtils.getString(XDateUtils.addDays(XDateUtils.parse(item.getDataDate()), 365))); item.setDataDate(DateUtil.formatDate(DateUtil.offset(DateUtil.parseDateTime(item.getDataDate()), DateField.YEAR, 1)));
} }
return XListResult.success(outputs); return XListResult.success(outputs);
} }
...@@ -117,12 +125,11 @@ public class PlantPredictedPowerDataService { ...@@ -117,12 +125,11 @@ public class PlantPredictedPowerDataService {
public XListResult<GetPlantPredictedPowerDataOutput> getThirtyPlantPredictedPowerData(XContext context, GetPlantPredictedPowerDataInput input) { public XListResult<GetPlantPredictedPowerDataOutput> getThirtyPlantPredictedPowerData(XContext context, GetPlantPredictedPowerDataInput input) {
PlantPredictedPowerLongTermDataMapper mapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class); PlantPredictedPowerLongTermDataMapper mapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
Date date = new Date(); Date date = new Date();
QueryWrapper<PlantPredictedPowerLongTermDataEnt> queryWrapper = new QueryWrapper<>(); List<PlantPredictedPowerLongTermDataEnt> list = mapper.selectList(new QueryWrapper<PlantPredictedPowerLongTermDataEnt>().select("id, plant_id, data_date, temperature, humidity, wind_speed, wind_direction, pressure, plane_irradiance, horizontal_irradiance, power as predicted_power, create_time")
queryWrapper.select("id, plant_id, data_date, temperature, humidity, wind_speed, wind_direction, pressure, plane_irradiance, horizontal_irradiance, power as predicted_power, create_time"); .lambda()
queryWrapper.lambda().eq(PlantPredictedPowerLongTermDataEnt::getPlantId, input.getPlantId()); .eq(PlantPredictedPowerLongTermDataEnt::getPlantId, input.getPlantId())
queryWrapper.lambda().ge(PlantPredictedPowerLongTermDataEnt::getDataDate, date); .ge(PlantPredictedPowerLongTermDataEnt::getDataDate, date)
queryWrapper.lambda().le(PlantPredictedPowerLongTermDataEnt::getDataDate, XDateUtils.addMonth(date, 1)); .le(PlantPredictedPowerLongTermDataEnt::getDataDate, DateUtil.offsetMonth(date, 1)));
List<PlantPredictedPowerLongTermDataEnt> list = mapper.selectList(queryWrapper);
List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(list, GetPlantPredictedPowerDataOutput.class); List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(list, GetPlantPredictedPowerDataOutput.class);
return XListResult.success(outputs); return XListResult.success(outputs);
} }
......
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import pps.cloud.prediction.service.PlantTrainPowerTaskCloudService; import pps.cloud.prediction.service.PlantTrainPowerTaskCloudService;
import pps.cloud.prediction.service.data.plant_train_power_task.GetPlantTrainPowerTaskCloudInput; import pps.cloud.prediction.service.data.plant_train_power_task.GetPlantTrainPowerTaskCloudInput;
...@@ -25,7 +26,7 @@ public class PlantTrainPowerTaskService implements PlantTrainPowerTaskCloudServi ...@@ -25,7 +26,7 @@ public class PlantTrainPowerTaskService implements PlantTrainPowerTaskCloudServi
.orderByDesc(PlantTrainPowerTaskEnt::getCreateTime) .orderByDesc(PlantTrainPowerTaskEnt::getCreateTime)
.last(BusinessConstant.LAST_LIMIT); .last(BusinessConstant.LAST_LIMIT);
PlantTrainPowerTaskEnt ent = mapper.selectOne(queryWrapper); PlantTrainPowerTaskEnt ent = mapper.selectOne(queryWrapper);
if (ent == null) { if (ObjectUtil.isNull(ent)) {
queryWrapper.clear(); queryWrapper.clear();
queryWrapper.eq(PlantTrainPowerTaskEnt::getModelKey, "all_plant_data") queryWrapper.eq(PlantTrainPowerTaskEnt::getModelKey, "all_plant_data")
.eq(PlantTrainPowerTaskEnt::getModelCycle, input.getModelCycle()) .eq(PlantTrainPowerTaskEnt::getModelCycle, input.getModelCycle())
......
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.prediction.entity.BaseDataEnt; import pps.core.prediction.entity.BaseDataEnt;
import pps.core.prediction.entity.BaseDataView; import pps.core.prediction.entity.BaseDataView;
...@@ -20,10 +21,10 @@ public class PredictionService { ...@@ -20,10 +21,10 @@ public class PredictionService {
@XApiGet @XApiGet
public XSingleResult<GetBaseDataOutput> getBaseData(XContext context, GetBaseDataInput input) { public XSingleResult<GetBaseDataOutput> getBaseData(XContext context, GetBaseDataInput input) {
BaseDataMapper mapper = context.getBean(BaseDataMapper.class); BaseDataMapper mapper = context.getBean(BaseDataMapper.class);
QueryWrapper<BaseDataEnt> queryWrapper = new QueryWrapper<>(); BaseDataEnt entity = mapper.selectOne(new QueryWrapper<BaseDataEnt>()
queryWrapper.lambda().eq(BaseDataEnt::getId, input.getId()); .lambda()
BaseDataEnt entity = mapper.selectOne(queryWrapper); .eq(BaseDataEnt::getId, input.getId()));
if (entity == null) { if (ObjectUtil.isNull(entity)) {
return XSingleResult.error(context, XError.NotFound); return XSingleResult.error(context, XError.NotFound);
} }
GetBaseDataOutput output = new GetBaseDataOutput(); GetBaseDataOutput output = new GetBaseDataOutput();
...@@ -36,7 +37,7 @@ public class PredictionService { ...@@ -36,7 +37,7 @@ public class PredictionService {
BaseDataViewMapper mapper = context.getBean(BaseDataViewMapper.class); BaseDataViewMapper mapper = context.getBean(BaseDataViewMapper.class);
BaseDataView view = XCopyUtils.copyNewObject(input, BaseDataView.class); BaseDataView view = XCopyUtils.copyNewObject(input, BaseDataView.class);
BaseDataView entity = mapper.selectOne(view); BaseDataView entity = mapper.selectOne(view);
if (entity == null) { if (ObjectUtil.isNull(entity)) {
return XSingleResult.error(context, XError.NotFound); return XSingleResult.error(context, XError.NotFound);
} }
GetBaseDataOutput output = new GetBaseDataOutput(); GetBaseDataOutput output = new GetBaseDataOutput();
......
package pps.core.prediction.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.utils.BaseUtils;
import pps.core.prediction.entity.PlantPredictedPowerDataEnt;
import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt;
import pps.core.prediction.mapper.PlantPredictedPowerDataMapper;
import pps.core.prediction.mapper.PlantPredictedPowerLongTermDataMapper;
import xstartup.base.XContext;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 统计分析基类
*
* @author ZWT
* @date 2023/09/28 10:21
*/
public class StatisticAnalysisBaseService {
/**
* 获得光伏发电
*
* @param context 上下文
* @param dateType 日期类型
* @param plantIdList 工厂id列表
* @param startTime 开始时间
* @param endTime 结束时间
* @return {@link List}
*/
public List getPhotovoltaicPowerGeneration(XContext context, Integer dateType,
List<String> plantIdList, Date startTime, Date endTime) {
List powerGenerationList = null;
//取当前时间
DateTime date = DateUtil.beginOfDay(DateUtil.date());
switch (dateType) {
case 0:
PlantPredictedPowerDataMapper powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
powerGenerationList = powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getYearTime, String.valueOf(date.year()))
.eq(PlantPredictedPowerDataEnt::getMonthTime, BaseUtils.getMonthString(date.month() + 1))
.eq(PlantPredictedPowerDataEnt::getDayTime, String.valueOf(date.dayOfMonth()))
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
break;
case 1:
powerGenerationList = this.getPlantPredictedPowerList(context, plantIdList,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 7).toString(BusinessConstant.DATE_FORMAT_DAY));
break;
case 2:
powerGenerationList = this.getPlantPredictedPowerLongList(context, plantIdList,
date.toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.offsetDay(date, 30).toString(BusinessConstant.DATE_FORMAT_DAY));
break;
case 3:
//判断当前时间距当前时间是否大于30天
if (Objects.isNull(startTime) || Objects.isNull(endTime)) {
return Collections.emptyList();
}
int between = (int) date.between(endTime, DateUnit.DAY);
//判断结束时间是否大于当前时间30天以后
if (endTime.compareTo(date) >= 0 && between >= 30) {
//长期预测
powerGenerationList = this.getPlantPredictedPowerLongList(context, plantIdList,
DateUtil.date(startTime).toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.date(endTime).toString(BusinessConstant.DATE_FORMAT_DAY));
} else {
//短期
powerGenerationList = this.getPlantPredictedPowerList(context, plantIdList,
DateUtil.date(startTime).toString(BusinessConstant.DATE_FORMAT_DAY),
DateUtil.date(endTime).toString(BusinessConstant.DATE_FORMAT_DAY));
}
break;
default:
}
return powerGenerationList;
}
/*-----------------------------------private-----------------------------------*/
/**
* 获取短期预测结果
*
* @param context 上下文
* @param plantIdList 工厂id列表
* @param startTime 开始时间
* @param endTime 结束时间
* @return {@link List}<{@link PlantPredictedPowerDataEnt}>
*/
private List<PlantPredictedPowerDataEnt> getPlantPredictedPowerList(XContext context, List<String> plantIdList,
String startTime, String endTime) {
PlantPredictedPowerDataMapper powerDataMapper = context.getBean(PlantPredictedPowerDataMapper.class);
return powerDataMapper.selectList(new QueryWrapper<PlantPredictedPowerDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerDataEnt::getDataDate, startTime, endTime)
.groupBy(PlantPredictedPowerDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerDataEnt::getHourTime)
);
}
/**
* 获取长期预测结果
*
* @param context 上下文
* @param plantIdList 工厂id列表
* @param startTime 开始时间
* @param endTime 结束时间
* @return {@link List}<{@link PlantPredictedPowerLongTermDataEnt}>
*/
private List<PlantPredictedPowerLongTermDataEnt> getPlantPredictedPowerLongList(XContext context, List<String> plantIdList,
String startTime, String endTime) {
PlantPredictedPowerLongTermDataMapper longTermDataMapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
return longTermDataMapper.selectList(new QueryWrapper<PlantPredictedPowerLongTermDataEnt>()
.select("hour_time",
"SUM( power ) AS power")
.lambda()
.in(PlantPredictedPowerLongTermDataEnt::getPlantId, plantIdList)
.between(PlantPredictedPowerLongTermDataEnt::getDataDate, startTime, endTime)
.groupBy(PlantPredictedPowerLongTermDataEnt::getHourTime)
.orderByAsc(PlantPredictedPowerLongTermDataEnt::getHourTime)
);
}
}
package pps.core.prediction.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.cloud.prediction.service.IStoragePredictedPowerCloudService;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerInput;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerOutput;
import pps.core.prediction.entity.StoragePredictedPowerDataEnt;
import pps.core.prediction.mapper.StoragePredictedPowerDataMapper;
import xstartup.annotation.XService;
import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils;
import xstartup.data.XListResult;
import java.util.Collections;
import java.util.List;
/**
* 储能预测电量数据Cloud模块(模拟数据测试用)
* todo: 模拟测试用,后续替换
*
* @author ZWT
* @date 2023/09/20 15:44
*/
@XService
public class StoragePredictedPowerCloudServiceImpl implements IStoragePredictedPowerCloudService {
/**
* 储能预测Cloud模块--条件查询时段储能电量平均值
*
* @param context 上下文
* @param input 输入
* @return {@link XListResult}<{@link DynamicQueryStoragePredictedPowerOutput}>
*/
@Override
public XListResult<DynamicQueryStoragePredictedPowerOutput> queryAverageEnergyStorageListByParam(XContext context, DynamicQueryStoragePredictedPowerInput input) {
String storageId = input.getStorageId();
List<String> storageIds = input.getStorageIds();
String yearTime = input.getYearTime();
String monthTime = input.getMonthTime();
String startTime = input.getStartTime();
String endTime = input.getEndTime();
StoragePredictedPowerDataMapper mapper = context.getBean(StoragePredictedPowerDataMapper.class);
List<StoragePredictedPowerDataEnt> list = mapper.selectList(
new QueryWrapper<StoragePredictedPowerDataEnt>()
.select("hour_time",
"min_time",
"AVG( power ) AS power")
.lambda()
.eq(CharSequenceUtil.isNotBlank(storageId), StoragePredictedPowerDataEnt::getStorageId, storageId)
.in(CollUtil.isNotEmpty(storageIds), StoragePredictedPowerDataEnt::getStorageId, storageIds)
.eq(CharSequenceUtil.isNotBlank(yearTime), StoragePredictedPowerDataEnt::getYearTime, yearTime)
.eq(CharSequenceUtil.isNotBlank(monthTime), StoragePredictedPowerDataEnt::getMonthTime, monthTime)
.between(CharSequenceUtil.isAllNotBlank(startTime, endTime), StoragePredictedPowerDataEnt::getDataDate, startTime, endTime)
.groupBy(StoragePredictedPowerDataEnt::getHourTime,
StoragePredictedPowerDataEnt::getMinTime)
.orderByAsc(StoragePredictedPowerDataEnt::getHourTime, StoragePredictedPowerDataEnt::getMinTime)
);
List<DynamicQueryStoragePredictedPowerOutput> outputs;
if (CollUtil.isEmpty(list)) {
outputs = Collections.emptyList();
} else {
outputs = XCopyUtils.copyNewList(list, DynamicQueryStoragePredictedPowerOutput.class);
}
return XListResult.success(outputs);
}
}
package pps.core.prediction.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import pps.core.prediction.entity.ThirdActivePowerEnt;
import pps.core.prediction.mapper.ThirdActivePowerMapper;
import pps.core.prediction.service.data.plant_predicted_power_mid_term.GetPlantPredictedPowerMidTermOutput;
import xstartup.base.XContext;
import xstartup.base.util.XDateUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
public class ThirdActivePowerServiceHelper {
public static void getActivePower(XContext context, List<GetPlantPredictedPowerMidTermOutput> outputs, String plantId, Date showTime) {
ThirdActivePowerMapper mapper = context.getBean(ThirdActivePowerMapper.class);
List<ThirdActivePowerEnt> powerList = mapper.selectList(new LambdaQueryWrapper<ThirdActivePowerEnt>()
.eq(ThirdActivePowerEnt::getStationId, plantId)
.ge(ThirdActivePowerEnt::getCreateDate, XDateUtils.addDays(new Date(), -2))
);
if (powerList.size() > 0) {
outputs.forEach(item -> {
if (item.getPower() == null && XDateUtils.compare(XDateUtils.parse(item.getDataDate()), new Date()) < 0) {
Date targetDate = XDateUtils.parse(item.getDataDate());
Date closeDate = powerList.get(0).getCreateDate();
BigDecimal photovoltaicPower = powerList.get(0).getPhotovoltaicPower();
for (ThirdActivePowerEnt power : powerList) {
if (Math.abs(power.getCreateDate().getTime() - targetDate.getTime())
< Math.abs(closeDate.getTime() - targetDate.getTime())) {
closeDate = power.getCreateDate();
photovoltaicPower = power.getPhotovoltaicPower();
}
}
item.setPower(photovoltaicPower);
}
});
}
}
}
\ No newline at end of file
package pps.core.prediction.utils; package pps.core.prediction.utils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class HttpUtils { public class HttpUtils {
public static Object sendPost(String url, Object param) {
// 请求头设置
HttpHeaders headers = new HttpHeaders();
List<MediaType> acceptableMediaType = new ArrayList<>();
acceptableMediaType.add(MediaType.APPLICATION_JSON);
headers.setAccept(acceptableMediaType);
headers.setContentType(MediaType.APPLICATION_JSON);
// 组装请求体
//String jsonString = XJsonUtils.toJson(param);
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity(param, headers);
//发起请求
RestTemplate restTemplate = new RestTemplate();
Object res = restTemplate.postForObject(url, request, Object.class);
return res;
}
public static String send2(String url, String param) throws Exception { public static String send2(String url, String param) throws Exception {
URL localURL = new URL(url); URL localURL = new URL(url);
URLConnection connection = localURL.openConnection(); URLConnection connection = localURL.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection) connection; HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
httpURLConnection.setDoOutput(true); httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST"); httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Accept", "application/json"); httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.setRequestProperty("Content-Type", "application/json"); httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(param.length())); httpURLConnection.setRequestProperty("Content-Length", String.valueOf(param.length()));
httpURLConnection.setConnectTimeout(10000); httpURLConnection.setConnectTimeout(10000);
OutputStream outputStream = null; OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null; OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null; InputStream inputStream = null;
InputStreamReader inputStreamReader = null; InputStreamReader inputStreamReader = null;
BufferedReader reader = null; BufferedReader reader = null;
String resultBuffer = ""; String resultBuffer = "";
try { try {
outputStream = httpURLConnection.getOutputStream(); outputStream = httpURLConnection.getOutputStream();
outputStreamWriter = new OutputStreamWriter(outputStream); outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(param.toString()); outputStreamWriter.write(param.toString());
outputStreamWriter.flush(); outputStreamWriter.flush();
if (httpURLConnection.getResponseCode() >= 300) { if (httpURLConnection.getResponseCode() >= 300) {
throw new Exception( throw new Exception(
"HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode()); "HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
} }
inputStream = httpURLConnection.getInputStream(); inputStream = httpURLConnection.getInputStream();
resultBuffer = convertStreamToString(inputStream); resultBuffer = convertStreamToString(inputStream);
System.out.println(resultBuffer);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (outputStreamWriter != null) { if (outputStreamWriter != null) {
outputStreamWriter.close(); outputStreamWriter.close();
} }
if (outputStream != null) { if (outputStream != null) {
outputStream.close(); outputStream.close();
} }
if (reader != null) {
reader.close();
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (inputStream != null) { if (inputStream != null) {
inputStream.close(); inputStream.close();
} }
} }
return resultBuffer; return resultBuffer;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment