Commit c5fa02d9 authored by ZWT's avatar ZWT

feat(吉林演示): 松原

1.开发间开优化结果统计功能,创建间开优化效果统计表,生成对应代码;
2.修改15天,10天,3天,1天间开优化功能,修改代码结构;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent 1df7399c
...@@ -5,6 +5,8 @@ import cn.hutool.core.date.DateTime; ...@@ -5,6 +5,8 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
...@@ -28,7 +30,7 @@ public class BusinessConstant { ...@@ -28,7 +30,7 @@ public class BusinessConstant {
/** /**
* 权重数组 * 权重数组
*/ */
public static final int[] LADDER = {10, 5, 3, 1}; public static final List<Integer> LADDER = Collections.unmodifiableList(Arrays.asList(10, 5, 3, 1));
/** /**
* 初始父级组织机构ID * 初始父级组织机构ID
......
...@@ -13,8 +13,8 @@ public enum BusinessError implements XError { ...@@ -13,8 +13,8 @@ public enum BusinessError implements XError {
UndiscoveredData(2205, "未发现数据,请检查后重新导入!"), UndiscoveredData(2205, "未发现数据,请检查后重新导入!"),
; ;
private int code; private final int code;
private String text; private final String text;
BusinessError(int code, String text) { BusinessError(int code, String text) {
this.code = code; this.code = code;
......
...@@ -53,8 +53,10 @@ public class CascadeWriteHandler implements SheetWriteHandler { ...@@ -53,8 +53,10 @@ public class CascadeWriteHandler implements SheetWriteHandler {
Cell proviCell = provinceRow.createCell(i + 1); Cell proviCell = provinceRow.createCell(i + 1);
proviCell.setCellValue(largeList.get(i)); proviCell.setCellValue(largeList.get(i));
} }
for (String key : this.siteMap.keySet()) { String key;
List<String> son = siteMap.get(key); for (Map.Entry<String, List<String>> entry : this.siteMap.entrySet()) {
key = entry.getKey();
List<String> son = entry.getValue();
Row row = hideSheet.createRow(rowId++); Row row = hideSheet.createRow(rowId++);
row.createCell(0).setCellValue(key); row.createCell(0).setCellValue(key);
for (int i = 0; i < son.size(); i++) { for (int i = 0; i < son.size(); i++) {
......
...@@ -47,7 +47,7 @@ public class VerificationCode { ...@@ -47,7 +47,7 @@ public class VerificationCode {
// 设置字体。 // 设置字体。
gd.setFont(font); gd.setFont(font);
// randomCode用于保存随机产生的验证码,以便用户登录后进行验证。 // randomCode用于保存随机产生的验证码,以便用户登录后进行验证。
StringBuffer randomCode = new StringBuffer(); StringBuffer randomCode = new StringBuffer(64);
int red, green, blue; int red, green, blue;
// 定义图片上显示验证码的个数 // 定义图片上显示验证码的个数
int codeCount = 4; int codeCount = 4;
......
...@@ -23,9 +23,9 @@ public enum OuLevelConstant implements DictEnum { ...@@ -23,9 +23,9 @@ public enum OuLevelConstant implements DictEnum {
DOWN_CLIENT(11, "上游客户", "DOWN_CLIENT"); DOWN_CLIENT(11, "上游客户", "DOWN_CLIENT");
@EnumValue @EnumValue
private Integer value; private final Integer value;
private String desc; private final String desc;
private String code; private final String code;
OuLevelConstant(Integer value, String desc, String code) { OuLevelConstant(Integer value, String desc, String code) {
this.value = value; this.value = value;
......
...@@ -6,11 +6,10 @@ import com.baomidou.mybatisplus.annotation.TableId; ...@@ -6,11 +6,10 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
@TableName("sys_user") @TableName("sys_user")
public class SysUserEnt implements Serializable { public class SysUserEnt {
@XText("主键") @XText("主键")
@TableId(type = IdType.ASSIGN_UUID) @TableId(type = IdType.ASSIGN_UUID)
private String id; private String id;
......
...@@ -4,11 +4,10 @@ import com.baomidou.mybatisplus.annotation.TableField; ...@@ -4,11 +4,10 @@ import com.baomidou.mybatisplus.annotation.TableField;
import xstartup.annotation.XText; import xstartup.annotation.XText;
import javax.persistence.Transient; import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class SysUserView implements Serializable { public class SysUserView {
@XText("主键") @XText("主键")
@TableField @TableField
private String id; private String id;
......
...@@ -30,8 +30,8 @@ public enum LoginError implements XError { ...@@ -30,8 +30,8 @@ public enum LoginError implements XError {
Account_Already_Exists(1010, "登录账户已存在"), Account_Already_Exists(1010, "登录账户已存在"),
; ;
private int code; private final int code;
private String text; private final String text;
LoginError(int code, String text) { LoginError(int code, String text) {
this.code = code; this.code = code;
......
...@@ -10,8 +10,8 @@ public enum MenuError implements XError { ...@@ -10,8 +10,8 @@ public enum MenuError implements XError {
NotDelete(1000, "有子集菜单无法删除父级菜单!"), NotDelete(1000, "有子集菜单无法删除父级菜单!"),
; ;
private int code; private final int code;
private String text; private final String text;
MenuError(int code, String text) { MenuError(int code, String text) {
this.code = code; this.code = code;
......
...@@ -65,9 +65,10 @@ public class PpsCoreSystemModule extends XModule { ...@@ -65,9 +65,10 @@ public class PpsCoreSystemModule extends XModule {
.gt(SysDictionaryEnt::getEndTime, DateUtil.date()) .gt(SysDictionaryEnt::getEndTime, DateUtil.date())
); );
//放入到缓存map中 //放入到缓存map中
for (String aliasObj : dictCashMap.keySet()) { String aliasObj;
List<SysDictionaryCache> sysDictionaryCaches = dictCashMap.get(aliasObj); for (Map.Entry<String, List<SysDictionaryCache>> entry : dictCashMap.entrySet()) {
Iterator<SysDictionaryCache> iterator = sysDictionaryCaches.iterator(); aliasObj = entry.getKey();
Iterator<SysDictionaryCache> iterator = entry.getValue().iterator();
if (iterator.hasNext()) { if (iterator.hasNext()) {
if (CollUtil.isNotEmpty(sysDictionaryChilds)) { if (CollUtil.isNotEmpty(sysDictionaryChilds)) {
SysDictionaryCache dict = iterator.next(); SysDictionaryCache dict = iterator.next();
...@@ -87,10 +88,8 @@ public class PpsCoreSystemModule extends XModule { ...@@ -87,10 +88,8 @@ public class PpsCoreSystemModule extends XModule {
size = dictIds.size(); size = dictIds.size();
} }
//放入到缓存redis //放入到缓存redis
for (String key : dictCashMap.keySet()) { for (Map.Entry<String, List<SysDictionaryCache>> entry : dictCashMap.entrySet()) {
List<SysDictionaryCache> sysDictionaryCaches = dictCashMap.get(key); SysDictionaryCache.set(context, entry.getKey(), entry.getValue());
SysDictionaryCache.deleteCache(context, key);
SysDictionaryCache.set(context, key, sysDictionaryCaches);
} }
XThreadHelper.async(() -> this.fixDicPath(context)); XThreadHelper.async(() -> this.fixDicPath(context));
} }
......
...@@ -23,8 +23,8 @@ public enum BusinessError implements XError { ...@@ -23,8 +23,8 @@ public enum BusinessError implements XError {
UndiscoveredData(2205, "未发现数据,请检查后重新导入!"), UndiscoveredData(2205, "未发现数据,请检查后重新导入!"),
; ;
private int code; private final int code;
private String text; private final String text;
BusinessError(int code, String text) { BusinessError(int code, String text) {
this.code = code; this.code = code;
......
...@@ -13,9 +13,9 @@ public enum ImportFieldDic { ...@@ -13,9 +13,9 @@ public enum ImportFieldDic {
power("power", "实际功率", 10), power("power", "实际功率", 10),
; ;
private String col; private final String col;
private String name; private final String name;
private Integer sort; private final Integer sort;
ImportFieldDic(String col, String name, Integer sort) { ImportFieldDic(String col, String name, Integer sort) {
this.col = col; this.col = col;
...@@ -36,23 +36,12 @@ public enum ImportFieldDic { ...@@ -36,23 +36,12 @@ public enum ImportFieldDic {
return col; return col;
} }
public void setCol(String col) {
this.col = col;
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) {
this.name = name;
}
public Integer getSort() { public Integer getSort() {
return sort; return sort;
} }
public void setSort(Integer sort) {
this.sort = sort;
}
} }
...@@ -49,9 +49,9 @@ public enum WeatherIconEnum { ...@@ -49,9 +49,9 @@ public enum WeatherIconEnum {
w99("-", 99), w99("-", 99),
; ;
private String icon; private final String icon;
private Integer type; private final Integer type;
WeatherIconEnum(String icon, Integer type) { WeatherIconEnum(String icon, Integer type) {
this.icon = icon; this.icon = icon;
...@@ -62,17 +62,11 @@ public enum WeatherIconEnum { ...@@ -62,17 +62,11 @@ public enum WeatherIconEnum {
return icon; return icon;
} }
public void setIcon(String icon) {
this.icon = icon;
}
public Integer getType() { public Integer getType() {
return type; return type;
} }
public void setType(Integer type) {
this.type = type;
}
/** /**
* 按值查找 * 按值查找
......
...@@ -16,8 +16,8 @@ public enum WindDirection implements DictEnum { ...@@ -16,8 +16,8 @@ public enum WindDirection implements DictEnum {
NO(360, "无持续风向"); NO(360, "无持续风向");
@EnumValue @EnumValue
private Integer value; private final Integer value;
private String desc; private final String desc;
WindDirection(Integer value, String desc) { WindDirection(Integer value, String desc) {
this.value = value; this.value = value;
......
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.read.listener.ReadListener;
import pps.core.base.entity.ThirdWindPowerGenerationView;
import pps.core.base.mapper.ThirdWindPowerGenerationViewMapper;
import pps.core.base.service.data.base_excel.WindPredictionExcel2Data;
import pps.core.common.utils.BaseUtils;
import xstartup.base.XContext;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* 风资源数据(测试用)
*
* @author ZWT
* @date 2024/08/30 15:46
*/
public class WindPredictionDataListener2 implements ReadListener<WindPredictionExcel2Data> {
private XContext context;
/**
* 缓存的数据
*/
private List<WindPredictionExcel2Data> cachedDataList = new ArrayList<>(4096);
public WindPredictionDataListener2(XContext context) {
this.context = context;
}
@Override
public void invoke(WindPredictionExcel2Data windPredictionExcelData, AnalysisContext analysisContext) {
cachedDataList.add(windPredictionExcelData);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
this.saveWindPredictionHistory(context, cachedDataList);
}
public void saveWindPredictionHistory(XContext context, List<WindPredictionExcel2Data> cachedDataList) {
if (CollUtil.isNotEmpty(cachedDataList)) {
List<ThirdWindPowerGenerationView> batchList = new ArrayList<>(cachedDataList.size());
String stationId = "f4816d9e4e134aaba0dbd483775e36b2";
String stationName = "吉林油田模拟电站";
DateTime date;
DateTime beginOfDay;
int minute;
Integer actualWindDirection;
for (WindPredictionExcel2Data data : cachedDataList) {
date = DateUtil.date(data.getDataTime());
beginOfDay = DateUtil.beginOfDay(date);
minute = date.minute();
//转换时间
switch (minute) {
case 10:
continue;
case 20:
date = DateUtil.offsetMinute(date, -5);
break;
case 40:
continue;
case 50:
date = DateUtil.offsetMinute(date, -5);
break;
}
//转换风向
BigDecimal accurateWindDirection = data.getAccurateWindDirection();
if (BigDecimal.valueOf(45).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 0;
} else if (BigDecimal.valueOf(90).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 45;
} else if (BigDecimal.valueOf(135).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 90;
} else if (BigDecimal.valueOf(180).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 135;
} else if (BigDecimal.valueOf(225).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 180;
} else if (BigDecimal.valueOf(270).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 225;
} else if (BigDecimal.valueOf(315).compareTo(accurateWindDirection) > 0) {
actualWindDirection = 270;
} else {
actualWindDirection = 315;
}
//封装
batchList.add(
ThirdWindPowerGenerationView.builder()
.stationName(stationName)
.stationId(stationId)
.collectTime(date)
.actualWindSpeed(data.getActualWindSpeed())
.actualPower(data.getActualPower())
.actualGeneration(BigDecimal.ZERO)
.accurateWindDirection(data.getAccurateWindDirection())
.actualWindDirection(actualWindDirection)
.inputTime(beginOfDay)
.systemSource("SY")
.build()
);
}
ThirdWindPowerGenerationViewMapper viewMapper = context.getBean(ThirdWindPowerGenerationViewMapper.class);
//批量新增
if (batchList.size() > BaseUtils.BATCH_SIZE) {
List<List<ThirdWindPowerGenerationView>> subList = BaseUtils.getSubList(batchList);
subList.forEach(viewMapper::batchInsert);
} else {
viewMapper.batchInsert(batchList);
}
}
}
}
...@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -10,7 +10,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import pps.core.base.entity.BaseDataEnt; import pps.core.base.entity.BaseDataEnt;
import pps.core.base.entity.BaseDataImportLogEnt; import pps.core.base.entity.BaseDataImportLogEnt;
import pps.core.base.entity.BaseModelValEnt; import pps.core.base.entity.BaseModelValEnt;
import pps.core.base.enums.ImportFieldDic;
import pps.core.base.mapper.BaseDataImportLogMapper; import pps.core.base.mapper.BaseDataImportLogMapper;
import pps.core.base.mapper.BaseDataMapper; import pps.core.base.mapper.BaseDataMapper;
import pps.core.base.mapper.BaseModelValMapper; import pps.core.base.mapper.BaseModelValMapper;
...@@ -34,7 +33,6 @@ import xstartup.feature.mybatis.helper.XMapperHelper; ...@@ -34,7 +33,6 @@ import xstartup.feature.mybatis.helper.XMapperHelper;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@XService @XService
public class BaseDataService { public class BaseDataService {
...@@ -189,83 +187,6 @@ public class BaseDataService { ...@@ -189,83 +187,6 @@ public class BaseDataService {
return XMapperHelper.query(mapper, input, BaseDataEnt.class, QueryBaseDataOutput.class); return XMapperHelper.query(mapper, input, BaseDataEnt.class, QueryBaseDataOutput.class);
} }
// @XText("下载导入模板")
// @XApiGet
// public XFileResult downloadImportTemplate(XContext context) {
// String fileSavePath = XStorageTool.getAbsolutePath("/temp/excel/导入模板_" + DateUtil.formatDate(new Date()) + ".xlsx");
// String templateFilePath = "template/import_template.xlsx";
// InputStream templateInputStream = this.getClass().getClassLoader().getResourceAsStream(templateFilePath);
// byte[] excelContent = ExportExcelUtils.genSingleExcelFileData(templateInputStream, null);
// try {
// ExportExcelUtils.outputFileData(excelContent, fileSavePath);
// } catch (Exception e) {
// context.getLogger().error(e);
// }
// return XFileResult.success(XFileType.APPLICATION_XLSX, fileSavePath);
// }
//
// @XText("新增导入")
// @XApiUpload
// public XServiceResult importFile(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<BaseDataView> dataList = new ArrayList<>(mapList.size());
// Date minDate = null;
// Date maxDate = null;
// for (Map<String, Object> objectMap : mapList) {
// BaseDataView dataView = BeanUtil.toBean(objectMap, BaseDataView.class);
// dataView.setOuId(input.getWellOuId());
// dataView.setLineId(input.getLineId());
// if (ObjectUtil.isNotNull(dataView.getDataDate())) {
// if (ObjectUtil.isNull(minDate)) {
// minDate = dataView.getDataDate();
// maxDate = dataView.getDataDate();
// }
// if (DateUtil.compare(minDate, dataView.getDataDate()) > 0) {
// minDate = dataView.getDataDate();
// } else if (DateUtil.compare(maxDate, dataView.getDataDate()) < 0) {
// maxDate = dataView.getDataDate();
// }
// }
// dataList.add(dataView);
// }
// if (ObjectUtil.isNull(minDate)) {
// return XServiceResult.error(1000, "日期错误");
// }
// BaseDataMapper mapper = context.getBean(BaseDataMapper.class);
// mapper.delete(new LambdaQueryWrapper<BaseDataEnt>()
// .eq(BaseDataEnt::getLineId, input.getLineId())
// .ge(BaseDataEnt::getDataDate, minDate)
// .le(BaseDataEnt::getDataDate, maxDate));
// BaseDataViewMapper viewMapper = context.getBean(BaseDataViewMapper.class);
// viewMapper.batchInsert(dataList);
// BaseDataImportLogMapper logMapper = context.getBean(BaseDataImportLogMapper.class);
// BaseDataImportLogEnt ent = new BaseDataImportLogEnt();
// ent.setOuId(input.getWellOuId());
// ent.setLineId(input.getLineId());
// ent.setBeginDate(minDate);
// ent.setEndDate(maxDate);
// ent.setCreateTime(new Date());
// logMapper.insert(ent);
// } catch (Exception e) {
// return XServiceResult.error(-1, e.getMessage());
// }
// return XServiceResult.OK;
// }
private List<String> getExcelHeaderList() {
List<Map<String, Object>> fieldList = new ArrayList<>();
for (ImportFieldDic value : ImportFieldDic.values()) {
Map<String, Object> map = new HashMap<>();
map.put("col", value.getCol());
map.put("sort", value.getSort());
fieldList.add(map);
}
fieldList.sort(Comparator.comparing(o -> ((Integer) o.get("sort"))));
return fieldList.stream().map(x -> ((String) x.get("col"))).collect(Collectors.toList());
}
@XText("获取预算") @XText("获取预算")
@XApiGet @XApiGet
public XServiceResult calcBaseData(XContext context, CalcBaseDataInput calcBaseDataInput) { public XServiceResult calcBaseData(XContext context, CalcBaseDataInput calcBaseDataInput) {
...@@ -336,11 +257,13 @@ public class BaseDataService { ...@@ -336,11 +257,13 @@ public class BaseDataService {
Map<String, Object> ytrueMap = XJsonUtils.toMap(output.getYtrue().replace("\\", "")); Map<String, Object> ytrueMap = XJsonUtils.toMap(output.getYtrue().replace("\\", ""));
Map<String, Object> yPreMap = XJsonUtils.toMap(output.getYpred().replace("\\", "")); Map<String, Object> yPreMap = XJsonUtils.toMap(output.getYpred().replace("\\", ""));
List<TrainBaseModelValDetailOutput> list = new ArrayList<>(); List<TrainBaseModelValDetailOutput> list = new ArrayList<>();
for (String key : ytrueMap.keySet()) { String key;
for (Map.Entry<String, Object> entry : ytrueMap.entrySet()) {
key = entry.getKey();
TrainBaseModelValDetailOutput detailOutput = new TrainBaseModelValDetailOutput(); TrainBaseModelValDetailOutput detailOutput = new TrainBaseModelValDetailOutput();
Date date = new Date(Long.parseLong(key)); Date date = new Date(Long.parseLong(key));
detailOutput.setKey(DateUtil.formatDateTime(date)); detailOutput.setKey(DateUtil.formatDateTime(date));
detailOutput.setPower(ytrueMap.get(key).toString()); detailOutput.setPower(entry.getValue().toString());
if (yPreMap.containsKey(key)) { if (yPreMap.containsKey(key)) {
detailOutput.setPredictedPower(yPreMap.get(key).toString()); detailOutput.setPredictedPower(yPreMap.get(key).toString());
} }
......
package pps.core.base.service; package pps.core.base.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel;
import pps.core.base.excel.ThirdApiWeatherDataListener;
import pps.core.base.excel.ThirdApiWeatherDataListener2;
import pps.core.base.excel.WindPredictionDataListener;
import pps.core.base.excel.WindPredictionDataListener2;
import pps.core.base.service.data.base_data.GetBaseDataInput;
import pps.core.base.service.data.base_excel.WindPredictionExcel2Data;
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 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.XStartup;
import xstartup.data.XListResult; import xstartup.data.XListResult;
import xstartup.data.XServiceResult;
import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost; import xstartup.feature.api.annotation.XApiPost;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@XService @XService
public class BaseLineService { public class BaseLineService {
...@@ -36,89 +17,4 @@ public class BaseLineService { ...@@ -36,89 +17,4 @@ public class BaseLineService {
BasePowerLineService bean = context.getBean(BasePowerLineService.class); BasePowerLineService bean = context.getBean(BasePowerLineService.class);
return bean.queryBasePowerLineList(context, input); return bean.queryBasePowerLineList(context, input);
} }
@XText("天气")
@XApiGet
public XServiceResult test(XContext context, GetBaseDataInput input) {
// BaseWeatherCloudServiceImpl bean = context.getBean(BaseWeatherCloudServiceImpl.class);
// bean.weatherDataProcess(context, input.getKeyName());
// WindPredictionHistoryCloudServiceImpl bean = context.getBean(WindPredictionHistoryCloudServiceImpl.class);
// bean.windPredictionHistoryJob(context);
// ThirdWindPowerGenerationCloudServiceImpl bean = context.getBean(ThirdWindPowerGenerationCloudServiceImpl.class);
// bean.thirdWindPowerGenerationJob(context);
// IWeatherAttachmentCloudService service = context.getBean(IWeatherAttachmentCloudService.class);
// XSingleResult<GetWeatherAttachmentRecordOutput> result = service.getEmail(context, GetWeatherAttachmentRecordInput.builder()
// .build());
// result.throwIfFail();
// GetWeatherAttachmentRecordOutput output = result.getResult();
// if (ObjectUtil.isNotNull(output) && CharSequenceUtil.isAllNotBlank(output.getEmailName(), output.getEmailAttachmentUrl())) {
// String filePath = this.createFilePath(output.getEmailName());
// HttpUtil.downloadFile(output.getEmailAttachmentUrl(), filePath);
// context.getLogger().info(FileUtil.readUtf8String(filePath));
// }
return XServiceResult.OK;
}
private static final String storeDir = XStartup.getCurrent().getProperty("weather.file.temp.path");
/**
* 创建文件路径
*
* @param fileName 文件名
* @return {@link String }
*/
private String createFilePath(String fileName) {
StringBuilder stringBuilder = new StringBuilder(storeDir)
.append(File.separator)
.append(DateTime.now().toString("yyyyMMdd"));
return stringBuilder.append(File.separator).append(fileName).toString();
}
@XText("风资源历史数据配置导入")
@XApiGet
public XServiceResult importWindPrediction(XContext context) {
String fileName = "D:\\工作\\尚博信\\数据智能事业部\\零碳\\演示\\吉林\\新需求\\20240828\\data\\";
Map<String, String> map = new HashMap<>();
map.put("11.csv", "0191993ac6707650bc41b04b04ce9b62");
map.put("12.csv", "0191993ac6707650bc41b04b04ce9b63");
map.put("13.csv", "0191993ac6707650bc41b04b04ce9b64");
map.put("14.csv", "0191993ac6707650bc41b04b04ce9b65");
map.put("15.csv", "0191993ac6707650bc41b04b04ce9b66");
map.put("16.csv", "11d04d59195746f48e14e149969940e5");
map.put("17.csv", "133dae9b74034bab8c0f96a2878c41aa");
map.put("18.csv", "8aa54645c3e34977ba3d121325881843");
map.put("20.csv", "c0e6e7a0163f4e75a6e5e05627c0731a");
map.forEach((key, value) -> {
EasyExcel.read(fileName + key, WindPredictionExcelData.class, new WindPredictionDataListener(context, value)).sheet().doRead();
});
return XServiceResult.OK;
}
@XText("实际风资源数据")
@XApiGet
public XServiceResult importWindPrediction2(XContext context) {
String fileName = "D:\\工作\\尚博信\\数据智能事业部\\零碳\\演示\\吉林\\新需求\\20240919\\导入实际数据.xlsx";
EasyExcel.read(fileName, WindPredictionExcel2Data.class, new WindPredictionDataListener2(context)).sheet().doRead();
return XServiceResult.OK;
}
@XText("风资源历史数据配置导入2")
@XApiGet(anonymous = true)
public XServiceResult importWindPrediction3(XContext context) {
String fileName = "D:\\工作\\尚博信\\数据智能事业部\\零碳\\演示\\吉林\\新需求\\20240919\\result 3\\result 3";
List<File> files = FileUtil.loopFiles(fileName);
for (File file : files) {
EasyExcel.read(file, ThirdApiWeatherExcelData.class, new ThirdApiWeatherDataListener2(context)).sheet().doRead();
}
return XServiceResult.OK;
}
@XText("天气历史数据导入")
@XApiGet
public XServiceResult importHistory(XContext context) {
String fileName = "D:\\home\\result_w.csv";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(fileName, ThirdApiWeatherExcelData.class, new ThirdApiWeatherDataListener(context)).sheet().doRead();
return XServiceResult.OK;
}
} }
\ No newline at end of file
...@@ -54,6 +54,7 @@ import java.math.RoundingMode; ...@@ -54,6 +54,7 @@ import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -394,9 +395,9 @@ public class BasePhotovoltaicPlantService { ...@@ -394,9 +395,9 @@ public class BasePhotovoltaicPlantService {
if (CollUtil.isEmpty(roleDicList)) { if (CollUtil.isEmpty(roleDicList)) {
return result; return result;
} }
List<String> roleIds = roleDicList.stream() Set<String> roleIds = roleDicList.stream()
.map(QuerySysDictionaryViewOutput::getDicKey) .map(QuerySysDictionaryViewOutput::getDicKey)
.collect(Collectors.toList()); .collect(Collectors.toSet());
//获取当前用户角色 //获取当前用户角色
SystemUserRoleRelService roleRelService = context.getBean(SystemUserRoleRelService.class); SystemUserRoleRelService roleRelService = context.getBean(SystemUserRoleRelService.class);
GetSysUserRoleRelInput getSysUserRoleRelInput = new GetSysUserRoleRelInput(); GetSysUserRoleRelInput getSysUserRoleRelInput = new GetSysUserRoleRelInput();
......
...@@ -85,8 +85,8 @@ public class ExcelService { ...@@ -85,8 +85,8 @@ public class ExcelService {
String province; String province;
String city; String city;
for (QueryBasePhotovoltaicPlantOutput item : items) { for (QueryBasePhotovoltaicPlantOutput item : items) {
QuerySysAreaOutput area = collect.get(item.getAreaCode());
if (collect.containsKey(item.getAreaCode())) { if (collect.containsKey(item.getAreaCode())) {
QuerySysAreaOutput area = collect.get(item.getAreaCode());
province = area.getProvince(); province = area.getProvince();
city = area.getCity(); city = area.getCity();
} else { } else {
...@@ -119,9 +119,11 @@ public class ExcelService { ...@@ -119,9 +119,11 @@ public class ExcelService {
//整理数据,放入一个Map中,key存放父地点,value 存放该地点下的子区域 //整理数据,放入一个Map中,key存放父地点,value 存放该地点下的子区域
Map<String, List<String>> siteMap = new HashMap<>(collect.size()); Map<String, List<String>> siteMap = new HashMap<>(collect.size());
List<String> provNameList = new ArrayList<>(); List<String> provNameList = new ArrayList<>();
for (String province : collect.keySet()) { String province;
for (Map.Entry<String, List<QuerySysAreaOutput>> entry : collect.entrySet()) {
province = entry.getKey();
provNameList.add(province); provNameList.add(province);
siteMap.put(province, collect.get(province).stream() siteMap.put(province, entry.getValue().stream()
.map(QuerySysAreaOutput::getCity) .map(QuerySysAreaOutput::getCity)
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
...@@ -623,9 +625,8 @@ public class ExcelService { ...@@ -623,9 +625,8 @@ public class ExcelService {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
Map<String, List<ExcelPriceStrategyTemplate>> collect = list.stream() Map<String, List<ExcelPriceStrategyTemplate>> collect = list.stream()
.collect(Collectors.groupingBy(ExcelPriceStrategyTemplate::getMonth)); .collect(Collectors.groupingBy(ExcelPriceStrategyTemplate::getMonth));
Set<String> monthSet = collect.keySet(); for (Map.Entry<String, List<ExcelPriceStrategyTemplate>> entry : collect.entrySet()) {
for (String month : monthSet) { List<ExcelPriceStrategyTemplate> templates = entry.getValue();
List<ExcelPriceStrategyTemplate> templates = collect.get(month);
if (templates.size() > 1) { if (templates.size() > 1) {
ExcelPriceStrategyTemplate start = templates.get(0); ExcelPriceStrategyTemplate start = templates.get(0);
DateTime firstEnd = start.getEnd(); DateTime firstEnd = start.getEnd();
...@@ -654,11 +655,11 @@ public class ExcelService { ...@@ -654,11 +655,11 @@ public class ExcelService {
PpsUserSession session = context.getSession(PpsUserSession.class); PpsUserSession session = context.getSession(PpsUserSession.class);
Map<String, String> dictMap = ServiceUtil.getDictionaryList(context, BusinessConstant.TIME_FRAME).stream() Map<String, String> dictMap = ServiceUtil.getDictionaryList(context, BusinessConstant.TIME_FRAME).stream()
.collect(Collectors.toMap(GetSysDictionaryViewOutput::getDicName, GetSysDictionaryViewOutput::getDicKey)); .collect(Collectors.toMap(GetSysDictionaryViewOutput::getDicName, GetSysDictionaryViewOutput::getDicKey));
List<BasePriceStrategyMonthView> monthViewList = new ArrayList<>(monthSet.size()); List<BasePriceStrategyMonthView> monthViewList = new ArrayList<>(collect.size());
for (String month : monthSet) { for (Map.Entry<String, List<ExcelPriceStrategyTemplate>> entry : collect.entrySet()) {
BasePriceStrategyMonthView view = BasePriceStrategyMonthView.builder() BasePriceStrategyMonthView view = BasePriceStrategyMonthView.builder()
.strategyId(strategyId) .strategyId(strategyId)
.strategyMonth(month) .strategyMonth(entry.getKey())
.build(); .build();
BaseUtils.createBaseModelDefault(view, session); BaseUtils.createBaseModelDefault(view, session);
monthViewList.add(view); monthViewList.add(view);
...@@ -687,16 +688,17 @@ public class ExcelService { ...@@ -687,16 +688,17 @@ public class ExcelService {
} }
//先按月份删除再新增 //先按月份删除再新增
return XTransactionHelper.begin(context, () -> { return XTransactionHelper.begin(context, () -> {
Set<String> strings = collect.keySet();
//删除 //删除
BasePriceStrategyMonthMapper monthEntMapper = context.getBean(BasePriceStrategyMonthMapper.class); BasePriceStrategyMonthMapper monthEntMapper = context.getBean(BasePriceStrategyMonthMapper.class);
monthEntMapper.delete(new LambdaQueryWrapper<BasePriceStrategyMonthEnt>() monthEntMapper.delete(new LambdaQueryWrapper<BasePriceStrategyMonthEnt>()
.eq(BasePriceStrategyMonthEnt::getStrategyId, strategyId) .eq(BasePriceStrategyMonthEnt::getStrategyId, strategyId)
.in(BasePriceStrategyMonthEnt::getStrategyMonth, monthSet) .in(BasePriceStrategyMonthEnt::getStrategyMonth, strings)
); );
BasePriceStrategyDetailMapper detailEntMapper = context.getBean(BasePriceStrategyDetailMapper.class); BasePriceStrategyDetailMapper detailEntMapper = context.getBean(BasePriceStrategyDetailMapper.class);
detailEntMapper.delete(new LambdaQueryWrapper<BasePriceStrategyDetailEnt>() detailEntMapper.delete(new LambdaQueryWrapper<BasePriceStrategyDetailEnt>()
.eq(BasePriceStrategyDetailEnt::getStrategyId, strategyId) .eq(BasePriceStrategyDetailEnt::getStrategyId, strategyId)
.in(BasePriceStrategyDetailEnt::getStrategyMonth, monthSet) .in(BasePriceStrategyDetailEnt::getStrategyMonth, strings)
); );
//新增 //新增
BasePriceStrategyMonthViewMapper monthMapper = context.getBean(BasePriceStrategyMonthViewMapper.class); BasePriceStrategyMonthViewMapper monthMapper = context.getBean(BasePriceStrategyMonthViewMapper.class);
......
...@@ -410,6 +410,7 @@ public class WindPredictionFutureService { ...@@ -410,6 +410,7 @@ public class WindPredictionFutureService {
case 315: case 315:
output.setNorthwest(future.getActualWindSpeed()); output.setNorthwest(future.getActualWindSpeed());
break; break;
default:
} }
} }
//计算率 //计算率
......
package pps.core.base.service.data.base_excel;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 风资源数据(测试用)
*
* @author ZWT
* @date 2024/08/30 15:33
*/
@Data
@ExcelIgnoreUnannotated
public class WindPredictionExcel2Data {
@ExcelProperty(value = "时间")
private Date dataTime;
@ExcelProperty(value = "实际风速")
private BigDecimal actualWindSpeed;
@ExcelProperty(value = "实际功率")
private BigDecimal actualPower;
@ExcelProperty(value = "实际风向")
private BigDecimal accurateWindDirection;
}
package pps.core.base.service.data.base_excel;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import xstartup.annotation.XText;
import java.math.BigDecimal;
import java.util.Date;
/**
* 风资源数据(测试用)
*
* @author ZWT
* @date 2024/08/30 15:33
*/
@Data
@ExcelIgnoreUnannotated
public class WindPredictionExcelData3 {
@XText("记录时间")
@ExcelProperty(value = "DATATIME")
private Date dataTime;
@XText("风向")
@ExcelProperty(value = "WINDDIRECTION")
private Integer windDirection;
@XText("预报风速(m/s)")
@ExcelProperty(value = "WINDSPEED")
private BigDecimal windSpeed;
@XText("气温(℃)")
@ExcelProperty(value = "TEMPERATURE")
private BigDecimal airTemperature;
@XText("湿度(%)")
@ExcelProperty(value = "HUMIDITY")
private BigDecimal humidity;
@XText("气压(hPa)")
@ExcelProperty(value = "PRESSURE")
private BigDecimal pressure;
@XText("实际风速(m/s)")
@ExcelProperty(value = "ROUND(A.WS,1)")
private BigDecimal actualWindSpeed;
@XText("实际功率(kw)")
@ExcelProperty(value = "ROUND(A.POWER,0)")
private BigDecimal actualPower;
@XText("预测功率(kw)")
@ExcelProperty(value = "PREPOWER")
private BigDecimal predictedPower;
}
package pps.core.base.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ArrayUtil;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 收到imapmail
*
* @author ZWT
* @date 2024/03/21
*/
public class ReceivedIMAPMail {
private MimeMessage mimeMessage;
/**
* 存放邮件内容的StringBuffer对象
*/
private StringBuffer bodyText = new StringBuffer();
/**
* 构造函数,初始化一个MimeMessage对象
*
* @param mimeMessage
*/
public ReceivedIMAPMail(MimeMessage mimeMessage) {
this.mimeMessage = mimeMessage;
}
/**
* 过滤邮箱信息
*
* @param messages
* @param fromMail 只读取该邮箱发来的邮件,如果为空则不过滤
* @param startDate 只读取该日期以后的邮件,如果为空则不过滤
* @return
* @throws MessagingException
*/
public static List<Message> filterMessage(Message[] messages, String fromMail, String startDate)
throws MessagingException, ParseException {
List<Message> messageList = new ArrayList<>();
if (ArrayUtil.isEmpty(messages)) {
return messageList;
}
boolean isEnptyFromMail = CharSequenceUtil.isBlank(fromMail);
boolean isEnptyStartDate = CharSequenceUtil.isBlank(startDate);
if (isEnptyFromMail && isEnptyStartDate) {
return Arrays.asList(messages);
}
String from;
for (Message message : messages) {
from = (message.getFrom()[0]).toString();
if (isEnptyFromMail) {
if (DateUtil.parseDateTime(startDate).compareTo(message.getSentDate()) > 0) {
continue;
}
} else if (CharSequenceUtil.isNotBlank(from) && CharSequenceUtil.contains(from, fromMail)) {
if (!isEnptyStartDate && DateUtil.parseDateTime(startDate).compareTo(message.getSentDate()) > 0) {
continue;
}
} else {
continue;
}
messageList.add(message);
}
return messageList;
}
/**
* 获得发件人的地址和姓名
*
* @return
* @throws MessagingException
*/
public String getFrom() throws MessagingException {
InternetAddress address[] = (InternetAddress[]) mimeMessage.getFrom();
String from = CharSequenceUtil.blankToDefault(address[0].getAddress(), "");
String personal = CharSequenceUtil.blankToDefault(address[0].getPersonal(), "");
return personal + "<" + from + ">";
}
/**
* 获得邮件主题
*
* @return
* @throws MessagingException
* @throws UnsupportedEncodingException
*/
public String getSubject() throws MessagingException, UnsupportedEncodingException {
return CharSequenceUtil.blankToDefault(MimeUtility.decodeText(mimeMessage.getSubject()), "");
}
/**
* 解析邮件,把得到的邮件内容保存到一个StringBuffer对象中,解析邮件 主要是根据MimeType类型的不同执行不同的操作,一步一步的解析
*
* @param part
* @throws MessagingException
* @throws IOException
*/
public void getMailContent(Part part) throws MessagingException, IOException {
String contentType = part.getContentType();
int nameIndex = contentType.indexOf("name");
boolean conName = false;
if (nameIndex != -1) {
conName = true;
}
if (part.isMimeType("text/plain") && !conName) {
bodyText.append((String) part.getContent());
} else if (part.isMimeType("text/html") && !conName) {
bodyText.append((String) part.getContent());
} else if (part.isMimeType("multipart/*")) {
Multipart multipart = (Multipart) part.getContent();
int counts = multipart.getCount();
for (int i = 0; i < counts; i++) {
this.getMailContent(multipart.getBodyPart(i));
}
} else if (part.isMimeType("message/rfc822")) {
this.getMailContent((Part) part.getContent());
}
}
/**
* 判断此邮件是否已读,如果未读返回false,反之返回true
*
* @return
* @throws MessagingException
*/
public boolean isNew() throws MessagingException {
boolean isNew = false;
Flags flags = mimeMessage.getFlags();
Flags.Flag[] flag = flags.getSystemFlags();
for (Flags.Flag value : flag) {
if (value == Flags.Flag.SEEN) {
isNew = true;
break;
}
}
return isNew;
}
}
\ No newline at end of file
...@@ -23,8 +23,8 @@ public enum BusinessError implements XError { ...@@ -23,8 +23,8 @@ public enum BusinessError implements XError {
UndiscoveredData(2111, "未发现数据"), UndiscoveredData(2111, "未发现数据"),
; ;
private int code; private final int code;
private String text; private final String text;
BusinessError(int code, String text) { BusinessError(int code, String text) {
this.code = code; this.code = code;
......
...@@ -117,11 +117,13 @@ public class DailyElectricityTrendCloudServiceImpl implements IDailyElectricityT ...@@ -117,11 +117,13 @@ public class DailyElectricityTrendCloudServiceImpl implements IDailyElectricityT
BigDecimal valleyElectricOpenHour; BigDecimal valleyElectricOpenHour;
List<GetBasePriceStrategyDetailOutput> strategyList; List<GetBasePriceStrategyDetailOutput> strategyList;
//遍历全量电站 //遍历全量电站
for (String stationName : powerMap.keySet()) { String stationName;
for (Map.Entry<String, List<GetThirdActivePowerOutput>> entry : powerMap.entrySet()) {
stationName = entry.getKey();
//取存在的间开 //取存在的间开
if (lineMap.containsKey(stationName)) { if (lineMap.containsKey(stationName)) {
//每15分钟有功功率 //每15分钟有功功率
thirdActivePowerList = powerMap.get(stationName); thirdActivePowerList = entry.getValue();
//按照启动顺序分组 //按照启动顺序分组
startSeqMap = lineMap.get(stationName).stream() startSeqMap = lineMap.get(stationName).stream()
.collect(Collectors.groupingBy(SpaceOptimizeShortDurationView::getStartSeq)); .collect(Collectors.groupingBy(SpaceOptimizeShortDurationView::getStartSeq));
......
...@@ -3020,13 +3020,13 @@ public class SpaceOptimizeBaseService { ...@@ -3020,13 +3020,13 @@ public class SpaceOptimizeBaseService {
//分级取时间段 //分级取时间段
List<SpaceOptimizeWeightDuration> weightDurationList = new ArrayList<>(32); List<SpaceOptimizeWeightDuration> weightDurationList = new ArrayList<>(32);
long between; long between;
for (int i1 = 0; i1 < BusinessConstant.LADDER.length; i1++) { for (int i1 = 0; i1 < BusinessConstant.LADDER.size(); i1++) {
int begin = -1; int begin = -1;
//取每级时间 //取每级时间
for (int i2 = 0; i2 < weightList.size(); i2++) { for (int i2 = 0; i2 < weightList.size(); i2++) {
weight = weightList.get(i2); weight = weightList.get(i2);
//过滤条件:权重相同 //过滤条件:权重相同
if (BusinessConstant.LADDER[i1] == weight.getWeight()) { if (BusinessConstant.LADDER.get(i1) == weight.getWeight()) {
//确定开始时间位置 //确定开始时间位置
if (begin == -1) { if (begin == -1) {
begin = i2; begin = i2;
...@@ -3042,7 +3042,7 @@ public class SpaceOptimizeBaseService { ...@@ -3042,7 +3042,7 @@ public class SpaceOptimizeBaseService {
.openIndex(begin) .openIndex(begin)
.closeIndex(i2) .closeIndex(i2)
.duration(between) .duration(between)
.weight(BusinessConstant.LADDER[i1]) .weight(BusinessConstant.LADDER.get(i1))
.build() .build()
); );
begin = -1; begin = -1;
......
...@@ -16,8 +16,8 @@ public enum BusinessError implements XError { ...@@ -16,8 +16,8 @@ public enum BusinessError implements XError {
MissingoilExtractionPlantID(2203, "缺少采油厂ID"), MissingoilExtractionPlantID(2203, "缺少采油厂ID"),
; ;
private int code; private final int code;
private String text; private final String text;
BusinessError(int code, String text) { BusinessError(int code, String text) {
this.code = code; this.code = code;
......
package pps.core.prediction.enums;
public enum ImportFieldDic {
dataDate("dataDate", "日期", 1),
windSpeed("windSpeed", "风速", 2),
windDirection("windDirection", "风向", 3),
temperature("temperature", "温度", 4),
pressure("pressure", "压强", 5),
humidity("humidity", "湿度", 6),
planeIrradiance("planeIrradiance", "组件平面辐照度", 7),
horizontalIrradiance("horizontalIrradiance", "全水平辐照度", 8),
power("power", "实际功率", 9),
;
private String col;
private String name;
private Integer sort;
ImportFieldDic(String col, String name, Integer sort) {
this.col = col;
this.name = name;
this.sort = sort;
}
public static ImportFieldDic findByValue(String col) {
for (ImportFieldDic item : values()) {
if (item.getCol().equals(col)) {
return item;
}
}
return null;
}
public String getCol() {
return col;
}
public void setCol(String col) {
this.col = col;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
}
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