refactor(db)!: clean up business SQL access
- make realtime replacement and analysis result writes transactional\n- consolidate SCADA repositories and remove process-global project state\n- validate SCADA batches and use indexed GIS-backed business queries\n\nBREAKING CHANGE: remove the public analysis result writer and the pipeline-health network_name query parameter.
This commit is contained in:
@@ -61,11 +61,15 @@ def _normalize_locations(sensor_location: list[str]) -> list[str]:
|
||||
def _sensor_points(
|
||||
network: str,
|
||||
sensor_location: list[str],
|
||||
*,
|
||||
nodes_by_id: dict[str, dict[str, Any]] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
nodes = sensor_placement_repository.get_sensor_placement_nodes(
|
||||
network, sensor_location
|
||||
)
|
||||
by_id = {str(node["node_id"]): node for node in nodes}
|
||||
if nodes_by_id is None:
|
||||
nodes = sensor_placement_repository.get_sensor_placement_nodes(
|
||||
network, sensor_location
|
||||
)
|
||||
nodes_by_id = {str(node["node_id"]): node for node in nodes}
|
||||
by_id = nodes_by_id
|
||||
missing = [node_id for node_id in sensor_location if node_id not in by_id]
|
||||
if missing:
|
||||
raise SensorPlacementValidationError(
|
||||
@@ -131,12 +135,26 @@ def get_sensor_placement_run(network: str, run_id: UUID) -> dict[str, Any]:
|
||||
|
||||
|
||||
def list_sensor_placement_runs(network: str) -> list[dict[str, Any]]:
|
||||
runs = sensor_placement_repository.get_all_sensor_placements(network)
|
||||
node_ids = list(
|
||||
dict.fromkeys(
|
||||
node_id
|
||||
for run in runs
|
||||
for node_id in run["sensor_locations"]
|
||||
)
|
||||
)
|
||||
nodes = sensor_placement_repository.get_sensor_placement_nodes(network, node_ids)
|
||||
nodes_by_id = {str(node["node_id"]): node for node in nodes}
|
||||
return [
|
||||
{
|
||||
**run,
|
||||
"sensor_points": _sensor_points(network, run["sensor_locations"]),
|
||||
"sensor_points": _sensor_points(
|
||||
network,
|
||||
run["sensor_locations"],
|
||||
nodes_by_id=nodes_by_id,
|
||||
),
|
||||
}
|
||||
for run in sensor_placement_repository.get_all_sensor_placements(network)
|
||||
for run in runs
|
||||
]
|
||||
|
||||
|
||||
@@ -161,7 +179,10 @@ def update_sensor_placement_run(
|
||||
if sensor_placement_repository.get_sensor_placement(network, run_id) is None:
|
||||
raise SensorPlacementNotFoundError("监测点优化运行不存在")
|
||||
raise SensorPlacementConflictError("运行结果已被其他用户修改,请重新加载")
|
||||
return get_sensor_placement_run(network, run_id)
|
||||
return {
|
||||
**updated,
|
||||
"sensor_points": _sensor_points(network, updated["sensor_locations"]),
|
||||
}
|
||||
|
||||
|
||||
def can_edit_sensor_placement(user: Any, run: dict[str, Any]) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user