Commit fb982d8b authored by ZWT's avatar ZWT

feat(能源管理系统): 邮件接收

1.添加天气数据邮件方式接收定时任务;
2.修改配置文件,增加新建定时任务,同时增加自定义参数;
3.创建天气邮件数据接收处理实现类,同时验证获取自定义参数方法;
4.添加收件工具类,验证是否能正常接收邮件;
5.天气邮件数据接收定时任务增加获取未读天气数据逻辑,增加附件文件临时存储方法并验证是否能正常读取文件数据同时转换为json数据;
6.增加查询运行中电站列表方法;

BREAKING CHANGE: 无

Closes 无

[skip ci]
parent 21684802
...@@ -114,119 +114,53 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService { ...@@ -114,119 +114,53 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
.collect(Collectors.groupingBy(BasePhotovoltaicPlantView::getCityCode)); .collect(Collectors.groupingBy(BasePhotovoltaicPlantView::getCityCode));
PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class); PlantPredictedPowerDataMapper mapper = context.getBean(PlantPredictedPowerDataMapper.class);
List<String> timeList = Arrays.asList("15:00", "30:00", "45:00"); List<String> timeList = Arrays.asList("15:00", "30:00", "45:00");
//读取附件
// for (Message message : messageList) {
// String tempFilePath = this.saveAttachment(message);
// FileReader fileReader = new FileReader(tempFilePath);
// String jsonString = fileReader.readString();
// JSONObject jsonObject = JSONObject.parseObject(jsonString);
// Map<String, List<DailyData>> cityDataMap = new HashMap<>(16);
// for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
// String key = entry.getKey();
// Object value = entry.getValue();
// if (value instanceof JSONArray) {
// cityDataMap.put(key, ((JSONArray) value).toJavaList(DailyData.class));
// }
// }
//
//
// FileUtil.del(tempFilePath);
// }
List<PlantPredictedPowerDataEnt> batchList = new ArrayList<>(); List<PlantPredictedPowerDataEnt> batchList = new ArrayList<>();
FileReader fileReader = new FileReader("D:\\home\\weather\\temp\\receive\\20231114\\1699943400000.json"); //读取附件
String jsonString = fileReader.readString(); for (Message message : messageList) {
JSONObject jsonObject = JSON.parseObject(jsonString); String tempFilePath = this.saveAttachment(message);
Map<String, List<DailyData>> cityDataMap = new HashMap<>(16); FileReader fileReader = new FileReader(tempFilePath);
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) { String jsonString = fileReader.readString();
String key = entry.getKey(); JSONObject jsonObject = JSON.parseObject(jsonString);
Object value = entry.getValue(); Map<String, List<DailyData>> cityDataMap = new HashMap<>(16);
if (value instanceof JSONArray) { for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
cityDataMap.put(key, ((JSONArray) value).toJavaList(DailyData.class)); String key = entry.getKey();
} Object value = entry.getValue();
} if (value instanceof JSONArray) {
for (String cityCode : cityDataMap.keySet()) { cityDataMap.put(key, ((JSONArray) value).toJavaList(DailyData.class));
if (!plantMap.containsKey(cityCode)) { }
continue;
} }
List<DailyData> dailyDataList = cityDataMap.get(cityCode); for (String cityCode : cityDataMap.keySet()) {
List<BasePhotovoltaicPlantView> plantViewList = plantMap.get(cityCode); if (!plantMap.containsKey(cityCode)) {
//遍历预测数据列表 continue;
for (DailyData dailyData : dailyDataList) { }
for (BasePhotovoltaicPlantView plant : plantViewList) { List<DailyData> dailyDataList = cityDataMap.get(cityCode);
List<PlantPredictedPowerDataEnt> allList = new ArrayList<>(); List<BasePhotovoltaicPlantView> plantViewList = plantMap.get(cityCode);
List<PlantPredictedPowerDataEnt> objList = new ArrayList<>(); //遍历预测数据列表
DateTime dateTime = DateTime.of(dailyData.getDateTime()); for (DailyData dailyData : dailyDataList) {
int hours = 0; for (BasePhotovoltaicPlantView plant : plantViewList) {
String plantId = plant.getId(); List<PlantPredictedPowerDataEnt> allList = new ArrayList<>();
DateTime date; List<PlantPredictedPowerDataEnt> objList = new ArrayList<>();
for (int i = 0; i < 8; i++) { DateTime dateTime = DateTime.of(dailyData.getDateTime());
//判断小时数与查到的小时数,如果查到的小时数小,判断为第二天 int hours = 0;
int hour = LocalTime.parse(dailyData.getHourTimeArray().get(i)).getHour(); String plantId = plant.getId();
if (hours >= hour) { DateTime date;
dateTime = DateUtil.offsetDay(dateTime, 1); for (int i = 0; i < 8; i++) {
} //判断小时数与查到的小时数,如果查到的小时数小,判断为第二天
hours = hour; int hour = LocalTime.parse(dailyData.getHourTimeArray().get(i)).getHour();
PlantPredictedPowerDataEnt dao = this.getPlantPredictedPowerEnt(plantId, if (hours >= hour) {
this.int2Str(hours), dateTime = DateUtil.offsetDay(dateTime, 1);
new BigDecimal(CharSequenceUtil.replace(dailyData.getTemperatureArray().get(i), "℃", "")),
new BigDecimal(CharSequenceUtil.replace(dailyData.getWindSpeedArray().get(i), "m/s", "")),
new BigDecimal(Objects.requireNonNull(WindDirection.findByValue(dailyData.getWindDirectionArray().get(i))).getValue()),
new BigDecimal(CharSequenceUtil.replace(dailyData.getPressureArray().get(i), "hPa", "")),
new BigDecimal(CharSequenceUtil.replace(dailyData.getHumidityArray().get(i), "%", "")),
String.valueOf(dateTime.year()),
this.int2Str(dateTime.month() + 1),
this.int2Str(dateTime.dayOfMonth())
);
// 5.执行SQL
mapper.delete(new LambdaQueryWrapper<PlantPredictedPowerDataEnt>()
.eq(PlantPredictedPowerDataEnt::getPlantId, plantId)
.eq(PlantPredictedPowerDataEnt::getYearTime, dao.getYearTime())
.eq(PlantPredictedPowerDataEnt::getMonthTime, dao.getMonthTime())
.eq(PlantPredictedPowerDataEnt::getDayTime, dao.getDayTime())
.eq(PlantPredictedPowerDataEnt::getHourTime, dao.getHourTime())
);
allList.add(dao);
PlantPredictedPowerDataEnt isExit = objList.stream().filter(item ->
CharSequenceUtil.equals(item.getYearTime(), dao.getYearTime()) &&
CharSequenceUtil.equals(item.getMonthTime(), dao.getMonthTime()) &&
CharSequenceUtil.equals(item.getDayTime(), dao.getDayTime()) &&
CharSequenceUtil.equals(item.getHourTime(), dao.getHourTime()))
.findFirst()
.orElse(null);
if (Objects.isNull(isExit)) {
objList.add(dao);
}
}
// 原站点时间结构为:08:00 11:00 14:00 17:00 20:00 23:00 02:00 05:00
// 两条数据中间差了两个小时,使用上下两条数据推算出中间差掉的两个小时
for (int i = 0; i < objList.size() - 1; i++) {
for (int y = 1; y < 3; y++) {
PlantPredictedPowerDataEnt dataEnt = objList.get(i);
date = DateUtil.parseDate(dataEnt.getDataDate());
String hourString;
Integer hourTime = Integer.valueOf(dataEnt.getHourTime());
if (hourTime.equals(23)) {
date = DateUtil.offsetDay(date, 1);
hourString = "0" + (y - 1);
} else {
if ((hourTime + y) < 10) {
hourString = "0" + (hourTime + y);
} else {
hourString = String.valueOf(hourTime + y);
}
} }
PlantPredictedPowerDataEnt nextData = objList.get(i + 1); hours = hour;
BigDecimal valueOf = BigDecimal.valueOf(0.3 * y);
PlantPredictedPowerDataEnt dao = this.getPlantPredictedPowerEnt(plantId, PlantPredictedPowerDataEnt dao = this.getPlantPredictedPowerEnt(plantId,
hourString, this.int2Str(hours),
this.compute(dataEnt.getTemperature(), nextData.getTemperature(), valueOf), new BigDecimal(CharSequenceUtil.replace(dailyData.getTemperatureArray().get(i), "℃", "")),
this.compute(dataEnt.getWindSpeed(), nextData.getWindSpeed(), valueOf), new BigDecimal(CharSequenceUtil.replace(dailyData.getWindSpeedArray().get(i), "m/s", "")),
dataEnt.getWindDirection(), new BigDecimal(Objects.requireNonNull(WindDirection.findByValue(dailyData.getWindDirectionArray().get(i))).getValue()),
this.compute(dataEnt.getPressure(), nextData.getPressure(), valueOf), new BigDecimal(CharSequenceUtil.replace(dailyData.getPressureArray().get(i), "hPa", "")),
this.compute(dataEnt.getHumidity(), nextData.getHumidity(), valueOf), new BigDecimal(CharSequenceUtil.replace(dailyData.getHumidityArray().get(i), "%", "")),
String.valueOf(date.year()), String.valueOf(dateTime.year()),
this.int2Str(date.month() + 1), this.int2Str(dateTime.month() + 1),
this.int2Str(date.dayOfMonth()) this.int2Str(dateTime.dayOfMonth())
); );
// 5.执行SQL // 5.执行SQL
mapper.delete(new LambdaQueryWrapper<PlantPredictedPowerDataEnt>() mapper.delete(new LambdaQueryWrapper<PlantPredictedPowerDataEnt>()
...@@ -237,49 +171,102 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService { ...@@ -237,49 +171,102 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
.eq(PlantPredictedPowerDataEnt::getHourTime, dao.getHourTime()) .eq(PlantPredictedPowerDataEnt::getHourTime, dao.getHourTime())
); );
allList.add(dao); allList.add(dao);
PlantPredictedPowerDataEnt isExit = objList.stream().filter(item ->
CharSequenceUtil.equals(item.getYearTime(), dao.getYearTime()) &&
CharSequenceUtil.equals(item.getMonthTime(), dao.getMonthTime()) &&
CharSequenceUtil.equals(item.getDayTime(), dao.getDayTime()) &&
CharSequenceUtil.equals(item.getHourTime(), dao.getHourTime()))
.findFirst()
.orElse(null);
if (Objects.isNull(isExit)) {
objList.add(dao);
}
} }
} // 原站点时间结构为:08:00 11:00 14:00 17:00 20:00 23:00 02:00 05:00
//入库 // 两条数据中间差了两个小时,使用上下两条数据推算出中间差掉的两个小时
List<PlantPredictedPowerDataEnt> sortList = allList.stream() for (int i = 0; i < objList.size() - 1; i++) {
.sorted(Comparator.comparing(PlantPredictedPowerDataEnt::getDataDate)) for (int y = 1; y < 3; y++) {
.collect(Collectors.toList()); PlantPredictedPowerDataEnt dataEnt = objList.get(i);
for (int i = 0; i < sortList.size(); i++) { date = DateUtil.parseDate(dataEnt.getDataDate());
PlantPredictedPowerDataEnt item = sortList.get(i); String hourString;
batchList.add(item); Integer hourTime = Integer.valueOf(dataEnt.getHourTime());
if (i < sortList.size() - 1) { if (hourTime.equals(23)) {
for (int y = 0; y < timeList.size(); y++) { date = DateUtil.offsetDay(date, 1);
PlantPredictedPowerDataEnt dao = XCopyUtils.copyNewObject(item); hourString = "0" + (y - 1);
dao.setMinTime(timeList.get(y)); } else {
dao.setDataDate(dao.getYearTime() + '-' + dao.getMonthTime() + '-' + dao.getDayTime() + ' ' + dao.getHourTime() + ':' + dao.getMinTime()); if ((hourTime + y) < 10) {
PlantPredictedPowerDataEnt nextData = sortList.get(i + 1); hourString = "0" + (hourTime + y);
BigDecimal valueOf = BigDecimal.valueOf(0.3 * (y + 1)); } else {
dao.setTemperature(this.compute(Objects.isNull(item.getTemperature()) ? BigDecimal.ZERO : item.getTemperature(), hourString = String.valueOf(hourTime + y);
Objects.isNull(nextData.getTemperature()) ? BigDecimal.ZERO : nextData.getTemperature(), }
valueOf)); }
dao.setHumidity(this.compute(Objects.isNull(item.getHumidity()) ? BigDecimal.ZERO : item.getHumidity(), PlantPredictedPowerDataEnt nextData = objList.get(i + 1);
Objects.isNull(nextData.getHumidity()) ? BigDecimal.ZERO : nextData.getHumidity(), BigDecimal valueOf = BigDecimal.valueOf(0.3 * y);
valueOf)); PlantPredictedPowerDataEnt dao = this.getPlantPredictedPowerEnt(plantId,
dao.setWindSpeed(this.compute(Objects.isNull(item.getWindSpeed()) ? BigDecimal.ZERO : item.getWindSpeed(), hourString,
Objects.isNull(nextData.getWindSpeed()) ? BigDecimal.ZERO : nextData.getWindSpeed(), this.compute(dataEnt.getTemperature(), nextData.getTemperature(), valueOf),
valueOf)); this.compute(dataEnt.getWindSpeed(), nextData.getWindSpeed(), valueOf),
dao.setPressure(this.compute(Objects.isNull(item.getPressure()) ? BigDecimal.ZERO : item.getPressure(), dataEnt.getWindDirection(),
Objects.isNull(nextData.getPressure()) ? BigDecimal.ZERO : nextData.getPressure(), this.compute(dataEnt.getPressure(), nextData.getPressure(), valueOf),
valueOf)); this.compute(dataEnt.getHumidity(), nextData.getHumidity(), valueOf),
dao.setPlaneIrradiance(this.compute(Objects.isNull(item.getPlaneIrradiance()) ? BigDecimal.ZERO : item.getPlaneIrradiance(), String.valueOf(date.year()),
Objects.isNull(nextData.getPlaneIrradiance()) ? BigDecimal.ZERO : nextData.getPlaneIrradiance(), this.int2Str(date.month() + 1),
valueOf)); this.int2Str(date.dayOfMonth())
dao.setHorizontalIrradiance(this.compute(Objects.isNull(item.getHorizontalIrradiance()) ? BigDecimal.ZERO : item.getHorizontalIrradiance(), );
Objects.isNull(nextData.getHorizontalIrradiance()) ? BigDecimal.ZERO : nextData.getHorizontalIrradiance(), // 5.执行SQL
valueOf)); mapper.delete(new LambdaQueryWrapper<PlantPredictedPowerDataEnt>()
dao.setPower(this.compute(Objects.isNull(item.getPower()) ? BigDecimal.ZERO : item.getPower(), .eq(PlantPredictedPowerDataEnt::getPlantId, plantId)
Objects.isNull(nextData.getPower()) ? BigDecimal.ZERO : nextData.getPower(), .eq(PlantPredictedPowerDataEnt::getYearTime, dao.getYearTime())
valueOf)); .eq(PlantPredictedPowerDataEnt::getMonthTime, dao.getMonthTime())
batchList.add(dao); .eq(PlantPredictedPowerDataEnt::getDayTime, dao.getDayTime())
.eq(PlantPredictedPowerDataEnt::getHourTime, dao.getHourTime())
);
allList.add(dao);
}
}
//入库
List<PlantPredictedPowerDataEnt> sortList = allList.stream()
.sorted(Comparator.comparing(PlantPredictedPowerDataEnt::getDataDate))
.collect(Collectors.toList());
for (int i = 0; i < sortList.size(); i++) {
PlantPredictedPowerDataEnt item = sortList.get(i);
batchList.add(item);
if (i < sortList.size() - 1) {
for (int y = 0; y < timeList.size(); y++) {
PlantPredictedPowerDataEnt dao = XCopyUtils.copyNewObject(item);
dao.setMinTime(timeList.get(y));
dao.setDataDate(dao.getYearTime() + '-' + dao.getMonthTime() + '-' + dao.getDayTime() + ' ' + dao.getHourTime() + ':' + dao.getMinTime());
PlantPredictedPowerDataEnt nextData = sortList.get(i + 1);
BigDecimal valueOf = BigDecimal.valueOf(0.3 * (y + 1));
dao.setTemperature(this.compute(Objects.isNull(item.getTemperature()) ? BigDecimal.ZERO : item.getTemperature(),
Objects.isNull(nextData.getTemperature()) ? BigDecimal.ZERO : nextData.getTemperature(),
valueOf));
dao.setHumidity(this.compute(Objects.isNull(item.getHumidity()) ? BigDecimal.ZERO : item.getHumidity(),
Objects.isNull(nextData.getHumidity()) ? BigDecimal.ZERO : nextData.getHumidity(),
valueOf));
dao.setWindSpeed(this.compute(Objects.isNull(item.getWindSpeed()) ? BigDecimal.ZERO : item.getWindSpeed(),
Objects.isNull(nextData.getWindSpeed()) ? BigDecimal.ZERO : nextData.getWindSpeed(),
valueOf));
dao.setPressure(this.compute(Objects.isNull(item.getPressure()) ? BigDecimal.ZERO : item.getPressure(),
Objects.isNull(nextData.getPressure()) ? BigDecimal.ZERO : nextData.getPressure(),
valueOf));
dao.setPlaneIrradiance(this.compute(Objects.isNull(item.getPlaneIrradiance()) ? BigDecimal.ZERO : item.getPlaneIrradiance(),
Objects.isNull(nextData.getPlaneIrradiance()) ? BigDecimal.ZERO : nextData.getPlaneIrradiance(),
valueOf));
dao.setHorizontalIrradiance(this.compute(Objects.isNull(item.getHorizontalIrradiance()) ? BigDecimal.ZERO : item.getHorizontalIrradiance(),
Objects.isNull(nextData.getHorizontalIrradiance()) ? BigDecimal.ZERO : nextData.getHorizontalIrradiance(),
valueOf));
dao.setPower(this.compute(Objects.isNull(item.getPower()) ? BigDecimal.ZERO : item.getPower(),
Objects.isNull(nextData.getPower()) ? BigDecimal.ZERO : nextData.getPower(),
valueOf));
batchList.add(dao);
}
} }
} }
} }
} }
} }
FileUtil.del(tempFilePath);
} }
PlantPredictedPowerDataViewMapper dataViewMapper = context.getBean(PlantPredictedPowerDataViewMapper.class); PlantPredictedPowerDataViewMapper dataViewMapper = context.getBean(PlantPredictedPowerDataViewMapper.class);
if (CollUtil.isNotEmpty(batchList)) { if (CollUtil.isNotEmpty(batchList)) {
...@@ -294,6 +281,8 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService { ...@@ -294,6 +281,8 @@ public class BaseWeatherCloudServiceImpl implements IBaseWeatherCloudService {
} }
} catch (MessagingException e) { } catch (MessagingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally { } finally {
NioUtil.close(folder); NioUtil.close(folder);
NioUtil.close(store); NioUtil.close(store);
......
...@@ -144,7 +144,7 @@ spring.cloud.servicecomb.credentials.account.password= ...@@ -144,7 +144,7 @@ spring.cloud.servicecomb.credentials.account.password=
spring.cloud.servicecomb.credentials.account.cipher= spring.cloud.servicecomb.credentials.account.cipher=
# \u81EA\u5B9A\u4E49\u914D\u7F6E # \u81EA\u5B9A\u4E49\u914D\u7F6E
weather.file.temp.path=D:\home\weather\temp\receive weather.file.temp.path=D:\home\weather\temp\receive\
weather.mail.host=pop.163.com weather.mail.host=pop.163.com
weather.mail.username=zhaowentao0117@163.com weather.mail.username=zhaowentao0117@163.com
weather.mail.password=JPFHTZWASWSDSSZP weather.mail.password=JPFHTZWASWSDSSZP
......
...@@ -232,7 +232,7 @@ spring.cloud.servicecomb.credentials.account.password=Xzypt@1020 ...@@ -232,7 +232,7 @@ spring.cloud.servicecomb.credentials.account.password=Xzypt@1020
spring.cloud.servicecomb.credentials.account.cipher=default spring.cloud.servicecomb.credentials.account.cipher=default
# \u81EA\u5B9A\u4E49\u914D\u7F6E # \u81EA\u5B9A\u4E49\u914D\u7F6E
weather.file.temp.path=/home/weather-jar/temp/receive weather.file.temp.path=/home/weather-jar/temp/receive/
weather.mail.host=pop.163.com weather.mail.host=pop.163.com
weather.mail.username=zhaowentao0117@163.com weather.mail.username=zhaowentao0117@163.com
weather.mail.password=JPFHTZWASWSDSSZP weather.mail.password=JPFHTZWASWSDSSZP
......
...@@ -233,7 +233,7 @@ spring.cloud.servicecomb.credentials.account.password= ...@@ -233,7 +233,7 @@ spring.cloud.servicecomb.credentials.account.password=
spring.cloud.servicecomb.credentials.account.cipher= spring.cloud.servicecomb.credentials.account.cipher=
# \u81EA\u5B9A\u4E49\u914D\u7F6E # \u81EA\u5B9A\u4E49\u914D\u7F6E
weather.file.temp.path=/home/weather-jar/temp/receive weather.file.temp.path=/home/weather-jar/temp/receive/
weather.mail.host=pop.163.com weather.mail.host=pop.163.com
weather.mail.username=zhaowentao0117@163.com weather.mail.username=zhaowentao0117@163.com
weather.mail.password=JPFHTZWASWSDSSZP weather.mail.password=JPFHTZWASWSDSSZP
......
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