From 293330c4180238a675d0a9f60eb172bec55cc8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 6 Mar 2026 15:51:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AC=B8=EC=84=9C=20rendered=5Fhtml=20?= =?UTF-8?q?=EC=8A=A4=EB=83=85=EC=83=B7=20=EC=A0=80=EC=9E=A5=20=EC=A7=80?= =?UTF-8?q?=EC=9B=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Document 모델 $fillable에 rendered_html 추가 - DocumentService create/update에서 rendered_html 저장 - StoreRequest/UpdateRequest에 rendered_html 검증 추가 - WorkOrderService 검사문서/작업일지 생성 시 rendered_html 전달 Co-Authored-By: Claude Opus 4.6 --- app/Http/Requests/Document/StoreRequest.php | 3 +++ app/Http/Requests/Document/UpdateRequest.php | 3 +++ app/Models/Documents/Document.php | 1 + app/Services/DocumentService.php | 9 +++++-- app/Services/WorkOrderService.php | 27 +++++++++++++++----- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/Http/Requests/Document/StoreRequest.php b/app/Http/Requests/Document/StoreRequest.php index a6681e1..4a4e977 100644 --- a/app/Http/Requests/Document/StoreRequest.php +++ b/app/Http/Requests/Document/StoreRequest.php @@ -28,6 +28,9 @@ public function rules(): array 'approvers.*.user_id' => 'required_with:approvers|integer|exists:users,id', 'approvers.*.role' => 'nullable|string|max:50', + // HTML 스냅샷 + 'rendered_html' => 'nullable|string', + // 문서 데이터 (EAV) 'data' => 'nullable|array', 'data.*.section_id' => 'nullable|integer', diff --git a/app/Http/Requests/Document/UpdateRequest.php b/app/Http/Requests/Document/UpdateRequest.php index 8388c00..8b07e69 100644 --- a/app/Http/Requests/Document/UpdateRequest.php +++ b/app/Http/Requests/Document/UpdateRequest.php @@ -27,6 +27,9 @@ public function rules(): array 'approvers.*.user_id' => 'required_with:approvers|integer|exists:users,id', 'approvers.*.role' => 'nullable|string|max:50', + // HTML 스냅샷 + 'rendered_html' => 'nullable|string', + // 문서 데이터 (EAV) 'data' => 'nullable|array', 'data.*.section_id' => 'nullable|integer', diff --git a/app/Models/Documents/Document.php b/app/Models/Documents/Document.php index 1f5b4ed..8ce6a10 100644 --- a/app/Models/Documents/Document.php +++ b/app/Models/Documents/Document.php @@ -73,6 +73,7 @@ class Document extends Model 'linkable_id', 'submitted_at', 'completed_at', + 'rendered_html', 'created_by', 'updated_by', 'deleted_by', diff --git a/app/Services/DocumentService.php b/app/Services/DocumentService.php index b939fe9..6877956 100644 --- a/app/Services/DocumentService.php +++ b/app/Services/DocumentService.php @@ -122,6 +122,7 @@ public function create(array $data): Document 'status' => Document::STATUS_DRAFT, 'linkable_type' => $data['linkable_type'] ?? null, 'linkable_id' => $data['linkable_id'] ?? null, + 'rendered_html' => $data['rendered_html'] ?? null, 'created_by' => $userId, 'updated_by' => $userId, ]); @@ -170,12 +171,16 @@ public function update(int $id, array $data): Document } // 기본 정보 수정 - $document->fill([ + $updateFields = [ 'title' => $data['title'] ?? $document->title, 'linkable_type' => $data['linkable_type'] ?? $document->linkable_type, 'linkable_id' => $data['linkable_id'] ?? $document->linkable_id, 'updated_by' => $userId, - ]); + ]; + if (isset($data['rendered_html'])) { + $updateFields['rendered_html'] = $data['rendered_html']; + } + $document->fill($updateFields); // 반려 상태에서 수정 시 DRAFT로 변경 if ($document->status === Document::STATUS_REJECTED) { diff --git a/app/Services/WorkOrderService.php b/app/Services/WorkOrderService.php index d18aa7d..ee5d342 100644 --- a/app/Services/WorkOrderService.php +++ b/app/Services/WorkOrderService.php @@ -2509,10 +2509,14 @@ public function createInspectionDocument(int $workOrderId, array $inspectionData ]) ->toArray(); - $document = $documentService->update($existingDocument->id, [ + $updateData = [ 'title' => $inspectionData['title'] ?? $existingDocument->title, 'data' => array_merge($existingBasicFields, $documentDataRecords), - ]); + ]; + if (isset($inspectionData['rendered_html'])) { + $updateData['rendered_html'] = $inspectionData['rendered_html']; + } + $document = $documentService->update($existingDocument->id, $updateData); $action = 'inspection_document_updated'; } else { @@ -2524,6 +2528,9 @@ public function createInspectionDocument(int $workOrderId, array $inspectionData 'data' => $documentDataRecords, 'approvers' => $inspectionData['approvers'] ?? [], ]; + if (isset($inspectionData['rendered_html'])) { + $documentData['rendered_html'] = $inspectionData['rendered_html']; + } $document = $documentService->create($documentData); $action = 'inspection_document_created'; @@ -3140,20 +3147,28 @@ public function createWorkLog(int $workOrderId, array $workLogData): array $documentDataRecords = $this->transformWorkLogDataToRecords($workLogData, $workOrder, $template); if ($existingDocument) { - $document = $documentService->update($existingDocument->id, [ + $updateData = [ 'title' => $workLogData['title'] ?? $existingDocument->title, 'data' => $documentDataRecords, - ]); + ]; + if (isset($workLogData['rendered_html'])) { + $updateData['rendered_html'] = $workLogData['rendered_html']; + } + $document = $documentService->update($existingDocument->id, $updateData); $action = 'work_log_updated'; } else { - $document = $documentService->create([ + $createData = [ 'template_id' => $templateId, 'title' => $workLogData['title'] ?? "작업일지 - {$workOrder->work_order_no}", 'linkable_type' => 'work_order', 'linkable_id' => $workOrderId, 'data' => $documentDataRecords, 'approvers' => $workLogData['approvers'] ?? [], - ]); + ]; + if (isset($workLogData['rendered_html'])) { + $createData['rendered_html'] = $workLogData['rendered_html']; + } + $document = $documentService->create($createData); $action = 'work_log_created'; }