매미킴

This commit is contained in:
DDD1542
2026-04-27 16:15:42 +09:00
parent 34a44e0d9c
commit ee8f274feb
3 changed files with 228 additions and 30 deletions

View File

@@ -3586,6 +3586,11 @@ export const getProcessList = async (
res: Response,
) => {
const pool = getPool();
const __debugTag = `[POP-DEBUG][getProcessList][${req.user!.userId}@${req.user!.companyCode}][${new Date().toISOString()}]`;
console.log(`${__debugTag} ▶ ENTER`, {
query: req.query,
headers_user_agent: req.headers["user-agent"],
});
try {
const companyCode = req.user!.companyCode;
@@ -3606,8 +3611,15 @@ export const getProcessList = async (
[companyCode],
);
const wops = wopRes.rows;
console.log(`${__debugTag} 1) wop SQL → rows:`, {
total: wops.length,
by_process: wops.reduce((m: Record<string, number>, w: any) => { m[w.process_code] = (m[w.process_code] || 0) + 1; return m; }, {}),
master_count: wops.filter((w: any) => !w.parent_process_id).length,
split_count: wops.filter((w: any) => w.parent_process_id).length,
});
if (wops.length === 0) {
console.log(`${__debugTag} ◀ EXIT (no wop)`);
return res.json({ success: true, data: [] });
}
@@ -3624,6 +3636,11 @@ export const getProcessList = async (
ORDER BY wop_id, seq ASC`,
[wopIds],
);
console.log(`${__debugTag} 2) wopr SQL → rows:`, {
total: resRes.rows.length,
by_status: resRes.rows.reduce((m: Record<string, number>, r: any) => { m[r.status] = (m[r.status] || 0) + 1; return m; }, {}),
rework_count: resRes.rows.filter((r: any) => r.is_rework === "Y").length,
});
const resultsByWop = new Map<string, any[]>();
for (const r of resRes.rows) {
@@ -3631,6 +3648,12 @@ export const getProcessList = async (
arr.push(r);
resultsByWop.set(r.wop_id, arr);
}
const __wopWithoutResult = wops.filter((w: any) => !resultsByWop.has(w.id));
console.log(`${__debugTag} 2-1) wop ↔ wopr 매핑:`, {
wop_with_result: wops.length - __wopWithoutResult.length,
wop_WITHOUT_result: __wopWithoutResult.length,
missing_sample: __wopWithoutResult.slice(0, 5).map((w: any) => ({ id: w.id, process_code: w.process_code, seq_no: w.seq_no })),
});
// 3) 대표 상태/수량은 첫 실적 기준으로 매핑 (프론트는 accepted_results도 별도 순회)
const data = wops.map((w: any) => {
@@ -3692,6 +3715,45 @@ export const getProcessList = async (
};
});
// 3) 응답 데이터 분포 로그
const masterFirstDist: Record<string, number> = {};
const p001WoprDist: Record<string, number> = {};
const reworkDist: Record<string, number> = {};
let totalWopr = 0;
const p001Cards: any[] = [];
for (const d of data) {
masterFirstDist[d.status] = (masterFirstDist[d.status] || 0) + 1;
if (d.process_code === "P001") {
p001Cards.push({
id: d.id,
seq_no: d.seq_no,
parent: d.parent_process_id,
master_status: d.status,
wopr_count: d.accepted_results.length,
wopr_statuses: d.accepted_results.map((r: any) => `${r.seq}:${r.status}${r.is_rework === "Y" ? "(R)" : ""}`),
});
}
for (const ar of d.accepted_results) {
totalWopr++;
if (d.process_code === "P001") {
p001WoprDist[ar.status] = (p001WoprDist[ar.status] || 0) + 1;
}
if (ar.is_rework === "Y") {
reworkDist[`${d.process_code}:${ar.status}`] = (reworkDist[`${d.process_code}:${ar.status}`] || 0) + 1;
}
}
}
console.log(`${__debugTag} 3) 응답 빌드 완료:`, {
data_length: data.length,
wopr_total_in_response: totalWopr,
master_first_status_dist: masterFirstDist,
p001_wopr_status_dist: p001WoprDist,
rework_dist: reworkDist,
});
console.log(`${__debugTag} 3-1) P001 카드 상세 (${p001Cards.length}개):`);
console.table(p001Cards);
console.log(`${__debugTag} ◀ EXIT`);
return res.json({ success: true, data });
} catch (error: any) {
logger.error("[pop/production] processes 조회 오류:", error);