Files
Aislo/M02_MasterTemplete/M02_MasterTemplete_Hopyo_Api.ts
T
eomsangdonandClaude Opus 5.5 cf4e2a0339 refactor(785-7): 옛 맞춤 화면 TS 지움 · 옛 [저장] · [모두 고정] 단추 걷음 · 390 줄 판 높이
- 지움(git rm) 15 파일 3,318 줄: Hopyo_Check · CheckRows · Choose · WizardSk · SkApi · SkLines · logic/SkPick · logic/Draft ·
  Left · Lost · Pick · SheetMake · Kids · ToItem · Compare(모두 옛 확인 창 · 마법사 단가산출 · 안 이은 줄 길 몫 · 부르는 곳 0)
- 단추 판단: 엑셀 보기 [저장](체크 호표) · [모두 고정으로 들여오기] 화면 단추 걷음 → 만들기 = [옮기기] 하나 ·
  모두 고정 서버 길(Builder · build_all)은 B09 · 붙여넣기가 써서 남김 · 목록 체크 칸 · 모달 껍데기(openHopyoSheet · raise · lower) 걷음
- Import: 「안 이은 줄」 띠 · [안 이은 줄 고르기] · 남은 줄 셈 걷음 · [끝내기] = 물음(확인하고 안 옮긴 수 = 판정 고름 캐시 moveBody)
- Api: 옛 맞춤 타입 · 길(readHopyoOne · guessHopyo · buildHopyo · buildHopyoAll · leftHopyo · listHopyoPicks · hopyoSiblings ·
  buildHopyoItem …) 걷음 · POLL_MS · HOPYO_BUILT 옮겨 옴 · 목록 꼴 = 1차 판정 줄상태(Judge.view)
- Labor_Pick: withHopyo(실무 호표 덧줄) → withSangeun(찾아 넣기 창 표시만) · Detail · Table 부름 바꿈
- Ledger: unitField 옮겨 옴 · SheetNav: 옛 확인 캐시 칠 걷음 · UI_Page: [구조물 조합으로] 듣기 걷음
- CSS: 옛 확인 창 · 고르기 창 규칙 34 걷음(481 → 287 줄) · 390 폭 = 줄 판 열리면 위 칸 넓힘 · 줄 판 높이 바닥 16rem

시험 정리(까닭 = 지운 화면 파일만 읽음):
- 지움: test_729_3_hopyo_left_screen · test_746_2_hopyo_compare_screen · test_778_5_sk_pick_screen · helper_729_3 · helper_m02_hopyo_check · pick · seam
- test_m02_hopyo_screen = 좌측 판 · 끝내기 둘만 · 627 · helper_778_5 = SheetSk 판 바꿈만 · 785_4 · 721 · 717_4 · 720 · 739_1 = 지금 꼴로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 01:32:17 +09:00

259 lines
8.9 KiB
TypeScript

/* =============================================================================
* M02_MasterTemplete_Hopyo_Api.ts
* 일위대가 실무자료(PLAN 324 · 338) 서버 길 — `/api/m02/layers/{층}/hopyo…` · 층 = 화면 층(`Api_Fetch` 지금 층) ·
* 올리기 = FormData(숨은 file 입력) · 그 밖 = 공용 `call`(서버 까닭 글 그대로) ·
* 목록 · 올림 · 엑셀 보기 머리(1차 판정 줄상태) · 격자 · 지우기 · 별칭 장부 · 붙여넣기 · 다시 잇기 —
* 판정 · 검산 · 옮기기 길 = `Hopyo_JudgeApi` · 옛 맞춤 꼴(줄 맞춤 · 확인 만들기 · 실무 호표)은 785-7 에서 지움.
* ========================================================================== */
import { API_BASE_URL } from "@config/config_frontend";
import type { Workbook } from "../A00_Common/spreadsheet/spreadsheet";
import { call, getActiveLayer, getActiveOwner, type Layer } from "./M02_MasterTemplete_Api_Fetch";
import type { LaborFixed } from "./M02_MasterTemplete_Labor_Calc";
/** 뒤 셈 중 다시 읽기 사이(밀리초) */
export const POLL_MS = 3000;
/** 사전조합 · 단가산출을 만들었음(document 알림) — 좌측 목록 · 엑셀 보기 칠 다시 */
export const HOPYO_BUILT = "m02-hopyo-built";
/** 층 · 주인(null = 자기 층) */
export interface HopyoScope {
layer: Layer;
owner: string | null;
}
export interface HopyoFile {
키: string;
파일: string;
올린때: string;
올린이: { id: number; 이름: string | null } | null;
시트: string;
호표수: number;
어긋남: number;
}
export type Money = Record<"계" | "노무비" | "재료비" | "경비", number | null>;
export interface HopyoBrief {
번: number;
이름: string;
규격: string;
단위: string;
금액: Money;
/** [1차 판정 제안 있음 수, 줄 수](785-7 `Judge.view`) */
맞춤: [number, number];
/** 줄마다 [차례, 1차 판정, 제안 있음] · 만든 SC 키(칠 · `SheetMap.BriefMarks`) */
줄상태?: [number, string, boolean][];
만든?: string | null;
/** 일위대가 시트 행 [시작, 끝](엑셀 1부터 · 329 · 옛 파일 없음) */
행?: [number, number];
}
/** 엑셀 보기 창 목록 한 줄 — 호표 · 단가산출 블록 행 범위 */
export interface HopyoSpan {
번: number;
이름: string;
행: [number, number];
}
/** 엑셀 보기 창 격자(329) — 시트 「일위대가」 · 「단가산출」 */
export interface HopyoGrid {
책: Workbook;
호표: HopyoSpan[];
단산: HopyoSpan[];
}
export interface HopyoView extends HopyoFile {
검산: { 어긋남: string[]; 총괄표: number };
호표: HopyoBrief[];
맞춤: [number, number];
/** 블록 풀이 뒤 셈(785-5 파생 저장본 · 끝 = 판정 칠 다 셈) */
셈?: { 끝: boolean; 까닭?: string };
}
/** [모두 고정으로 들여오기] 결과(705-3) */
export interface HopyoBuiltAll {
호표: number;
줄: number;
품셈: number;
고정: number;
호표참조: number;
빠짐: number;
이음: number;
이음후보: number;
같음: number;
그대로: number;
다름: {
번: number;
이름: string;
엑셀: number | null;
우리: number | null;
차이: number | null;
}[];
실패: { 번: number; 까닭: string }[];
/** 만든 · 그대로 둔 사전조합(705-2 · 다시 잇기) */
만듦?: { 번: number; 이름: string; 키: string }[];
}
/** 별칭 장부 짝 하나 */
export interface LedgerPair {
로직?: string;
자재?: string;
입력값: Record<string, unknown>;
배: number;
몫: number | null;
}
/** 별칭 장부 한 줄(쓰기 꼴) */
export interface LedgerEntry {
원래: { 품명: string; 규격: string; 단위: string };
갈래: "짝" | "우리에 없음" | "안 씀";
짝: LedgerPair[];
엑셀조항?: unknown[];
}
/** 별칭 장부 보기 한 줄 — 층 · 고침(이 층 · 쓰기 권한) */
export interface LedgerRow extends LedgerEntry {
열쇠: string;
누가: { id: number; 이름: string | null } | null;
때: string | null;
처음파일: string | null;
층: Layer;
주인: string | null;
고침: boolean;
/** 739-1 M01 승인 상태 — 마스터 줄 = 승인 */
상태?: "승인" | "대기" | "반려";
}
const enc = encodeURIComponent;
/** 지금 화면 층(구조물 조합 층) */
export const pageScope = (): HopyoScope => ({ layer: getActiveLayer(), owner: getActiveOwner() });
export const at = (scope: HopyoScope, path: string): string => {
const who = scope.owner && scope.layer !== "system" ? `owner=${enc(scope.owner)}` : "";
const join = path.includes("?") ? "&" : "?";
return `/layers/${scope.layer}${path}${who ? join + who : ""}`;
};
export const listHopyo = async (scope: HopyoScope): Promise<HopyoFile[]> =>
(await call<{ 줄: HopyoFile[] }>(at(scope, "/hopyo"))).줄;
export const readHopyo = (scope: HopyoScope, key: string): Promise<HopyoView> =>
call(at(scope, `/hopyo/${enc(key)}`));
/** 격자 — 없으면 404 「격자 없음 — 다시 올리면 보임」(옛 파일) */
export const readHopyoGrid = (scope: HopyoScope, key: string): Promise<HopyoGrid> =>
call(at(scope, `/hopyo-grid/${enc(key)}`));
export const readLedger = async (scope: HopyoScope): Promise<LedgerRow[]> =>
(await call<{ 줄: LedgerRow[] }>(at(scope, "/hopyo-ledger"))).줄;
/** 별칭 장부 [저장] — 고친 줄 · null(지움) · 이 층만 */
export const saveLedger = async (
scope: HopyoScope,
줄: Record<string, LedgerEntry | null>,
): Promise<LedgerRow[]> =>
(
await call<{ 줄: LedgerRow[] }>(at(scope, "/hopyo-ledger"), {
method: "PUT",
body: JSON.stringify({ 줄 }),
})
).줄;
/** [끝내기] · 화면 떠남(743-1) — `keepalive` = 페이지를 닫아도 요청은 감 */
export const deleteHopyo = (scope: HopyoScope, key: string, keepalive = false): Promise<unknown> =>
call(at(scope, `/hopyo/${enc(key)}`), { method: "DELETE", keepalive });
/** 엑셀 올리기 — 서버 까닭 글 그대로(시트 없음 · 20 MB · 엉터리) */
export async function uploadHopyo(scope: HopyoScope, file: File): Promise<HopyoFile> {
const form = new FormData();
form.append("file", file);
const response = await fetch(`${API_BASE_URL}/m02${at(scope, "/hopyo")}`, {
method: "POST",
credentials: "include",
body: form,
});
const body = (await response.json().catch(() => ({}))) as { detail?: unknown } & HopyoFile;
if (!response.ok)
throw new Error(typeof body.detail === "string" ? body.detail : `HTTP ${response.status}`);
return body;
}
/** 엑셀 붙여넣기 열 짝(705-2) — 칸 차례(0부터) · 노 · 재 · 경 = 단가 칸 · 금액 = 합계 금액 칸 */
export type PasteCols = Partial<
Record<"품명" | "규격" | "수량" | "단위" | "금액" | "노" | "재" | "경", number>
>;
/** 붙여넣기 답 — 물음(열 짝 짐작 + 보기) · 줄(고정 줄 · 문서에 넣음) · 만듦(호표마다 사전조합) */
export type PasteResult =
| { 갈래: "물음"; 열: PasteCols; 짐작: boolean; 보기: string[][] }
| {
갈래: "줄";
열: PasteCols;
줄: { 고정: LaborFixed; 별칭: string | null; 메모: string; 수량: { 손: number | null } }[];
엑셀: number;
이음: number;
이음후보: number;
}
| ({ 갈래: "만듦"; 열: PasteCols; 키: string } & HopyoBuiltAll);
/** [Ctrl+V](705-2) — 붙인 글 그대로(숫자는 서버가 글에서) */
export const pasteHopyo = (
scope: HopyoScope,
글: string,
열: PasteCols | null,
opt: { 줄만?: boolean; 있음?: string[] } = {},
): Promise<PasteResult> =>
call(at(scope, "/hopyo-paste"), {
method: "POST",
body: JSON.stringify({ 글, ...(열 ? { 열 } : {}), ...opt }),
});
/** 다시 잇기 표 한 줄(705-2) — 붙인 단가 · 이은 단가(지금) · 후보 */
export interface RelinkRow {
키: string | null;
줄: string;
이름: string;
규격: string;
단위: string;
수량: number | null;
붙인: Record<"노무비" | "재료비" | "경비", number>;
이음: Record<"노임" | "자재", string | null>;
지금: Partial<Record<"노임" | "자재", number | null>>;
후보: {
비목: "노임" | "자재";
키: string;
이름: string;
규격: string;
단위: string;
단가: number | null;
}[];
}
/** 바꿈 한 줄 — 값 null = 이음 풂 */
export interface RelinkChange {
키: string;
줄: string;
노임?: string | null;
자재?: string | null;
}
export const relinkRows = async (
scope: HopyoScope,
body: { 키?: string[]; 문서?: unknown },
): Promise<RelinkRow[]> =>
(
await call<{ 줄: RelinkRow[] }>(at(scope, "/hopyo-relink/rows"), {
method: "POST",
body: JSON.stringify(body),
})
).줄;
export const relinkApply = (
scope: HopyoScope,
바꿈: RelinkChange[],
): Promise<{
바뀜: number;
문서: { 키: string; 이름: string; 전: number | null; 후: number | null }[];
되돌림: RelinkChange[];
}> => call(at(scope, "/hopyo-relink"), { method: "POST", body: JSON.stringify({ 바꿈 }) });