feat: 리워크 원점 복귀 추적 — 원본 공정 도달 시 마크 해제
- accept-process: rework_source_id 전달 시 원본 seq_no와 비교 - 현재 seq < 원본 seq → is_rework='Y' 유지 (마크 표시) - 현재 seq >= 원본 seq → is_rework 해제 (합류, 마크 없음) - save-result 응답에 rework_source_id 포함 (프론트 추적용) - accept-process 응답에 rework_source_id 포함
This commit is contained in:
@@ -1192,9 +1192,22 @@ export const saveResult = async (
|
||||
[work_order_process_id, companyCode]
|
||||
);
|
||||
|
||||
// 리워크 정보도 응답에 포함 (프론트에서 다음 공정 접수 시 전달 가능)
|
||||
const responseData = latestData.rows[0] || result.rows[0];
|
||||
if (responseData) {
|
||||
const reworkInfo = await pool.query(
|
||||
`SELECT is_rework, rework_source_id FROM work_order_process WHERE id = $1`,
|
||||
[work_order_process_id]
|
||||
);
|
||||
if (reworkInfo.rows[0]?.rework_source_id) {
|
||||
responseData.rework_source_id = reworkInfo.rows[0].rework_source_id;
|
||||
responseData.is_rework = reworkInfo.rows[0].is_rework;
|
||||
}
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
data: latestData.rows[0] || result.rows[0],
|
||||
data: responseData,
|
||||
});
|
||||
} catch (error: any) {
|
||||
logger.error("[pop/production] save-result 오류:", error);
|
||||
@@ -1828,12 +1841,33 @@ export const acceptProcess = async (req: AuthenticatedRequest, res: Response) =>
|
||||
const batchId = req.body.batch_id || `BATCH-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
||||
const hasBatchCol = _batchMigrationDone;
|
||||
|
||||
// 리워크 카드에서 접수 시 is_rework, rework_source_id 전달
|
||||
const parentReworkInfo = isRework ? await client.query(
|
||||
`SELECT is_rework, rework_source_id FROM work_order_process WHERE id = $1`, [work_order_process_id]
|
||||
) : null;
|
||||
const splitIsRework = parentReworkInfo?.rows[0]?.is_rework || null;
|
||||
const splitReworkSourceId = parentReworkInfo?.rows[0]?.rework_source_id || null;
|
||||
// 리워크 정보 전달: 리워크 카드 접수 또는 프론트에서 전달한 경우
|
||||
let splitIsRework: string | null = null;
|
||||
let splitReworkSourceId: string | null = null;
|
||||
|
||||
if (isRework) {
|
||||
// 리워크 카드에서 직접 접수
|
||||
const parentReworkInfo = await client.query(
|
||||
`SELECT is_rework, rework_source_id FROM work_order_process WHERE id = $1`, [work_order_process_id]
|
||||
);
|
||||
splitIsRework = parentReworkInfo?.rows[0]?.is_rework || null;
|
||||
splitReworkSourceId = parentReworkInfo?.rows[0]?.rework_source_id || null;
|
||||
} else if (req.body.rework_source_id) {
|
||||
// 프론트에서 리워크 추적 정보 전달 (다음 공정 접수 시)
|
||||
// 원본 불량 공정의 seq_no를 조회하여 현재 공정과 비교
|
||||
const originProc = await client.query(
|
||||
`SELECT seq_no FROM work_order_process WHERE id = $1`, [req.body.rework_source_id]
|
||||
);
|
||||
const originSeq = parseInt(originProc.rows[0]?.seq_no, 10) || 0;
|
||||
const currentSeqNum = parseInt(row.seq_no, 10);
|
||||
|
||||
if (currentSeqNum < originSeq) {
|
||||
// 아직 원본 공정에 도달 안 함 → 리워크 마크 유지
|
||||
splitIsRework = "Y";
|
||||
splitReworkSourceId = req.body.rework_source_id;
|
||||
}
|
||||
// currentSeqNum >= originSeq → 원본 공정 도달 → 마크 해제 (splitIsRework = null)
|
||||
}
|
||||
|
||||
// 분할 행 INSERT (batch_id는 컬럼 존재 시에만, 리워크 정보 포함)
|
||||
const reworkCols = splitIsRework ? ", is_rework, rework_source_id" : "";
|
||||
@@ -1901,9 +1935,15 @@ export const acceptProcess = async (req: AuthenticatedRequest, res: Response) =>
|
||||
checklistCount,
|
||||
});
|
||||
|
||||
const acceptData = result.rows[0] || {};
|
||||
if (splitReworkSourceId) {
|
||||
acceptData.rework_source_id = splitReworkSourceId;
|
||||
acceptData.is_rework = splitIsRework;
|
||||
}
|
||||
|
||||
return res.json({
|
||||
success: true,
|
||||
data: result.rows[0],
|
||||
data: acceptData,
|
||||
message: `${qty}개 접수 완료 (총 접수합계: ${newTotalInput})`,
|
||||
});
|
||||
} catch (error: any) {
|
||||
|
||||
Reference in New Issue
Block a user