Commit 63bca7e2 authored by ZWT's avatar ZWT

feat(吉林演示): 松原

1.天气数据接收定时任务,解决代码扫描问题,修改文件读取相关代码,解决资源未关流问题;
2.修改登录验证码生成工具类,解决代码扫描问题,修复随机数不安全问题;
3.删除除主程序启动类外其他启动类模块,解决代码扫描问题;
4.删除自定义httputlis类,解决代码扫描问题,替换部分代码远程调用方法;
5.重构光伏预测模块下载电站实际发电数据导入模板接口,解决代码扫描问题;
6.重构光伏预测模块导入电站实际发电数据接口,解决代码扫描问题;
7.删除公用excel导入导出工具类及poi相关pom依赖,解决代码扫描问题;
8.光伏功率预测模块,增加查询线路列表接口,解决页面接口报错问题;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent e221921a
package pps.core.base.excel; package pps.core.base.excel;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.listener.ReadListener;
import pps.core.base.service.BaseLineService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import pps.core.base.entity.BasePhotovoltaicPlantView;
import pps.core.base.entity.PlantPredictedPowerDataEnt;
import pps.core.base.entity.ThirdWeatherDataEnt;
import pps.core.base.entity.ThirdWeatherDataView;
import pps.core.base.mapper.*;
import pps.core.base.service.data.third_weather_data.ThirdApiWeatherExcelData; import pps.core.base.service.data.third_weather_data.ThirdApiWeatherExcelData;
import pps.core.base.service.data.third_weather_data.WeatherDeleteCondition;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.utils.BaseUtils;
import xstartup.base.XContext; import xstartup.base.XContext;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -34,7 +47,213 @@ public class ThirdApiWeatherDataListener implements ReadListener<ThirdApiWeather ...@@ -34,7 +47,213 @@ public class ThirdApiWeatherDataListener implements ReadListener<ThirdApiWeather
@Override @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) { public void doAfterAllAnalysed(AnalysisContext analysisContext) {
BaseLineService bean = context.getBean(BaseLineService.class); this.saveHistory(context, cachedDataList);
bean.saveHistory(context, cachedDataList); }
private void saveHistory(XContext context, List<ThirdApiWeatherExcelData> cachedDataList) {
DateTime date = DateUtil.date();
//查第二采油厂所有电站
BasePhotovoltaicPlantViewMapper viewMapper = context.getBean(BasePhotovoltaicPlantViewMapper.class);
List<BasePhotovoltaicPlantView> plantList = viewMapper.selectPlantList(BasePhotovoltaicPlantView.builder()
.ouId("2c4c9d1c-ad55-4c14-b889-4dc33e3461e2")
.build());
//新数据删除接收
List<WeatherDeleteCondition> deleteList = new ArrayList<>(32);
List<ThirdWeatherDataView> weatherDataViewList = new ArrayList<>(2048);
//todo 老表逻辑(后期删除):后续可能替换
List<PlantPredictedPowerDataEnt> oldDeleteList = new ArrayList<>(32);
List<PlantPredictedPowerDataEnt> oldBatchList = new ArrayList<>(13312);
BigDecimal longitude = new BigDecimal("108.321784");
BigDecimal latitude = new BigDecimal("36.485083");
//获取开始结束时间,添加删除条件
Date beginTime = DateUtil.offsetMinute(DateUtil.parseDateTime(cachedDataList.get(0).getTime()), -5);
Date endTime = DateUtil.offsetMinute(DateUtil.parseDateTime(cachedDataList.get(cachedDataList.size() - 1).getTime()), 15);
deleteList.add(
WeatherDeleteCondition.builder()
.longitude(longitude)
.latitude(latitude)
.beginTime(beginTime)
.endTime(endTime)
.build()
);
//todo 老表逻辑(后期删除):删除数据逻辑
for (BasePhotovoltaicPlantView plantView : plantList) {
oldDeleteList.add(PlantPredictedPowerDataEnt.builder()
.plantId(plantView.getId())
.createTime(beginTime)
.endTime(endTime)
.build());
}
//天气数据处理
for (ThirdApiWeatherExcelData excel : cachedDataList) {
DateTime time = DateUtil.parseDateTime(excel.getTime());
ThirdWeatherDataView thirdWeatherDataView = ThirdWeatherDataView.builder()
.dni(excel.getDni())
.ghi(excel.getGhi())
.dhi(excel.getDhi())
.forecastTime(time)
.tem(excel.getTem())
.rhu(excel.getRhu())
.wns(excel.getWns())
.wnd(excel.getWnd())
.wnsGrd(excel.getWnsGrd())
.gust(excel.getGust())
.pre(excel.getPre())
.prsQfe(excel.getPrsQfe())
.vis(excel.getVis())
.clo(excel.getClo())
.uvb(excel.getUvb())
.uvi(0)
.phs(excel.getPhs())
.wep(excel.getWep())
.wnd100m(excel.getWnd100m())
.wns100m(excel.getWns100m())
.wnsGrd100m(excel.getWnsGrd100m())
.longitude(longitude)
.latitude(latitude)
.createTime(date)
.updateTime(date)
.build();
weatherDataViewList.add(
thirdWeatherDataView
);
//todo 老表逻辑(后期删除):封装预测数据
for (BasePhotovoltaicPlantView plantView : plantList) {
this.addPlantPredictedPower(oldBatchList, plantView.getId(), thirdWeatherDataView);
}
}
//todo 老表逻辑(后期删除):删除/新增预测数据
this.deletePlantPredictedPowerList(context, oldDeleteList);
this.insertBatchPlantPredictedPowerList(context, oldBatchList);
if (CollUtil.isNotEmpty(deleteList)) {
ThirdWeatherDataMapper dataMapper = context.getBean(ThirdWeatherDataMapper.class);
if (deleteList.size() > BaseUtils.BATCH_SIZE) {
List<List<WeatherDeleteCondition>> subList = BaseUtils.getSubList(deleteList);
for (List<WeatherDeleteCondition> list : subList) {
LambdaQueryWrapper<ThirdWeatherDataEnt> wrapper = new LambdaQueryWrapper<>();
for (WeatherDeleteCondition dataEnt : list) {
wrapper.or(w -> w.eq(ThirdWeatherDataEnt::getLatitude, dataEnt.getLatitude())
.eq(ThirdWeatherDataEnt::getLongitude, dataEnt.getLongitude())
.between(ThirdWeatherDataEnt::getForecastTime, dataEnt.getBeginTime(), dataEnt.getEndTime())
);
}
dataMapper.delete(wrapper);
}
} else {
LambdaQueryWrapper<ThirdWeatherDataEnt> wrapper = new LambdaQueryWrapper<>();
for (WeatherDeleteCondition dataEnt : deleteList) {
wrapper.or(w -> w.eq(ThirdWeatherDataEnt::getLatitude, dataEnt.getLatitude())
.eq(ThirdWeatherDataEnt::getLongitude, dataEnt.getLongitude())
.between(ThirdWeatherDataEnt::getForecastTime, dataEnt.getBeginTime(), dataEnt.getEndTime())
);
}
dataMapper.delete(wrapper);
}
}
if (CollUtil.isNotEmpty(weatherDataViewList)) {
ThirdWeatherDataViewMapper dataViewMapper = context.getBean(ThirdWeatherDataViewMapper.class);
if (weatherDataViewList.size() > BaseUtils.BATCH_SIZE) {
List<List<ThirdWeatherDataView>> subList = BaseUtils.getSubList(weatherDataViewList);
subList.forEach(dataViewMapper::insertBatch);
} else {
dataViewMapper.insertBatch(weatherDataViewList);
}
}
}
/**
* 添加电厂预测功率
*
* @param batchList 批处理列表
* @param plantId 植物id
* @param thirdWeatherDataView 第三天气数据视图
*/
private void addPlantPredictedPower(List<PlantPredictedPowerDataEnt> batchList, String plantId, ThirdWeatherDataView thirdWeatherDataView) {
DateTime date = DateUtil.date(thirdWeatherDataView.getForecastTime());
batchList.add(PlantPredictedPowerDataEnt.builder()
.plantId(plantId)
.createTime(thirdWeatherDataView.getCreateTime())
.yearTime(String.valueOf(date.year()))
.monthTime(this.zeroFill(date.monthBaseOne()))
.dayTime(this.zeroFill(date.dayOfMonth()))
.hourTime(this.zeroFill(date.hour(true)))
.minTime(this.zeroFill(date.minute()))
.dataDate(date.toString(BusinessConstant.DATE_FORMAT_ALL))
.temperature(thirdWeatherDataView.getTem())
.windSpeed(thirdWeatherDataView.getWns100m())
.windDirection(new BigDecimal(thirdWeatherDataView.getWnd()))
.pressure(thirdWeatherDataView.getPrsQfe())
.humidity(thirdWeatherDataView.getRhu())
.planeIrradiance(thirdWeatherDataView.getDni())
.horizontalIrradiance(thirdWeatherDataView.getGhi())
.power(BigDecimal.ZERO)
.build());
}
/**
* 条件删除预测数据
*
* @param context 上下文
* @param deleteList 删除列表
*/
private void deletePlantPredictedPowerList(XContext context, List<PlantPredictedPowerDataEnt> deleteList) {
if (CollUtil.isNotEmpty(deleteList)) {
PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class);
int size = deleteList.size();
context.getLogger().info("------ deletePlantPredictedPowerList batchDelete delete size: {}", size);
if (size > BaseUtils.BATCH_SIZE) {
List<List<PlantPredictedPowerDataEnt>> subList = BaseUtils.getSubList(deleteList);
for (List<PlantPredictedPowerDataEnt> list : subList) {
LambdaQueryWrapper<PlantPredictedPowerDataEnt> wrapper = new LambdaQueryWrapper<>();
for (PlantPredictedPowerDataEnt dataEnt : list) {
wrapper.or(w -> w.eq(PlantPredictedPowerDataEnt::getPlantId, dataEnt.getPlantId())
.between(PlantPredictedPowerDataEnt::getDataDate, dataEnt.getCreateTime(), dataEnt.getEndTime())
);
}
mapper.delete(wrapper);
}
} else {
LambdaQueryWrapper<PlantPredictedPowerDataEnt> wrapper = new LambdaQueryWrapper<>();
for (PlantPredictedPowerDataEnt dataEnt : deleteList) {
wrapper.or(w -> w.eq(PlantPredictedPowerDataEnt::getPlantId, dataEnt.getPlantId())
.between(PlantPredictedPowerDataEnt::getDataDate, dataEnt.getCreateTime(), dataEnt.getEndTime())
);
}
mapper.delete(wrapper);
}
}
}
/**
* 插入间歇装置预测功率列表
*
* @param context 上下文
* @param batchList 批处理列表
*/
private void insertBatchPlantPredictedPowerList(XContext context, List<PlantPredictedPowerDataEnt> batchList) {
if (CollUtil.isNotEmpty(batchList)) {
PlantPredictedPowerDataViewMapper dataViewMapper = context.getBean(PlantPredictedPowerDataViewMapper.class);
int size = batchList.size();
context.getLogger().info("------ insertBatchPlantPredictedPowerList batchList insert size: {}", size);
if (size > BaseUtils.BATCH_SIZE) {
List<List<PlantPredictedPowerDataEnt>> subList = BaseUtils.getSubList(batchList);
subList.forEach(dataViewMapper::insertBatch);
} else {
dataViewMapper.insertBatch(batchList);
}
}
}
/**
* 零填充
*
* @param number 数字
* @return {@link String}
*/
private String zeroFill(int number) {
if (number < 10) {
return "0" + number;
}
return String.valueOf(number);
} }
} }
package pps.core.base.excel; package pps.core.base.excel;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener; import com.alibaba.excel.read.listener.ReadListener;
import pps.core.base.service.BaseLineService; import pps.core.base.entity.WindPredictionFutureView;
import pps.core.base.entity.WindPredictionHistoryView;
import pps.core.base.mapper.WindPredictionFutureViewMapper;
import pps.core.base.mapper.WindPredictionHistoryViewMapper;
import pps.core.base.service.data.base_excel.WindPredictionExcelData; import pps.core.base.service.data.base_excel.WindPredictionExcelData;
import pps.core.common.utils.BaseUtils;
import xstartup.base.XContext; import xstartup.base.XContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
/** /**
...@@ -37,7 +45,83 @@ public class WindPredictionDataListener implements ReadListener<WindPredictionEx ...@@ -37,7 +45,83 @@ public class WindPredictionDataListener implements ReadListener<WindPredictionEx
@Override @Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) { public void doAfterAllAnalysed(AnalysisContext analysisContext) {
BaseLineService bean = context.getBean(BaseLineService.class); this.saveWindPredictionHistory(context, cachedDataList, stationId);
bean.saveWindPredictionHistory(context, cachedDataList, stationId); }
public void saveWindPredictionHistory(XContext context, List<WindPredictionExcelData> cachedDataList, String stationId) {
if (CollUtil.isNotEmpty(cachedDataList)) {
List<WindPredictionFutureView> futureList = new ArrayList<>(cachedDataList.size());
List<WindPredictionHistoryView> historyList = new ArrayList<>(cachedDataList.size());
//按日期顺序排序
cachedDataList.sort(Comparator.comparing(WindPredictionExcelData::getDataTime));
//数据分界线
DateTime futureFlag = DateUtil.offsetDay(DateUtil.beginOfDay(CollUtil.getLast(cachedDataList).getDataTime()), -20);
//数据分片
for (WindPredictionExcelData excelData : cachedDataList) {
if (DateUtil.compare(excelData.getDataTime(), futureFlag) >= 0) {
//未来数据
WindPredictionFutureView build = WindPredictionFutureView.builder()
.stationId(stationId)
.dataTime(excelData.getDataTime())
.windDirection(excelData.getWindDirection())
.windSpeed(excelData.getWindSpeed())
.airTemperature(excelData.getAirTemperature())
.humidity(excelData.getHumidity())
.pressure(excelData.getPressure())
.actualWindSpeed(excelData.getActualWindSpeed())
.actualPower(excelData.getActualPower())
.predictedPower(excelData.getPredictedPower())
.build();
//去重
if (futureList.stream()
.noneMatch(item -> DateUtil.compare(item.getDataTime(), build.getDataTime()) == 0)) {
futureList.add(build);
}
} else {
//历史数据
WindPredictionHistoryView build = WindPredictionHistoryView.builder()
.stationId(stationId)
.dataTime(excelData.getDataTime())
.windDirection(excelData.getWindDirection())
.windSpeed(excelData.getWindSpeed())
.airTemperature(excelData.getAirTemperature())
.humidity(excelData.getHumidity())
.pressure(excelData.getPressure())
.actualWindSpeed(excelData.getActualWindSpeed())
.actualPower(excelData.getActualPower())
.predictedPower(excelData.getPredictedPower())
.build();
//去重
if (historyList.stream()
.noneMatch(item -> DateUtil.compare(item.getDataTime(), build.getDataTime()) == 0)) {
historyList.add(build);
}
}
}
//记录
String futureStart = DateUtil.formatDateTime(CollUtil.getFirst(futureList).getDataTime());
String futureEnd = DateUtil.formatDateTime(CollUtil.getLast(futureList).getDataTime());
String historyStart = DateUtil.formatDateTime(CollUtil.getFirst(historyList).getDataTime());
String historyEnd = DateUtil.formatDateTime(CollUtil.getLast(historyList).getDataTime());
//入库
if (CollUtil.isNotEmpty(futureList)) {
WindPredictionFutureViewMapper futureMapper = context.getBean(WindPredictionFutureViewMapper.class);
if (futureList.size() > BaseUtils.BATCH_SIZE) {
List<List<WindPredictionFutureView>> subList = BaseUtils.getSubList(futureList);
subList.forEach(futureMapper::insertBatch);
} else {
futureMapper.insertBatch(futureList);
}
}
if (CollUtil.isNotEmpty(historyList)) {
WindPredictionHistoryViewMapper historyMapper = context.getBean(WindPredictionHistoryViewMapper.class);
if (historyList.size() > BaseUtils.BATCH_SIZE) {
List<List<WindPredictionHistoryView>> subList = BaseUtils.getSubList(historyList);
subList.forEach(historyMapper::batchInsert);
} else {
historyMapper.batchInsert(historyList);
}
}
}
} }
} }
package pps.core.base.service; package pps.core.base.service;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import pps.core.base.entity.*;
import pps.core.base.excel.ThirdApiWeatherDataListener; import pps.core.base.excel.ThirdApiWeatherDataListener;
import pps.core.base.excel.WindPredictionDataListener; import pps.core.base.excel.WindPredictionDataListener;
import pps.core.base.mapper.*;
import pps.core.base.service.data.base_data.GetBaseDataInput; import pps.core.base.service.data.base_data.GetBaseDataInput;
import pps.core.base.service.data.base_excel.WindPredictionExcelData; import pps.core.base.service.data.base_excel.WindPredictionExcelData;
import pps.core.base.service.data.base_power_line.DynamicQueryBasePowerLineInput; import pps.core.base.service.data.base_power_line.DynamicQueryBasePowerLineInput;
import pps.core.base.service.data.base_power_line.DynamicQueryBasePowerLineOutput; import pps.core.base.service.data.base_power_line.DynamicQueryBasePowerLineOutput;
import pps.core.base.service.data.third_weather_data.ThirdApiWeatherExcelData; import pps.core.base.service.data.third_weather_data.ThirdApiWeatherExcelData;
import pps.core.base.service.data.third_weather_data.WeatherDeleteCondition;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.utils.BaseUtils;
import xstartup.annotation.XService; import xstartup.annotation.XService;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import xstartup.base.XContext; import xstartup.base.XContext;
...@@ -25,8 +16,8 @@ import xstartup.data.XServiceResult; ...@@ -25,8 +16,8 @@ import xstartup.data.XServiceResult;
import xstartup.feature.api.annotation.XApiGet; import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost; import xstartup.feature.api.annotation.XApiPost;
import java.math.BigDecimal; import java.util.HashMap;
import java.util.*; import java.util.Map;
@XService @XService
public class BaseLineService { public class BaseLineService {
...@@ -78,324 +69,4 @@ public class BaseLineService { ...@@ -78,324 +69,4 @@ public class BaseLineService {
EasyExcel.read(fileName, ThirdApiWeatherExcelData.class, new ThirdApiWeatherDataListener(context)).sheet().doRead(); EasyExcel.read(fileName, ThirdApiWeatherExcelData.class, new ThirdApiWeatherDataListener(context)).sheet().doRead();
return XServiceResult.OK; return XServiceResult.OK;
} }
@XText("重载天气数据")
@XApiGet
public XServiceResult overloadThirdWeather(XContext context) {
ThirdWeatherDataViewMapper mapper = context.getBean(ThirdWeatherDataViewMapper.class);
List<ThirdWeatherDataView> weatherDataViewList = mapper.selectList(null);
//查第二采油厂所有电站
BasePhotovoltaicPlantViewMapper viewMapper = context.getBean(BasePhotovoltaicPlantViewMapper.class);
List<BasePhotovoltaicPlantView> plantList = viewMapper.selectPlantList(BasePhotovoltaicPlantView.builder()
.ouId("2c4c9d1c-ad55-4c14-b889-4dc33e3461e2")
.build());
//todo 老表逻辑(后期删除):后续可能替换
List<PlantPredictedPowerDataEnt> oldDeleteList = new ArrayList<>(32);
List<PlantPredictedPowerDataEnt> oldBatchList = new ArrayList<>(13312);
//获取开始结束时间,添加删除条件
Date beginTime = DateUtil.offsetMinute(weatherDataViewList.get(0).getForecastTime(), -5);
Date endTime = DateUtil.offsetMinute(weatherDataViewList.get(weatherDataViewList.size() - 1).getForecastTime(), 15);
//todo 老表逻辑(后期删除):删除数据逻辑
for (BasePhotovoltaicPlantView plantView : plantList) {
oldDeleteList.add(PlantPredictedPowerDataEnt.builder()
.plantId(plantView.getId())
.createTime(beginTime)
.endTime(endTime)
.build());
}
for (ThirdWeatherDataView thirdWeatherDataView : weatherDataViewList) {
//todo 老表逻辑(后期删除):封装预测数据
for (BasePhotovoltaicPlantView plantView : plantList) {
this.addPlantPredictedPower(oldBatchList, plantView.getId(), thirdWeatherDataView);
}
}
//todo 老表逻辑(后期删除):删除/新增预测数据
this.deletePlantPredictedPowerList(context, oldDeleteList);
this.insertBatchPlantPredictedPowerList(context, oldBatchList);
return XServiceResult.OK;
}
public void saveWindPredictionHistory(XContext context, List<WindPredictionExcelData> cachedDataList, String stationId) {
if (CollUtil.isNotEmpty(cachedDataList)) {
List<WindPredictionFutureView> futureList = new ArrayList<>(cachedDataList.size());
List<WindPredictionHistoryView> historyList = new ArrayList<>(cachedDataList.size());
//按日期顺序排序
cachedDataList.sort(Comparator.comparing(WindPredictionExcelData::getDataTime));
//数据分界线
DateTime futureFlag = DateUtil.offsetDay(DateUtil.beginOfDay(CollUtil.getLast(cachedDataList).getDataTime()), -20);
//数据分片
for (WindPredictionExcelData excelData : cachedDataList) {
if (DateUtil.compare(excelData.getDataTime(), futureFlag) >= 0) {
//未来数据
WindPredictionFutureView build = WindPredictionFutureView.builder()
.stationId(stationId)
.dataTime(excelData.getDataTime())
.windDirection(excelData.getWindDirection())
.windSpeed(excelData.getWindSpeed())
.airTemperature(excelData.getAirTemperature())
.humidity(excelData.getHumidity())
.pressure(excelData.getPressure())
.actualWindSpeed(excelData.getActualWindSpeed())
.actualPower(excelData.getActualPower())
.predictedPower(excelData.getPredictedPower())
.build();
//去重
if (futureList.stream()
.noneMatch(item -> DateUtil.compare(item.getDataTime(), build.getDataTime()) == 0)) {
futureList.add(build);
}
} else {
//历史数据
WindPredictionHistoryView build = WindPredictionHistoryView.builder()
.stationId(stationId)
.dataTime(excelData.getDataTime())
.windDirection(excelData.getWindDirection())
.windSpeed(excelData.getWindSpeed())
.airTemperature(excelData.getAirTemperature())
.humidity(excelData.getHumidity())
.pressure(excelData.getPressure())
.actualWindSpeed(excelData.getActualWindSpeed())
.actualPower(excelData.getActualPower())
.predictedPower(excelData.getPredictedPower())
.build();
//去重
if (historyList.stream()
.noneMatch(item -> DateUtil.compare(item.getDataTime(), build.getDataTime()) == 0)) {
historyList.add(build);
}
}
}
//记录
String futureStart = DateUtil.formatDateTime(CollUtil.getFirst(futureList).getDataTime());
String futureEnd = DateUtil.formatDateTime(CollUtil.getLast(futureList).getDataTime());
String historyStart = DateUtil.formatDateTime(CollUtil.getFirst(historyList).getDataTime());
String historyEnd = DateUtil.formatDateTime(CollUtil.getLast(historyList).getDataTime());
//入库
if (CollUtil.isNotEmpty(futureList)) {
WindPredictionFutureViewMapper futureMapper = context.getBean(WindPredictionFutureViewMapper.class);
if (futureList.size() > BaseUtils.BATCH_SIZE) {
List<List<WindPredictionFutureView>> subList = BaseUtils.getSubList(futureList);
subList.forEach(futureMapper::insertBatch);
} else {
futureMapper.insertBatch(futureList);
}
}
if (CollUtil.isNotEmpty(historyList)) {
WindPredictionHistoryViewMapper historyMapper = context.getBean(WindPredictionHistoryViewMapper.class);
if (historyList.size() > BaseUtils.BATCH_SIZE) {
List<List<WindPredictionHistoryView>> subList = BaseUtils.getSubList(historyList);
subList.forEach(historyMapper::batchInsert);
} else {
historyMapper.batchInsert(historyList);
}
}
}
}
public void saveHistory(XContext context, List<ThirdApiWeatherExcelData> cachedDataList) {
DateTime date = DateUtil.date();
//查第二采油厂所有电站
BasePhotovoltaicPlantViewMapper viewMapper = context.getBean(BasePhotovoltaicPlantViewMapper.class);
List<BasePhotovoltaicPlantView> plantList = viewMapper.selectPlantList(BasePhotovoltaicPlantView.builder()
.ouId("2c4c9d1c-ad55-4c14-b889-4dc33e3461e2")
.build());
//新数据删除接收
List<WeatherDeleteCondition> deleteList = new ArrayList<>(32);
List<ThirdWeatherDataView> weatherDataViewList = new ArrayList<>(2048);
//todo 老表逻辑(后期删除):后续可能替换
List<PlantPredictedPowerDataEnt> oldDeleteList = new ArrayList<>(32);
List<PlantPredictedPowerDataEnt> oldBatchList = new ArrayList<>(13312);
BigDecimal longitude = new BigDecimal("108.321784");
BigDecimal latitude = new BigDecimal("36.485083");
//获取开始结束时间,添加删除条件
Date beginTime = DateUtil.offsetMinute(DateUtil.parseDateTime(cachedDataList.get(0).getTime()), -5);
Date endTime = DateUtil.offsetMinute(DateUtil.parseDateTime(cachedDataList.get(cachedDataList.size() - 1).getTime()), 15);
deleteList.add(
WeatherDeleteCondition.builder()
.longitude(longitude)
.latitude(latitude)
.beginTime(beginTime)
.endTime(endTime)
.build()
);
//todo 老表逻辑(后期删除):删除数据逻辑
for (BasePhotovoltaicPlantView plantView : plantList) {
oldDeleteList.add(PlantPredictedPowerDataEnt.builder()
.plantId(plantView.getId())
.createTime(beginTime)
.endTime(endTime)
.build());
}
//天气数据处理
for (ThirdApiWeatherExcelData excel : cachedDataList) {
DateTime time = DateUtil.parseDateTime(excel.getTime());
ThirdWeatherDataView thirdWeatherDataView = ThirdWeatherDataView.builder()
.dni(excel.getDni())
.ghi(excel.getGhi())
.dhi(excel.getDhi())
.forecastTime(time)
.tem(excel.getTem())
.rhu(excel.getRhu())
.wns(excel.getWns())
.wnd(excel.getWnd())
.wnsGrd(excel.getWnsGrd())
.gust(excel.getGust())
.pre(excel.getPre())
.prsQfe(excel.getPrsQfe())
.vis(excel.getVis())
.clo(excel.getClo())
.uvb(excel.getUvb())
.uvi(0)
.phs(excel.getPhs())
.wep(excel.getWep())
.wnd100m(excel.getWnd100m())
.wns100m(excel.getWns100m())
.wnsGrd100m(excel.getWnsGrd100m())
.longitude(longitude)
.latitude(latitude)
.createTime(date)
.updateTime(date)
.build();
weatherDataViewList.add(
thirdWeatherDataView
);
//todo 老表逻辑(后期删除):封装预测数据
for (BasePhotovoltaicPlantView plantView : plantList) {
this.addPlantPredictedPower(oldBatchList, plantView.getId(), thirdWeatherDataView);
}
}
//todo 老表逻辑(后期删除):删除/新增预测数据
this.deletePlantPredictedPowerList(context, oldDeleteList);
this.insertBatchPlantPredictedPowerList(context, oldBatchList);
if (CollUtil.isNotEmpty(deleteList)) {
ThirdWeatherDataMapper dataMapper = context.getBean(ThirdWeatherDataMapper.class);
if (deleteList.size() > BaseUtils.BATCH_SIZE) {
List<List<WeatherDeleteCondition>> subList = BaseUtils.getSubList(deleteList);
for (List<WeatherDeleteCondition> list : subList) {
LambdaQueryWrapper<ThirdWeatherDataEnt> wrapper = new LambdaQueryWrapper<>();
for (WeatherDeleteCondition dataEnt : list) {
wrapper.or(w -> w.eq(ThirdWeatherDataEnt::getLatitude, dataEnt.getLatitude())
.eq(ThirdWeatherDataEnt::getLongitude, dataEnt.getLongitude())
.between(ThirdWeatherDataEnt::getForecastTime, dataEnt.getBeginTime(), dataEnt.getEndTime())
);
}
dataMapper.delete(wrapper);
}
} else {
LambdaQueryWrapper<ThirdWeatherDataEnt> wrapper = new LambdaQueryWrapper<>();
for (WeatherDeleteCondition dataEnt : deleteList) {
wrapper.or(w -> w.eq(ThirdWeatherDataEnt::getLatitude, dataEnt.getLatitude())
.eq(ThirdWeatherDataEnt::getLongitude, dataEnt.getLongitude())
.between(ThirdWeatherDataEnt::getForecastTime, dataEnt.getBeginTime(), dataEnt.getEndTime())
);
}
dataMapper.delete(wrapper);
}
}
if (CollUtil.isNotEmpty(weatherDataViewList)) {
ThirdWeatherDataViewMapper dataViewMapper = context.getBean(ThirdWeatherDataViewMapper.class);
if (weatherDataViewList.size() > BaseUtils.BATCH_SIZE) {
List<List<ThirdWeatherDataView>> subList = BaseUtils.getSubList(weatherDataViewList);
subList.forEach(dataViewMapper::insertBatch);
} else {
dataViewMapper.insertBatch(weatherDataViewList);
}
}
}
/**
* 添加电厂预测功率
*
* @param batchList 批处理列表
* @param plantId 植物id
* @param thirdWeatherDataView 第三天气数据视图
*/
private void addPlantPredictedPower(List<PlantPredictedPowerDataEnt> batchList, String plantId, ThirdWeatherDataView thirdWeatherDataView) {
DateTime date = DateUtil.date(thirdWeatherDataView.getForecastTime());
batchList.add(PlantPredictedPowerDataEnt.builder()
.plantId(plantId)
.createTime(thirdWeatherDataView.getCreateTime())
.yearTime(String.valueOf(date.year()))
.monthTime(this.zeroFill(date.monthBaseOne()))
.dayTime(this.zeroFill(date.dayOfMonth()))
.hourTime(this.zeroFill(date.hour(true)))
.minTime(this.zeroFill(date.minute()))
.dataDate(date.toString(BusinessConstant.DATE_FORMAT_ALL))
.temperature(thirdWeatherDataView.getTem())
.windSpeed(thirdWeatherDataView.getWns100m())
.windDirection(new BigDecimal(thirdWeatherDataView.getWnd()))
.pressure(thirdWeatherDataView.getPrsQfe())
.humidity(thirdWeatherDataView.getRhu())
.planeIrradiance(thirdWeatherDataView.getDni())
.horizontalIrradiance(thirdWeatherDataView.getGhi())
.power(BigDecimal.ZERO)
.build());
}
/**
* 条件删除预测数据
*
* @param context 上下文
* @param deleteList 删除列表
*/
private void deletePlantPredictedPowerList(XContext context, List<PlantPredictedPowerDataEnt> deleteList) {
if (CollUtil.isNotEmpty(deleteList)) {
PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class);
int size = deleteList.size();
context.getLogger().info("------ deletePlantPredictedPowerList batchDelete delete size: {}", size);
if (size > BaseUtils.BATCH_SIZE) {
List<List<PlantPredictedPowerDataEnt>> subList = BaseUtils.getSubList(deleteList);
for (List<PlantPredictedPowerDataEnt> list : subList) {
LambdaQueryWrapper<PlantPredictedPowerDataEnt> wrapper = new LambdaQueryWrapper<>();
for (PlantPredictedPowerDataEnt dataEnt : list) {
wrapper.or(w -> w.eq(PlantPredictedPowerDataEnt::getPlantId, dataEnt.getPlantId())
.between(PlantPredictedPowerDataEnt::getDataDate, dataEnt.getCreateTime(), dataEnt.getEndTime())
);
}
mapper.delete(wrapper);
}
} else {
LambdaQueryWrapper<PlantPredictedPowerDataEnt> wrapper = new LambdaQueryWrapper<>();
for (PlantPredictedPowerDataEnt dataEnt : deleteList) {
wrapper.or(w -> w.eq(PlantPredictedPowerDataEnt::getPlantId, dataEnt.getPlantId())
.between(PlantPredictedPowerDataEnt::getDataDate, dataEnt.getCreateTime(), dataEnt.getEndTime())
);
}
mapper.delete(wrapper);
}
}
}
/**
* 插入间歇装置预测功率列表
*
* @param context 上下文
* @param batchList 批处理列表
*/
private void insertBatchPlantPredictedPowerList(XContext context, List<PlantPredictedPowerDataEnt> batchList) {
if (CollUtil.isNotEmpty(batchList)) {
PlantPredictedPowerDataViewMapper dataViewMapper = context.getBean(PlantPredictedPowerDataViewMapper.class);
int size = batchList.size();
context.getLogger().info("------ insertBatchPlantPredictedPowerList batchList insert size: {}", size);
if (size > BaseUtils.BATCH_SIZE) {
List<List<PlantPredictedPowerDataEnt>> subList = BaseUtils.getSubList(batchList);
subList.forEach(dataViewMapper::insertBatch);
} else {
dataViewMapper.insertBatch(batchList);
}
}
}
/**
* 零填充
*
* @param number 数字
* @return {@link String}
*/
private String zeroFill(int number) {
if (number < 10) {
return "0" + number;
}
return String.valueOf(number);
}
} }
\ No newline at end of file
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