랩탑 창이 측점 design 에 pipe_length_m 을 넣어 줘서 마지막 조각이 채워짐.
B08 은 잇기만 하고 길이를 짓지 않음.
값이 어디서 오나
관 자체(있나·어디·관경·관종) → pipe_points.json (레지스트리 managed_by)
관 연장(m) → 측점 design.pipe_length_m
(B06 이 서버 Node 로 m 단위 올림까지 끝낸 값)
관종 → 공종코드 → work_item_mapping 의 pipe.kind_codes
파형강관 FP-12-11-03 · 흄관 FP-12-11-02 · VR관 FP-12-11-01
⚠ facility 가 pipe 인 점만 배관 — pipe_points.json 은 계곡 통과 시설 전부의
정본이라 BOX암거·물넘이·세월교가 같은 파일에 있음. 관경 유무로 가르면
관경 미지정 관을 놓침. 실측: 5601e828 11점 중 관 9 · 세월교 2
⚠ 관종 기본값(파형강관)은 2026-08-17 사용자 확정값이라 근거가 있으나
조용히 쓰지 않고 「기본값으로 섰습니다」를 알림에 실음
⚠ 안 붙인 것 둘 — 터파기·되메우기(관 부설과 각각 오면 같은 굴착을 두 번 셈,
B09 ㉡ 가드 자리) · 유출입부 기슭막이(관 옵션이 정본이고 구조물에서 빠졌음)
연장이 없는 관은 0 으로 때우지 않고 blocked_reason 과 함께 감
「횡단설계에서 [저장]을 한 번 누르면 그 측점의 관 길이가 남고 값이 섭니다」
시험 10건 — 세월교 걸러짐 · 관경 없어도 관임 · 연장 없으면 안 섬 ·
관종 셋이 갈림 · 기본값을 알림 · 모르는 관종은 못 고름 ·
⚠ 좁게: 옆 측점 길이를 물어 오지 않음 · 실제 자료 정본 대조
시험: 697 passed · 24 skipped (B05 코리도 1건 기존 깨짐, 무관).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
228 lines
10 KiB
Python
228 lines
10 KiB
Python
"""B08 구조물 원단위·자재총괄 조회 라우터 (일감 6·7 · PLAN 8-2·8-6·8-7).
|
|
|
|
값은 어디서 오나
|
|
치수 정본은 **`structures.json` 하나**다(B05 가 주인). B08 은 자기 치수표를 들지 않고
|
|
그 제원을 읽어 전개할 뿐이다 — 도면은 H=1.5 인데 수량은 옛 치수로 도는 사고를 막는다.
|
|
|
|
⚠ `design_owner` 가 붙은 타입은 건너뛴다
|
|
측구가 그렇다 — 횡단 설계가 이미 터파기 단면적까지 셈하므로 구조물로 또 세면 **같은 것을
|
|
두 번 계상**한다(레지스트리 주석, 2026-09-07 조사). 건너뛴 것은 숨기지 않고 응답에 적는다.
|
|
|
|
⚠ 할증은 자재총괄 한 곳뿐이다 (㉠)
|
|
원단위표는 할증 **전** 값(`surcharge_applied: False`)으로 오고, 자재총괄이 한 번 붙인다.
|
|
응답에 두 깃발이 다 실리므로 화면·B09 가 어느 쪽 값인지 헷갈릴 일이 없다.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import Any
|
|
from uuid import UUID
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from B03_FileInput.B03_FileInput_Repository import get_project_storage_relative_path
|
|
from B05_Profile.B05_Profile_Structures_Repository import load_structures
|
|
from B05_Profile.B05_Profile_Structures_Schema import structure_type_map
|
|
from B08_Quantity.B08_Quantity_Engine_Handoff import build_handoff, load_mapping, summarize
|
|
from B08_Quantity.B08_Quantity_Engine_MaterialSummary import build_table as build_material_table
|
|
from B08_Quantity.B08_Quantity_Engine_UnitQuantity import build_table as build_unit_table
|
|
from common_util.common_util_project_settings import (
|
|
concrete_placing_method,
|
|
quantity_settings,
|
|
rock_classes,
|
|
rock_method,
|
|
)
|
|
from common_util.common_util_storage import resolve_stored_project_path
|
|
from config.config_db import run_with_connection
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter(prefix="/api/projects", tags=["B08 Quantity"])
|
|
|
|
|
|
def _collect_structures(
|
|
project_root: str,
|
|
) -> tuple[list[dict[str, Any]], dict[str, str], list[str]]:
|
|
"""전개 대상 구조물·타입명·건너뛴 사유를 함께 낸다."""
|
|
_revision, items = load_structures(project_root)
|
|
types = structure_type_map()
|
|
targets: list[dict[str, Any]] = []
|
|
names: dict[str, str] = {}
|
|
skipped: list[str] = []
|
|
for item in items:
|
|
payload = item.model_dump()
|
|
type_id = str(payload.get("type_id") or "")
|
|
definition = types.get(type_id)
|
|
if definition is None:
|
|
skipped.append(f"{type_id}: 레지스트리에 없는 타입")
|
|
continue
|
|
names[type_id] = definition.name
|
|
if definition.design_owner:
|
|
skipped.append(
|
|
f"{definition.name}: {definition.design_owner} 가 이미 셈 — 중복 계상 방지"
|
|
)
|
|
continue
|
|
if definition.reference_only:
|
|
skipped.append(f"{definition.name}: 전문 상세설계 대상 — 배치까지만")
|
|
continue
|
|
targets.append(payload)
|
|
return targets, names, sorted(set(skipped))
|
|
|
|
|
|
@router.get("/{project_id}/quantity/material-summary")
|
|
async def get_material_summary(project_id: UUID) -> JSONResponse:
|
|
"""구조물 원단위와 자재총괄을 **한 응답**으로 낸다.
|
|
|
|
자재총괄은 원단위의 `material` 성분만 모은 것이라 따로 부르면 같은 전개를 두 번 돈다.
|
|
"""
|
|
try:
|
|
stored_path = await run_with_connection(get_project_storage_relative_path, project_id)
|
|
project_root = resolve_stored_project_path(stored_path)
|
|
except Exception:
|
|
logger.exception("B08 자재총괄 조회 실패(경로): project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content={"status": "error", "message": "프로젝트 저장 폴더를 찾지 못했습니다."},
|
|
)
|
|
|
|
try:
|
|
structures, names, skipped = _collect_structures(project_root)
|
|
except Exception:
|
|
logger.exception("B08 구조물 정본 읽기 실패: project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=500,
|
|
content={"status": "error", "message": "구조물 정본을 읽지 못했습니다."},
|
|
)
|
|
|
|
unit_table = build_unit_table(structures, names)
|
|
settings = quantity_settings(project_root)
|
|
material_table = build_material_table(
|
|
unit_table,
|
|
supply_map=settings.get("material_supply") or {},
|
|
)
|
|
# 묶음으로 서는 구조물의 조각을 화면에도 보인다 — 코드만으로는 사람이 검증 못 한다.
|
|
handoff = build_handoff(unit_quantity_table=unit_table)
|
|
composite = [
|
|
{
|
|
"name": row["name"],
|
|
"parts": row["composite_parts"],
|
|
"not_ready": row.get("composite_not_ready"),
|
|
}
|
|
for row in handoff["work_items"]
|
|
# 조각이 없어도(원단위 자체가 없어 못 세운 경우) 사유는 보여야 한다.
|
|
if row.get("composite_parts") or row.get("composite_not_ready")
|
|
]
|
|
return JSONResponse(
|
|
content={
|
|
"unit_quantity": unit_table,
|
|
"material": material_table,
|
|
"composite": composite,
|
|
"skipped_structures": skipped,
|
|
"structure_count": len(structures),
|
|
}
|
|
)
|
|
|
|
|
|
@router.get("/{project_id}/quantity/handoff")
|
|
async def get_handoff(project_id: UUID) -> JSONResponse:
|
|
"""B09 로 넘길 두 벌 — 작업 공종 축과 자재 축 (일감 9).
|
|
|
|
⚠ **한 벌로 합치지 않는다.** 내역 줄은 작업 공종이고 자재는 자재다.
|
|
자재에 공종코드를 붙이면 자재가 내역 줄로 오해된다(8-2 이중계상 함정).
|
|
|
|
⚠ 토공·운반은 토적표 라우터가 이미 만드는 표를 그대로 받는다 — 여기서 다시 계산하지
|
|
않는다. 같은 값을 두 벌로 짜지 않는다는 규칙(CLAUDE.md 5장)이 여기에도 걸린다.
|
|
"""
|
|
try:
|
|
stored_path = await run_with_connection(get_project_storage_relative_path, project_id)
|
|
project_root = resolve_stored_project_path(stored_path)
|
|
except Exception:
|
|
logger.exception("B08 인계 조회 실패(경로): project_id=%s", project_id)
|
|
return JSONResponse(
|
|
status_code=404,
|
|
content={"status": "error", "message": "프로젝트 저장 폴더를 찾지 못했습니다."},
|
|
)
|
|
|
|
structures, names, skipped = _collect_structures(project_root)
|
|
unit_table = build_unit_table(structures, names)
|
|
settings = quantity_settings(project_root)
|
|
material_table = build_material_table(
|
|
unit_table, supply_map=settings.get("material_supply") or {}
|
|
)
|
|
|
|
# 토공·운반 표는 토적표 라우터의 것을 그대로 쓴다 — 여기서 다시 만들지 않는다.
|
|
earthwork = await _earthwork_tables(project_id)
|
|
|
|
handoff = build_handoff(
|
|
summary_table=earthwork.get("summary"),
|
|
haul_table=earthwork.get("haul"),
|
|
unit_quantity_table=unit_table,
|
|
material_table=material_table,
|
|
# 준비공·사방공 — 값이 서는 줄도, 못 내는 줄도 함께 넘긴다(빼면 빠진 줄이 안 보임).
|
|
preparation_table=earthwork.get("preparation"),
|
|
# 배수관 — 관 정본은 `pipe_points.json`, 연장은 측점 `design.pipe_length_m` 다.
|
|
pipe_table=_pipe_table(project_root, earthwork.get("pipe_lengths") or []),
|
|
ground_class_set=settings.get("rock_class_set"),
|
|
ground_classes=rock_classes(settings),
|
|
ground_methods={name: rock_method(settings, name) for name in rock_classes(settings)},
|
|
# 타설 방식 — 안 정했으면 기본값으로 서되 그 사실을 `placing_notes` 가 알린다.
|
|
concrete_placing_method=concrete_placing_method(settings)[0],
|
|
)
|
|
handoff["summary"] = summarize(handoff)
|
|
handoff["skipped_structures"] = skipped
|
|
handoff["earthwork_available"] = bool(earthwork)
|
|
return JSONResponse(content=handoff)
|
|
|
|
|
|
def _pipe_table(project_root: str, pipe_lengths: list[dict[str, Any]]) -> dict[str, Any]:
|
|
"""배수관 표 — 정본 셋을 읽어 잇는다. 못 읽으면 **빈 표**(줄이 안 서는 것이 정직하다).
|
|
|
|
⚠ 관 정본은 `structures.json` 이 아니라 `pipe_points.json` 이다
|
|
(레지스트리 `pipe` 타입이 `managed_by: pipe_points`).
|
|
"""
|
|
from B08_Quantity.B08_Quantity_Engine_Pipe import build_rows as build_pipe_rows
|
|
from common_util.common_util_drainage_pipes import pipe_points_path_in
|
|
|
|
path = pipe_points_path_in(Path(project_root))
|
|
if not path.is_file():
|
|
return {"rows": [], "notes": [], "pipe_count": 0, "ready_count": 0, "length_total_m": 0.0}
|
|
try:
|
|
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
except (OSError, ValueError):
|
|
logger.exception("B08 관 지점 읽기 실패: %s", path)
|
|
return {
|
|
"rows": [],
|
|
"notes": ["관 지점 파일을 읽지 못했습니다"],
|
|
"pipe_count": 0,
|
|
"ready_count": 0,
|
|
"length_total_m": 0.0,
|
|
}
|
|
points = payload.get("points") or payload.get("items") or []
|
|
# 토적표 라우터가 실어 준 모양을 엔진이 읽는 모양으로 옮긴다.
|
|
designs = [
|
|
{"chainage_m": row.get("chainage_m"), "design": {"pipe_length_m": row.get("pipe_length_m")}}
|
|
for row in pipe_lengths
|
|
]
|
|
return build_pipe_rows(points, designs, (load_mapping().pipe or {}))
|
|
|
|
|
|
async def _earthwork_tables(project_id: UUID) -> dict[str, Any]:
|
|
"""토적표 라우터가 만든 집계·운반 표를 얻는다. 노선이 없으면 빈 값."""
|
|
from B08_Quantity.B08_Quantity_Router_Earthwork import (
|
|
get_earthwork_table_for_current_route,
|
|
)
|
|
|
|
try:
|
|
response = await get_earthwork_table_for_current_route(project_id)
|
|
except Exception:
|
|
logger.exception("B08 인계 — 토적표 조회 실패: project_id=%s", project_id)
|
|
return {}
|
|
if response.status_code != 200:
|
|
return {}
|
|
import json as _json
|
|
|
|
return _json.loads(bytes(response.body).decode("utf-8"))
|