- M02_Machine_Hourly.pick = 목록 › 그 기계 식 › 꼴(내 기계와 같은 규칙) · why = 값 모자란 까닭(가격 없음 · 범위 · 일 단위 손료 …) - 데이터 흐름 · 사본 모으기 · M01 · 불러오기 · 줄 쌓기 모두 pick 을 씀(데이터 흐름 옛 짝 고름 지움) - 내 기계 꼴: 전력 · 전력 + 조종원 · 직종 입력 · 손료계수 한 칸 · 직접(GC001199 — 줄 쌓기 회색 풀림) · 연료 + 전력 = 400 - M01 [새 기계] 저장 = 꼴 식 「기계」 목록에 등록 · M01 에서 만든 기계 지우면 목록에서 뺌 · 상세 「쓰는 계산식」(POST /machine/formula) · 목록 시간당 「—」 대신 까닭 글 - 미리보기 짝: 잡품 = (주연료 + 전력) × %(전력 기종 = 전력비의 %) - 시험 test_822_2 새로 · test_804_2 갈래에 전력 줄 더함(손료만 식과 전력 식은 다른 갈래 — 모르타르 믹서) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
2.8 KiB
TypeScript
78 lines
2.8 KiB
TypeScript
/* =============================================================================
|
|
* M01_MasterData_Machine_Api.ts
|
|
* M01 기계 화면 서버 호출(PLAN 821-2) — 양식 목록 · 시간당 경비 · 쓰는 곳 · 비슷한 기계 찾기 · 한 줄.
|
|
* 서버 = `M01_MasterData_Machine.py` · 시스템 관리자만.
|
|
* ========================================================================== */
|
|
|
|
import { API_BASE_URL } from "@config/config_frontend";
|
|
import type { MachinePick } from "@ui/ui_template_machine_form";
|
|
import type { 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 const fetchMachineUses = async (key: string): Promise<string[]> =>
|
|
(await get<{ uses: string[] }>("/uses", { key })).uses;
|
|
|
|
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 });
|