|
|
@@ -1,5 +1,10 @@
|
|
|
package com.zksy.cockpit.overview;
|
|
|
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.domain.WaterPlantInfo;
|
|
|
+import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
|
|
|
+import com.zksy.WaterSupply.WaterPumpStation.domain.PumpStationType;
|
|
|
+import com.zksy.WaterSupply.WaterPumpStation.domain.WaterPumpStation;
|
|
|
+import com.zksy.WaterSupply.WaterPumpStation.service.IWaterPumpStationService;
|
|
|
import com.zksy.base.domain.EquipmentBase;
|
|
|
import com.zksy.base.domain.EquipmentType;
|
|
|
import com.zksy.base.domain.PipeNetworkBase;
|
|
|
@@ -28,9 +33,10 @@ import java.util.stream.Collectors;
|
|
|
* 总体概览-基础设施 真实数据适配器(BT-5)。
|
|
|
*
|
|
|
* <p>智能设备按 {@code equipment_type} 分组计数({@code objectKind=SMART_DEVICE});
|
|
|
+ * 水厂和泵站分别取自其设施台账,共用泵站按 {@code station_type} 区分供水/排水。
|
|
|
* 管网设施按 {@code pipe_network_base.network_type} 分组计数({@code objectKind=FACILITY})。
|
|
|
- * 设施类型无行业字典,{@code industry} 如实为 {@code null};设施长度由 {@code length}(米)换算公里。
|
|
|
- * {@code updatedAt} 取台账/设施表最新更新时间。
|
|
|
+ * 管网类型无可信行业字典,{@code industry} 如实为 {@code null};设施长度由 {@code length}(米)换算公里。
|
|
|
+ * {@code updatedAt} 取各台账最新更新时间。
|
|
|
*/
|
|
|
@Component
|
|
|
@Primary
|
|
|
@@ -43,22 +49,29 @@ public class BusinessCockpitOverviewInfrastructureAdapter
|
|
|
private final EquipmentTypeService equipmentTypeService;
|
|
|
private final EquipmentBaseService equipmentBaseService;
|
|
|
private final PipeNetworkBaseService pipeNetworkBaseService;
|
|
|
+ private final IWaterPlantInfoService plantService;
|
|
|
+ private final IWaterPumpStationService pumpStationService;
|
|
|
|
|
|
public BusinessCockpitOverviewInfrastructureAdapter(
|
|
|
EquipmentTypeService equipmentTypeService,
|
|
|
EquipmentBaseService equipmentBaseService,
|
|
|
- PipeNetworkBaseService pipeNetworkBaseService) {
|
|
|
+ PipeNetworkBaseService pipeNetworkBaseService,
|
|
|
+ IWaterPlantInfoService plantService,
|
|
|
+ IWaterPumpStationService pumpStationService) {
|
|
|
this.equipmentTypeService = equipmentTypeService;
|
|
|
this.equipmentBaseService = equipmentBaseService;
|
|
|
this.pipeNetworkBaseService = pipeNetworkBaseService;
|
|
|
+ this.plantService = plantService;
|
|
|
+ this.pumpStationService = pumpStationService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CockpitOverviewInfrastructureSnapshot load() {
|
|
|
- Map<Integer, EquipmentType> types = equipmentTypes();
|
|
|
+ List<EquipmentType> equipmentTypes = safeList(equipmentTypeService.list());
|
|
|
+ Map<Integer, EquipmentType> types = equipmentTypes(equipmentTypes);
|
|
|
|
|
|
List<CockpitOverviewInfrastructureSnapshot.SourceType> sourceTypes = new ArrayList<>();
|
|
|
- for (EquipmentType type : safeList(equipmentTypeService.list())) {
|
|
|
+ for (EquipmentType type : equipmentTypes) {
|
|
|
if (type == null || type.getId() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -70,9 +83,10 @@ public class BusinessCockpitOverviewInfrastructureAdapter
|
|
|
"SMART_DEVICE"));
|
|
|
}
|
|
|
|
|
|
+ List<EquipmentBase> devices = safeList(equipmentBaseService.list());
|
|
|
List<CockpitOverviewInfrastructureSnapshot.SourceCount> counts = new ArrayList<>();
|
|
|
Map<Integer, Integer> deviceCountByType = new LinkedHashMap<>();
|
|
|
- for (EquipmentBase device : safeList(equipmentBaseService.list())) {
|
|
|
+ for (EquipmentBase device : devices) {
|
|
|
if (device == null || device.getEquipmentTypeId() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -84,7 +98,8 @@ public class BusinessCockpitOverviewInfrastructureAdapter
|
|
|
}
|
|
|
|
|
|
Map<String, FacilityAggregate> facilityByType = new LinkedHashMap<>();
|
|
|
- for (PipeNetworkBase facility : safeList(pipeNetworkBaseService.list())) {
|
|
|
+ List<PipeNetworkBase> facilities = safeList(pipeNetworkBaseService.list());
|
|
|
+ for (PipeNetworkBase facility : facilities) {
|
|
|
if (facility == null) {
|
|
|
continue;
|
|
|
}
|
|
|
@@ -112,29 +127,74 @@ public class BusinessCockpitOverviewInfrastructureAdapter
|
|
|
new CockpitOverviewInfrastructureSnapshot.SourceValue(lengthKm, "km", null)));
|
|
|
}
|
|
|
|
|
|
+ List<WaterPlantInfo> plants = safeList(plantService.list());
|
|
|
+ int plantCount = 0;
|
|
|
+ for (WaterPlantInfo plant : plants) {
|
|
|
+ if (!isBlank(plant.getPlantCode())) {
|
|
|
+ plantCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addFacilityCount(sourceTypes, counts, "WATER_PLANT", "水厂", "WATER_SUPPLY", plantCount);
|
|
|
+
|
|
|
+ List<WaterPumpStation> stations = safeList(pumpStationService.list());
|
|
|
+ int waterStationCount = 0;
|
|
|
+ int drainageStationCount = 0;
|
|
|
+ for (WaterPumpStation station : stations) {
|
|
|
+ if (isBlank(station.getStationCode())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String stationType = trimToNull(station.getStationType());
|
|
|
+ if (PumpStationType.WATER_SUPPLY.equalsIgnoreCase(stationType)) {
|
|
|
+ waterStationCount++;
|
|
|
+ } else if (PumpStationType.DRAINAGE.equalsIgnoreCase(stationType)) {
|
|
|
+ drainageStationCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addFacilityCount(sourceTypes, counts, "WATER_PUMP_STATION", "供水泵站", "WATER_SUPPLY", waterStationCount);
|
|
|
+ addFacilityCount(sourceTypes, counts, "DRAINAGE_PUMP_STATION", "排水泵站", "DRAINAGE", drainageStationCount);
|
|
|
+
|
|
|
LocalDateTime updatedAt = null;
|
|
|
- for (EquipmentBase device : safeList(equipmentBaseService.list())) {
|
|
|
+ for (EquipmentBase device : devices) {
|
|
|
if (device == null) {
|
|
|
continue;
|
|
|
}
|
|
|
updatedAt = latest(updatedAt, device.getUpdateTime());
|
|
|
updatedAt = latest(updatedAt, device.getCreateTime());
|
|
|
}
|
|
|
- for (PipeNetworkBase facility : safeList(pipeNetworkBaseService.list())) {
|
|
|
+ for (PipeNetworkBase facility : facilities) {
|
|
|
if (facility == null) {
|
|
|
continue;
|
|
|
}
|
|
|
updatedAt = latest(updatedAt, facility.getUpdateTime());
|
|
|
updatedAt = latest(updatedAt, facility.getCreateTime());
|
|
|
}
|
|
|
+ for (WaterPlantInfo plant : plants) {
|
|
|
+ updatedAt = latest(updatedAt, plant.getUpdateTime());
|
|
|
+ updatedAt = latest(updatedAt, plant.getCreateTime());
|
|
|
+ }
|
|
|
+ for (WaterPumpStation station : stations) {
|
|
|
+ updatedAt = latest(updatedAt, station.getUpdateTime());
|
|
|
+ updatedAt = latest(updatedAt, station.getCreateTime());
|
|
|
+ }
|
|
|
|
|
|
return new CockpitOverviewInfrastructureSnapshot(
|
|
|
offsetTime(updatedAt), sourceTypes, counts);
|
|
|
}
|
|
|
|
|
|
- private Map<Integer, EquipmentType> equipmentTypes() {
|
|
|
+ private static void addFacilityCount(
|
|
|
+ List<CockpitOverviewInfrastructureSnapshot.SourceType> types,
|
|
|
+ List<CockpitOverviewInfrastructureSnapshot.SourceCount> counts,
|
|
|
+ String code, String name, String industry, int count) {
|
|
|
+ if (count == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ types.add(new CockpitOverviewInfrastructureSnapshot.SourceType(code, name, industry, null, "FACILITY"));
|
|
|
+ counts.add(new CockpitOverviewInfrastructureSnapshot.SourceCount("FACILITY", code, count));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<Integer, EquipmentType> equipmentTypes(List<EquipmentType> values) {
|
|
|
Map<Integer, EquipmentType> result = new HashMap<>();
|
|
|
- for (EquipmentType type : safeList(equipmentTypeService.list())) {
|
|
|
+ for (EquipmentType type : values) {
|
|
|
if (type != null && type.getId() != null) {
|
|
|
result.put(type.getId(), type);
|
|
|
}
|
|
|
@@ -163,6 +223,10 @@ public class BusinessCockpitOverviewInfrastructureAdapter
|
|
|
return value.trim();
|
|
|
}
|
|
|
|
|
|
+ private static boolean isBlank(String value) {
|
|
|
+ return value == null || value.trim().isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
private static <T> List<T> safeList(List<T> value) {
|
|
|
return value == null ? Collections.emptyList() : value.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
}
|