feat(project): 연간 목표 상·하반기 칸·반기 접기·이름 바로 수정·월 칸 병합·로아스 %

- 6월·12월 오른쪽에 상반기·하반기 칸 추가. 매출 목표·실적은 반기 합계,
  달성률은 연간과 같은 규칙, 업무 영역 글 칸은 month 13·14 로 저장
- 반기 칸 머리 버튼으로 1~6월 / 7~12월 칸을 접었다 펴기(너비 애니메이션,
  localStorage pj_goal_fold). 표를 width:1px + table-layout:fixed 로 바꿔
  펼칠 때도 애니메이션이 적용되게 함
- 업무 영역·줄 이름을 눌러 그 자리에서 수정(✎ 버튼 제거)
- 월 칸 가로 병합(goal_cell_merges, 반기 안에서만): Shift+클릭 선택 후
  병합 버튼, 우클릭 메뉴로 좌/우 병합·해제. 병합 시 글은 월 순서대로 첫 칸에 모음
- 로아스 목표·실적 칸 % 표기
- 마이그레이션 014 (goal_cells month CHECK 0~14, goal_cell_merges)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 08:24:13 +09:00
parent 91bdc12e78
commit 5d07770ce2
15 changed files with 750 additions and 88 deletions
+94 -3
View File
@@ -1840,6 +1840,11 @@ class ProjectStore:
with self._pool.connection() as conn:
return self._table_exists(conn, "goal_years")
def goals_halves_enabled(self) -> bool:
"""상·하반기 글 칸·월 칸 병합(마이그레이션 014) 적용 여부."""
with self._pool.connection() as conn:
return self._table_exists(conn, "goal_cell_merges")
def list_goal_years(self) -> list[int]:
"""목표를 만든 연도(최근 연도 먼저). 013 미적용이면 UndefinedTable."""
with self._pool.connection() as conn:
@@ -1913,7 +1918,9 @@ class ProjectStore:
"""한 해 목표 표 전체. 연도가 없으면 None.
metrics = {"sales": {"target": {1: 12.0, ...}, "actual": {...}}, "roas": {...}}
areas = [{id, name, color, rows: [{id, label, cells: {0: "연간 글", 1: "1월 글", ...}}]}]
areas = [{id, name, color, rows: [{id, label, cells: {0: "연간 글", 1: "1월 글", 13: "상반기 글", ...},
merges: {시작월: 칸 수}}]}]
halves = 마이그레이션 014 적용 여부(상·하반기 글 칸·병합)
"""
with self._pool.connection() as conn:
head = conn.execute(
@@ -1940,6 +1947,13 @@ class ProjectStore:
"WHERE a.year = %s",
(year,),
).fetchall()
halves = self._table_exists(conn, "goal_cell_merges")
merge_rows = conn.execute(
"SELECT m.row_id, m.start_month, m.span FROM goal_cell_merges m "
"JOIN goal_rows r ON r.id = m.row_id JOIN goal_areas a ON a.id = r.area_id "
"WHERE a.year = %s",
(year,),
).fetchall() if halves else []
metrics: dict[str, dict[str, dict[int, float]]] = {
m: {k: {} for k in store.GOAL_KINDS} for m in store.GOAL_METRICS
}
@@ -1948,10 +1962,15 @@ class ProjectStore:
cells: dict[int, dict[int, str]] = {}
for c in cell_rows:
cells.setdefault(int(c["row_id"]), {})[int(c["month"])] = c["body"]
merges: dict[int, dict[int, int]] = {}
for g in merge_rows:
merges.setdefault(int(g["row_id"]), {})[int(g["start_month"])] = int(g["span"])
rows_by_area: dict[int, list[dict[str, Any]]] = {}
for r in row_rows:
rid = int(r["id"])
rows_by_area.setdefault(int(r["area_id"]), []).append(
{"id": int(r["id"]), "label": r["label"], "cells": cells.get(int(r["id"]), {})}
{"id": rid, "label": r["label"], "cells": cells.get(rid, {}),
"merges": merges.get(rid, {})}
)
areas = [
{"id": int(a["id"]), "name": a["name"], "color": a["color"],
@@ -1959,7 +1978,7 @@ class ProjectStore:
for a in area_rows
]
return {"year": int(head["year"]), "sales_unit": head["sales_unit"],
"metrics": metrics, "areas": areas}
"metrics": metrics, "areas": areas, "halves": halves}
def set_goal_metric(
self, *, year: int, metric: str, kind: str, month: int, value: float | None, updated_by: str = ""
@@ -2094,6 +2113,17 @@ class ProjectStore:
with self._pool.connection() as conn:
if not conn.execute("SELECT 1 FROM goal_rows WHERE id = %s", (row_id,)).fetchone():
raise KeyError(row_id)
if m != store.GOAL_YEAR:
halves = self._table_exists(conn, "goal_cell_merges")
if m > 12 and not halves:
raise store.GoalMigration014Needed()
# 병합된 칸의 가운데·끝 월(글은 병합 시작 월에만 둔다) — 다른 창에서 병합된 뒤의 늦은 저장
if m <= 12 and halves and conn.execute(
"SELECT 1 FROM goal_cell_merges WHERE row_id = %s "
"AND start_month < %s AND start_month + span - 1 >= %s",
(row_id, m, m),
).fetchone():
raise ValueError("병합된 칸입니다. 새로고침해 주세요.")
if not text:
conn.execute("DELETE FROM goal_cells WHERE row_id = %s AND month = %s", (row_id, m))
else:
@@ -2104,6 +2134,67 @@ class ProjectStore:
(row_id, m, text, store.norm_str(updated_by, lower=True)),
)
def merge_goal_cells(self, *, row_id: int, start: Any, end: Any, updated_by: str = "") -> tuple[int, int]:
"""업무 영역 줄의 start~end 월 칸을 가로로 합친다 → (시작 월, 칸 수).
걸쳐 있는 기존 병합은 통째로 흡수한다(병합은 서로 겹치지 않고 반기 안이라 범위도 반기 안).
글은 범위 안 칸들의 글을 월 순서대로 줄바꿈으로 이어 시작 월 칸에 두고, 나머지 칸 글은 지운다."""
s, e = store.validate_goal_merge(start, end)
who = store.norm_str(updated_by, lower=True)
with self._pool.connection() as conn:
with conn.transaction():
if not self._table_exists(conn, "goal_cell_merges"):
raise store.GoalMigration014Needed()
if not conn.execute(
"SELECT 1 FROM goal_rows WHERE id = %s FOR UPDATE", (row_id,)
).fetchone():
raise KeyError(row_id)
for g in conn.execute(
"SELECT start_month, span FROM goal_cell_merges WHERE row_id = %s", (row_id,)
).fetchall():
gs, ge = int(g["start_month"]), int(g["start_month"]) + int(g["span"]) - 1
if gs <= e and ge >= s:
s, e = min(s, gs), max(e, ge)
bodies = [
str(c["body"]).strip() for c in conn.execute(
"SELECT body FROM goal_cells WHERE row_id = %s AND month BETWEEN %s AND %s "
"ORDER BY month",
(row_id, s, e),
).fetchall()
]
text = store.validate_goal_text("\n".join(b for b in bodies if b))
conn.execute(
"DELETE FROM goal_cell_merges WHERE row_id = %s AND start_month BETWEEN %s AND %s",
(row_id, s, e),
)
conn.execute(
"DELETE FROM goal_cells WHERE row_id = %s AND month BETWEEN %s AND %s",
(row_id, s, e),
)
if text:
conn.execute(
"INSERT INTO goal_cells (row_id, month, body, updated_by) VALUES (%s,%s,%s,%s)",
(row_id, s, text, who),
)
conn.execute(
"INSERT INTO goal_cell_merges (row_id, start_month, span, updated_by) "
"VALUES (%s, %s, %s, %s)",
(row_id, s, e - s + 1, who),
)
return s, e - s + 1
def unmerge_goal_cells(self, *, row_id: int, start: int) -> None:
"""병합 해제 — 글은 시작 월 칸에 그대로 남는다."""
with self._pool.connection() as conn:
if not self._table_exists(conn, "goal_cell_merges"):
raise store.GoalMigration014Needed()
row = conn.execute(
"DELETE FROM goal_cell_merges WHERE row_id = %s AND start_month = %s RETURNING row_id",
(row_id, start),
).fetchone()
if row is None:
raise KeyError(row_id)
# ════════════════════════════════════════════════════════════
# 직렬화
# ════════════════════════════════════════════════════════════