|
@@ -0,0 +1,212 @@
|
|
|
|
|
+package com.zksy.cockpit.infrastructure;
|
|
|
|
|
+
|
|
|
|
|
+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.PipeNetworkBase;
|
|
|
|
|
+import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
|
|
+import com.zksy.drainage.domain.EngineeringFacility;
|
|
|
|
|
+import com.zksy.drainage.service.EngineeringFacilityService;
|
|
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.time.Clock;
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.ZoneId;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 基础档案真实数据适配器(BT-5 第 6 片)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * <p>组合现有设施表,不新增投影:水厂、共用泵站、统一管网基础表和排水工程设施。
|
|
|
|
|
+ * 只有实体明确提供的字段才映射;缺少统一来源的规模、区域或长度保持 null,避免把
|
|
|
|
|
+ * 容量、坐标或展示文本误当作基础档案事实。
|
|
|
|
|
+ */
|
|
|
|
|
+@Component
|
|
|
|
|
+@Primary
|
|
|
|
|
+public class BusinessCockpitInfrastructureBaseArchivesAdapter
|
|
|
|
|
+ implements CockpitInfrastructureBaseArchivesAdapter {
|
|
|
|
|
+
|
|
|
|
|
+ private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
|
|
+ private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
|
|
|
|
+ private static final List<CockpitInfrastructureBaseArchivesSnapshot.SourceType> TYPES = Arrays.asList(
|
|
|
|
|
+ type("WATER_PLANT", "水厂", "WATER_SUPPLY"),
|
|
|
|
|
+ type("WATER_PUMP_STATION", "供水泵站", "WATER_SUPPLY"),
|
|
|
|
|
+ type("WATER_PIPE", "供水管线", "WATER_SUPPLY"),
|
|
|
|
|
+ type("GAS_PIPE", "燃气管线", "GAS"),
|
|
|
|
|
+ type("DRAINAGE_PIPE", "排水管线", "DRAINAGE"),
|
|
|
|
|
+ type("DRAINAGE_GATE", "排水闸门", "DRAINAGE"),
|
|
|
|
|
+ type("DRAINAGE_STORAGE", "排水调蓄设施", "DRAINAGE"),
|
|
|
|
|
+ type("DRAINAGE_PUMP_STATION", "排水泵站", "DRAINAGE"));
|
|
|
|
|
+
|
|
|
|
|
+ private final IWaterPlantInfoService plantService;
|
|
|
|
|
+ private final IWaterPumpStationService pumpStationService;
|
|
|
|
|
+ private final PipeNetworkBaseService pipeNetworkBaseService;
|
|
|
|
|
+ private final EngineeringFacilityService engineeringFacilityService;
|
|
|
|
|
+ private final Clock clock;
|
|
|
|
|
+
|
|
|
|
|
+ public BusinessCockpitInfrastructureBaseArchivesAdapter(
|
|
|
|
|
+ IWaterPlantInfoService plantService,
|
|
|
|
|
+ IWaterPumpStationService pumpStationService,
|
|
|
|
|
+ PipeNetworkBaseService pipeNetworkBaseService,
|
|
|
|
|
+ EngineeringFacilityService engineeringFacilityService,
|
|
|
|
|
+ Clock clock) {
|
|
|
|
|
+ this.plantService = plantService;
|
|
|
|
|
+ this.pumpStationService = pumpStationService;
|
|
|
|
|
+ this.pipeNetworkBaseService = pipeNetworkBaseService;
|
|
|
|
|
+ this.engineeringFacilityService = engineeringFacilityService;
|
|
|
|
|
+ this.clock = clock;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CockpitInfrastructureBaseArchivesSnapshot load() {
|
|
|
|
|
+ List<CockpitInfrastructureBaseArchivesSnapshot.SourceFacility> facilities = new ArrayList<>();
|
|
|
|
|
+ addPlants(facilities);
|
|
|
|
|
+ addPumpStations(facilities);
|
|
|
|
|
+ addPipes(facilities);
|
|
|
|
|
+ addDrainageFacilities(facilities);
|
|
|
|
|
+ return new CockpitInfrastructureBaseArchivesSnapshot(
|
|
|
|
|
+ TIME_FORMATTER.format(clock.instant().atZone(BUSINESS_ZONE)), TYPES, facilities);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addPlants(List<CockpitInfrastructureBaseArchivesSnapshot.SourceFacility> facilities) {
|
|
|
|
|
+ for (WaterPlantInfo plant : safeList(plantService.list())) {
|
|
|
|
|
+ String code = trimToNull(plant.getPlantCode());
|
|
|
|
|
+ if (code == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ facilities.add(facility(code, "WATER_PLANT", null, null,
|
|
|
|
|
+ plant.getCommissionDate(), null));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addPumpStations(List<CockpitInfrastructureBaseArchivesSnapshot.SourceFacility> facilities) {
|
|
|
|
|
+ for (WaterPumpStation station : safeList(pumpStationService.list())) {
|
|
|
|
|
+ String code = trimToNull(station.getStationCode());
|
|
|
|
|
+ if (code == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String stationType = trimToNull(station.getStationType());
|
|
|
|
|
+ String typeCode = PumpStationType.DRAINAGE.equalsIgnoreCase(stationType)
|
|
|
|
|
+ ? "DRAINAGE_PUMP_STATION"
|
|
|
|
|
+ : PumpStationType.WATER_SUPPLY.equalsIgnoreCase(stationType)
|
|
|
|
|
+ ? "WATER_PUMP_STATION" : null;
|
|
|
|
|
+ if (typeCode == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ facilities.add(facility(code, typeCode, null, null,
|
|
|
|
|
+ station.getCommissionDate(), null));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addPipes(List<CockpitInfrastructureBaseArchivesSnapshot.SourceFacility> facilities) {
|
|
|
|
|
+ for (PipeNetworkBase pipe : safeList(pipeNetworkBaseService.list())) {
|
|
|
|
|
+ String code = trimToNull(pipe.getNetworkCode());
|
|
|
|
|
+ String typeCode = pipeType(pipe == null ? null : pipe.getNetworkType());
|
|
|
|
|
+ if (code == null || typeCode == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal lengthKm = pipe.getLength() == null
|
|
|
|
|
+ ? null : pipe.getLength().divide(BigDecimal.valueOf(1000));
|
|
|
|
|
+ LocalDate builtAt = pipe.getBuildDate() == null
|
|
|
|
|
+ ? null : new java.sql.Date(pipe.getBuildDate().getTime()).toLocalDate();
|
|
|
|
|
+ facilities.add(facility(code, typeCode, null, lengthKm, null, builtAt));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void addDrainageFacilities(
|
|
|
|
|
+ List<CockpitInfrastructureBaseArchivesSnapshot.SourceFacility> facilities) {
|
|
|
|
|
+ for (EngineeringFacility source : safeList(engineeringFacilityService.list())) {
|
|
|
|
|
+ String code = trimToNull(source.getId());
|
|
|
|
|
+ String typeCode = drainageFacilityType(source.getFacilityType());
|
|
|
|
|
+ if (code == null || typeCode == null) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ facilities.add(facility(code, typeCode, trimToNull(source.getArea()), null, null,
|
|
|
|
|
+ source.getCreateTime() == null ? null : source.getCreateTime().toLocalDate()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String pipeType(String networkType) {
|
|
|
|
|
+ String normalized = trimToNull(networkType);
|
|
|
|
|
+ if (normalized == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("2".equals(normalized)
|
|
|
|
|
+ || "WATER_SUPPLY".equalsIgnoreCase(normalized)
|
|
|
|
|
+ || "供水".equals(normalized)
|
|
|
|
|
+ || "供水管网".equals(normalized)) {
|
|
|
|
|
+ return "WATER_PIPE";
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("GAS".equalsIgnoreCase(normalized)
|
|
|
|
|
+ || "3".equals(normalized)
|
|
|
|
|
+ || "燃气".equals(normalized)
|
|
|
|
|
+ || "燃气管网".equals(normalized)) {
|
|
|
|
|
+ return "GAS_PIPE";
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("DRAINAGE".equalsIgnoreCase(normalized)
|
|
|
|
|
+ || "排水".equals(normalized)
|
|
|
|
|
+ || "排水管网".equals(normalized)
|
|
|
|
|
+ || "SEWER".equalsIgnoreCase(normalized)) {
|
|
|
|
|
+ return "DRAINAGE_PIPE";
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String drainageFacilityType(String facilityType) {
|
|
|
|
|
+ String normalized = trimToNull(facilityType);
|
|
|
|
|
+ if (normalized == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (normalized.contains("闸")) {
|
|
|
|
|
+ return "DRAINAGE_GATE";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (normalized.contains("调蓄") || normalized.contains("蓄水")) {
|
|
|
|
|
+ return "DRAINAGE_STORAGE";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (normalized.contains("泵站")) {
|
|
|
|
|
+ return "DRAINAGE_PUMP_STATION";
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static CockpitInfrastructureBaseArchivesSnapshot.SourceFacility facility(
|
|
|
|
|
+ String code,
|
|
|
|
|
+ String typeCode,
|
|
|
|
|
+ String region,
|
|
|
|
|
+ BigDecimal lengthKm,
|
|
|
|
|
+ LocalDate commissionedAt,
|
|
|
|
|
+ LocalDate builtAt) {
|
|
|
|
|
+ return new CockpitInfrastructureBaseArchivesSnapshot.SourceFacility(
|
|
|
|
|
+ code, typeCode, region, lengthKm, null, commissionedAt, builtAt);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static CockpitInfrastructureBaseArchivesSnapshot.SourceType type(
|
|
|
|
|
+ String code, String name, String industry) {
|
|
|
|
|
+ return new CockpitInfrastructureBaseArchivesSnapshot.SourceType(
|
|
|
|
|
+ code, name, industry, "FACILITY");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static <T> List<T> safeList(List<T> value) {
|
|
|
|
|
+ return value == null
|
|
|
|
|
+ ? Collections.emptyList()
|
|
|
|
|
+ : value.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static String trimToNull(String value) {
|
|
|
|
|
+ return isBlank(value) ? null : value.trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isBlank(String value) {
|
|
|
|
|
+ return value == null || value.trim().isEmpty();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|