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