feat(sensor): 返回候选节点最大管径

This commit is contained in:
2026-08-03 19:00:00 +08:00
parent b0e9d480ef
commit 1432934f12
8 changed files with 203 additions and 5 deletions
+16 -1
View File
@@ -66,8 +66,22 @@ def get_sensor_placement_nodes(
with conn.cursor(row_factory=dict_row) as cur:
cur.execute(
"""
WITH incident_pipe_diameters AS (
SELECT node_id, MAX(diameter) AS max_pipe_diameter
FROM (
SELECT node1 AS node_id, diameter
FROM pipes
WHERE node1 = ANY(%s)
UNION ALL
SELECT node2 AS node_id, diameter
FROM pipes
WHERE node2 = ANY(%s)
) AS incident_pipes
GROUP BY node_id
)
SELECT DISTINCT ON (gj.id)
gj.id AS node_id,
ipd.max_pipe_diameter,
gj.elevation,
ST_X(c.coord) AS project_x,
ST_Y(c.coord) AS project_y,
@@ -75,10 +89,11 @@ def get_sensor_placement_nodes(
ST_Y(gj.geom) AS map_y
FROM geo_junctions_mat AS gj
JOIN coordinates AS c ON c.node = gj.id
LEFT JOIN incident_pipe_diameters AS ipd ON ipd.node_id = gj.id
WHERE gj.id = ANY(%s)
ORDER BY gj.id
""",
(node_ids,),
(node_ids, node_ids, node_ids),
)
return list(cur.fetchall())