feat: 문서 rendered_html 스냅샷 저장 지원
- Document 모델 $fillable에 rendered_html 추가 - DocumentService create/update에서 rendered_html 저장 - StoreRequest/UpdateRequest에 rendered_html 검증 추가 - WorkOrderService 검사문서/작업일지 생성 시 rendered_html 전달 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -73,6 +73,7 @@ class Document extends Model
|
||||
'linkable_id',
|
||||
'submitted_at',
|
||||
'completed_at',
|
||||
'rendered_html',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user