feat(m02-df): 입력 판 인력 · 기계 · 유가전력 조건 찾기(이름 또는 키 같음) — 방식 고르기 · 미리 보기

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ACSGaHdLgnkEkoA4LDtMU
This commit is contained in:
2026-10-01 23:42:50 +09:00
co-authored by Claude Sonnet 5.5
parent 2a93b92050
commit bad349783b
4 changed files with 284 additions and 12 deletions
@@ -162,16 +162,21 @@ export function matches(
return rule.op === "같음" ? target === v : target.includes(v);
}
/** 지금 잡히는 품목 미리 보기 글 — 0 이면 까닭 · 여럿이면 알림 */
/** 지금 잡히는 것 미리 보기 글 — 0 이면 까닭 · 여럿이면 알림(noun = 재료 · 줄) */
export function catchNote(
found: number,
firstName = "",
noun = "재료",
): { kind: "none" | "one" | "many"; text: string } {
if (found === 0) return { kind: "none", text: "맞는 재료가 없음 — 범위나 규칙을 넓혀 봄" };
if (found === 1) return { kind: "one", text: `재료 하나가 잡힘 — ${firstName}` };
if (found === 0)
return {
kind: "none",
text: `맞는 ${noun}${noun === "줄" ? "이" : "가"} 없음 — 범위나 규칙을 넓혀 봄`,
};
if (found === 1) return { kind: "one", text: `${noun} 하나가 잡힘 — ${firstName}` };
return {
kind: "many",
text: `재료 ${found} 개가 잡힘 — 둘 이상이면 가장 싼 값을 씀 · 규칙을 더 좁히면 하나로 잡힘`,
text: `${noun} ${found} 개가 잡힘 — 둘 이상이면 ${noun === "줄" ? "첫 줄" : "가장 싼 값"}을 씀 · 규칙을 더 좁히면 하나로 잡힘`,
};
}
@@ -566,3 +571,36 @@ export function reconcileUnit(lg: CfLogic, id: string): CfLogic {
? lg
: { ...lg, boxes: lg.boxes.map((b) => (b.id === id ? { ...b, unit: want } : b)) };
}
/* ── 조건 찾기(rule) — 인력 · 기계 · 유가전력도 씀: 이름 또는 키가 변수 알약 값과 같은 줄(옛 로직 LB:{직종} · EQ:{기계} 꼴) ── */
/** 조건 찾기를 쓰는 그룹 — 재료는 재료 판(규격 · 이름 포함) · 선택 자리(choice)는 재료만 */
export const RULE_GROUPS: CfGroup[] = ["인력", "기계", "유가전력"];
export type GroupRuleField = "이름" | "키";
/** 이 줄이 규칙에 맞나 — 이름 또는 키(원문번호도)가 알약 값과 같음(띄어쓰기 · 대소문자는 가리지 않음) */
export function matchesRow(row: M01Row, field: GroupRuleField, value: unknown): boolean {
const v = squash(value);
if (!v) return false;
const targets = field === "키" ? [row["키"], row["원문번호"]] : [row["이름"]];
return targets.some((x) => squash(x) === v);
}
/** 조건 찾기 요소 — 품목 키는 비우고 알약 이름 = 자리 이름 · 규칙 = 같음(Model 규칙 꼴에 「키」 칸을 더해 씀) */
export function groupRuleElement(
name: string,
field: GroupRuleField,
from: CfMaterialRule["from"],
): CfElementRef {
const rule = { field, op: "같음", from } as unknown as CfMaterialRule;
return { ref: "", name: name.trim(), slot: name.trim(), spec: "", unit: "-", mode: "rule", rule };
}
/** 넣기 전 검사 — 쉬운 말 한 줄 · 괜찮으면 null */
export function checkGroupRule(el: CfElementRef, others: CfElementRef[]): string | null {
if (!el.name) return "자리 이름을 적어 주세요";
if (others.some((o) => o.name === el.name)) return "같은 이름의 알약이 이미 있음";
if (!el.rule?.from.name) return "규칙에 쓸 변수 알약을 골라 주세요";
return null;
}