fix(b06): 관 종류 바꿈 = 그 측점 옛 조정값(세션 아홉 칸 · 미리 뜬 횡단 사본) 버림 · [저장] 때 structure_reset 으로 정본 옛 조정값 비움 · 같은 행 여러 줄 이어 얹음(CASE 첫 WHEN 만 쓰던 것) (318-4 · 요구 216)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C6BNBFXFndbqYxu6sZuknK
This commit is contained in:
@@ -37,7 +37,7 @@ async def merge_cross_section_designs(
|
||||
"""측점 여러 곳의 `data.design` 을 한 번에 쓴다. 실제로 바뀐 행 수를 돌려준다.
|
||||
|
||||
`replace=True` 면 design 을 통째로 갈아 끼우고(`update_cross_section_design` 과 같은 뜻),
|
||||
`False` 면 키만 얹는다(`merge_cross_section_design_patch` 와 같은 뜻).
|
||||
`False` 면 키만 얹는다(`merge_cross_section_design_patch` 와 같은 뜻 · 값 None = 그 키 지움).
|
||||
|
||||
행이 없는 측점은 `project_id` 가 오면 새로 만든다 — 구조물(비정규) 측점은 B05 확정이
|
||||
파일만 쓰고 DB 행을 안 만들기 때문이다(한 행짜리 함수와 같은 규칙).
|
||||
@@ -66,14 +66,20 @@ async def merge_cross_section_designs(
|
||||
best = row_id
|
||||
return best
|
||||
|
||||
updates: list[tuple[int, str]] = []
|
||||
# 행마다 한 벌 — 같은 행에 여러 줄이 오면 앞 줄 결과 위에 얹음(`CASE id` 는 첫 WHEN 만 씀 ·
|
||||
# 318-4 옛 조정값 비움 뒤 새 값)
|
||||
updates: dict[int, str] = {}
|
||||
inserts: list[tuple[str, int, float, str]] = []
|
||||
for chainage_m, payload in entries:
|
||||
if not payload and not replace:
|
||||
continue
|
||||
# 얹기의 None = 그 열쇠 지움(JSON merge-patch · 318-4 관 종류 바꿈 옛 조정값)
|
||||
drop = [] if replace else [key for key, value in payload.items() if value is None]
|
||||
if drop:
|
||||
payload = {key: value for key, value in payload.items() if value is not None}
|
||||
row_id = find(chainage_m)
|
||||
if row_id is None:
|
||||
if project_id is None:
|
||||
if project_id is None or not (payload or replace):
|
||||
continue
|
||||
inserts.append(
|
||||
(
|
||||
@@ -91,8 +97,11 @@ async def merge_cross_section_designs(
|
||||
design = data.get("design")
|
||||
design = dict(design) if isinstance(design, dict) else {}
|
||||
design.update(payload)
|
||||
for key in drop:
|
||||
design.pop(key, None)
|
||||
data["design"] = design
|
||||
updates.append((row_id, json.dumps(data, ensure_ascii=False)))
|
||||
existing[row_id] = data
|
||||
updates[row_id] = json.dumps(data, ensure_ascii=False)
|
||||
|
||||
written = 0
|
||||
async with connection.cursor() as cursor:
|
||||
@@ -100,9 +109,9 @@ async def merge_cross_section_designs(
|
||||
# 한 문장 — `CASE id WHEN … THEN …` 이라 왕복이 한 번이다.
|
||||
cases = " ".join("WHEN %s THEN %s" for _ in updates)
|
||||
params: list[Any] = []
|
||||
for row_id, blob in updates:
|
||||
for row_id, blob in updates.items():
|
||||
params.extend((row_id, blob))
|
||||
params.extend(row_id for row_id, _ in updates)
|
||||
params.extend(updates)
|
||||
placeholders = ", ".join("%s" for _ in updates)
|
||||
await cursor.execute(
|
||||
f"UPDATE cross_sections SET data = CASE id {cases} END "
|
||||
|
||||
Reference in New Issue
Block a user