diff --git a/src/main/java/org/lucoenergia/conluz/domain/production/huawei/sync/SyncHuaweiProductionService.java b/src/main/java/org/lucoenergia/conluz/domain/production/huawei/sync/SyncHuaweiProductionService.java index a0532a3..ae2a702 100644 --- a/src/main/java/org/lucoenergia/conluz/domain/production/huawei/sync/SyncHuaweiProductionService.java +++ b/src/main/java/org/lucoenergia/conluz/domain/production/huawei/sync/SyncHuaweiProductionService.java @@ -1,5 +1,7 @@ package org.lucoenergia.conluz.domain.production.huawei.sync; +import org.lucoenergia.conluz.domain.production.huawei.HuaweiConfig; +import org.lucoenergia.conluz.domain.production.huawei.get.GetHuaweiConfigRepository; import org.lucoenergia.conluz.domain.production.plant.Plant; import org.lucoenergia.conluz.domain.production.InverterProvider; import org.lucoenergia.conluz.domain.production.get.GetEnergyStationRepository; @@ -8,25 +10,34 @@ import org.lucoenergia.conluz.domain.production.huawei.persist.PersistHuaweiProductionRepository; import org.lucoenergia.conluz.infrastructure.production.huawei.get.GetHuaweiHourlyProductionRepositoryRest; import org.lucoenergia.conluz.infrastructure.production.huawei.get.GetHuaweiRealTimeProductionRepositoryRest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service public class SyncHuaweiProductionService { + private static final Logger LOGGER = LoggerFactory.getLogger(SyncHuaweiProductionService.class); + private final PersistHuaweiProductionRepository persistHuaweiProductionRepository; private final GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest; private final GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest; private final GetEnergyStationRepository getEnergyStationRepository; + private final GetHuaweiConfigRepository getHuaweiConfigRepository; public SyncHuaweiProductionService(PersistHuaweiProductionRepository persistHuaweiProductionRepository, - GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest, GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest, - GetEnergyStationRepository getEnergyStationRepository) { + GetHuaweiRealTimeProductionRepositoryRest getHuaweiRealTimeProductionRepositoryRest, + GetHuaweiHourlyProductionRepositoryRest getHuaweiHourlyProductionRepositoryRest, + GetEnergyStationRepository getEnergyStationRepository, + GetHuaweiConfigRepository getHuaweiConfigRepository) { this.persistHuaweiProductionRepository = persistHuaweiProductionRepository; this.getHuaweiRealTimeProductionRepositoryRest = getHuaweiRealTimeProductionRepositoryRest; this.getHuaweiHourlyProductionRepositoryRest = getHuaweiHourlyProductionRepositoryRest; this.getEnergyStationRepository = getEnergyStationRepository; + this.getHuaweiConfigRepository = getHuaweiConfigRepository; } /** @@ -36,8 +47,19 @@ public SyncHuaweiProductionService(PersistHuaweiProductionRepository persistHuaw */ public void syncRealTimeProduction() { + // Get Huawei configuration + Optional huaweiConfig = getHuaweiConfigRepository.getHuaweiConfig(); + if (huaweiConfig.isEmpty()) { + LOGGER.debug("No Huawei config found"); + return; + } + // Get all energy stations with Huawei inverter List huaweiStations = getEnergyStationRepository.findAllByInverterProvider(InverterProvider.HUAWEI); + if (huaweiStations.isEmpty()) { + LOGGER.debug("No Huawei stations found"); + return; + } // Get the productions for every station List productions = getHuaweiRealTimeProductionRepositoryRest.getRealTimeProduction(huaweiStations); @@ -48,8 +70,19 @@ public void syncRealTimeProduction() { public void syncHourlyProduction() { + // Get Huawei configuration + Optional huaweiConfig = getHuaweiConfigRepository.getHuaweiConfig(); + if (huaweiConfig.isEmpty()) { + LOGGER.debug("No Huawei config found"); + return; + } + // Get all energy stations with Huawei inverter List huaweiStations = getEnergyStationRepository.findAllByInverterProvider(InverterProvider.HUAWEI); + if (huaweiStations.isEmpty()) { + LOGGER.debug("No Huawei stations found"); + return; + } // Get the productions for every station List productions = getHuaweiHourlyProductionRepositoryRest.getHourlyProduction(huaweiStations); diff --git a/src/main/java/org/lucoenergia/conluz/domain/production/plant/Plant.java b/src/main/java/org/lucoenergia/conluz/domain/production/plant/Plant.java index fb7c355..dfd783e 100644 --- a/src/main/java/org/lucoenergia/conluz/domain/production/plant/Plant.java +++ b/src/main/java/org/lucoenergia/conluz/domain/production/plant/Plant.java @@ -7,6 +7,7 @@ import org.lucoenergia.conluz.infrastructure.shared.uuid.ValidUUID; import java.time.LocalDate; +import java.util.Objects; import java.util.UUID; public class Plant { @@ -147,4 +148,25 @@ public Plant build() { return station; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Plant plant)) return false; + return Objects.equals(getId(), plant.getId()) && Objects.equals(getName(), plant.getName()) && Objects.equals(getCode(), plant.getCode()); + } + + @Override + public int hashCode() { + return Objects.hash(getId(), getName(), getCode()); + } + + @Override + public String toString() { + return "Plant{" + + "name='" + name + '\'' + + ", code='" + code + '\'' + + ", id=" + id + + '}'; + } } diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiHourlyProductionRepositoryRest.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiHourlyProductionRepositoryRest.java index 4214173..79b6227 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiHourlyProductionRepositoryRest.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiHourlyProductionRepositoryRest.java @@ -56,6 +56,7 @@ public List getHourlyProduction(List stations) { List result = new ArrayList<>(); if (stations == null || stations.isEmpty()) { + LOGGER.debug("No Huawei stations provided"); return result; } diff --git a/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiRealTimeProductionRepositoryRest.java b/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiRealTimeProductionRepositoryRest.java index 8d8b2b4..deba426 100644 --- a/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiRealTimeProductionRepositoryRest.java +++ b/src/main/java/org/lucoenergia/conluz/infrastructure/production/huawei/get/GetHuaweiRealTimeProductionRepositoryRest.java @@ -55,6 +55,7 @@ public List getRealTimeProduction(List stations) { List result = new ArrayList<>(); if (stations == null || stations.isEmpty()) { + LOGGER.debug("No Huawei stations provided"); return result; }