feat: [QMS] 점검표 템플릿 관리 백엔드 구현

- checklist_templates 테이블 마이그레이션 + 기본 시딩
- ChecklistTemplate 모델 (BelongsToTenant, Auditable, SoftDeletes)
- ChecklistTemplateService: 조회/저장/파일 업로드/삭제
- SaveChecklistTemplateRequest: 중첩 JSON 검증
- ChecklistTemplateController: 5개 엔드포인트
- 라우트 등록 (quality/checklist-templates, quality/qms-documents)
This commit is contained in:
2026-03-11 20:04:29 +09:00
parent 3bae303447
commit 12373edf8c
6 changed files with 536 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('checklist_templates', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트ID');
$table->string('name', 255)->default('품질인정심사 점검표')->comment('템플릿명');
$table->string('type', 50)->default('day1_audit')->comment('심사유형: day1_audit, day2_lot 등');
$table->json('categories')->comment('카테고리/항목 JSON');
$table->json('options')->nullable()->comment('확장 속성');
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
$table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
$table->timestamps();
$table->softDeletes();
$table->unique(['tenant_id', 'type'], 'uq_checklist_templates_tenant_type');
$table->index(['tenant_id', 'type'], 'idx_checklist_templates_tenant_type');
$table->foreign('tenant_id')->references('id')->on('tenants');
$table->foreign('created_by')->references('id')->on('users')->onDelete('set null');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('set null');
});
// 기존 테넌트에 기본 템플릿 시딩
$this->seedDefaultTemplates();
}
public function down(): void
{
Schema::dropIfExists('checklist_templates');
}
private function seedDefaultTemplates(): void
{
$defaultCategories = json_encode([
[
'id' => 'cat-1',
'title' => '원재료 품질관리 기준',
'subItems' => [
['id' => 'cat-1-1', 'name' => '수입검사 기준 확인'],
['id' => 'cat-1-2', 'name' => '불합격품 처리 기준 확인'],
['id' => 'cat-1-3', 'name' => '자재 보관 기준 확인'],
],
],
[
'id' => 'cat-2',
'title' => '제조공정 관리 기준',
'subItems' => [
['id' => 'cat-2-1', 'name' => '작업표준서 확인'],
['id' => 'cat-2-2', 'name' => '공정검사 기준 확인'],
['id' => 'cat-2-3', 'name' => '부적합품 처리 기준 확인'],
],
],
[
'id' => 'cat-3',
'title' => '제품 품질관리 기준',
'subItems' => [
['id' => 'cat-3-1', 'name' => '제품검사 기준 확인'],
['id' => 'cat-3-2', 'name' => '출하검사 기준 확인'],
['id' => 'cat-3-3', 'name' => '클레임 처리 기준 확인'],
],
],
[
'id' => 'cat-4',
'title' => '제조설비 관리',
'subItems' => [
['id' => 'cat-4-1', 'name' => '설비관리 기준 확인'],
['id' => 'cat-4-2', 'name' => '설비점검 이력 확인'],
],
],
[
'id' => 'cat-5',
'title' => '검사설비 관리',
'subItems' => [
['id' => 'cat-5-1', 'name' => '검사설비 관리 기준 확인'],
['id' => 'cat-5-2', 'name' => '교정 이력 확인'],
],
],
[
'id' => 'cat-6',
'title' => '문서 및 인증 관리',
'subItems' => [
['id' => 'cat-6-1', 'name' => '문서관리 기준 확인'],
['id' => 'cat-6-2', 'name' => 'KS/인증 관리 현황 확인'],
],
],
], JSON_UNESCAPED_UNICODE);
$tenantIds = DB::table('tenants')->pluck('id');
$now = now();
foreach ($tenantIds as $tenantId) {
DB::table('checklist_templates')->insert([
'tenant_id' => $tenantId,
'name' => '품질인정심사 점검표',
'type' => 'day1_audit',
'categories' => $defaultCategories,
'created_at' => $now,
'updated_at' => $now,
]);
}
}
};