feat(migration): ADR-028 migration architecture refactor
- เพิ่ม POST /api/ai/jobs + GET /api/ai/jobs/:jobId endpoints (FR-001, FR-002) - เพิ่ม BullMQ Worker MigrateDocumentWorker + OCR auto-detect (FR-003, FR-004) - เพิ่ม cleanup-temp-files + expire-pending-reviews workers (FR-005, FR-005a/b) - สร้าง SQL deltas: tags, correspondence_tags, alter migration_review_queue (FR-006, ADR-009) - เพิ่ม MigrationReviewService.commitRecord() + SELECT FOR UPDATE (FR-007, FR-007a) - เพิ่ม CASL permission migration.commit + MigrationReviewController (FR-007) - สร้าง TagsModule + TagsService + TagsController (US3) - สร้าง Migration Review Queue frontend page + ReviewQueueTable (US2) - อัปเดต n8n guide: deterministic Idempotency-Key + token pre-flight (FR-001a, FR-010a/b) - สร้าง spec.md, plan.md, tasks.md, data-model.md, contracts/, quickstart.md - สร้าง ADR-028 document + validation-report.md (PASS 32/32 tasks, 173/173 tests)
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
// File: src/modules/ai/dto/ai-job-result.dto.ts
|
||||
// Change Log:
|
||||
// - 2026-05-22: สร้าง AiJobResultDto สำหรับจัดรูปแบบและตรวจสอบผลลัพธ์ของงาน AI (ADR-028)
|
||||
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNumber,
|
||||
IsString,
|
||||
IsArray,
|
||||
ValidateNested,
|
||||
IsOptional,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
/**
|
||||
* แท็กที่ AI แนะนำจากการวิเคราะห์เอกสาร
|
||||
*/
|
||||
export class SuggestedTagDto {
|
||||
@ApiProperty({ description: 'ชื่อแท็กที่แนะนำ' })
|
||||
@IsString()
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({ description: 'คำอธิบายเกี่ยวกับแท็ก' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string;
|
||||
|
||||
@ApiProperty({ description: 'ระบุว่าเป็นแท็กใหม่ในระบบหรือไม่' })
|
||||
@IsBoolean()
|
||||
isNew!: boolean;
|
||||
|
||||
@ApiProperty({ description: 'ระดับความมั่นใจของ AI ต่อแท็กนี้ (0.0–1.0)' })
|
||||
@IsNumber()
|
||||
confidence!: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* ผลลัพธ์จากการวิเคราะห์เอกสารของ AI สำหรับการย้ายระบบ
|
||||
*/
|
||||
export class AiJobResultDto {
|
||||
@ApiProperty({ description: 'เอกสารมีความถูกต้องและสมบูรณ์หรือไม่' })
|
||||
@IsBoolean()
|
||||
isValid!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ระดับความมั่นใจเฉลี่ยโดยรวมของเอกสาร (0.0–1.0)',
|
||||
})
|
||||
@IsNumber()
|
||||
confidence!: number;
|
||||
|
||||
@ApiProperty({ description: 'หมวดหมู่ของเอกสารโต้ตอบที่แนะนำ' })
|
||||
@IsString()
|
||||
category!: string;
|
||||
|
||||
@ApiProperty({ description: 'บทสรุปโดยย่อของเอกสาร' })
|
||||
@IsString()
|
||||
summary!: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: [SuggestedTagDto],
|
||||
description: 'รายการแท็กที่ AI แนะนำ',
|
||||
})
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => SuggestedTagDto)
|
||||
suggestedTags!: SuggestedTagDto[];
|
||||
|
||||
@ApiProperty({
|
||||
type: [String],
|
||||
description: 'รายการจุดผิดพลาดหรือข้อควรระวังที่พบในเอกสาร',
|
||||
})
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
detectedIssues!: string[];
|
||||
|
||||
@ApiProperty({
|
||||
enum: ['fast-path', 'slow-path'],
|
||||
description: 'วิธีการสกัดข้อความจากเอกสาร',
|
||||
})
|
||||
@IsString()
|
||||
ocrMethod!: 'fast-path' | 'slow-path';
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ระยะเวลาที่ใช้ในการสกัดข้อมูลและวิเคราะห์ (ms)',
|
||||
})
|
||||
@IsNumber()
|
||||
processingTimeMs!: number;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// File: src/modules/ai/dto/submit-ai-job.dto.ts
|
||||
// Change Log:
|
||||
// - 2026-05-22: สร้าง SubmitAiJobDto สำหรับรับงานประมวลผลการย้ายเอกสารของ AI (ADR-028)
|
||||
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsUUID,
|
||||
IsString,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsArray,
|
||||
ValidateNested,
|
||||
IsObject,
|
||||
IsIn,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
/**
|
||||
* ตัวเลือกแท็กประกอบการวิเคราะห์ของ AI
|
||||
*/
|
||||
export class TagOptionDto {
|
||||
@ApiPropertyOptional({ description: 'UUID ของแท็กที่มีอยู่แล้วในโครงการ' })
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
publicId?: string;
|
||||
|
||||
@ApiProperty({ description: 'ชื่อแท็ก' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
tagName!: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'รหัสสีของแท็ก' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
colorCode?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Payload ข้อมูลเอกสารเก่าสำหรับการทำ Migration
|
||||
*/
|
||||
export class MigrateDocumentPayloadDto {
|
||||
@ApiProperty({ description: 'UUID ของ temp attachment ในระบบ' })
|
||||
@IsUUID()
|
||||
tempAttachmentId!: string;
|
||||
|
||||
@ApiProperty({ description: 'เลขที่เอกสารเก่า' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
documentNumber!: string;
|
||||
|
||||
@ApiProperty({ description: 'ชื่อเรื่องเอกสาร' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
title!: string;
|
||||
|
||||
@ApiProperty({
|
||||
type: [TagOptionDto],
|
||||
description: 'รายการแท็กโครงการที่มีอยู่ก่อนแล้ว',
|
||||
})
|
||||
@IsArray()
|
||||
@IsOptional()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => TagOptionDto)
|
||||
existingTags?: TagOptionDto[];
|
||||
|
||||
@ApiProperty({ type: [String], description: 'หมวดหมู่เอกสารหลักที่มีในระบบ' })
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
systemCategories?: string[];
|
||||
|
||||
@ApiProperty({ description: 'รหัสกลุ่มการนำเข้า (Batch ID)' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
batchId!: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* DTO สำหรับส่งคำขอเปิดงานประมวลผล AI (AI processing job submission)
|
||||
*/
|
||||
export class SubmitAiJobDto {
|
||||
@ApiProperty({
|
||||
example: 'migrate-document',
|
||||
description: 'ชนิดงานประมวลผล AI',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsIn(['migrate-document'])
|
||||
type!: string;
|
||||
|
||||
@ApiProperty({ type: MigrateDocumentPayloadDto })
|
||||
@IsObject()
|
||||
@ValidateNested()
|
||||
@Type(() => MigrateDocumentPayloadDto)
|
||||
payload!: MigrateDocumentPayloadDto;
|
||||
}
|
||||
Reference in New Issue
Block a user