Commit 30224d8e authored by ZWT's avatar ZWT

feat(吉林演示): 松原

1.天气数据接收定时任务,解决代码扫描问题,修改文件读取相关代码,解决资源未关流问题;
2.修改登录验证码生成工具类,解决代码扫描问题,修复随机数不安全问题;
3.删除除主程序启动类外其他启动类模块,解决代码扫描问题;
4.删除自定义httputlis类,解决代码扫描问题,替换部分代码远程调用方法;
5.重构光伏预测模块下载电站实际发电数据导入模板接口,解决代码扫描问题;
6.重构光伏预测模块导入电站实际发电数据接口,解决代码扫描问题;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent dec4e87b
......@@ -3,7 +3,10 @@ package pps.core.prediction.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import xstartup.annotation.XText;
import java.io.Serializable;
......@@ -11,6 +14,9 @@ import java.math.BigDecimal;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PlantPowerDataView implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
......@@ -54,5 +60,4 @@ public class PlantPowerDataView implements Serializable {
@XText("实际功率")
@TableField
private BigDecimal power;
}
\ No newline at end of file
package pps.core.prediction.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.CharSequenceUtil;
......@@ -11,7 +11,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.common.constant.BusinessConstant;
import pps.core.common.excel.util.EasyExcelUtil;
import pps.core.common.excel.util.ExcelStyleTool;
import pps.core.common.utils.ExcelUtils;
import pps.core.prediction.entity.PlantPowerDataEnt;
import pps.core.prediction.entity.PlantPowerDataView;
import pps.core.prediction.enums.ImportFieldDic;
......@@ -21,11 +20,11 @@ import pps.core.prediction.service.data.plant_power_data.ExcelPlantPowerTemplate
import pps.core.prediction.service.data.plant_power_data.ImportFileInput;
import pps.core.prediction.service.data.plant_power_data.QueryPlantPowerDataInput;
import pps.core.prediction.service.data.plant_power_data.QueryPlantPowerDataOutput;
import pps.core.prediction.utils.HttpUtils;
import xstartup.annotation.XService;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.tool.XStorageTool;
import xstartup.base.util.XHttpUtils;
import xstartup.data.XFileResult;
import xstartup.data.XFileType;
import xstartup.data.XPageResult;
......@@ -64,15 +63,15 @@ public class PlantPowerDataService {
@XText("下载电站实际发电数据导入模板")
@XApiGet
public XFileResult downloadImportTemplate(XContext context) {
String today = DateUtil.formatDate(DateUtil.date());
String fileSavePath = XStorageTool.getAbsolutePath("/temp/excel/导入模板_" + DateUtil.formatDate(DateUtil.date()) + ".xlsx");
DateTime date = DateUtil.date();
String fileSavePath = XStorageTool.getAbsolutePath("/temp/excel/导入模板_" + DateUtil.formatDate(date) + ".xlsx");
//生成模板
EasyExcelFactory.write(FileUtil.touch(fileSavePath))
.registerWriteHandler(ExcelStyleTool.getStyleStrategy())
.autoCloseStream(Boolean.TRUE)
.build()
.write(CollUtil.list(false, ExcelPlantPowerTemplate.builder()
.dataDate(today)
.dataDate(date)
.windSpeed(BusinessConstant.BIG_DECIMAL_6_67)
.windDirection(BigDecimal.ZERO)
.temperature(BusinessConstant.BIG_DECIMAL_4)
......@@ -86,33 +85,49 @@ public class PlantPowerDataService {
return XFileResult.success(XFileType.APPLICATION_XLSX, fileSavePath);
}
/**
* 导入工厂电力数据
*
* @param context 上下文
* @param input 输入
* @return {@link XServiceResult }
*/
@XText("导入电站实际发电数据")
@XApiUpload(anonymous = true)
@XApiUpload
public XServiceResult importPlantPowerData(XContext context, ImportFileInput input) {
List<String> headerList = getExcelHeaderList();
List<Map<String, Object>> mapList = ExcelUtils.readExcel(input.getFile().getInputStream(), input.getFile().getFileName(), headerList, 0);
try {
List<PlantPowerDataView> dataList = new ArrayList<>();
Date minDate = null;
Date maxDate = null;
for (Map<String, Object> objectMap : mapList) {
PlantPowerDataView dataView = BeanUtil.toBean(objectMap, PlantPowerDataView.class);
dataView.setPlantId(input.getPlantId());
if (ObjectUtil.isNotNull(dataView.getDataDate())) {
List<ExcelPlantPowerTemplate> list = EasyExcelUtil.getExcelDataAndCheck(input.getFile(), ExcelPlantPowerTemplate.class,
null, null);
if (CollUtil.isNotEmpty(list)) {
DateTime dateTime;
DateTime minDate = null;
DateTime maxDate = null;
List<PlantPowerDataView> dataList = new ArrayList<>(list.size());
for (ExcelPlantPowerTemplate template : list) {
if (ObjectUtil.isNotNull(template.getDataDate())) {
dateTime = DateUtil.date(template.getDataDate());
if (ObjectUtil.isNull(minDate)) {
minDate = dataView.getDataDate();
maxDate = dataView.getDataDate();
minDate = dateTime;
maxDate = dateTime;
}
if (minDate.compareTo(dataView.getDataDate()) > 0) {
minDate = dataView.getDataDate();
} else if (maxDate.compareTo(dataView.getDataDate()) < 0) {
maxDate = dataView.getDataDate();
}
dataList.add(dataView);
if (minDate.compareTo(dateTime) > 0) {
minDate = dateTime;
} else if (dateTime.compareTo(maxDate) > 0) {
maxDate = dateTime;
}
dataList.add(
PlantPowerDataView.builder()
.dataDate(dateTime)
.windSpeed(BusinessConstant.BIG_DECIMAL_6_67)
.windDirection(BigDecimal.ZERO)
.temperature(BusinessConstant.BIG_DECIMAL_4)
.pressure(BigDecimal.ONE)
.humidity(BusinessConstant.BIG_DECIMAL_3)
.planeIrradiance(BusinessConstant.BIG_DECIMAL_2)
.horizontalIrradiance(BusinessConstant.BIG_DECIMAL_4)
.power(BusinessConstant.BIG_DECIMAL_60)
.build()
);
}
if (ObjectUtil.isNull(minDate)) {
return XServiceResult.error(1000, "日期错误");
}
PlantPowerDataMapper mapper = context.getBean(PlantPowerDataMapper.class);
mapper.delete(new QueryWrapper<PlantPowerDataEnt>()
......@@ -124,8 +139,6 @@ public class PlantPowerDataService {
viewMapper.insertBatch(dataList);
//进行训练
doTrainData(context, input.getPlantId());
} catch (Exception e) {
return XServiceResult.error(-1, e.getMessage());
}
return XServiceResult.OK;
}
......@@ -144,11 +157,9 @@ public class PlantPowerDataService {
public void doTrainData(XContext context, String plantId) {
try {
Object ret = HttpUtils.send2("http://127.0.0.1:10098/aiprediction/xgbtrain?plantId=" + plantId,
"");
context.getLogger().info(ret.toString());
XHttpUtils.postAsJson("http://127.0.0.1:10098/aiprediction/xgbtrain?plantId=" + plantId, 10000);
} catch (Exception e) {
throw new RuntimeException("调用训练接口失败");
context.getLogger().error(e.getMessage());
}
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* excel预测算法训练
......@@ -29,7 +30,7 @@ public class ExcelPlantPowerTemplate implements Serializable {
* 日期
*/
@ExcelProperty(index = 0, value = "日期")
private String dataDate;
private Date dataDate;
/**
* 风速
......
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