|
@@ -16,7 +16,6 @@ import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
-import java.util.HashSet;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -24,6 +23,7 @@ import java.util.Set;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
|
|
|
+ private static final List<String> TYPE_ORDER = List.of("source", "plant", "pumpStation", "pipe", "user");
|
|
|
private static final Set<String> SUPPORTED_TYPES = Set.of("source", "plant", "pumpStation", "pipe", "user");
|
|
private static final Set<String> SUPPORTED_TYPES = Set.of("source", "plant", "pumpStation", "pipe", "user");
|
|
|
private static final Map<String, String> TYPE_NAMES = Map.of("source", "水源地", "plant", "水厂", "pumpStation", "泵站", "pipe", "供水管网", "user", "用水户");
|
|
private static final Map<String, String> TYPE_NAMES = Map.of("source", "水源地", "plant", "水厂", "pumpStation", "泵站", "pipe", "供水管网", "user", "用水户");
|
|
|
|
|
|
|
@@ -62,18 +62,44 @@ public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
|
@Override
|
|
@Override
|
|
|
public List<GisOverviewItemDTO> getOverview() {
|
|
public List<GisOverviewItemDTO> getOverview() {
|
|
|
List<GisOverviewItemDTO> rows = mapper.selectOverview();
|
|
List<GisOverviewItemDTO> rows = mapper.selectOverview();
|
|
|
- if (rows == null || rows.isEmpty()) return Collections.emptyList();
|
|
|
|
|
|
|
+ Map<String, GisOverviewItemDTO> rowsByType = rows == null
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : rows.stream().collect(java.util.stream.Collectors.toMap(
|
|
|
|
|
+ GisOverviewItemDTO::getFacilityType,
|
|
|
|
|
+ item -> item,
|
|
|
|
|
+ (left, right) -> left));
|
|
|
|
|
+ List<GisOverviewItemDTO> result = new ArrayList<>();
|
|
|
|
|
+ for (String type : TYPE_ORDER) {
|
|
|
|
|
+ GisOverviewItemDTO item = rowsByType.getOrDefault(type, emptyOverviewItem(type));
|
|
|
|
|
+ item.setTotalCount(zeroIfNull(item.getTotalCount()));
|
|
|
|
|
+ item.setGeoCompleteCount(zeroIfNull(item.getGeoCompleteCount()));
|
|
|
|
|
+ item.setGeoMissingCount(zeroIfNull(item.getGeoMissingCount()));
|
|
|
|
|
+ result.add(item);
|
|
|
|
|
+ }
|
|
|
GisOverviewItemDTO total = new GisOverviewItemDTO();
|
|
GisOverviewItemDTO total = new GisOverviewItemDTO();
|
|
|
total.setFacilityType("total");
|
|
total.setFacilityType("total");
|
|
|
total.setFacilityTypeName("合计");
|
|
total.setFacilityTypeName("合计");
|
|
|
- total.setTotalCount(rows.stream().mapToLong(item -> item.getTotalCount() == null ? 0 : item.getTotalCount()).sum());
|
|
|
|
|
- total.setGeoCompleteCount(rows.stream().mapToLong(item -> item.getGeoCompleteCount() == null ? 0 : item.getGeoCompleteCount()).sum());
|
|
|
|
|
- total.setGeoMissingCount(rows.stream().mapToLong(item -> item.getGeoMissingCount() == null ? 0 : item.getGeoMissingCount()).sum());
|
|
|
|
|
- List<GisOverviewItemDTO> result = new ArrayList<>(rows);
|
|
|
|
|
|
|
+ total.setTotalCount(result.stream().mapToLong(GisOverviewItemDTO::getTotalCount).sum());
|
|
|
|
|
+ total.setGeoCompleteCount(result.stream().mapToLong(GisOverviewItemDTO::getGeoCompleteCount).sum());
|
|
|
|
|
+ total.setGeoMissingCount(result.stream().mapToLong(GisOverviewItemDTO::getGeoMissingCount).sum());
|
|
|
result.add(total);
|
|
result.add(total);
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private GisOverviewItemDTO emptyOverviewItem(String type) {
|
|
|
|
|
+ GisOverviewItemDTO item = new GisOverviewItemDTO();
|
|
|
|
|
+ item.setFacilityType(type);
|
|
|
|
|
+ item.setFacilityTypeName(TYPE_NAMES.get(type));
|
|
|
|
|
+ item.setTotalCount(0L);
|
|
|
|
|
+ item.setGeoCompleteCount(0L);
|
|
|
|
|
+ item.setGeoMissingCount(0L);
|
|
|
|
|
+ return item;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private long zeroIfNull(Long value) {
|
|
|
|
|
+ return value == null ? 0L : value;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public GisFeatureDTO toPipeFeature(Map<String, Object> row) {
|
|
public GisFeatureDTO toPipeFeature(Map<String, Object> row) {
|
|
|
GisFeatureDTO feature = baseFeature("pipe", row);
|
|
GisFeatureDTO feature = baseFeature("pipe", row);
|
|
@@ -90,6 +116,7 @@ public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
|
private void addPointFeatures(GisFeatureCollectionDTO collection, String type, List<Map<String, Object>> rows) {
|
|
private void addPointFeatures(GisFeatureCollectionDTO collection, String type, List<Map<String, Object>> rows) {
|
|
|
if (rows == null) return;
|
|
if (rows == null) return;
|
|
|
for (Map<String, Object> row : rows) {
|
|
for (Map<String, Object> row : rows) {
|
|
|
|
|
+ if (!hasValues(row, "longitude", "latitude")) continue;
|
|
|
GisFeatureDTO feature = baseFeature(type, row);
|
|
GisFeatureDTO feature = baseFeature(type, row);
|
|
|
Map<String, Object> geometry = new LinkedHashMap<>();
|
|
Map<String, Object> geometry = new LinkedHashMap<>();
|
|
|
geometry.put("type", "Point");
|
|
geometry.put("type", "Point");
|
|
@@ -100,7 +127,15 @@ public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void addPipeFeatures(GisFeatureCollectionDTO collection, List<Map<String, Object>> rows) {
|
|
private void addPipeFeatures(GisFeatureCollectionDTO collection, List<Map<String, Object>> rows) {
|
|
|
- if (rows != null) for (Map<String, Object> row : rows) collection.getFeatures().add(toPipeFeature(row));
|
|
|
|
|
|
|
+ if (rows != null) {
|
|
|
|
|
+ for (Map<String, Object> row : rows) {
|
|
|
|
|
+ if (!hasCoordinate(row, "startLongitude", "start_longitude")
|
|
|
|
|
+ || !hasCoordinate(row, "startLatitude", "start_latitude")
|
|
|
|
|
+ || !hasCoordinate(row, "endLongitude", "end_longitude")
|
|
|
|
|
+ || !hasCoordinate(row, "endLatitude", "end_latitude")) continue;
|
|
|
|
|
+ collection.getFeatures().add(toPipeFeature(row));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private GisFeatureDTO baseFeature(String type, Map<String, Object> row) {
|
|
private GisFeatureDTO baseFeature(String type, Map<String, Object> row) {
|
|
@@ -132,4 +167,13 @@ public class WaterSupplyGisMapServiceImpl implements WaterSupplyGisMapService {
|
|
|
Object value = value(row, keys);
|
|
Object value = value(row, keys);
|
|
|
return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString());
|
|
return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private boolean hasValues(Map<String, Object> row, String... keys) {
|
|
|
|
|
+ for (String key : keys) if (value(row, key) == null) return false;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean hasCoordinate(Map<String, Object> row, String... aliases) {
|
|
|
|
|
+ return value(row, aliases) != null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|