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;
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.DynamicQueryPlantPredictedPowerOutput;
import pps.cloud.prediction.service.data.storage_predicted_power_data.DynamicQueryStoragePredictedPowerInput;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.entity.BaseModel;
import pps.core.common.utils.BaseUtils;
......@@ -689,11 +688,7 @@ public class SpaceOptimizeBaseService {
case "0":
this.offGridOptimization(context, wellheadDTOList, durationDTOList, unOptimizeDurationList,
relation.getWellheadsByInstitutionIdIdMap().get(detail.getId()), relation.getStorageAvgMap(), detail, periodId,
DynamicQueryStoragePredictedPowerInput.builder()
.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
powerInput, offset > 1 ? startDate : optimizeDate
);
break;
default:
......@@ -851,14 +846,13 @@ public class SpaceOptimizeBaseService {
* @param storageAvgMap 存储平均值映射
* @param detail 细节
* @param periodId 期间id
* @param input 输入
* @param plantPowerInput 电厂功率输入
* @param optimizeDate 优化日期
*/
public void offGridOptimization(XContext context, List<SpaceOptimizeWellheadDTO> wellheadDTOList, List<SpaceOptimizeDurationDTO> durationDTOList,
List<SpaceOptimizeDurationDTO> unOptimizeDurationList, List<SpaceInstitutionWellheadView> spaceWellheadList,
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());
//获取当前制度对应的光伏预测数据列表
......
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;
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 pps.core.common.utils.ExcelUtils;
import pps.core.common.utils.ExportExcelUtils;
......@@ -17,8 +20,6 @@ import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.tool.XStorageTool;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.data.XFileResult;
import xstartup.data.XFileType;
import xstartup.data.XPageResult;
......@@ -40,9 +41,9 @@ public class PlantPowerDataService {
PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class);
QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isNotEmpty(input.getStartTime()))
if (CharSequenceUtil.isNotBlank(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().orderByDesc(PlantPowerDataEnt::getDataDate);
return XMapperHelper.query(mapper, input, queryWrapper, QueryPlantPowerDataOutput.class);
......@@ -51,14 +52,14 @@ public class PlantPowerDataService {
@XText("下载电站实际发电数据导入模板")
@XApiGet
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";
InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(templateFilePath);
byte[] excelContent = ExportExcelUtils.genSingleExcelFileData(templateInputStream, null);
try {
ExportExcelUtils.outputFileData(excelContent, fileSavePath);
} catch (Exception e) {
e.printStackTrace();
context.getLogger().error(e);
}
return XFileResult.success(XFileType.APPLICATION_XLSX, fileSavePath);
}
......@@ -75,8 +76,8 @@ public class PlantPowerDataService {
for (Map<String, Object> objectMap : mapList) {
PlantPowerDataView dataView = BeanUtil.toBean(objectMap, PlantPowerDataView.class);
dataView.setPlantId(input.getPlantId());
if (dataView.getDataDate() != null) {
if (minDate == null) {
if (ObjectUtil.isNotNull(dataView.getDataDate())) {
if (ObjectUtil.isNull(minDate)) {
minDate = dataView.getDataDate();
maxDate = dataView.getDataDate();
}
......@@ -88,15 +89,15 @@ public class PlantPowerDataService {
dataList.add(dataView);
}
}
if (minDate == null) {
if (ObjectUtil.isNull(minDate)) {
return XServiceResult.error(1000, "日期错误");
}
PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class);
QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, input.getPlantId())
mapper.delete(new QueryWrapper<PlantPowerDataEnt>()
.lambda()
.eq(PlantPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPowerDataEnt::getDataDate, minDate)
.le(PlantPowerDataEnt::getDataDate, maxDate);
mapper.delete(queryWrapper);
.le(PlantPowerDataEnt::getDataDate, maxDate));
PlantPowerDataViewMapper viewMapper = context.getBean(PlantPowerDataViewMapper.class);
viewMapper.insertBatch(dataList);
//进行训练
......
......@@ -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.DynamicQueryPlantPredictedPowerOutput;
import pps.core.auth.HttpRequestClient;
import pps.core.common.constant.BusinessConstant;
import pps.core.prediction.constant.ThirdPartyApiConstant;
import pps.core.prediction.entity.PredictedPowerView;
import pps.core.prediction.entity.WellheadDailyProductionSituationView;
......@@ -181,7 +182,7 @@ public class PlantPredictedPowerCloudServiceImpl implements IPlantPredictedPower
String token = ServiceUtil.getToken(context);
HttpRequestClient client = new HttpRequestClient(token);
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");
url += ThirdPartyApiConstant.CQ_WELL_TECH_DAILY;
String resultStr = client.doPostForm(url, param);
......
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 pps.core.common.constant.BusinessConstant;
import pps.core.prediction.entity.PlantPredictedPowerDataEnt;
import pps.core.prediction.entity.PlantPredictedPowerLongTermDataEnt;
import pps.core.prediction.mapper.PlantPredictedPowerDataMapper;
......@@ -13,8 +18,6 @@ import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils;
import xstartup.base.util.XDateUtils;
import xstartup.base.util.XStringUtils;
import xstartup.data.XListResult;
import xstartup.data.XServiceResult;
import xstartup.feature.api.annotation.XApiGet;
......@@ -36,13 +39,13 @@ public class PlantPredictedPowerDataService {
Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isEmpty(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date);
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addHours(date, 4));
if (CharSequenceUtil.isBlank(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetHour(date, 4));
} else {
String dataDate = XDateUtils.getDateString(new Date()) + " " + input.getStartTime() + ":00";
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, dataDate);
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addHours(XDateUtils.parse(dataDate), 4));
String dataDate = DateUtil.formatDate(date) + " " + input.getStartTime() + BusinessConstant.INITIALIZATION_SECOND;
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, dataDate)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetHour(DateUtil.parseDateTime(dataDate), 4));
}
queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate);
List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper);
......@@ -60,12 +63,12 @@ public class PlantPredictedPowerDataService {
Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
if (XStringUtils.isEmpty(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date);
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, 7));
if (CharSequenceUtil.isBlank(input.getStartTime())) {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(date, 7));
} else {
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, input.getStartTime());
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(XDateUtils.parse(input.getStartTime()), 7));
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, input.getStartTime())
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(DateUtil.parseDateTime(input.getStartTime()), 7));
}
queryWrapper.lambda().orderByAsc(PlantPredictedPowerDataEnt::getDataDate);
List<PlantPredictedPowerDataEnt> list = mapper.selectList(queryWrapper);
......@@ -83,31 +86,36 @@ public class PlantPredictedPowerDataService {
PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class);
Date date = new Date();
QueryWrapper<PlantPredictedPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power");
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, date);
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, 7));
queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPredictedPowerDataEnt::getDataDate, date)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(date, 7));
PlantPredictedPowerDataEnt currentData = mapper.selectOne(queryWrapper);
queryWrapper.clear();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power");
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -365));
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -358));
DateTime lastYear = DateUtil.offset(date, DateField.YEAR, -1);
queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPredictedPowerDataEnt::getDataDate, lastYear)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(lastYear, 7));
PlantPredictedPowerDataEnt lastData = mapper.selectOne(queryWrapper);
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);
}
queryWrapper.clear();
queryWrapper.select(" data_date , power ");
queryWrapper.lambda().eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId());
queryWrapper.lambda().ge(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -365));
queryWrapper.lambda().le(PlantPredictedPowerDataEnt::getDataDate, XDateUtils.addDays(date, -335));
queryWrapper.select("data_date, power")
.lambda()
.eq(PlantPredictedPowerDataEnt::getPlantId, input.getPlantId())
.ge(PlantPredictedPowerDataEnt::getDataDate, lastYear)
.le(PlantPredictedPowerDataEnt::getDataDate, DateUtil.offsetDay(lastYear, 30));
List<PlantPredictedPowerDataEnt> lastList = mapper.selectList(queryWrapper);
//获取去年30天的数据,预测今年30天的数据
List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(lastList, GetPlantPredictedPowerDataOutput.class);
for (GetPlantPredictedPowerDataOutput item : outputs) {
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);
}
......@@ -117,12 +125,11 @@ public class PlantPredictedPowerDataService {
public XListResult<GetPlantPredictedPowerDataOutput> getThirtyPlantPredictedPowerData(XContext context, GetPlantPredictedPowerDataInput input) {
PlantPredictedPowerLongTermDataMapper mapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
Date date = new Date();
QueryWrapper<PlantPredictedPowerLongTermDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.select("id, plant_id, data_date, temperature, humidity, wind_speed, wind_direction, pressure, plane_irradiance, horizontal_irradiance, power as predicted_power, create_time");
queryWrapper.lambda().eq(PlantPredictedPowerLongTermDataEnt::getPlantId, input.getPlantId());
queryWrapper.lambda().ge(PlantPredictedPowerLongTermDataEnt::getDataDate, date);
queryWrapper.lambda().le(PlantPredictedPowerLongTermDataEnt::getDataDate, XDateUtils.addMonth(date, 1));
List<PlantPredictedPowerLongTermDataEnt> list = mapper.selectList(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")
.lambda()
.eq(PlantPredictedPowerLongTermDataEnt::getPlantId, input.getPlantId())
.ge(PlantPredictedPowerLongTermDataEnt::getDataDate, date)
.le(PlantPredictedPowerLongTermDataEnt::getDataDate, DateUtil.offsetMonth(date, 1)));
List<GetPlantPredictedPowerDataOutput> outputs = XCopyUtils.copyNewList(list, GetPlantPredictedPowerDataOutput.class);
return XListResult.success(outputs);
}
......
package pps.core.prediction.service;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.cloud.base.service.BasePhotovoltaicPlantCloudService;
import pps.cloud.base.service.data.base_photovoltaic_plant.GetBasePhotovoltaicPlantCloudInput;
......@@ -14,12 +17,12 @@ import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.util.XCopyUtils;
import xstartup.base.util.XDateUtils;
import xstartup.data.XListResult;
import xstartup.data.XServiceResult;
import xstartup.feature.api.annotation.XApiGet;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
......@@ -33,69 +36,74 @@ import java.util.List;
*/
@XService
public class PlantPredictedPowerLongTermDataCloudServiceImpl implements PlantPredictedPowerLongTermDataCloudService {
@XText("定时运行预测长期数据")
@Override
@XApiGet
@XText("定时运行预测长期数据")
public XServiceResult runPlantPredictedPowerLongTermData(XContext context) {
//获取所有的电站
BasePhotovoltaicPlantCloudService cloudService = context.getBean(BasePhotovoltaicPlantCloudService.class);
XListResult<GetBasePhotovoltaicPlantCloudOutput> result = cloudService.getBasePhotovoltaicPlantList(context, new GetBasePhotovoltaicPlantCloudInput());
if (!result.isSuccess())
if (!result.isSuccess()) {
return XServiceResult.error(500, "未查询到电站数据");
}
List<GetBasePhotovoltaicPlantCloudOutput> list = result.getResult();
PlantPowerDataMapper powerDataMapper = context.getBean(PlantPowerDataMapper.class);
Date currentDate = new Date();
for (GetBasePhotovoltaicPlantCloudOutput output : list) {
//获取最近七天的实际数据
QueryWrapper<PlantPowerDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power ");
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, output.getId());
queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, XDateUtils.addDays(currentDate, -7));
queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
.lambda()
.eq(PlantPowerDataEnt::getPlantId, output.getId())
.ge(PlantPowerDataEnt::getDataDate, DateUtil.offsetDay(currentDate, -7));
PlantPowerDataEnt currentEnt = powerDataMapper.selectOne(queryWrapper);
//获取同期七天的实际数据
queryWrapper.clear();
queryWrapper.select(" IFNULL(avg(power ) , 0 ) power ");
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, output.getId());
queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, XDateUtils.addYear(currentDate, -1));
queryWrapper.select("IFNULL(avg(power ) , 0 ) power")
.lambda()
.eq(PlantPowerDataEnt::getPlantId, output.getId())
.ge(PlantPowerDataEnt::getDataDate, DateUtil.offset(currentDate, DateField.YEAR, -1));
PlantPowerDataEnt lastEnt = powerDataMapper.selectOne(queryWrapper);
//获取同比 = 当前/同期
BigDecimal compare = new BigDecimal(1);
if (lastEnt.getPower().compareTo(BigDecimal.ZERO) > 0 && currentEnt.getPower().compareTo(BigDecimal.ZERO) != 0)
compare = currentEnt.getPower().divide(lastEnt.getPower(), 6, BigDecimal.ROUND_HALF_UP);
if (lastEnt.getPower().compareTo(BigDecimal.ZERO) > 0 && currentEnt.getPower().compareTo(BigDecimal.ZERO) != 0) {
compare = currentEnt.getPower().divide(lastEnt.getPower(), 6, RoundingMode.HALF_UP);
}
//获取同期30天数据
queryWrapper.clear();
queryWrapper.select(" plant_id, data_date, temperature, humidity, wind_speed, wind_direction, pressure, plane_irradiance, horizontal_irradiance, power ");
queryWrapper.lambda().eq(PlantPowerDataEnt::getPlantId, output.getId());
queryWrapper.lambda().ge(PlantPowerDataEnt::getDataDate, XDateUtils.addYear(currentDate, -1));
queryWrapper.lambda().le(PlantPowerDataEnt::getDataDate, XDateUtils.addMonth(currentDate, -11));
queryWrapper.select("plant_id, data_date, temperature, humidity, wind_speed, wind_direction, pressure, plane_irradiance, horizontal_irradiance, power");
queryWrapper.lambda()
.eq(PlantPowerDataEnt::getPlantId, output.getId())
.ge(PlantPowerDataEnt::getDataDate, DateUtil.offset(currentDate, DateField.YEAR, -1))
.le(PlantPowerDataEnt::getDataDate, DateUtil.offsetMonth(currentDate, -11));
List<PlantPowerDataEnt> lastList = powerDataMapper.selectList(queryWrapper);
//未来30天=同期30*同比
List<PlantPredictedPowerLongTermDataEnt> insertList = new ArrayList<>();
for (PlantPowerDataEnt item : lastList) {
item.setPower(item.getPower().multiply(compare));
item.setDataDate(XDateUtils.getString(XDateUtils.addYear(XDateUtils.parse(item.getDataDate()), 1)));
item.setDataDate(DateUtil.formatDate(DateUtil.offset(DateUtil.parseDateTime(item.getDataDate()), DateField.YEAR, 1)));
PlantPredictedPowerLongTermDataEnt insertData = XCopyUtils.copyNewObject(item, PlantPredictedPowerLongTermDataEnt.class);
insertData.setCreateTime(currentDate);
insertList.add(insertData);
}
//插入数据前,先删除数据
PlantPredictedPowerLongTermDataMapper longTermDataMapper = context.getBean(PlantPredictedPowerLongTermDataMapper.class);
QueryWrapper<PlantPredictedPowerLongTermDataEnt> longTermDataWrapper = new QueryWrapper<>();
longTermDataWrapper.lambda().eq(PlantPredictedPowerLongTermDataEnt::getPlantId, output.getId());
longTermDataWrapper.lambda().ge(PlantPredictedPowerLongTermDataEnt::getDataDate, currentDate);
longTermDataWrapper.lambda().le(PlantPredictedPowerLongTermDataEnt::getDataDate, XDateUtils.addMonth(currentDate, 1));
longTermDataMapper.delete(longTermDataWrapper);
longTermDataMapper.delete(new QueryWrapper<PlantPredictedPowerLongTermDataEnt>().lambda()
.eq(PlantPredictedPowerLongTermDataEnt::getPlantId, output.getId())
.ge(PlantPredictedPowerLongTermDataEnt::getDataDate, currentDate)
.le(PlantPredictedPowerLongTermDataEnt::getDataDate, DateUtil.offsetMonth(currentDate, 1)));
PlantPredictedPowerLongTermDataViewMapper longTermDataViewMapper = context.getBean(PlantPredictedPowerLongTermDataViewMapper.class);
List<PlantPredictedPowerLongTermDataEnt> batchList = new ArrayList<>();
List<String> timeList = Arrays.asList("15", "30", "45");
for (int i = 0; i < insertList.size(); i++) {
PlantPredictedPowerLongTermDataEnt item = insertList.get(i);
Date date = XDateUtils.parse(item.getDataDate());
item.setYearTime(XDateUtils.getYear(date) + "");
item.setMonthTime(String.format("%02d", XDateUtils.getMonth(date)));
item.setDayTime(String.format("%02d", XDateUtils.getDay(date)));
item.setHourTime(String.format("%02d", XDateUtils.getHour24(date)));
item.setMinTime(String.format("%02d", XDateUtils.getMinute(date)) + ":00");
DateTime dateTime = DateUtil.parseDateTime(item.getDataDate());
item.setYearTime(dateTime.year() + "");
item.setMonthTime(String.format("%02d", dateTime.monthBaseOne()));
item.setDayTime(String.format("%02d", dateTime.dayOfMonth()));
item.setHourTime(String.format("%02d", dateTime.hour(true)));
item.setMinTime(String.format("%02d", dateTime.minute() + ":00"));
batchList.add(item);
if (i < insertList.size() - 1) {
for (int y = 0; y < timeList.size(); y++) {
......@@ -105,25 +113,25 @@ public class PlantPredictedPowerLongTermDataCloudServiceImpl implements PlantPre
int I_i = i + 1;
BigDecimal temperature_1 = insertList.get(i).getTemperature() == null ? new BigDecimal(0) : insertList.get(i).getTemperature();
BigDecimal temperature_2 = insertList.get(I_i).getTemperature() == null ? new BigDecimal(0) : insertList.get(I_i).getTemperature();
dao.setTemperature(temperature_1.add(temperature_2.subtract(temperature_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setTemperature(temperature_1.add(temperature_2.subtract(temperature_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal humidity_1 = insertList.get(i).getHumidity() == null ? new BigDecimal(0) : insertList.get(i).getHumidity();
BigDecimal humidity_2 = insertList.get(I_i).getHumidity() == null ? new BigDecimal(0) : insertList.get(I_i).getHumidity();
dao.setHumidity(humidity_1.add(humidity_2.subtract(humidity_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setHumidity(humidity_1.add(humidity_2.subtract(humidity_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal windSpeed_1 = insertList.get(i).getWindSpeed() == null ? new BigDecimal(0) : insertList.get(i).getWindSpeed();
BigDecimal windSpeed_2 = insertList.get(I_i).getWindSpeed() == null ? new BigDecimal(0) : insertList.get(I_i).getWindSpeed();
dao.setWindSpeed(windSpeed_1.add(windSpeed_2.subtract(windSpeed_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setWindSpeed(windSpeed_1.add(windSpeed_2.subtract(windSpeed_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal pressure_1 = insertList.get(i).getPressure() == null ? new BigDecimal(0) : insertList.get(i).getPressure();
BigDecimal pressure_2 = insertList.get(I_i).getPressure() == null ? new BigDecimal(0) : insertList.get(I_i).getPressure();
dao.setPressure(pressure_1.add(pressure_2.subtract(pressure_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setPressure(pressure_1.add(pressure_2.subtract(pressure_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal planeIrradiance_1 = insertList.get(i).getPlaneIrradiance() == null ? new BigDecimal(0) : insertList.get(i).getPlaneIrradiance();
BigDecimal planeIrradiance_2 = insertList.get(I_i).getPlaneIrradiance() == null ? new BigDecimal(0) : insertList.get(I_i).getPlaneIrradiance();
dao.setPlaneIrradiance(planeIrradiance_1.add(planeIrradiance_2.subtract(planeIrradiance_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setPlaneIrradiance(planeIrradiance_1.add(planeIrradiance_2.subtract(planeIrradiance_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal horizontalIrradiance_1 = insertList.get(i).getHorizontalIrradiance() == null ? new BigDecimal(0) : insertList.get(i).getHorizontalIrradiance();
BigDecimal horizontalIrradiance_2 = insertList.get(I_i).getHorizontalIrradiance() == null ? new BigDecimal(0) : insertList.get(I_i).getHorizontalIrradiance();
dao.setHorizontalIrradiance(horizontalIrradiance_1.add(horizontalIrradiance_2.subtract(horizontalIrradiance_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setHorizontalIrradiance(horizontalIrradiance_1.add(horizontalIrradiance_2.subtract(horizontalIrradiance_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
BigDecimal power_1 = insertList.get(i).getPower() == null ? new BigDecimal(0) : insertList.get(i).getPower();
BigDecimal power_2 = insertList.get(I_i).getPower() == null ? new BigDecimal(0) : insertList.get(I_i).getPower();
dao.setPower(power_1.add(power_2.subtract(power_1).multiply(new BigDecimal(0.3 * (y + 1)))));
dao.setPower(power_1.add(power_2.subtract(power_1).multiply(BigDecimal.valueOf(0.3 * (y + 1)))));
batchList.add(dao);
}
}
......@@ -132,21 +140,7 @@ public class PlantPredictedPowerLongTermDataCloudServiceImpl implements PlantPre
batchList = new ArrayList<>();
}
}
// for(PlantPredictedPowerLongTermDataEnt item : insertList){
// Date date = XDateUtils.parse(item.getDataDate());
// item.setYearTime(XDateUtils.getYear(date)+"");
// item.setMonthTime(String.format("%02d", XDateUtils.getMonth(date)));
// item.setDayTime(String.format("%02d", XDateUtils.getDay(date)));
// item.setHourTime(String.format("%02d", XDateUtils.getHour24(date)));
// item.setMinTime(String.format("%02d", XDateUtils.getMinute(date)) + ":00");
// //longTermDataMapper.insert(item);
// batchList.add(item);
// if(batchList.size() > 500){
// longTermDataViewMapper.insertBatch(batchList);
// batchList = new ArrayList<>();
// }
// }
if (batchList.size() > 0)
if (!batchList.isEmpty())
longTermDataViewMapper.insertBatch(batchList);
}
return XServiceResult.OK;
......
package pps.core.prediction.service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import pps.cloud.prediction.service.PlantTrainPowerTaskCloudService;
import pps.cloud.prediction.service.data.plant_train_power_task.GetPlantTrainPowerTaskCloudInput;
......@@ -25,7 +26,7 @@ public class PlantTrainPowerTaskService implements PlantTrainPowerTaskCloudServi
.orderByDesc(PlantTrainPowerTaskEnt::getCreateTime)
.last(BusinessConstant.LAST_LIMIT);
PlantTrainPowerTaskEnt ent = mapper.selectOne(queryWrapper);
if (ent == null) {
if (ObjectUtil.isNull(ent)) {
queryWrapper.clear();
queryWrapper.eq(PlantTrainPowerTaskEnt::getModelKey, "all_plant_data")
.eq(PlantTrainPowerTaskEnt::getModelCycle, input.getModelCycle())
......
package pps.core.prediction.service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.prediction.entity.BaseDataEnt;
import pps.core.prediction.entity.BaseDataView;
......@@ -20,10 +21,10 @@ public class PredictionService {
@XApiGet
public XSingleResult<GetBaseDataOutput> getBaseData(XContext context, GetBaseDataInput input) {
BaseDataMapper mapper = context.getBean(BaseDataMapper.class);
QueryWrapper<BaseDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(BaseDataEnt::getId, input.getId());
BaseDataEnt entity = mapper.selectOne(queryWrapper);
if (entity == null) {
BaseDataEnt entity = mapper.selectOne(new QueryWrapper<BaseDataEnt>()
.lambda()
.eq(BaseDataEnt::getId, input.getId()));
if (ObjectUtil.isNull(entity)) {
return XSingleResult.error(context, XError.NotFound);
}
GetBaseDataOutput output = new GetBaseDataOutput();
......@@ -36,7 +37,7 @@ public class PredictionService {
BaseDataViewMapper mapper = context.getBean(BaseDataViewMapper.class);
BaseDataView view = XCopyUtils.copyNewObject(input, BaseDataView.class);
BaseDataView entity = mapper.selectOne(view);
if (entity == null) {
if (ObjectUtil.isNull(entity)) {
return XSingleResult.error(context, XError.NotFound);
}
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;
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.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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 {
URL localURL = new URL(url);
URLConnection connection = localURL.openConnection();
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(param.length()));
httpURLConnection.setConnectTimeout(10000);
OutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
String resultBuffer = "";
try {
outputStream = httpURLConnection.getOutputStream();
outputStreamWriter = new OutputStreamWriter(outputStream);
outputStreamWriter.write(param.toString());
outputStreamWriter.flush();
if (httpURLConnection.getResponseCode() >= 300) {
throw new Exception(
"HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
}
inputStream = httpURLConnection.getInputStream();
resultBuffer = convertStreamToString(inputStream);
System.out.println(resultBuffer);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStreamWriter != null) {
outputStreamWriter.close();
}
if (outputStream != null) {
outputStream.close();
}
if (reader != null) {
reader.close();
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
if (inputStream != null) {
inputStream.close();
}
}
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