// STMATE 재현 앱 일위대가(B)·중기(X) 조립 — stdin {costn_rows, bdqty_rows, start_ini} const E = require("../../tools/stmate-test/smt_eval.js"); let buf = ""; process.stdin.setEncoding("utf8"); process.stdin.on("data", (d) => (buf += d)); process.stdin.on("end", () => { const d = JSON.parse(buf); const ini = d.start_ini || {}; const by = {}; for (const r of d.costn_rows) by[r.CODE.trim()] = r; const slot = (r) => (Number(r.NAGCD) > 0 ? 2 : 1); const lookup = (c) => { const r = by[c]; if (!r) return null; const s = slot(r); return { M: +r[`MAMT${s}`], L: +r[`LAMT${s}`], S: +r[`SAMT${s}`], unit: r.UNIT }; }; const conld = String(ini.CONLD || ""); const labor = new Set(conld.match(/.{1,6}/g) || []); const groups = {}; for (const r of d.bdqty_rows) (groups[r.BDCODE] = groups[r.BDCODE] || []).push(r); const out = {}; for (const [parent, rows] of Object.entries(groups)) { if (!by[parent] || !/^[BX]/.test(parent)) continue; const ev = E.evaluateComposition(rows, lookup, { totalFirst: parent[0] === "B" && String(ini.CHBNM ?? "1") === "0", order: ini.OPTNM || "SML", sbmok: String(by[parent].SBMOK || "").trim(), labor: parent[0] === "X" ? labor : null, rx: ini.RXXNM, usdRate: ini.EXLNM1, }); out[parent] = [ev.M, ev.L, ev.S]; } process.stdout.write(JSON.stringify(out)); });