|
@@ -1,6 +1,9 @@
|
|
|
package com.jiayue.biz.job;
|
|
|
|
|
|
|
|
|
+import ch.qos.logback.classic.spi.STEUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.db.Entity;
|
|
|
import cn.hutool.json.JSONObject;
|
|
@@ -20,6 +23,11 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.beans.IntrospectionException;
|
|
|
+import java.beans.PropertyDescriptor;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.sql.Timestamp;
|
|
@@ -56,6 +64,7 @@ public class AirDensityJob {
|
|
|
private final com.jiayue.biz.api.apiHDY apiHDY;
|
|
|
|
|
|
private final FanModelDataService fanModelDataService;
|
|
|
+ private final TotalBatteryDataService totalBatteryDataService;
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0 19 * * ?")
|
|
@@ -219,7 +228,7 @@ public class AirDensityJob {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //存储杨总数据 TODO 缺少TD Engine 逻辑
|
|
|
+ //存储杨总数据
|
|
|
// @Scheduled(cron = "0 30 14 6 7 ?")
|
|
|
public void saveJsonY() {
|
|
|
// String s = apiHDY.jsonY(DateUtil.format(new Date(), "yyyyMMdd"));
|
|
@@ -233,58 +242,96 @@ public class AirDensityJob {
|
|
|
continue;
|
|
|
}
|
|
|
FanJsonInfo towerJsonInfo = jsonObject1.toBean(FanJsonInfo.class);
|
|
|
- String[] strArr = new String[]{towerJsonInfo.getFdln(), towerJsonInfo.getFd1n(), towerJsonInfo.getFd2n(), towerJsonInfo.getFd3n(), towerJsonInfo.getFd4n()};
|
|
|
- List<String> collect = new ArrayList<>();
|
|
|
- if (stationInfo.getStationBasicInfo().getStationType().equals("风")) {
|
|
|
- collect = stationInfo.getFanTowerList().stream().map(FanTower::getFanModel).distinct().collect(Collectors.toList());
|
|
|
- } else {
|
|
|
- collect = stationInfo.getInverterInfos().stream().map(InverterInfo::getModelNumber).distinct().collect(Collectors.toList());
|
|
|
- }
|
|
|
- String fdn = "";
|
|
|
- for (int i = 0; i < collect.size(); i++) {
|
|
|
- if (collect.size() == 1) {
|
|
|
- fdn = strArr[i];
|
|
|
- } else {
|
|
|
- fdn = strArr[i + 1];
|
|
|
- }
|
|
|
- String s1 = collect.get(i);
|
|
|
- if (StrUtil.isBlank(s1)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- BigDecimal realTimeTotal = BigDecimal.ZERO;
|
|
|
+ //存储tdEngine
|
|
|
+ convertData(towerJsonInfo, stationInfo);
|
|
|
+ //存储mongo
|
|
|
+// saveMongoBattery(stationInfo, towerJsonInfo, fanModelDataList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ public void saveMongoBattery(StationInfo stationInfo, FanJsonInfo towerJsonInfo, List<FanModelData> fanModelDataList) {
|
|
|
+ String[] strArr = new String[]{towerJsonInfo.getFdln(), towerJsonInfo.getFd1n(), towerJsonInfo.getFd2n(), towerJsonInfo.getFd3n(), towerJsonInfo.getFd4n()};
|
|
|
|
|
|
- String s2 = CalculationUtil.getNumberFromStringForDian(s1);
|
|
|
- if (StrUtil.isBlank(s2)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- //根据风机类型分组
|
|
|
- Map<String, List<FanTower>> modelMap = stationInfo.getFanTowerList().stream()
|
|
|
- .collect(Collectors.groupingBy(FanTower::getFanModel));
|
|
|
- int fanTotal = modelMap.get(s1).size();
|
|
|
- fdn = new BigDecimal(fdn).multiply(BigDecimal.valueOf(10)).toString();
|
|
|
- realTimeTotal = new BigDecimal(fdn).divide(new BigDecimal(s2).multiply(new BigDecimal(fanTotal)), 2, BigDecimal.ROUND_HALF_UP);//满发小时数(年)
|
|
|
-
|
|
|
- //一期
|
|
|
- FanModelData fanModelData = new FanModelData(UUID.randomUUID().toString(), stationInfo.getId(),
|
|
|
- stationInfo.getStationBasicInfo().getStationName(), s1, stationInfo.getStationBasicInfo().getAbbreviation(),
|
|
|
- new BigDecimal(towerJsonInfo.getPjfs()).setScale(2, RoundingMode.HALF_UP).toString(), towerJsonInfo.getZfx(),
|
|
|
- fdn, realTimeTotal.toString());
|
|
|
- //发电量(年)
|
|
|
- fdn = new BigDecimal(towerJsonInfo.getFd2n()).setScale(2, RoundingMode.HALF_UP).toString();
|
|
|
- List<FanModelData> modelDataList = fanModelDataList.stream().filter(f -> f.getStationId().equals(stationInfo.getId())
|
|
|
- && f.getModelName().equals(s1)).collect(Collectors.toList());
|
|
|
- if (modelDataList.size() > 0) {
|
|
|
+ List<String> collect = new ArrayList<>();
|
|
|
+ if (stationInfo.getStationBasicInfo().getStationType().equals("风")) {
|
|
|
+ collect = stationInfo.getFanTowerList().stream().map(FanTower::getFanModel).distinct().collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ collect = stationInfo.getInverterInfos().stream().map(InverterInfo::getModelNumber).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ String fdn = "";
|
|
|
+ for (int i = 0; i < collect.size(); i++) {
|
|
|
+ if (collect.size() == 1) {
|
|
|
+ fdn = strArr[i];
|
|
|
+ } else {
|
|
|
+ fdn = strArr[i + 1];
|
|
|
+ }
|
|
|
+ String s1 = collect.get(i);
|
|
|
+ if (StrUtil.isBlank(s1)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal realTimeTotal = BigDecimal.ZERO;
|
|
|
+ String s2 = CalculationUtil.getNumberFromStringForDian(s1);
|
|
|
+ if (StrUtil.isBlank(s2)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //根据风机类型分组
|
|
|
+ Map<String, List<FanTower>> modelMap = stationInfo.getFanTowerList().stream()
|
|
|
+ .collect(Collectors.groupingBy(FanTower::getFanModel));
|
|
|
+ int fanTotal = modelMap.get(s1).size();
|
|
|
+ fdn = new BigDecimal(fdn).multiply(BigDecimal.valueOf(10)).toString();
|
|
|
+ realTimeTotal = new BigDecimal(fdn).divide(new BigDecimal(s2).multiply(new BigDecimal(fanTotal)), 2, BigDecimal.ROUND_HALF_UP);//满发小时数(年)
|
|
|
+ //一期
|
|
|
+ FanModelData fanModelData = new FanModelData(UUID.randomUUID().toString(), stationInfo.getId(),
|
|
|
+ stationInfo.getStationBasicInfo().getStationName(), s1, stationInfo.getStationBasicInfo().getAbbreviation(),
|
|
|
+ new BigDecimal(towerJsonInfo.getPjfs()).setScale(2, RoundingMode.HALF_UP).toString(), towerJsonInfo.getZfx(),
|
|
|
+ fdn, realTimeTotal.toString());
|
|
|
+ //发电量(年)
|
|
|
+ fdn = new BigDecimal(towerJsonInfo.getFd2n()).setScale(2, RoundingMode.HALF_UP).toString();
|
|
|
+ List<FanModelData> modelDataList = fanModelDataList.stream().filter(f -> f.getStationId().equals(stationInfo.getId())
|
|
|
+ && f.getModelName().equals(s1)).collect(Collectors.toList());
|
|
|
+ if (modelDataList.size() > 0) {
|
|
|
// System.out.println("删除");
|
|
|
// fanModelDataService.deleteFanModelData(modelDataList.get(0).getId());
|
|
|
//
|
|
|
- }
|
|
|
+ }
|
|
|
// System.out.println("新增");
|
|
|
// mongoTemplate.save(fanModelData);
|
|
|
//
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ public void convertData(FanJsonInfo towerJsonInfo, StationInfo stationInfo) {
|
|
|
+ TotalBatteryData totalBatteryData = new TotalBatteryData();
|
|
|
+ BeanUtil.copyProperties(towerJsonInfo, totalBatteryData);
|
|
|
+ batteryMultiplyTen(totalBatteryData);
|
|
|
+ DateTime yesterday = DateUtil.yesterday();
|
|
|
+ totalBatteryData.setTs(new Timestamp(DateUtil.beginOfDay(yesterday).getTime()));
|
|
|
+ if (StrUtil.isNotBlank(stationInfo.getStationBasicInfo().getCapacity())) {
|
|
|
+ BigDecimal equivalentHour = new BigDecimal(totalBatteryData.getFdln()).divide(new BigDecimal(stationInfo.getStationBasicInfo().getCapacity()), 3, RoundingMode.HALF_UP);
|
|
|
+ totalBatteryData.setEquivalentHour(equivalentHour.floatValue());
|
|
|
+ }
|
|
|
+ totalBatteryData.setStationNameEasy(stationInfo.getStationBasicInfo().getAbbreviation());
|
|
|
+ totalBatteryDataService.insertOne(totalBatteryData);
|
|
|
+ }
|
|
|
|
|
|
+ public void batteryMultiplyTen(TotalBatteryData totalBatteryData) {
|
|
|
+ try {
|
|
|
+ Class<? extends TotalBatteryData> aClass = totalBatteryData.getClass();
|
|
|
+ Field[] declaredFields = aClass.getDeclaredFields();
|
|
|
+ for (Field declaredField : declaredFields) {
|
|
|
+ if (declaredField.getName().contains("fd")) {
|
|
|
+ declaredField.setAccessible(true);
|
|
|
+ PropertyDescriptor pd = new PropertyDescriptor(declaredField.getName(), aClass);
|
|
|
+ Method getMethod = pd.getReadMethod();
|
|
|
+ String invoke = (String) getMethod.invoke(totalBatteryData);
|
|
|
+ BigDecimal batteryTen = new BigDecimal(invoke).multiply(BigDecimal.valueOf(10)).setScale(2,RoundingMode.HALF_UP);
|
|
|
+ declaredField.set(totalBatteryData, batteryTen.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
}
|