- 쓰는 곳 색인(M01_MasterData_Machine_Uses) — 수식 문서 기계 고르기 목록 · 박힌 입력(집게 · 브레이커 포함) · EQ 요소 = 직접 · 기본 선택 · 부름 사슬 따로 · 655 대 조사 목록과 다름 0 - 단가산출 역색인 — 모든 층 + 프로젝트 사본 · 사본 단가 기계 · 바탕(원본 · 부름) · 덮음(② 내 고침 · ① 위덮음 848-1 계약) · 파일 자국 기억 · 파생 저장본(지워도 다시 지음) - 영향 셈(M01_MasterData_Machine_Impact) — 저장과 같은 손질 뒤 고친 기계를 얹은 얕은 복사 마스터로 영향 기초만 전 · 후 셈 · 바뀐 기초 수 · 크게 바뀐 다섯 · 정본 기억 안 건드림 - M01 페이지 [저장] 전 확인창 · 기계 상세 쓰는 곳 표시 새 꼴 · 내 기계 [저장] 전 확인창(이 층 쓰는 단가산출 · 따로 고친 곳) - [새 기계] 저장 = 로직 목록과 같은 더함 · 뺌을 수식 문서 기계 고르기 목록에도 - 옛 「쓰는 곳」(로직 JSON 입력 이름 「기계」 · 글자 찾기) 걷음 - 시험: test_848_5 새로 · test_821_2 · test_822_2 임시 폴더에 수식 문서도 복사(새 기계 저장이 문서 목록도 고쳐 정본 폴더에 쓰지 않게) · test_821_2 쓰는 곳 = 임시 storage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
4.2 KiB
TypeScript
120 lines
4.2 KiB
TypeScript
/* =============================================================================
|
|
* M01_MasterData_Machine_Api.ts
|
|
* M01 기계 화면 서버 호출(PLAN 821-2) — 양식 목록 · 시간당 경비 · 쓰는 곳 · 저장 전 영향(848-5) ·
|
|
* 비슷한 기계 찾기 · 한 줄.
|
|
* 서버 = `M01_MasterData_Machine.py` · 시스템 관리자만.
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import type { MachinePick } from "../common_util/common_util_machine_sheet";
|
|
import type { FileChanges, Row } from "./M01_MasterData_Api_Fetch";
|
|
|
|
export interface MachineLists {
|
|
fuels: MachinePick[];
|
|
jobs: MachinePick[];
|
|
power: number;
|
|
hour: number;
|
|
books: string[];
|
|
/** 구분 → 원문 */
|
|
groups: Record<string, string>;
|
|
}
|
|
|
|
export interface MachineHourly {
|
|
노무비?: number;
|
|
재료비?: number;
|
|
경비?: number;
|
|
계?: number;
|
|
reason?: string;
|
|
}
|
|
|
|
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
|
|
const query = new URLSearchParams(params);
|
|
const res = await fetch(`${API_BASE_URL}/m01/machine${path}?${query}`, {
|
|
credentials: "include",
|
|
});
|
|
const body = (await res.json()) as T & { detail?: unknown };
|
|
if (!res.ok) throw new Error(String(body.detail ?? `HTTP ${res.status}`));
|
|
return body;
|
|
}
|
|
|
|
let lists: Promise<MachineLists> | null = null;
|
|
/** 한 번 받아 둠(페이지 다시 그리면 다시 받음) */
|
|
export const fetchMachineLists = (fresh = false): Promise<MachineLists> => {
|
|
if (!lists || fresh)
|
|
lists = get<MachineLists>("/lists").catch((e) => ((lists = null), Promise.reject(e)));
|
|
return lists;
|
|
};
|
|
|
|
export const fetchMachineHourly = (keys: string[]): Promise<Record<string, MachineHourly>> =>
|
|
keys.length ? get("/hourly", { keys: keys.join(",") }) : Promise.resolve({});
|
|
|
|
/** 단가산출 층별 수(이름 없음 — 남의 층 이름 안 냄) */
|
|
export type LayerCounts = Record<"마스터" | "회사" | "개인" | "프로젝트", number>;
|
|
|
|
/** 쓰는 곳(848-5 · 수식 문서 기준) — uses = 직접 쓰는 기초 글 */
|
|
export interface MachineUses {
|
|
uses: string[];
|
|
직접: number;
|
|
기본: number;
|
|
사슬: number;
|
|
고침: { 기초: number; 단가산출: number; 위층: number };
|
|
단가산출: LayerCounts;
|
|
}
|
|
|
|
export const fetchMachineUses = (key: string): Promise<MachineUses> => get("/uses", { key });
|
|
|
|
/** 저장 전 영향(848-5) — 기계마다 수 · 금액 바뀐 기초 수 · 크게 바뀐 다섯 */
|
|
export interface MachineImpact {
|
|
기계: {
|
|
키: string;
|
|
이름: string;
|
|
규격: string;
|
|
칸: string[];
|
|
직접: number;
|
|
사슬: number;
|
|
고침: { 기초: number; 단가산출: number; 위층: number };
|
|
단가산출: LayerCounts;
|
|
}[];
|
|
바뀜: number;
|
|
셈: number;
|
|
위: { 키: string; 이름: string; 단위: string; 전: number | null; 후: number | null }[];
|
|
}
|
|
|
|
export async function fetchMachineImpact(files: FileChanges[]): Promise<MachineImpact> {
|
|
const res = await fetch(`${API_BASE_URL}/m01/machine/impact`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ files }),
|
|
});
|
|
const body = (await res.json()) as MachineImpact & { detail?: unknown };
|
|
if (!res.ok) throw new Error(String(body.detail ?? `HTTP ${res.status}`));
|
|
return body;
|
|
}
|
|
|
|
export const findMachines = async (q: string): Promise<Row[]> =>
|
|
(await get<{ rows: Row[] }>("/find", { q })).rows;
|
|
|
|
/** 쓰는 계산식(822-2) — 방법 = 목록 · 꼴 · 그 기계 식 · 까닭 = 값이 모자란 칸 */
|
|
export interface MachineFormula {
|
|
키?: string;
|
|
이름?: string;
|
|
방법: "목록" | "꼴" | "그 기계 식";
|
|
까닭: string;
|
|
}
|
|
|
|
export async function fetchMachineFormula(row: Row): Promise<MachineFormula> {
|
|
const res = await fetch(`${API_BASE_URL}/m01/machine/formula`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(row),
|
|
});
|
|
const body = (await res.json()) as MachineFormula & { detail?: unknown };
|
|
if (!res.ok) throw new Error(String(body.detail ?? `HTTP ${res.status}`));
|
|
return body;
|
|
}
|
|
|
|
export const fetchMachineRow = (key: string): Promise<{ version: string; row: Row }> =>
|
|
get("/row", { key });
|