|
@@ -5,18 +5,14 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.gyee.gaia.common.data.point.PointData;
|
|
|
import com.gyee.gaia.common.data.point.TestingPoint;
|
|
|
-import com.gyee.gaia.common.data.power.ModelPowerDetails;
|
|
|
import com.gyee.gaia.common.data.taos.RealtimeAverageTarget;
|
|
|
-import com.gyee.gaia.common.data.windturbine.Equipment;
|
|
|
-import com.gyee.gaia.dao.sql.Windturbine.IEquipmentService;
|
|
|
import com.gyee.gaia.dao.sql.point.ITestingPointService;
|
|
|
-import com.gyee.gaia.dao.sql.power.IModelPowerDetailsService;
|
|
|
import com.gyee.gaia.dao.sql.taos.IRealtimeAverageTargetService;
|
|
|
import com.gyee.gaia.electricity.wind.adapter.IAdapterApi;
|
|
|
-import com.gyee.gaia.electricity.wind.config.AppConfig;
|
|
|
import com.gyee.gaia.electricity.wind.entity.EquipPowerGenDay;
|
|
|
-import com.gyee.gaia.electricity.wind.init.CacheContext;
|
|
|
+import com.gyee.gaia.electricity.wind.entity.StateCause;
|
|
|
import com.gyee.gaia.electricity.wind.iservice.IEquipPowerGenDayService;
|
|
|
+import com.gyee.gaia.electricity.wind.iservice.IStateCauseService;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -38,67 +34,166 @@ public class CalcEquipPowerGenDay {
|
|
|
@Resource
|
|
|
private ITestingPointService testingPointService;
|
|
|
@Resource
|
|
|
- private IEquipmentService equipmentService;
|
|
|
- @Resource
|
|
|
private IEquipPowerGenDayService equipPowerGenDayService;
|
|
|
@Resource
|
|
|
private IRealtimeAverageTargetService realtimeAverageTargetService;
|
|
|
@Resource
|
|
|
- private IModelPowerDetailsService modelPowerDetailsService;
|
|
|
- @Resource
|
|
|
- private AppConfig appConfig;
|
|
|
+ private IStateCauseService stateCauseService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 风机id,1分钟理论发电量
|
|
|
+ */
|
|
|
+ private Map<String, List<RealtimeAverageTarget>> ratsListMap;
|
|
|
+ /**
|
|
|
+ * 风机id,日信息
|
|
|
+ */
|
|
|
+ private Map<String, EquipPowerGenDay> sepgdMap;
|
|
|
|
|
|
@XxlJob("CalcEquipPowerGenDay")
|
|
|
public void calcEquipPowerGenDay() {
|
|
|
|
|
|
//2,获取当前日期,当日开始时间
|
|
|
DateTime startDateTime = DateUtil.beginOfDay(DateUtil.yesterday());
|
|
|
- DateTime endDateTime = DateUtil.beginOfDay(DateUtil.date());
|
|
|
+ DateTime endDateTime = DateUtil.endOfDay(DateUtil.yesterday());
|
|
|
|
|
|
calcGeneratingCapacity(startDateTime, endDateTime);
|
|
|
calcTheoryGeneration(startDateTime, endDateTime);
|
|
|
+ calcLossPower(startDateTime, endDateTime);
|
|
|
|
|
|
+ equipPowerGenDayService.saveBatch(sepgdMap.values());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算损失电量
|
|
|
*/
|
|
|
- private List<EquipPowerGenDay> calcLossPower(DateTime time1, DateTime time2){
|
|
|
+ private void calcLossPower(DateTime time1, DateTime time2) {
|
|
|
+
|
|
|
+ //查询1分钟理论发电量
|
|
|
+ QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
|
|
|
+ ratWrapper.select("time", "theory_generation", "equipment_id").eq("uniform_code", "1FZPJZB")
|
|
|
+ .between("time", time1.getTime(), time2.getTime());
|
|
|
+ List<RealtimeAverageTarget> ratList = realtimeAverageTargetService.list(ratWrapper);
|
|
|
+ ratsListMap = ratList.stream().collect(Collectors.groupingBy(RealtimeAverageTarget::getEquipmentId));
|
|
|
+
|
|
|
+ /*查询日电量信息
|
|
|
+ QueryWrapper<EquipPowerGenDay> epgdWrapper = new QueryWrapper<>();
|
|
|
+ epgdWrapper.eq("date", time1);
|
|
|
+ List<EquipPowerGenDay> epgdList = equipPowerGenDayService.list(epgdWrapper);
|
|
|
+
|
|
|
+ Map<String, EquipPowerGenDay> sepgdMap = new HashMap<>();
|
|
|
+ if (epgdList.size() > 0) {
|
|
|
+ sepgdMap = epgdList.stream().collect(Collectors.toMap(EquipPowerGenDay::getFacilityId, Function.identity()));
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //查询损失时间
|
|
|
+ QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
|
|
|
+ scWrapper.select("start_time", "end_time", "event", "time", "station_id", "equipment_id").ne("event", "待机")
|
|
|
+ .ge("start_time", time1).le("end_time", time2);
|
|
|
+ List<StateCause> scList = stateCauseService.list(scWrapper);
|
|
|
+ Map<String, List<StateCause>> scsListMap = scList.stream().collect(Collectors.groupingBy(StateCause::getEquipmentId));
|
|
|
+
|
|
|
+ String equipId;
|
|
|
+ EquipPowerGenDay epgd;
|
|
|
+ for (List<StateCause> value : scsListMap.values()) {
|
|
|
+ equipId = value.get(0).getEquipmentId();
|
|
|
+
|
|
|
+ double faultLossPower = 0;//故障损失电量
|
|
|
+ double limitLossPower = 0;//限电损失电量
|
|
|
+ double maintainLossPower = 0;//计划检修损失电量
|
|
|
+ double implicateLossPower = 0;//受累损失电量
|
|
|
+ for (StateCause cause : value) {
|
|
|
+ switch (cause.getEvent()) {
|
|
|
+ case "故障":
|
|
|
+ faultLossPower += cause2DoubleSum(cause);
|
|
|
+ break;
|
|
|
+ case "限电":
|
|
|
+ limitLossPower += cause2DoubleSum(cause);
|
|
|
+ break;
|
|
|
+ case "计划检修":
|
|
|
+ maintainLossPower += cause2DoubleSum(cause);
|
|
|
+ break;
|
|
|
+ case "受累":
|
|
|
+ implicateLossPower += cause2DoubleSum(cause);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ epgd = sepgdMap.get(equipId);
|
|
|
+ if(epgd==null) continue;
|
|
|
+ //损失电量
|
|
|
+ BigDecimal losspower = epgd.getTheoryGeneration().subtract(epgd.getGeneratingCapacity());
|
|
|
+ if (losspower.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ epgd.setLossPower(BigDecimal.ZERO);
|
|
|
+ epgd.setFaultLossPower(BigDecimal.ZERO);
|
|
|
+ epgd.setMaintainLossPower(BigDecimal.ZERO);
|
|
|
+ epgd.setImplicateLossPower(BigDecimal.ZERO);
|
|
|
+ epgd.setLimitLossPower(BigDecimal.ZERO);
|
|
|
+ epgd.setPerformanceLossPower(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ epgd.setLossPower(losspower);
|
|
|
+ epgd.setFaultLossPower(BigDecimal.valueOf(faultLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setMaintainLossPower(BigDecimal.valueOf(maintainLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setImplicateLossPower(BigDecimal.valueOf(implicateLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setLimitLossPower(BigDecimal.valueOf(limitLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ BigDecimal performanceLossPower = epgd.getLossPower().subtract(epgd.getFaultLossPower())
|
|
|
+ .subtract(epgd.getMaintainLossPower()).subtract(epgd.getImplicateLossPower())
|
|
|
+ .subtract(epgd.getLimitLossPower());
|
|
|
+ epgd.setPerformanceLossPower(performanceLossPower.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : performanceLossPower);
|
|
|
+ }
|
|
|
+ /*if (epgd == null) {
|
|
|
+ epgd = new EquipPowerGenDay();
|
|
|
+ epgd.setDate(time1.toLocalDateTime().toLocalDate());
|
|
|
+ epgd.setStation(value.get(0).getStationId());
|
|
|
+ epgd.setCategory("windturbine");
|
|
|
+ epgd.setFacilityId(equipId);
|
|
|
+
|
|
|
+ epgd.setFaultLossPower(BigDecimal.valueOf(faultLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setMaintainLossPower(BigDecimal.valueOf(maintainLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setImplicateLossPower(BigDecimal.valueOf(implicateLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ epgd.setLimitLossPower(BigDecimal.valueOf(limitLossPower).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ epgdList.add(epgd);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }*/
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private double cause2DoubleSum(StateCause cause) {
|
|
|
+ return ratsListMap.get(cause.getEquipmentId()).stream().filter(target -> target.getTime().getTime() >= cause.getStartTime().getTime() &&
|
|
|
+ target.getTime().getTime() <= cause.getEndTime().getTime()).mapToDouble(RealtimeAverageTarget::getTheoryGeneration).sum();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算理论电量
|
|
|
*/
|
|
|
- private List<EquipPowerGenDay> calcTheoryGeneration(DateTime time1, DateTime time2) {
|
|
|
+ private void calcTheoryGeneration(DateTime time1, DateTime time2) {
|
|
|
|
|
|
//查询1分钟平均风速
|
|
|
QueryWrapper<RealtimeAverageTarget> ratWrapper = new QueryWrapper<>();
|
|
|
- ratWrapper.select("time", "wind_speed", "station_id", "equipment_id").eq("uniform_code", "1FZPJZB")
|
|
|
- .between("time", time1, time2).orderByAsc("time");
|
|
|
+ ratWrapper.select("AVG(wind_speed) wind_speed", "SUM(theory_generation) theory_generation", "equipment_id").eq("uniform_code", "1FZPJZB")
|
|
|
+ .between("time", time1.getTime(), time2.getTime()).groupBy("equipment_id");//.orderByAsc("time");
|
|
|
List<RealtimeAverageTarget> ratList = realtimeAverageTargetService.list(ratWrapper);
|
|
|
- Map<String, List<RealtimeAverageTarget>> ratsListMap = ratList.stream().collect(Collectors.groupingBy(RealtimeAverageTarget::getEquipmentId));
|
|
|
+ Map<String, RealtimeAverageTarget> sratMap = ratList.stream().collect(Collectors.toMap(RealtimeAverageTarget::getEquipmentId, Function.identity()));
|
|
|
+ //Map<String, List<RealtimeAverageTarget>> ratsListMap = ratList.stream().collect(Collectors.groupingBy(RealtimeAverageTarget::getEquipmentId));
|
|
|
|
|
|
//查询日电量信息
|
|
|
- QueryWrapper<EquipPowerGenDay> epgdWrapper = new QueryWrapper<>();
|
|
|
+ /*QueryWrapper<EquipPowerGenDay> epgdWrapper = new QueryWrapper<>();
|
|
|
epgdWrapper.eq("date", time1);
|
|
|
List<EquipPowerGenDay> epgdList = equipPowerGenDayService.list(epgdWrapper);
|
|
|
|
|
|
- Map<String, EquipPowerGenDay> sepgdMap=new HashMap<>();
|
|
|
- if(epgdList.size()>0){
|
|
|
+ Map<String, EquipPowerGenDay> sepgdMap = new HashMap<>();
|
|
|
+ if (epgdList.size() > 0) {
|
|
|
sepgdMap = epgdList.stream().collect(Collectors.toMap(EquipPowerGenDay::getFacilityId, Function.identity()));
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
String equipId;
|
|
|
- List<RealtimeAverageTarget> targets;
|
|
|
- EquipPowerGenDay epgd;
|
|
|
- for (Map.Entry<String, List<RealtimeAverageTarget>> ratslEntry : ratsListMap.entrySet()) {
|
|
|
- equipId = ratslEntry.getKey();
|
|
|
- targets = ratslEntry.getValue();
|
|
|
-
|
|
|
- epgd = sepgdMap.get(equipId);
|
|
|
- if(epgd==null) {
|
|
|
+ for (EquipPowerGenDay value : sepgdMap.values()) {
|
|
|
+ equipId = value.getFacilityId();
|
|
|
+ /*epgd = sepgdMap.get(equipId);
|
|
|
+ if (epgd == null) {
|
|
|
epgd = new EquipPowerGenDay();
|
|
|
epgd.setDate(time1.toLocalDateTime().toLocalDate());
|
|
|
epgd.setStation(targets.get(0).getStationId());
|
|
@@ -107,7 +202,6 @@ public class CalcEquipPowerGenDay {
|
|
|
epgdList.add(epgd);
|
|
|
}
|
|
|
double theoryPower = targets.stream().mapToDouble(RealtimeAverageTarget::getTheoryGeneration).sum();
|
|
|
- /*double theoryPower = 0;
|
|
|
for (RealtimeAverageTarget target : targets) {
|
|
|
Double power = CacheContext.mpdsMapMap.get(CacheContext.equipModelMap.get(equipId)).get(target.getWindSpeed());
|
|
|
if(power==null) {
|
|
@@ -115,22 +209,23 @@ public class CalcEquipPowerGenDay {
|
|
|
}
|
|
|
theoryPower += power / 1000 / 60;
|
|
|
}*/
|
|
|
- epgd.setGeneratingCapacity(BigDecimal.valueOf(theoryPower/1000).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ value.setTheoryGeneration(BigDecimal.valueOf(sratMap.get(equipId).getTheoryGeneration()).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ value.setMeanWindSpeed(BigDecimal.valueOf(sratMap.get(equipId).getWindSpeed()).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- return epgdList;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算日发电量
|
|
|
*/
|
|
|
- private List<EquipPowerGenDay> calcGeneratingCapacity(DateTime time1, DateTime time2) {
|
|
|
+ private void calcGeneratingCapacity(DateTime time1, DateTime time2) {
|
|
|
|
|
|
//开始时间00:00:01
|
|
|
- DateTime dateTime1 = DateUtil.offsetSecond(time1, 1);
|
|
|
+ //DateTime dateTime1 = DateUtil.offsetSecond(time1, 1);
|
|
|
//结束时间第二天00:00:01
|
|
|
- DateTime dateTime2 = DateUtil.offsetSecond(time2, 1);
|
|
|
+ //DateTime dateTime2 = DateUtil.offsetSecond(time2, 2);
|
|
|
|
|
|
- List<EquipPowerGenDay> epgdList = new ArrayList<>();
|
|
|
+ sepgdMap = new HashMap<>();
|
|
|
|
|
|
//1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
|
|
|
List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").eq("thing_type", "windturbine"));
|
|
@@ -139,10 +234,10 @@ public class CalcEquipPowerGenDay {
|
|
|
//获取测点code
|
|
|
String pointcode = testingPoint.getCode();
|
|
|
//获取设备ID
|
|
|
- String thingId = testingPoint.getThingId();
|
|
|
+ //String thingId = testingPoint.getThingId();
|
|
|
|
|
|
//8,通过适配器拿到一天的发电量数据,
|
|
|
- List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
|
|
|
+ List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, time1.getTime(), time2.getTime());
|
|
|
|
|
|
//定义日发电量,先给0
|
|
|
BigDecimal rfdl = new BigDecimal(0);
|
|
@@ -151,7 +246,7 @@ public class CalcEquipPowerGenDay {
|
|
|
if (historyRaw.size() > 0) {
|
|
|
BigDecimal bigDecimal1 = new BigDecimal(Double.toString(historyRaw.get(0).getValue()));
|
|
|
BigDecimal bigDecimal2 = new BigDecimal(Double.toString(historyRaw.get(historyRaw.size() - 1).getValue()));
|
|
|
- rfdl = bigDecimal2.subtract(bigDecimal1);
|
|
|
+ rfdl = bigDecimal2.subtract(bigDecimal1).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
//如果日发电量大于50000千瓦时或者小于0,说明数据异常进行处理
|
|
|
if (rfdl.doubleValue() > 50000 || rfdl.doubleValue() < 0) {
|
|
@@ -170,7 +265,7 @@ public class CalcEquipPowerGenDay {
|
|
|
for (int j = 1; j < arrayList.size(); j++) {
|
|
|
double difference = arrayList.get(j) - arrayList.get(j - 1);
|
|
|
//如果变化值difference大于阈值或者小于0,返回当前突变数据的索引
|
|
|
- if (difference > threshold || difference < 0) {
|
|
|
+ if (difference > threshold || difference < -1) {
|
|
|
index = j;
|
|
|
break;
|
|
|
}
|
|
@@ -185,7 +280,7 @@ public class CalcEquipPowerGenDay {
|
|
|
double valueGrow1 = arrayList.get(index - 1);
|
|
|
BigDecimal bigDecimalGrow1 = new BigDecimal(Double.toString(valueGrow1));
|
|
|
//计算日发电量(结束值-突变值)+(突变值前值-开始值)
|
|
|
- rfdl = (bigDecimal2.subtract(bigDecimalGrow2).add(bigDecimalGrow1).subtract(bigDecimal1));
|
|
|
+ rfdl = (bigDecimal2.subtract(bigDecimalGrow2).add(bigDecimalGrow1).subtract(bigDecimal1).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -198,9 +293,8 @@ public class CalcEquipPowerGenDay {
|
|
|
epgd.setCategory(testingPoint.getThingType());
|
|
|
epgd.setFacilityId(testingPoint.getThingId());
|
|
|
epgd.setGeneratingCapacity(rfdl);
|
|
|
- epgdList.add(epgd);
|
|
|
+ sepgdMap.put(testingPoint.getThingId(), epgd);
|
|
|
}
|
|
|
- return epgdList;
|
|
|
}
|
|
|
|
|
|
}
|