251218:1701 On going update to 1.7.0: Documnet Number rebuild
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# Quick Start Guide
|
||||
|
||||
**Project:** LCBP3-DMS
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
---
|
||||
|
||||
@@ -491,9 +491,9 @@ SHOW CREATE TABLE document_number_counters;
|
||||
|
||||
### Learn More
|
||||
|
||||
1. **Architecture** - [System Architecture](../02-architecture/system-architecture.md)
|
||||
2. **Development** - [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
3. **Deployment** - [Deployment Guide](../04-operations/deployment-guide.md)
|
||||
1. **Architecture** - [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
2. **Development** - [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
3. **Deployment** - [Deployment Guide](../04-operations/04-01-deployment-guide.md)
|
||||
4. **Decisions** - [ADR Index](../05-decisions/README.md)
|
||||
|
||||
### Join the Team
|
||||
@@ -536,7 +536,7 @@ git push origin feature/my-feature
|
||||
|
||||
### Code Review
|
||||
|
||||
- Review [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
- Review [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
- Check test coverage
|
||||
- Verify documentation updated
|
||||
- Run linter: `npm run lint`
|
||||
@@ -551,11 +551,11 @@ git push origin feature/my-feature
|
||||
- **Documentation:** `/specs` directory
|
||||
- **API Docs:** <http://localhost:3000/api/docs>
|
||||
- **Issue Tracker:** [Link to issue tracker]
|
||||
|
||||
- **Slack:** #lcbp3-dms
|
||||
### Contact
|
||||
|
||||
- **Tech Lead:** [Email]
|
||||
- **DevOps:** [Email]
|
||||
- **Tech Lead:** peancharoen@gmail.com
|
||||
- **DevOps:** peancharoen.pclcp3@gmail.com
|
||||
- **Slack:** #lcbp3-dms
|
||||
|
||||
---
|
||||
@@ -571,13 +571,13 @@ git push origin feature/my-feature
|
||||
- [ ] Access frontend (<http://localhost:3001>)
|
||||
- [ ] Login with default credentials
|
||||
- [ ] Run tests
|
||||
- [ ] Read [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [ ] Read [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
- [ ] Read [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [ ] Read [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
- [ ] Pick first task from [Tasks](../06-tasks/README.md)
|
||||
|
||||
---
|
||||
|
||||
**Welcome aboard! 🎉**
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
@@ -1,8 +1,8 @@
|
||||
# Glossary - คำศัพท์และคำย่อทางเทคนิค
|
||||
|
||||
**Project:** LCBP3-DMS
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
---
|
||||
|
||||
@@ -393,13 +393,13 @@ Logging library สำหรับ Node.js
|
||||
การท่าเรือแห่งประเทศไทย - เจ้าของโครงการ
|
||||
|
||||
**สค©. (Supervision Consultant)**
|
||||
ที่ปรึกษาควบคุมงาน
|
||||
สำนักงานโครงการ ท่าเรือแหลมฉบัง
|
||||
|
||||
**TEAM (Design Consultant)**
|
||||
ที่ปรึกษาออกแบบ
|
||||
|
||||
**คคง. (Construction Supervision)**
|
||||
ผู้ควบคุมงานก่อสร้าง
|
||||
ที่ปรึกษาควบคุมงานก่อสร้าง
|
||||
|
||||
**ผรม. (Contractor)**
|
||||
ผู้รับเหมาก่อสร้าง
|
||||
@@ -418,7 +418,7 @@ Logging library สำหรับ Node.js
|
||||
แบบคู่สัญญา
|
||||
|
||||
**Shop Drawing**
|
||||
แบบก่อสร้าง / แบบการผลิต
|
||||
แบบก่อสร้าง
|
||||
|
||||
**Transmittal**
|
||||
เอกสารนำส่ง
|
||||
@@ -491,6 +491,6 @@ Logging library สำหรับ Node.js
|
||||
|
||||
---
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
**Next Review:** 2026-03-01
|
||||
@@ -203,20 +203,20 @@ lcbp3/
|
||||
|
||||
| Category | Document | Description |
|
||||
| ------------------ | ---------------------------------------------------------------------------------- | ------------------------------------- |
|
||||
| **Overview** | [Glossary](./glossary.md) | Technical terminology & abbreviations |
|
||||
| **Overview** | [Quick Start](./quick-start.md) | 5-minute getting started guide |
|
||||
| **Requirements** | [Functional Requirements](../01-requirements/03-functional-requirements.md) | Feature specifications |
|
||||
| **Requirements** | [Document Numbering](../01-requirements/03.11-document-numbering.md) | Document numbering requirements |
|
||||
| **Architecture** | [System Architecture](../02-architecture/system-architecture.md) | Overall system design |
|
||||
| **Architecture** | [Data Model](../02-architecture/data-model.md) | Database schema |
|
||||
| **Architecture** | [API Design](../02-architecture/api-design.md) | REST API specifications |
|
||||
| **Implementation** | [Backend Guidelines](../03-implementation/backend-guidelines.md) | Backend coding standards |
|
||||
| **Implementation** | [Frontend Guidelines](../03-implementation/frontend-guidelines.md) | Frontend coding standards |
|
||||
| **Implementation** | [Document Numbering Implementation](../03-implementation/document-numbering.md) | Document numbering implementation |
|
||||
| **Implementation** | [Testing Strategy](../03-implementation/testing-strategy.md) | Testing approach |
|
||||
| **Operations** | [Deployment Guide](../04-operations/deployment-guide.md) | How to deploy |
|
||||
| **Operations** | [Monitoring](../04-operations/monitoring-alerting.md) | Monitoring & alerts |
|
||||
| **Operations** | [Document Numbering Operations](../04-operations/document-numbering-operations.md) | Doc numbering ops guide |
|
||||
| **Overview** | [Glossary](./00-02-glossary.md) | Technical terminology & abbreviations |
|
||||
| **Overview** | [Quick Start](./00-01-quick-start.md) | 5-minute getting started guide |
|
||||
| **Requirements** | [Functional Requirements](../01-requirements/01-03-functional-requirements.md) | Feature specifications |
|
||||
| **Requirements** | [Document Numbering](../01-requirements/01-03.11-document-numbering.md) | Document numbering requirements |
|
||||
| **Architecture** | [System Architecture](../02-architecture/02-01-system-architecture.md) | Overall system design |
|
||||
| **Architecture** | [Data Model](../02-architecture/02-03-data-model.md) | Database schema |
|
||||
| **Architecture** | [API Design](../02-architecture/02-02-api-design.md) | REST API specifications |
|
||||
| **Implementation** | [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md) | Backend coding standards |
|
||||
| **Implementation** | [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md) | Frontend coding standards |
|
||||
| **Implementation** | [Document Numbering Implementation](../03-implementation/03-04-document-numbering.md) | Document numbering implementation |
|
||||
| **Implementation** | [Testing Strategy](../03-implementation/03-05-testing-strategy.md) | Testing approach |
|
||||
| **Operations** | [Deployment Guide](../04-operations/04-01-deployment-guide.md) | How to deploy |
|
||||
| **Operations** | [Monitoring](../04-operations/04-03-monitoring-alerting.md) | Monitoring & alerts |
|
||||
| **Operations** | [Document Numbering Operations](../04-operations/04-08-document-numbering-operations.md) | Doc numbering ops guide |
|
||||
| **Decisions** | [ADR Index](../05-decisions/README.md) | Architecture decisions |
|
||||
| **Tasks** | [Backend Tasks](../06-tasks/README.md) | Development tasks |
|
||||
|
||||
@@ -236,9 +236,9 @@ lcbp3/
|
||||
|
||||
1. **Read Documentation**
|
||||
|
||||
- Start with [Quick Start Guide](./quick-start.md)
|
||||
- Review [System Architecture](../02-architecture/system-architecture.md)
|
||||
- Study [Backend](../03-implementation/backend-guidelines.md) / [Frontend](../03-implementation/frontend-guidelines.md) guidelines
|
||||
- Start with [Quick Start Guide](./00-01-quick-start.md)
|
||||
- Review [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- Study [Backend](../03-implementation/03-02-backend-guidelines.md) / [Frontend](../03-implementation/03-03-frontend-guidelines.md) guidelines
|
||||
|
||||
2. **Setup Development Environment**
|
||||
|
||||
@@ -258,20 +258,20 @@ lcbp3/
|
||||
|
||||
1. **Infrastructure Setup**
|
||||
|
||||
- Review [Environment Setup](../04-operations/environment-setup.md)
|
||||
- Review [Environment Setup](../04-operations/04-02-environment-setup.md)
|
||||
- Configure QNAP Container Station
|
||||
- Setup Docker Compose
|
||||
|
||||
2. **Deployment**
|
||||
|
||||
- Follow [Deployment Guide](../04-operations/deployment-guide.md)
|
||||
- Configure [Backup & Recovery](../04-operations/backup-recovery.md)
|
||||
- Setup [Monitoring](../04-operations/monitoring-alerting.md)
|
||||
- Follow [Deployment Guide](../04-operations/04-01-deployment-guide.md)
|
||||
- Configure [Backup & Recovery](../04-operations/04-04-backup-recovery.md)
|
||||
- Setup [Monitoring](../04-operations/04-03-monitoring-alerting.md)
|
||||
|
||||
3. **Maintenance**
|
||||
- Review [Maintenance Procedures](../04-operations/maintenance-procedures.md)
|
||||
- Setup [Incident Response](../04-operations/incident-response.md)
|
||||
- Configure [Security Operations](../04-operations/security-operations.md)
|
||||
- Review [Maintenance Procedures](../04-operations/04-05-maintenance-procedures.md)
|
||||
- Setup [Incident Response](../04-operations/04-07-incident-response.md)
|
||||
- Configure [Security Operations](../04-operations/04-06-security-operations.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -289,9 +289,9 @@ lcbp3/
|
||||
### Stakeholders
|
||||
|
||||
- **Port Authority of Thailand (กทท.)** - Owner
|
||||
- **Project Supervisors (สค©.)** - Consultants
|
||||
- **Project Administrators (สค©.)** - Administrator
|
||||
- **Design Consultants (TEAM)** - Designers
|
||||
- **Construction Supervisors (คคง.)** - Supervision
|
||||
- **Project Supervisors (คคง.)** - Consultants
|
||||
- **Contractors (ผรม.1-4)** - Construction
|
||||
|
||||
---
|
||||
@@ -384,9 +384,9 @@ lcbp3/
|
||||
|
||||
## 📝 Document Control
|
||||
|
||||
- **Version:** 1.6.0
|
||||
- **Version:** 1.7.0
|
||||
- **Status:** Active Development
|
||||
- **Last Updated:** 2025-12-13
|
||||
- **Last Updated:** 2025-12-18
|
||||
- **Next Review:** 2026-01-01
|
||||
- **Owner:** System Architect
|
||||
- **Classification:** Internal Use Only
|
||||
|
||||
@@ -28,48 +28,48 @@ related:
|
||||
|
||||
## 3.1 การจัดการโครงสร้างโครงการและองค์กร (Project Management)
|
||||
|
||||
[specs/01-requirements/03.1-project-management.md](./03.1-project-management.md)
|
||||
[specs/01-requirements/03.1-project-management.md](01-03.1-project-management.md)
|
||||
|
||||
## 3.2 การจัดการเอกสารโครงการ (Correspondence)
|
||||
|
||||
[specs/01-requirements/03.2-correspondence.md](./03.2-correspondence.md)
|
||||
[specs/01-requirements/03.2-correspondence.md](01-03.2-correspondence.md)
|
||||
|
||||
## 3.3 การจัดการเอกสารโครงการ (RFA)
|
||||
|
||||
[specs/01-requirements/03.3-rfa.md](./03.3-rfa.md)
|
||||
[specs/01-requirements/03.3-rfa.md](01-03.3-rfa.md)
|
||||
|
||||
## 3.4 การจัดการแบบคู่สัญญา (Contract Drawing)
|
||||
|
||||
[specs/01-requirements/03.4-contract-drawing.md](./03.4-contract-drawing.md)
|
||||
[specs/01-requirements/03.4-contract-drawing.md](01-03.4-contract-drawing.md)
|
||||
|
||||
## 3.5 การจัดกาแบบก่อสร้าง (Shop Drawing)
|
||||
|
||||
[specs/01-requirements/03.5-shop-drawing.md](./03.5-shop-drawing.md)
|
||||
[specs/01-requirements/03.5-shop-drawing.md](01-03.5-shop-drawing.md)
|
||||
|
||||
## 3.6 การจัดการ Workflow (Unified Workflow)
|
||||
|
||||
[specs/01-requirements/03.6-unified-workflow.md](./03.6-unified-workflow.md)
|
||||
[specs/01-requirements/03.6-unified-workflow.md](01-03.6-unified-workflow.md)
|
||||
|
||||
## 3.7 การจัดการเอกสารนำส่ง (Transmittals)
|
||||
|
||||
[specs/01-requirements/03.7-transmittals.md](./03.7-transmittals.md)
|
||||
[specs/01-requirements/03.7-transmittals.md](01-03.7-transmittals.md)
|
||||
|
||||
## 3.8 การจัดการใบเวียนเอกสาร (Circulation Sheet)
|
||||
|
||||
[specs/01-requirements/03.8-circulation-sheet.md](./03.8-circulation-sheet.md)
|
||||
[specs/01-requirements/03.8-circulation-sheet.md](01-03.8-circulation-sheet.md)
|
||||
|
||||
## 3.9 ประวัติการแก้ไข (logs)
|
||||
|
||||
[specs/01-requirements/03.9-logs.md](./03.9-logs.md)
|
||||
[specs/01-requirements/03.9-logs.md](01-03.9-logs.md)
|
||||
|
||||
## 3.10 การจัดเก็บไฟล์ (File Handling)
|
||||
|
||||
[specs/01-requirements/03.10-file-handling.md](./03.10-file-handling.md)
|
||||
[specs/01-requirements/03.10-file-handling.md](01-03.10-file-handling.md)
|
||||
|
||||
## 3.11 การจัดการเลขที่เอกสาร (Document Numbering)
|
||||
|
||||
[specs/01-requirements/03.11-document-numbering.md](./03.11-document-numbering.md)
|
||||
[specs/01-requirements/03.11-document-numbering.md](01-03.11-document-numbering.md)
|
||||
|
||||
## 3.12 การจัดการ JSON Details (JSON & Performance - ปรับปรุง)
|
||||
|
||||
[specs/01-requirements/03.12-json-details.md](./03.12-json-details.md)
|
||||
[specs/01-requirements/03.12-json-details.md](01-03.12-json-details.md)
|
||||
@@ -7,13 +7,14 @@ status: draft
|
||||
owner: Nattanin Peancharoen
|
||||
last_updated: 2025-12-17
|
||||
related:
|
||||
- specs/01-requirements/01-objectives.md
|
||||
- specs/01-requirements/02-architecture.md
|
||||
- specs/01-requirements/03unctional-requirements.md
|
||||
- specs/03-implementation/document-numbering.md
|
||||
- specs/04-operations/document-numbering-operations.md
|
||||
- specs/04-data-dictionary/4_Data_Dictionary_V1_4_4.md
|
||||
- specs/05-decisions/adr-018-document-numbering.md
|
||||
- specs/01-requirements/01-01-objectives.md
|
||||
- specs/01-requirements/01-02-architecture.md
|
||||
- specs/01-requirements/01-03-functional-requirements.md
|
||||
- specs/01-requirements/01-03.11-document-numbering.md
|
||||
- specs/03-implementation/03-04-document-numbering.md
|
||||
- specs/04-operations/04-08-document-numbering-operations.md
|
||||
- specs/07-database/07-01-data-dictionary-v1.7.0.md
|
||||
- specs/05-decisions/ADR-002-document-numbering-strategy.md
|
||||
Clean Version v1.6.2 – Scope of Changes:
|
||||
- เลือกใช้ Single Numbering System (Option A)
|
||||
- แก้ Primary Key design ให้ implement ได้จริง
|
||||
@@ -27,8 +28,8 @@ Clean Version v1.6.2 – Scope of Changes:
|
||||
|
||||
> **📖 เอกสารที่เกี่ยวข้อง**
|
||||
>
|
||||
> - **Implementation Guide**: [document-numbering.md](file:///d:/nap-dms.lcbp3/specs/03-implementation/document-numbering.md) - รายละเอียดการ implement ด้วย NestJS, TypeORM, Redis
|
||||
> - **Operations Guide**: [document-numbering-operations.md](file:///d:/nap-dms.lcbp3/specs/04-operations/document-numbering-operations.md) - Monitoring, Troubleshooting, Maintenance Procedures
|
||||
> - **Implementation Guide**: [03-implementation/03-04-document-numbering.md](../03-implementation/03-04-document-numbering.md) - รายละเอียดการ implement ด้วย NestJS, TypeORM, Redis
|
||||
> - **Operations Guide**: [04-operations/04-08-document-numbering-operations.md](../04-operations/04-08-document-numbering-operations.md) - Monitoring, Troubleshooting, Maintenance Procedures
|
||||
|
||||
---
|
||||
|
||||
@@ -638,16 +639,17 @@ DIGIT := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
||||
```sql
|
||||
CREATE TABLE document_number_counters (
|
||||
project_id INT NOT NULL,
|
||||
correspondence_type_id INT NULL,-- NULL = default format for project
|
||||
originator_organization_id INT NOT NULL,
|
||||
recipient_organization_id INT NOT NULL DEFAULT 0, -- 0 = no recipient (RFA)
|
||||
correspondence_type_id INT NOT NULL,
|
||||
sub_type_id INT DEFAULT 0,
|
||||
rfa_type_id INT DEFAULT 0,
|
||||
discipline_id INT DEFAULT 0,
|
||||
reset_scope VARCHAR(20) NOT NULL,
|
||||
last_number INT DEFAULT 0 NOT NULL,
|
||||
version INT DEFAULT 0 NOT NULL,
|
||||
|
||||
created_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
updated_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
PRIMARY KEY (
|
||||
project_id,
|
||||
originator_organization_id,
|
||||
@@ -661,7 +663,6 @@ CREATE TABLE document_number_counters (
|
||||
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (originator_organization_id) REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (recipient_organization_id) REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci
|
||||
COMMENT = 'ตารางเก็บ Running Number Counters';
|
||||
@@ -691,6 +692,12 @@ ON document_number_counters (
|
||||
originator_organization_id,
|
||||
reset_scope
|
||||
);
|
||||
|
||||
-- Index สำหรับ updated_at
|
||||
CREATE INDEX idx_counter_updated
|
||||
ON document_number_counters (
|
||||
updated_at
|
||||
);
|
||||
```
|
||||
|
||||
### 3.11.11.3 Numbering Configuration Table
|
||||
@@ -715,28 +722,93 @@ CREATE TABLE document_numbering_configs (
|
||||
CREATE TABLE document_number_audit (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
document_id INT NOT NULL,
|
||||
generated_number VARCHAR(100) NOT NULL,
|
||||
document_type VARCHAR(50),
|
||||
document_number VARCHAR(100) NOT NULL,
|
||||
operation ENUM('RESERVE', 'CONFIRM', 'CANCEL', 'MANUAL_OVERRIDE', 'VOID', 'GENERATE') NOT NULL,
|
||||
status ENUM('RESERVED', 'CONFIRMED', 'CANCELLED', 'VOID', 'MANUAL'),
|
||||
counter_key JSON NOT NULL COMMENT 'Counter key used (JSON format)',
|
||||
reservation_token VARCHAR(36) NULL,
|
||||
originator_organization_id INT NULL,
|
||||
recipient_organization_id INT NULL,
|
||||
|
||||
template_used VARCHAR(200) NOT NULL,
|
||||
old_value TEXT NULL,
|
||||
new_value TEXT NULL,
|
||||
|
||||
user_id INT NOT NULL,
|
||||
ip_address VARCHAR(45),
|
||||
user_agent TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
is_success BOOLEAN DEFAULT TRUE,
|
||||
|
||||
-- Performance & Error Tracking
|
||||
retry_count INT DEFAULT 0,
|
||||
lock_wait_ms INT COMMENT 'Lock acquisition time in milliseconds',
|
||||
total_duration_ms INT COMMENT 'Total generation time',
|
||||
fallback_used ENUM('NONE', 'DB_LOCK', 'RETRY') DEFAULT 'NONE',
|
||||
metadata JSON NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_operation (operation),
|
||||
INDEX idx_document_number (document_number),
|
||||
INDEX idx_reservation_token (reservation_token);
|
||||
INDEX idx_created_at (created_at),
|
||||
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
) ENGINE=InnoDB COMMENT='Document Number Generation Audit Trail';
|
||||
```
|
||||
|
||||
### 3.11.11.5 Reservation Table
|
||||
```sql
|
||||
CREATE TABLE document_number_reservations (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
|
||||
-- Reservation Details
|
||||
token VARCHAR(36) NOT NULL UNIQUE COMMENT 'UUID v4',
|
||||
document_number VARCHAR(100) NOT NULL UNIQUE,
|
||||
status ENUM('RESERVED', 'CONFIRMED', 'CANCELLED', 'VOID') NOT NULL DEFAULT 'RESERVED',
|
||||
|
||||
-- Linkage
|
||||
document_id INT NULL COMMENT 'FK to documents (NULL until confirmed)',
|
||||
|
||||
-- Context (for debugging)
|
||||
project_id INT NOT NULL,
|
||||
correspondence_type_id INT NOT NULL,
|
||||
originator_organization_id INT NOT NULL,
|
||||
recipient_organization_id INT DEFAULT 0,
|
||||
user_id INT NOT NULL,
|
||||
|
||||
-- Timestamps
|
||||
reserved_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
expires_at DATETIME(6) NOT NULL,
|
||||
confirmed_at DATETIME(6) NULL,
|
||||
cancelled_at DATETIME(6) NULL,
|
||||
|
||||
-- Audit
|
||||
ip_address VARCHAR(45),
|
||||
user_agent TEXT,
|
||||
metadata JSON NULL COMMENT 'Additional context',
|
||||
|
||||
-- Indexes
|
||||
INDEX idx_token (token),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_status_expires (status, expires_at),
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_reserved_at (reserved_at),
|
||||
|
||||
-- Foreign Keys
|
||||
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||
COMMENT='Document Number Reservations - Two-Phase Commit';
|
||||
|
||||
```
|
||||
### 3.11.11.5 Error Log Table
|
||||
|
||||
```sql
|
||||
@@ -1254,9 +1326,9 @@ expected_duplicates: 0
|
||||
|
||||
## 3.11.23 References
|
||||
|
||||
- [Implementation Guide](file:///d:/nap-dms.lcbp3/specs/03-implementation/document-numbering.md)
|
||||
- [Operations Guide](file:///d:/nap-dms.lcbp3/specs/04-operations/document-numbering-operations.md)
|
||||
- [API Design](file:///d:/nap-dms.lcbp3/specs/02-architecture/api-design.md)
|
||||
- [Implementation Guide](../03-implementation/03-04-document-numbering.md)
|
||||
- [Operations Guide](../04-operations/04-08-document-numbering-operations.md)
|
||||
- [API Design](../02-architecture/02-02-api-design.md)
|
||||
- [Data Dictionary](file:///d:/nap-dms.lcbp3/specs/04-data-dictionary/4_Data_Dictionary_V1_4_4.md)
|
||||
- [ADR-018: Document Numbering Strategy](file:///d:/nap-dms.lcbp3/specs/05-decisions/adr-018-document-numbering.md)
|
||||
- [Two-Phase Commit Pattern](https://en.wikipedia.org/wiki/Two-phase_commit_protocol)
|
||||
@@ -1,8 +1,8 @@
|
||||
# 📋 Requirements Specification
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Version:** 1.7.0
|
||||
**Status:** Active
|
||||
**Last Updated:** 2025-12-13
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
---
|
||||
|
||||
@@ -16,31 +16,31 @@ This directory contains the functional and non-functional requirements for the L
|
||||
|
||||
### Core Requirements
|
||||
|
||||
1. [Objectives & Goals](./01-objectives.md) - Project objectives and success criteria
|
||||
2. [System Architecture & Technology](./02-architecture.md) - High-level architecture requirements
|
||||
3. [Functional Requirements](./03-functional-requirements.md) - Detailed feature specifications
|
||||
1. [Objectives & Goals](./01-01-objectives.md) - Project objectives and success criteria
|
||||
2. [System Architecture & Technology](./01-02-architecture.md) - High-level architecture requirements
|
||||
3. [Functional Requirements](./01-03-functional-requirements.md) - Detailed feature specifications
|
||||
|
||||
### Functional Areas
|
||||
|
||||
#### Document Management
|
||||
|
||||
- [3.1 Project & Organization Management](./03.1-project-management.md) - Projects, contracts, organizations
|
||||
- [3.2 Correspondence Management](./03.2-correspondence.md) - Letters and communications
|
||||
- [3.3 RFA Management](./03.3-rfa.md) - Request for Approval
|
||||
- [3.4 Contract Drawing Management](./03.4-contract-drawing.md) - Contract drawings (แบบคู่สัญญา)
|
||||
- [3.5 Shop Drawing Management](./03.5-shop-drawing.md) - Shop drawings (แบบก่อสร้าง)
|
||||
- [3.1 Project & Organization Management](./01-03.1-project-management.md) - Projects, contracts, organizations
|
||||
- [3.2 Correspondence Management](./01-03.2-correspondence.md) - Letters and communications
|
||||
- [3.3 RFA Management](./01-03.3-rfa.md) - Request for Approval
|
||||
- [3.4 Contract Drawing Management](./01-03.4-contract-drawing.md) - Contract drawings (แบบคู่สัญญา)
|
||||
- [3.5 Shop Drawing Management](./01-03.5-shop-drawing.md) - Shop drawings (แบบก่อสร้าง)
|
||||
|
||||
#### Supporting Features
|
||||
|
||||
- [3.6 Unified Workflow](./03.6-unified-workflow.md) - Workflow engine and routing
|
||||
- [3.7 Transmittals Management](./03.7-transmittals.md) - Document transmittals
|
||||
- [3.8 Circulation Sheet Management](./03.8-circulation-sheet.md) - Document circulation
|
||||
- [3.9 Revisions Management](./03.9-revisions.md) - Version control
|
||||
- [3.10 File Handling](./03.10-file-handling.md) - File storage and processing
|
||||
- [3.6 Unified Workflow](./01-03.6-unified-workflow.md) - Workflow engine and routing
|
||||
- [3.7 Transmittals Management](./01-03.7-transmittals.md) - Document transmittals
|
||||
- [3.8 Circulation Sheet Management](./01-03.8-circulation-sheet.md) - Document circulation
|
||||
- [3.9 Revisions Management](./01-03.9-logs.md) - Version control
|
||||
- [3.10 File Handling](./01-03.10-file-handling.md) - File storage and processing
|
||||
|
||||
#### **⭐ Document Numbering System**
|
||||
|
||||
- [3.11 Document Numbering](./03.11-document-numbering.md) - **Requirements**
|
||||
- [3.11 Document Numbering](./01-03.11-document-numbering.md) - **Requirements**
|
||||
- Automatic number generation
|
||||
- Template-based formatting
|
||||
- Concurrent request handling
|
||||
@@ -48,19 +48,19 @@ This directory contains the functional and non-functional requirements for the L
|
||||
|
||||
**Implementation & Operations:**
|
||||
|
||||
- 📘 [Implementation Guide](../03-implementation/document-numbering.md) - NestJS, TypeORM, Redis code examples
|
||||
- 📗 [Operations Guide](../04-operations/document-numbering-operations.md) - Monitoring, troubleshooting, runbooks
|
||||
- 📘 [Implementation Guide](../03-implementation/03-04-document-numbering.md) - NestJS, TypeORM, Redis code examples
|
||||
- 📗 [Operations Guide](../04-operations/04-08-document-numbering-operations.md) - Monitoring, troubleshooting, runbooks
|
||||
|
||||
#### Technical Details
|
||||
|
||||
- [3.12 JSON Details](./03.12-json-details.md) - JSON field specifications
|
||||
- [3.12 JSON Details](./01-03.12-json-details.md) - JSON field specifications
|
||||
|
||||
### Cross-Cutting Concerns
|
||||
|
||||
4. [Access Control & RBAC](./04-access-control.md) - 4-level hierarchical RBAC
|
||||
5. [UI/UX Requirements](./05-ui-ux.md) - User interface specifications
|
||||
6. [Non-Functional Requirements](./06-non-functional.md) - Performance, security, scalability
|
||||
7. [Testing Requirements](./07-testing.md) - Test strategy and coverage
|
||||
4. [Access Control & RBAC](./01-04-access-control.md) - 4-level hierarchical RBAC
|
||||
5. [UI/UX Requirements](./01-05-ui-ux.md) - User interface specifications
|
||||
6. [Non-Functional Requirements](./01-06-non-functional.md) - Performance, security, scalability
|
||||
7. [Testing Requirements](./01-07-testing.md) - Test strategy and coverage
|
||||
|
||||
---
|
||||
|
||||
@@ -76,8 +76,8 @@ This directory contains the functional and non-functional requirements for the L
|
||||
|
||||
- ✅ **Reorganized Document Numbering documentation**
|
||||
- Split into: Requirements → Implementation → Operations
|
||||
- Created [document-numbering.md](../03-implementation/document-numbering.md) implementation guide
|
||||
- Created [document-numbering-operations.md](../04-operations/document-numbering-operations.md) ops guide
|
||||
- Created [document-numbering.md](../03-implementation/03-04-document-numbering.md) implementation guide
|
||||
- Created [document-numbering-operations.md](../04-operations/04-08-document-numbering-operations.md) ops guide
|
||||
- ✅ Updated schema to match v1.6.0 requirements
|
||||
- ✅ Enhanced cross-references between documents
|
||||
|
||||
@@ -101,19 +101,19 @@ See [CHANGELOG.md](../../CHANGELOG.md) for detailed version history.
|
||||
|
||||
### By Feature Status
|
||||
|
||||
| Feature Area | Requirements Doc | Status | Implementation | Operations |
|
||||
| ------------------------- | -------------------------------------- | ---------- | ----------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| Correspondence Management | [03.2](./03.2-correspondence.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| RFA Management | [03.3](./03.3-rfa.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Contract Drawing | [03.4](./03.4-contract-drawing.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Shop Drawing | [03.5](./03.5-shop-drawing.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Workflow Engine | [03.6](./03.6-unified-workflow.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Transmittals | [03.7](./03.7-transmittals.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Circulation Sheets | [03.8](./03.8-circulation-sheet.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| **Document Numbering** | [03.11](./03.11-document-numbering.md) | ✅ Complete | ✅ [Guide](../03-implementation/document-numbering.md) | ✅ [Guide](../04-operations/document-numbering-operations.md) |
|
||||
| Access Control (RBAC) | [04](./04-access-control.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Search (Elasticsearch) | N/A | ✅ Complete | 🔄 95% | Available |
|
||||
| Dashboard & Analytics | N/A | ✅ Complete | ✅ Complete | Available |
|
||||
| Feature Area | Requirements Doc | Status | Implementation | Operations |
|
||||
| ------------------------- | ----------------------------------------- | ---------- | ----------------------------------------------------------- | ------------------------------------------------------------------ |
|
||||
| Correspondence Management | [03.2](./01-03.2-correspondence.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| RFA Management | [03.3](./01-03.3-rfa.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Contract Drawing | [03.4](./01-03.4-contract-drawing.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Shop Drawing | [03.5](./01-03.5-shop-drawing.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Workflow Engine | [03.6](./01-03.6-unified-workflow.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Transmittals | [03.7](./01-03.7-transmittals.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Circulation Sheets | [03.8](./01-03.8-circulation-sheet.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| **Document Numbering** | [03.11](./01-03.11-document-numbering.md) | ✅ Complete | ✅ [Guide](../03-implementation/03-04-document-numbering.md) | ✅ [Guide](../04-operations/04-08-document-numbering-operations.md) |
|
||||
| Access Control (RBAC) | [04](./01-04-access-control.md) | ✅ Complete | ✅ Complete | Available |
|
||||
| Search (Elasticsearch) | N/A | ✅ Complete | 🔄 95% | Available |
|
||||
| Dashboard & Analytics | N/A | ✅ Complete | ✅ Complete | Available |
|
||||
|
||||
### By Priority
|
||||
|
||||
@@ -141,8 +141,8 @@ All requirements documents must meet these criteria:
|
||||
|
||||
### For Product Owners / Business Analysts
|
||||
|
||||
1. Start with [Objectives & Goals](./01-objectives.md)
|
||||
2. Review [Functional Requirements](./03-functional-requirements.md)
|
||||
1. Start with [Objectives & Goals](./01-01-objectives.md)
|
||||
2. Review [Functional Requirements](./01-03-functional-requirements.md)
|
||||
3. Check specific feature requirements (3.1-3.12)
|
||||
|
||||
### For Developers
|
||||
@@ -154,13 +154,13 @@ All requirements documents must meet these criteria:
|
||||
|
||||
### For QA / Testers
|
||||
|
||||
1. Review [Testing Requirements](./07-testing.md)
|
||||
1. Review [Testing Requirements](./01-07-testing.md)
|
||||
2. Use requirements as test case source
|
||||
3. Verify [Non-Functional Requirements](./06-non-functional.md)
|
||||
3. Verify [Non-Functional Requirements](./01-06-non-functional.md)
|
||||
|
||||
### For Operations Team
|
||||
|
||||
1. Read [Non-Functional Requirements](./06-non-functional.md) for SLAs
|
||||
1. Read [Non-Functional Requirements](01-06-non-functional.md) for SLAs
|
||||
2. Check [Operations Guides](../04-operations/) for specific features
|
||||
3. Review monitoring and alerting requirements
|
||||
|
||||
@@ -178,8 +178,8 @@ All requirements documents must meet these criteria:
|
||||
|
||||
## 📝 Document Control
|
||||
|
||||
- **Version:** 1.6.0
|
||||
- **Version:** 1.7.0
|
||||
- **Owner:** System Architect (Nattanin Peancharoen)
|
||||
- **Last Review:** 2025-12-13
|
||||
- **Last Review:** 2025-12-18
|
||||
- **Next Review:** 2026-01-01
|
||||
- **Classification:** Internal Use Only
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
---
|
||||
|
||||
**title:** 'System Architecture'
|
||||
**version:** 1.6.2
|
||||
**version:** 1.7.0
|
||||
**status:** first-draft
|
||||
**owner:** Nattanin Peancharoen
|
||||
**last_updated:** 2025-12-17
|
||||
**last_updated:** 2025-12-18
|
||||
**related:**
|
||||
|
||||
- specs/01-requirements/02-architecture.md
|
||||
- specs/01-requirements/06-non-functional.md
|
||||
- specs/03-implementation/fullftack-js-v1.6.2.md
|
||||
- specs/01-requirements/01-02-architecture.md
|
||||
- specs/01-requirements/01-06-non-functional.md
|
||||
- specs/03-implementation/03-01-fullftack-js-v1.7.0.md
|
||||
|
||||
---
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
---
|
||||
|
||||
**title:** 'API Design'
|
||||
**version:** 1.6.0
|
||||
**version:** 1.7.0
|
||||
**status:** active
|
||||
**owner:** Nattanin Peancharoen
|
||||
**last_updated:** 2025-12-02
|
||||
**last_updated:** 2025-12-18
|
||||
**related:**
|
||||
|
||||
- specs/01-requirements/02-architecture.md
|
||||
- specs/02-architecture/system-architecture.md
|
||||
- specs/03-implementation/fullftack-js-v1.5.0.md
|
||||
- specs/01-requirements/01-02-architecture.md
|
||||
- specs/02-architecture/02-01-system-architecture.md
|
||||
- specs/03-implementation/03-01-fullftack-js-v1.7.0.md
|
||||
|
||||
---
|
||||
|
||||
@@ -546,7 +546,7 @@ X-API-Deprecation-Info: https://docs.np-dms.work/migration/v2
|
||||
|
||||
**Document Control:**
|
||||
|
||||
- **Version:** 1.6.0
|
||||
- **Version:** 1.7.0
|
||||
- **Status:** Active
|
||||
- **Last Updated:** 2025-12-13
|
||||
- **Last Updated:** 2025-12-18
|
||||
- **Owner:** Nattanin Peancharoen
|
||||
@@ -612,11 +612,11 @@ SELECT * FROM correspondences WHERE deleted_at IS NULL;
|
||||
|
||||
## 🔗 Related Documentation
|
||||
|
||||
- [System Architecture](./02-architecture.md) - สถาปัตยกรรมระบบโดยรวม
|
||||
- [API Design](./api-design.md) - การออกแบบ API
|
||||
- [System Architecture](../01-requirements/01-02-architecture.md) - สถาปัตยกรรมระบบโดยรวม
|
||||
- [API Design](02-02-api-design.md) - การออกแบบ API
|
||||
- [Data Dictionary v1.4.5](../../docs/4_Data_Dictionary_V1_4_5.md) - รายละเอียดตารางทั้งหมด
|
||||
- [SQL Schema v1.4.5](../../docs/8_lcbp3_v1_4_5.sql) - SQL Script สำหรับสร้างฐานข้อมูล
|
||||
- [Functional Requirements](../01-requirements/03-functional-requirements.md) - ความต้องการด้านฟังก์ชัน
|
||||
- [Functional Requirements](../01-requirements/01-03-functional-requirements.md) - ความต้องการด้านฟังก์ชัน
|
||||
|
||||
---
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
| Attribute | Value |
|
||||
| ------------------ | -------------------------------- |
|
||||
| **Version** | 1.6.2 |
|
||||
| **Version** | 1.7.0 |
|
||||
| **Status** | Active |
|
||||
| **Last Updated** | 2025-12-17 |
|
||||
| **Last Updated** | 2025-12-18 |
|
||||
| **Owner** | Nattanin Peancharoen |
|
||||
| **Classification** | Internal Technical Documentation |
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
## 📖 เอกสารสถาปัตยกรรม
|
||||
|
||||
### 1. [System Architecture](./system-architecture.md)
|
||||
### 1. [System Architecture](./02-01-system-architecture.md)
|
||||
|
||||
**สถาปัตยกรรมระบบโดยรวม**
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
- ✅ Caching Strategy
|
||||
- ✅ Rate Limiting
|
||||
|
||||
### 2. [API Design](./api-design.md)
|
||||
### 2. [API Design](./02-02-api-design.md)
|
||||
|
||||
**การออกแบบ API แบบ RESTful**
|
||||
|
||||
@@ -111,12 +111,12 @@
|
||||
- ✅ Rate Limiting per Role
|
||||
- ✅ File Upload Security
|
||||
|
||||
### 3. [Data Model](./data-model.md)
|
||||
### 3. [Data Model](./02-03-data-model.md)
|
||||
|
||||
**โครงสร้างฐานข้อมูลและ Entity Relationships**
|
||||
|
||||
> [!NOTE]
|
||||
> เอกสารนี้อยู่ระหว่างการพัฒนา กรุณาอ้างอิง [Data Dictionary](../../docs/4_Data_Dictionary_V1_4_5.md) สำหรับข้อมูลละเอียด
|
||||
> เอกสารนี้อยู่ระหว่างการพัฒนา กรุณาอ้างอิง [Data Dictionary](../07-database/data-dictionary-v1.7.0.md) สำหรับข้อมูลละเอียด
|
||||
|
||||
**Expected Content:**
|
||||
|
||||
@@ -272,9 +272,9 @@ Layer 6: File Security (Virus Scanning, Access Control)
|
||||
- **Counter Key:** Composite PK (8 columns)
|
||||
|
||||
**Documentation:**
|
||||
- 📋 [Requirements](../01-requirements/03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/document-numbering-operations.md)
|
||||
- 📋 [Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/03-04-document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/04-08-document-numbering-operations.md)
|
||||
|
||||
**Related:** [ADR-002](../05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
|
||||
@@ -492,7 +492,7 @@ sequenceDiagram
|
||||
|
||||
**LCBP3-DMS Architecture Specification v1.6.0**
|
||||
|
||||
[System Architecture](./system-architecture.md) • [API Design](./api-design.md) • [Data Model](./data-model.md)
|
||||
[System Architecture](02-01-system-architecture.md) • [API Design](02-02-api-design.md) • [Data Model](02-03-data-model.md)
|
||||
|
||||
[Main README](../../README.md) • [Requirements](../01-requirements/README.md) • [Implementation](../03-implementation/README.md)
|
||||
|
||||
|
||||
@@ -462,7 +462,7 @@ async approve(@Param('id') id: string, @CurrentUser() user: User) {
|
||||
|
||||
## 📚 เอกสารอ้างอิง
|
||||
|
||||
- [FullStack Guidelines](./fullftack-js-V1.5.0.md)
|
||||
- [FullStack Guidelines](03-01-fullftack-js-v1.7.0.md)
|
||||
- [Backend Plan v1.4.5](../../docs/2_Backend_Plan_V1_4_5.md)
|
||||
- [Data Dictionary](../../docs/4_Data_Dictionary_V1_4_5.md)
|
||||
- [Workflow Engine Plan](../../docs/2_Backend_Plan_V1_4_4.Phase6A.md)
|
||||
@@ -642,7 +642,7 @@ test.describe('Correspondence Workflow', () => {
|
||||
|
||||
## 📚 เอกสารอ้างอิง
|
||||
|
||||
- [FullStack Guidelines](./fullftack-js-V1.5.0.md)
|
||||
- [FullStack Guidelines](03-01-fullftack-js-v1.7.0.md)
|
||||
- [Frontend Plan v1.4.5](../../docs/3_Frontend_Plan_V1_4_5.md)
|
||||
- [Next.js Documentation](https://nextjs.org/docs)
|
||||
- [TanStack Query](https://tanstack.com/query)
|
||||
@@ -109,15 +109,17 @@ CREATE TABLE document_number_formats (
|
||||
```sql
|
||||
CREATE TABLE document_number_counters (
|
||||
project_id INT NOT NULL,
|
||||
correspondence_type_id INT NULL,
|
||||
originator_organization_id INT NOT NULL,
|
||||
recipient_organization_id INT NULL,
|
||||
correspondence_type_id INT NOT NULL,
|
||||
recipient_organization_id INT NOT NULL DEFAULT 0, -- 0 = no recipient (RFA)
|
||||
sub_type_id INT DEFAULT 0,
|
||||
rfa_type_id INT DEFAULT 0,
|
||||
discipline_id INT DEFAULT 0,
|
||||
current_year INT NOT NULL,
|
||||
reset_scope VARCHAR(20) NOT NULL,
|
||||
last_number INT DEFAULT 0 NOT NULL,,
|
||||
version INT DEFAULT 0 NOT NULL,
|
||||
last_number INT DEFAULT 0,
|
||||
created_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
updated_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
|
||||
PRIMARY KEY (
|
||||
project_id,
|
||||
@@ -127,19 +129,24 @@ CREATE TABLE document_number_counters (
|
||||
sub_type_id,
|
||||
rfa_type_id,
|
||||
discipline_id,
|
||||
current_year
|
||||
reset_scope
|
||||
),
|
||||
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (originator_organization_id) REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (recipient_organization_id) REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE,
|
||||
|
||||
INDEX idx_counter_lookup (project_id, correspondence_type_id, current_year),
|
||||
INDEX idx_counter_org (originator_organization_id, current_year),
|
||||
INDEX idx_counter_lookup (project_id, correspondence_type_id, reset_scope),
|
||||
INDEX idx_counter_org (originator_organization_id, reset_scope),
|
||||
INDEX idx_counter_updated (updated_at),
|
||||
|
||||
CONSTRAINT chk_last_number_positive CHECK (last_number >= 0),
|
||||
CONSTRAINT chk_current_year_valid CHECK (current_year BETWEEN 2020 AND 2100)
|
||||
CONSTRAINT chk_reset_scope_format CHECK (
|
||||
reset_scope IN ('NONE') OR
|
||||
reset_scope LIKE 'YEAR_%' OR
|
||||
reset_scope LIKE 'MONTH_%' OR
|
||||
reset_scope LIKE 'CONTRACT_%'
|
||||
)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||
COMMENT='Running Number Counters';
|
||||
```
|
||||
@@ -149,18 +156,25 @@ CREATE TABLE document_number_counters (
|
||||
```sql
|
||||
CREATE TABLE document_number_audit (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
operation ENUM('RESERVE', 'CONFIRM', 'CANCEL', 'MANUAL_OVERRIDE', 'VOID', 'GENERATE') NOT NULL,
|
||||
document_id INT NULL COMMENT 'FK to documents (NULL initially)',
|
||||
document_type VARCHAR(50),
|
||||
generated_number VARCHAR(100) NOT NULL,
|
||||
document_number VARCHAR(100) NOT NULL,
|
||||
operation ENUM('RESERVE', 'CONFIRM', 'CANCEL', 'MANUAL_OVERRIDE', 'VOID', 'GENERATE') NOT NULL,
|
||||
status ENUM('RESERVED', 'CONFIRMED', 'CANCELLED', 'VOID', 'MANUAL'),
|
||||
counter_key JSON NOT NULL COMMENT 'Counter key used (JSON format)',
|
||||
reservation_token VARCHAR(36) NULL,
|
||||
originator_organization_id INT NULL,
|
||||
recipient_organization_id INT NULL,
|
||||
|
||||
template_used VARCHAR(200) NOT NULL,
|
||||
old_value TEXT NULL,
|
||||
new_value TEXT NULL,
|
||||
user_id INT NULL COMMENT 'FK to users (Allow NULL for system generation)',
|
||||
ip_address VARCHAR(45),
|
||||
|
||||
user_agent TEXT,
|
||||
is_success BOOLEAN DEFAULT TRUE,
|
||||
|
||||
retry_count INT DEFAULT 0,
|
||||
lock_wait_ms INT COMMENT 'Lock acquisition time in milliseconds',
|
||||
total_duration_ms INT COMMENT 'Total generation time',
|
||||
@@ -168,10 +182,11 @@ CREATE TABLE document_number_audit (
|
||||
metadata JSON NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
INDEX idx_operation (operation),
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_document_number (generated_number),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_operation (operation),
|
||||
INDEX idx_document_number (document_number),
|
||||
INDEX idx_created_at (created_at),
|
||||
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
@@ -206,7 +221,55 @@ CREATE TABLE document_number_errors (
|
||||
INDEX idx_user_id (user_id)
|
||||
) ENGINE=InnoDB COMMENT='Document Numbering Error Log';
|
||||
```
|
||||
### 2.5 Reservation Table
|
||||
|
||||
```sql
|
||||
CREATE TABLE document_number_reservations (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
|
||||
-- Reservation Details
|
||||
token VARCHAR(36) NOT NULL UNIQUE COMMENT 'UUID v4',
|
||||
document_number VARCHAR(100) NOT NULL UNIQUE,
|
||||
status ENUM('RESERVED', 'CONFIRMED', 'CANCELLED', 'VOID') NOT NULL DEFAULT 'RESERVED',
|
||||
|
||||
-- Linkage
|
||||
document_id INT NULL COMMENT 'FK to documents (NULL until confirmed)',
|
||||
|
||||
-- Context (for debugging)
|
||||
project_id INT NOT NULL,
|
||||
correspondence_type_id INT NOT NULL,
|
||||
originator_organization_id INT NOT NULL,
|
||||
recipient_organization_id INT DEFAULT 0,
|
||||
user_id INT NOT NULL,
|
||||
|
||||
-- Timestamps
|
||||
reserved_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
expires_at DATETIME(6) NOT NULL,
|
||||
confirmed_at DATETIME(6) NULL,
|
||||
cancelled_at DATETIME(6) NULL,
|
||||
|
||||
-- Audit
|
||||
ip_address VARCHAR(45),
|
||||
user_agent TEXT,
|
||||
metadata JSON NULL COMMENT 'Additional context',
|
||||
|
||||
-- Indexes
|
||||
INDEX idx_token (token),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_status_expires (status, expires_at),
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_reserved_at (reserved_at),
|
||||
|
||||
-- Foreign Keys
|
||||
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
|
||||
COMMENT='Document Number Reservations - Two-Phase Commit';
|
||||
```
|
||||
---
|
||||
|
||||
## 3. Core Services
|
||||
@@ -748,10 +811,10 @@ GRAFANA_PORT=3000
|
||||
|
||||
## References
|
||||
|
||||
- [Requirements](file:///d:/nap-dms.lcbp3/specs/01-requirements/03.11-document-numbering.md)
|
||||
- [Operations Guide](file:///d:/nap-dms.lcbp3/specs/04-operations/document-numbering-operations.md)
|
||||
- [Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
- [Operations Guide](../04-operations/04-08-document-numbering-operations.md)
|
||||
- [ADR-018 Document Numbering](file:///d:/nap-dms.lcbp3/specs/05-decisions/adr-018-document-numbering.md)
|
||||
- [Backend Guidelines](file:///d:/nap-dms.lcbp3/specs/03-implementation/backend-guidelines.md)
|
||||
- [Backend Guidelines](03-02-backend-guidelines.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -1229,10 +1229,10 @@ describe('[ClassName/FeatureName]', () => {
|
||||
|
||||
## 🔗 Related Documentation
|
||||
|
||||
- [Backend Guidelines](./backend-guidelines.md) - Backend development standards
|
||||
- [Frontend Guidelines](./frontend-guidelines.md) - Frontend development standards
|
||||
- [System Architecture](../02-architecture/system-architecture.md) - System overview
|
||||
- [API Design](../02-architecture/api-design.md) - API specifications
|
||||
- [Backend Guidelines](03-02-backend-guidelines.md) - Backend development standards
|
||||
- [Frontend Guidelines](03-03-frontend-guidelines.md) - Frontend development standards
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md) - System overview
|
||||
- [API Design](../02-architecture/02-02-api-design.md) - API specifications
|
||||
|
||||
---
|
||||
|
||||
119
specs/03-implementation/README.md
Normal file
119
specs/03-implementation/README.md
Normal file
@@ -0,0 +1,119 @@
|
||||
# 🛠️ Implementation Specification
|
||||
|
||||
> **แนวทางการพัฬนาและมาตรฐานทางเทคนิคของระบบ LCBP3-DMS**
|
||||
>
|
||||
> เอกสารชุดนี้รวบรวมมาตรฐานการเขียนโปรแกรม แนวทางการพัฒนา และรายละเอียดการนำสถาปัตยกรรมไปใช้งานจริง ทั้งในส่วนของ Backend และ Frontend
|
||||
|
||||
---
|
||||
|
||||
## 📊 Document Status
|
||||
|
||||
| Attribute | Value |
|
||||
| ------------------ | -------------------------------- |
|
||||
| **Version** | 1.7.0 |
|
||||
| **Status** | Active |
|
||||
| **Last Updated** | 2025-12-18 |
|
||||
| **Owner** | Nattanin Peancharoen |
|
||||
| **Classification** | Internal Technical Documentation |
|
||||
|
||||
---
|
||||
|
||||
## 📚 Table of Contents
|
||||
|
||||
- [หลักการพัฒนาหลัก (Core Principles)](#-หลักการพัฒนาหลัก-core-principles)
|
||||
- [คู่มือการพัฒนา (Implementation Guides)](#-คู่มือการพัฒนา-implementation-guides)
|
||||
- [มาตรฐานการเขียนโปรแกรม (Coding Standards)](#-มาตรฐานการเขียนโปรแกรม-coding-standards)
|
||||
- [Technology Stack Recap](#-technology-stack-recap)
|
||||
- [Testing Strategy](#-testing-strategy)
|
||||
- [Related Documents](#-related-documents)
|
||||
|
||||
---
|
||||
|
||||
## 🎯 หลักการพัฒนาหลัก (Core Principles)
|
||||
|
||||
เพื่อให้ระบบมีความมั่นคง ยืดหยุ่น และดูแลรักษาง่าย การพัฒนาต้องยึดหลักการดังนี้:
|
||||
|
||||
1. **Type Safety Everywhere** - ใช้ TypeScript อย่างเข้มงวด ห้ามใช้ `any`
|
||||
2. **Modular Dependency** - แยก Logic ตาม Module หลีกเลี่ยง Circular Dependency
|
||||
3. **Idempotency** - การสร้างหรือแก้ไขข้อมูลต้องรองรับการกดซ้ำได้ (Idempotency-Key)
|
||||
4. **Security by Default** - ตรวจสอบ Permission (RBAC) และ Validation ในทุก Endpoint
|
||||
5. **Fail Fast & Log Everything** - ดักจับ Error ตั้งแต่เนิ่นๆ และบันทึก Audit Logs ที่สำคัญ
|
||||
|
||||
---
|
||||
|
||||
## 📖 คู่มือการพัฒนา (Implementation Guides)
|
||||
|
||||
### 1. [FullStack JS Guidelines](./03-01-fullftack-js-v1.7.0.md)
|
||||
**แนวทางการพัฒนาภาพรวมทั้งระบบ (v1.7.0)**
|
||||
- โครงสร้างโปรเจกต์ (Monorepo-like focus)
|
||||
- Naming Conventions & Code Style
|
||||
- Secrets & Environment Management
|
||||
- Two-Phase File Storage Algorithm
|
||||
- Double-Lock Mechanism for Numbering
|
||||
|
||||
### 2. [Backend Guidelines](./03-02-backend-guidelines.md)
|
||||
**แนวทางการพัฒนา NestJS Backend**
|
||||
- Modular Architecture Detail
|
||||
- DTO Validation & Transformer
|
||||
- TypeORM Best Practices & Optimistic Locking
|
||||
- JWT Authentication & CASL Authorization
|
||||
- BullMQ for Background Jobs
|
||||
|
||||
### 3. [Frontend Guidelines](./03-03-frontend-guidelines.md)
|
||||
**แนวทางการพัฒนา Next.js Frontend**
|
||||
- App Router Patterns
|
||||
- Shadcn/UI & Tailwind Styling
|
||||
- TanStack Query for Data Fetching
|
||||
- React Hook Form + Zod for Client Validation
|
||||
- API Client Interceptors (Auth & Idempotency)
|
||||
|
||||
### 4. [Document Numbering System](./03-04-document-numbering.md)
|
||||
**รายละเอียดการนำระบบออกเลขที่เอกสารไปใช้งาน**
|
||||
- Table Schema: Templates, Counters, Audit
|
||||
- Double-Lock Strategy (Redis Redlock + Database VersionColumn)
|
||||
- Reservation Flow (Phase 1: Reserve, Phase 2: Confirm)
|
||||
- API Specs for Numbering Management
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Testing Strategy
|
||||
|
||||
รายละเอียดอยู่ในเอกสาร: **[Testing Strategy](./03-05-testing-strategy.md)**
|
||||
|
||||
- **Unit Testing:** NestJS (Jest), React (Vitest)
|
||||
- **Integration Testing:** API Endpoints (Supertest)
|
||||
- **E2E Testing:** Playwright สำหรับ Critical Flows
|
||||
- **Special Tests:** Concurrency Tests สำหรับ Document Numbering
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Technology Stack Recap
|
||||
|
||||
| Layer | Primary Technology | Secondary/Supporting |
|
||||
| ------------ | ------------------ | -------------------- |
|
||||
| **Backend** | NestJS (Node.js) | TypeORM, BullMQ |
|
||||
| **Frontend** | Next.js 14+ | Shadcn/UI, Tailwind |
|
||||
| **Database** | MariaDB 11.8 | Redis 7 (Cache/Lock) |
|
||||
| **Search** | Elasticsearch | - |
|
||||
| **Testing** | Jest, Vitest | Playwright |
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Related Documents
|
||||
|
||||
- 📋 [Requirements Specification](../01-requirements/README.md)
|
||||
- 🏗️ [Architecture Specification](../02-architecture/README.md)
|
||||
- 🚀 [Operations Specification](../04-operations/README.md)
|
||||
- 🎯 [Active Tasks](../06-tasks/README.md)
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
|
||||
**LCBP3-DMS Implementation Specification v1.7.0**
|
||||
|
||||
[FullStack](./03-01-fullftack-js-v1.7.0.md) • [Backend](./03-02-backend-guidelines.md) • [Frontend](./03-03-frontend-guidelines.md) • [Testing](./03-05-testing-strategy.md)
|
||||
|
||||
[Main README](../../README.md) • [Architecture](../02-architecture/README.md) • [Requirements](../01-requirements/README.md)
|
||||
|
||||
</div>
|
||||
@@ -924,10 +924,10 @@ docker exec lcbp3-mariadb mysql -u root -p -e "
|
||||
|
||||
## 📚 Related Documentation
|
||||
|
||||
- [Environment Setup Guide](./environment-setup.md)
|
||||
- [Backup & Recovery](./backup-recovery.md)
|
||||
- [Monitoring & Alerting](./monitoring-alerting.md)
|
||||
- [Maintenance Procedures](./maintenance-procedures.md)
|
||||
- [Environment Setup Guide](04-02-environment-setup.md)
|
||||
- [Backup & Recovery](04-04-backup-recovery.md)
|
||||
- [Monitoring & Alerting](04-03-monitoring-alerting.md)
|
||||
- [Maintenance Procedures](04-05-maintenance-procedures.md)
|
||||
- [ADR-015: Deployment Infrastructure](../05-decisions/ADR-015-deployment-infrastructure.md)
|
||||
|
||||
---
|
||||
@@ -452,8 +452,8 @@ docker exec lcbp3-backend env | grep NODE_ENV
|
||||
|
||||
## 📚 Related Documents
|
||||
|
||||
- [Deployment Guide](./deployment-guide.md)
|
||||
- [Security Operations](./security-operations.md)
|
||||
- [Deployment Guide](04-01-deployment-guide.md)
|
||||
- [Security Operations](04-06-security-operations.md)
|
||||
- [ADR-005: Technology Stack](../05-decisions/ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
@@ -432,8 +432,8 @@ ab -n 1000 -c 10 \
|
||||
|
||||
## 🔗 Related Documents
|
||||
|
||||
- [Backup & Recovery](./backup-recovery.md)
|
||||
- [Incident Response](./incident-response.md)
|
||||
- [Backup & Recovery](04-04-backup-recovery.md)
|
||||
- [Incident Response](04-07-incident-response.md)
|
||||
- [ADR-010: Logging Strategy](../05-decisions/ADR-010-logging-monitoring-strategy.md)
|
||||
|
||||
---
|
||||
@@ -363,9 +363,9 @@ WHERE created_at < DATE_SUB(NOW(), INTERVAL 1 YEAR);
|
||||
|
||||
## 🔗 Related Documents
|
||||
|
||||
- [Deployment Guide](./deployment-guide.md)
|
||||
- [Monitoring & Alerting](./monitoring-alerting.md)
|
||||
- [Incident Response](./incident-response.md)
|
||||
- [Deployment Guide](04-01-deployment-guide.md)
|
||||
- [Monitoring & Alerting](04-03-monitoring-alerting.md)
|
||||
- [Incident Response](04-07-incident-response.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -490,9 +490,9 @@ echo "Security maintenance completed: $(date)"
|
||||
|
||||
## 📚 Related Documents
|
||||
|
||||
- [Deployment Guide](./deployment-guide.md)
|
||||
- [Backup & Recovery](./backup-recovery.md)
|
||||
- [Monitoring & Alerting](./monitoring-alerting.md)
|
||||
- [Deployment Guide](04-01-deployment-guide.md)
|
||||
- [Backup & Recovery](04-04-backup-recovery.md)
|
||||
- [Monitoring & Alerting](04-03-monitoring-alerting.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -433,8 +433,8 @@ echo "Account compromise response completed for User ID: $USER_ID"
|
||||
|
||||
## 🔗 Related Documents
|
||||
|
||||
- [Incident Response](./incident-response.md)
|
||||
- [Monitoring & Alerting](./monitoring-alerting.md)
|
||||
- [Incident Response](04-07-incident-response.md)
|
||||
- [Monitoring & Alerting](04-03-monitoring-alerting.md)
|
||||
- [ADR-004: RBAC Implementation](../05-decisions/ADR-004-rbac-implementation.md)
|
||||
|
||||
---
|
||||
@@ -472,9 +472,9 @@ Database connection pool was exhausted due to slow queries not releasing connect
|
||||
|
||||
## 🔗 Related Documents
|
||||
|
||||
- [Monitoring & Alerting](./monitoring-alerting.md)
|
||||
- [Backup & Recovery](./backup-recovery.md)
|
||||
- [Security Operations](./security-operations.md)
|
||||
- [Monitoring & Alerting](04-03-monitoring-alerting.md)
|
||||
- [Backup & Recovery](04-04-backup-recovery.md)
|
||||
- [Security Operations](04-06-security-operations.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# Document Numbering Operations Guide
|
||||
|
||||
---
|
||||
title: 'Operations Guide: Document Numbering System'
|
||||
version: 1.6.2
|
||||
title: 'Document Numbering Operations Guide'
|
||||
version: 1.7.0
|
||||
status: APPROVED
|
||||
owner: Operations Team
|
||||
last_updated: 2025-12-17
|
||||
last_updated: 2025-12-18
|
||||
related:
|
||||
- specs/01-requirements/03.11-document-numbering.md
|
||||
- specs/03-implementation/document-numbering.md
|
||||
- specs/04-operations/monitoring-alerting.md
|
||||
- specs/03-implementation/03-08-document-numbering.md
|
||||
- specs/04-operations/04-08-monitoring-alerting.md
|
||||
- specs/05-decisions/ADR-002-document-numbering-strategy.md
|
||||
---
|
||||
|
||||
@@ -675,12 +675,12 @@ PUT /api/v1/document-numbering/configs/{configId}
|
||||
|
||||
### 6.2. Recovery Procedures
|
||||
|
||||
See: [Backup & Recovery Guide](file:///e:/np-dms/lcbp3/specs/04-operations/backup-recovery.md)
|
||||
See: [Backup & Recovery Guide](./04-04-backup-recovery.md)
|
||||
|
||||
## References
|
||||
|
||||
- [Requirements](file:///d:/nap-dms.lcbp3/specs/01-requirements/03.11-document-numbering.md)
|
||||
- [Implementation Guide](file:///d:/nap-dms.lcbp3/specs/03-implementation/document-numbering.md)
|
||||
- [ADR-002 Document Numbering Strategy](file:///d:/nap-dms.lcbp3/specs/05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
- [Monitoring & Alerting](file:///d:/nap-dms.lcbp3/specs/04-operations/monitoring-alerting.md)
|
||||
- [Incident Response](file:///d:/nap-dms.lcbp3/specs/04-operations/incident-response.md)
|
||||
- [Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
- [Implementation Guide](../03-implementation/03-04-document-numbering.md)
|
||||
- [ADR-002 Document Numbering Strategy](../05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
- [Monitoring & Alerting](../04-operations/04-03-monitoring-alerting.md)
|
||||
- [Incident Response](../04-operations/04-07-incident-response.md)
|
||||
@@ -1,8 +1,8 @@
|
||||
# Operations Documentation
|
||||
|
||||
**Project:** LCBP3-DMS (Laem Chabang Port Phase 3 - Document Management System)
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
---
|
||||
|
||||
@@ -18,23 +18,23 @@ This directory contains operational documentation for deploying, maintaining, an
|
||||
|
||||
| Document | Description | Status |
|
||||
| ---------------------------------------------- | ------------------------------------------------------ | ---------- |
|
||||
| [deployment-guide.md](./deployment-guide.md) | Docker deployment procedures on QNAP Container Station | ✅ Complete |
|
||||
| [environment-setup.md](./environment-setup.md) | Environment variables and configuration management | ✅ Complete |
|
||||
| [deployment-guide.md](04-01-deployment-guide.md) | Docker deployment procedures on QNAP Container Station | ✅ Complete |
|
||||
| [environment-setup.md](04-02-environment-setup.md) | Environment variables and configuration management | ✅ Complete |
|
||||
|
||||
### Monitoring & Maintenance
|
||||
|
||||
| Document | Description | Status |
|
||||
| -------------------------------------------------------- | --------------------------------------------------- | ---------- |
|
||||
| [monitoring-alerting.md](./monitoring-alerting.md) | Monitoring setup, health checks, and alerting rules | ✅ Complete |
|
||||
| [backup-recovery.md](./backup-recovery.md) | Backup strategies and disaster recovery procedures | ✅ Complete |
|
||||
| [maintenance-procedures.md](./maintenance-procedures.md) | Routine maintenance and update procedures | ✅ Complete |
|
||||
| [monitoring-alerting.md](04-03-monitoring-alerting.md) | Monitoring setup, health checks, and alerting rules | ✅ Complete |
|
||||
| [backup-recovery.md](04-04-backup-recovery.md) | Backup strategies and disaster recovery procedures | ✅ Complete |
|
||||
| [maintenance-procedures.md](04-05-maintenance-procedures.md) | Routine maintenance and update procedures | ✅ Complete |
|
||||
|
||||
### Security & Compliance
|
||||
|
||||
| Document | Description | Status |
|
||||
| -------------------------------------------------- | ---------------------------------------------- | ---------- |
|
||||
| [security-operations.md](./security-operations.md) | Security monitoring and incident response | ✅ Complete |
|
||||
| [incident-response.md](./incident-response.md) | Incident classification and response playbooks | ✅ Complete |
|
||||
| [security-operations.md](04-06-security-operations.md) | Security monitoring and incident response | ✅ Complete |
|
||||
| [incident-response.md](04-07-incident-response.md) | Incident classification and response playbooks | ✅ Complete |
|
||||
|
||||
---
|
||||
|
||||
@@ -42,10 +42,10 @@ This directory contains operational documentation for deploying, maintaining, an
|
||||
|
||||
### Initial Setup
|
||||
|
||||
1. **Read Deployment Guide** - [deployment-guide.md](./deployment-guide.md)
|
||||
2. **Configure Environment** - [environment-setup.md](./environment-setup.md)
|
||||
3. **Setup Monitoring** - [monitoring-alerting.md](./monitoring-alerting.md)
|
||||
4. **Configure Backups** - [backup-recovery.md](./backup-recovery.md)
|
||||
1. **Read Deployment Guide** - [deployment-guide.md](04-01-deployment-guide.md)
|
||||
2. **Configure Environment** - [environment-setup.md](04-02-environment-setup.md)
|
||||
3. **Setup Monitoring** - [monitoring-alerting.md](04-03-monitoring-alerting.md)
|
||||
4. **Configure Backups** - [backup-recovery.md](04-04-backup-recovery.md)
|
||||
|
||||
### Daily Operations
|
||||
|
||||
@@ -185,6 +185,7 @@ graph TB
|
||||
|
||||
---
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
**Status:** Active
|
||||
**Classification:** Internal Use Only
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**Decision Makers:** Development Team, System Architect
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [Unified Workflow Requirements](../01-requirements/03.6-unified-workflow.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [Unified Workflow Requirements](../01-requirements/01-03.6-unified-workflow.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -326,7 +326,7 @@ export class WorkflowEngineService {
|
||||
เป็นไปตาม:
|
||||
|
||||
- [Backend Plan Section 2.4.1](../../docs/2_Backend_Plan_V1_4_5.md) - Unified Workflow Engine
|
||||
- [Requirements 3.6](../01-requirements/03.6-unified-workflow.md) - Unified Workflow Specification
|
||||
- [Requirements 3.6](../01-requirements/01-03.6-unified-workflow.md) - Unified Workflow Specification
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# ADR-002: Document Numbering Strategy
|
||||
|
||||
**Status:** Accepted
|
||||
**Date:** 2025-12-02
|
||||
**Date:** 2025-12-18
|
||||
**Decision Makers:** Development Team, System Architect
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [Document Numbering Requirements](../01-requirements/03.11-document-numbering.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [Document Numbering Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -179,7 +179,7 @@ CREATE TABLE document_number_audit (
|
||||
> [!IMPORTANT]
|
||||
> **Updated to align with Requirements Specification**
|
||||
>
|
||||
> This ADR now uses token names from [03.11-document-numbering.md](../01-requirements/03.11-document-numbering.md) for consistency.
|
||||
> This ADR now uses token names from [03.11-document-numbering.md](../01-requirements/01-03.11-document-numbering.md) for consistency.
|
||||
|
||||
รองรับ Token ทั้งหมด:
|
||||
|
||||
@@ -205,7 +205,7 @@ CREATE TABLE document_number_audit (
|
||||
> - ~~`{TYPE}`~~ → Use `{CORR_TYPE}`, `{SUB_TYPE}`, or `{RFA_TYPE}` (context-specific)
|
||||
> - ~~`{CATEGORY}`~~ → Not used in current system
|
||||
>
|
||||
> **Always refer to**: [03.11-document-numbering.md](../01-requirements/03.11-document-numbering.md) as source of truth
|
||||
> **Always refer to**: [03.11-document-numbering.md](../01-requirements/01-03.11-document-numbering.md) as source of truth
|
||||
|
||||
### Format Resolution Strategy (Fallback Logic)
|
||||
|
||||
@@ -934,9 +934,9 @@ ensure:
|
||||
|
||||
เป็นไปตาม:
|
||||
|
||||
- ✅ [Requirements 3.11](../01-requirements/03.11-document-numbering.md) - Document Numbering Management (v1.6.2)
|
||||
- ✅ [Implementation Guide](../03-implementation/document-numbering.md) - DocumentNumberingModule (v1.6.1)
|
||||
- ✅ [Operations Guide](../04-operations/document-numbering-operations.md) - Monitoring & Troubleshooting
|
||||
- ✅ [Requirements 3.11](../01-requirements/01-03.11-document-numbering.md) - Document Numbering Management (v1.6.2)
|
||||
- ✅ [Implementation Guide](../03-implementation/03-04-document-numbering.md) - DocumentNumberingModule (v1.6.1)
|
||||
- ✅ [Operations Guide](../04-operations/04-08-document-numbering-operations.md) - Monitoring & Troubleshooting
|
||||
- ✅ [Security Best Practices](../02-architecture/security-architecture.md) - Rate Limiting, Audit Logging
|
||||
|
||||
---
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**Decision Makers:** Development Team, System Architect
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [File Handling Requirements](../01-requirements/03.10-file-handling.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [File Handling Requirements](../01-requirements/01-03.10-file-handling.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -487,8 +487,8 @@ export class CorrespondenceController {
|
||||
เป็นไปตาม:
|
||||
|
||||
- [Backend Plan Section 4.2.1](../../docs/2_Backend_Plan_V1_4_5.md) - FileStorageService
|
||||
- [Requirements 3.10](../01-requirements/03.10-file-handling.md) - File Handling
|
||||
- [System Architecture Section 5.2](../02-architecture/system-architecture.md) - File Upload Flow
|
||||
- [Requirements 3.10](../01-requirements/01-03.10-file-handling.md) - File Handling
|
||||
- [System Architecture Section 5.2](../02-architecture/02-01-system-architecture.md) - File Upload Flow
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**Decision Makers:** Development Team, Security Team
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [Access Control Requirements](../01-requirements/04-access-control.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [Access Control Requirements](../01-requirements/01-04-access-control.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -405,7 +405,7 @@ Global (ทั้งระบบ)
|
||||
|
||||
เป็นไปตาม:
|
||||
|
||||
- [Requirements Section 4](../01-requirements/04-access-control.md) - Access Control
|
||||
- [Requirements Section 4](../01-requirements/01-04-access-control.md) - Access Control
|
||||
- [Backend Plan Section 2 RBAC](../../docs/2_Backend_Plan_V1_4_5.md#rbac)
|
||||
|
||||
---
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**Decision Makers:** Development Team, CTO
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [FullStack JS Guidelines](../03-implementation/fullftack-js-v1.5.0.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [FullStack JS Guidelines](../03-implementation/03-01-fullftack-js-v1.7.0.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -271,9 +271,9 @@ lcbp3-dms/
|
||||
|
||||
เป็นไปตาม:
|
||||
|
||||
- [FullStack JS Guidelines](../03-implementation/fullftack-js-v1.5.0.md)
|
||||
- [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
- [Frontend Guidelines](../03-implementation/frontend-guidelines.md)
|
||||
- [FullStack JS Guidelines](../03-implementation/03-01-fullftack-js-v1.7.0.md)
|
||||
- [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
- [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
**Decision Makers:** Development Team, System Architect
|
||||
**Related Documents:**
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [Performance Requirements](../01-requirements/06-non-functional.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [Performance Requirements](../01-requirements/01-06-non-functional.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -418,8 +418,8 @@ export class RedisMonitoringService {
|
||||
|
||||
เป็นไปตาม:
|
||||
|
||||
- [System Architecture Section 3.5](../02-architecture/system-architecture.md#redis)
|
||||
- [Performance Requirements](../01-requirements/06-non-functional.md)
|
||||
- [System Architecture Section 3.5](../02-architecture/02-01-system-architecture.md#redis)
|
||||
- [Performance Requirements](../01-requirements/01-06-non-functional.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Backend Team, System Architect
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/backend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Backend Team, System Architect
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/backend-guidelines.md), [TASK-BE-011](../06-tasks/TASK-BE-011-notification-audit.md)
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md), [TASK-BE-011](../06-tasks/README.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -372,7 +372,7 @@ async notifyWorkflowTransition(
|
||||
## Related ADRs
|
||||
|
||||
- [ADR-006: Redis Caching Strategy](./ADR-006-redis-caching-strategy.md) - ใช้ Redis สำหรับ Queue
|
||||
- [TASK-BE-011: Notification & Audit](../06-tasks/TASK-BE-011-notification-audit.md)
|
||||
- [TASK-BE-011: Notification & Audit](../06-tasks/README.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Backend Team, DevOps Team, System Architect
|
||||
**Related Documents:** [TASK-BE-001](../06-tasks/TASK-BE-001-database-migrations.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
**Related Documents:** [TASK-BE-001](../06-tasks/TASK-BE-015-schema-v160-migration.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -367,7 +367,7 @@ describe('Migrations', () => {
|
||||
## Related ADRs
|
||||
|
||||
- [ADR-005: Technology Stack](./ADR-005-technology-stack.md) - เลือกใช้ TypeORM
|
||||
- [TASK-BE-001: Database Migrations](../06-tasks/TASK-BE-001-database-migrations.md)
|
||||
- [TASK-BE-001: Database Migrations](../06-tasks/TASK-BE-015-schema-v160-migration.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Backend Team, DevOps Team
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
**Related Documents:** [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Frontend Team, System Architect
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/frontend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Frontend Team, UX Designer
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/frontend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md), [ADR-005: Technology Stack](./ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Frontend Team
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/frontend-guidelines.md)
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**Status:** ✅ Accepted
|
||||
**Date:** 2025-12-01
|
||||
**Decision Makers:** Frontend Team
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/frontend-guidelines.md), [ADR-011: App Router](./ADR-011-nextjs-app-router.md)
|
||||
**Related Documents:** [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md), [ADR-011: App Router](./ADR-011-nextjs-app-router.md)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Architecture Decision Records (ADRs)
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
**Project:** LCBP3-DMS (Laem Chabang Port Phase 3 - Document Management System)
|
||||
|
||||
---
|
||||
@@ -83,9 +83,9 @@ Architecture Decision Records (ADRs) เป็นเอกสารที่บ
|
||||
### 2. Data Integrity & Concurrency
|
||||
|
||||
- **ADR-002:** Document Numbering - Double-lock (Redis Redlock + DB Optimistic) เพื่อป้องกัน Race Condition
|
||||
- 📋 [Requirements](../01-requirements/03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/document-numbering-operations.md)
|
||||
- 📋 [Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/03-04-document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/04-08-document-numbering-operations.md)
|
||||
- **ADR-003:** File Storage - Two-phase เพื่อ Transaction safety
|
||||
- **ADR-009:** Database Migration - TypeORM Migrations พร้อม Blue-Green Deployment
|
||||
|
||||
@@ -285,11 +285,11 @@ graph TB
|
||||
|
||||
## 🔗 Related Documentation
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md) - สถาปัตยกรรมระบบโดยรวม
|
||||
- [Data Model](../02-architecture/data-model.md) - โครงสร้างฐานข้อมูล
|
||||
- [API Design](../02-architecture/api-design.md) - การออกแบบ API
|
||||
- [Backend Guidelines](../03-implementation/backend-guidelines.md) - มาตรฐานการพัฒนา Backend
|
||||
- [Frontend Guidelines](../03-implementation/frontend-guidelines.md) - มาตรฐานการพัฒนา Frontend
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md) - สถาปัตยกรรมระบบโดยรวม
|
||||
- [Data Model](../02-architecture/02-03-data-model.md) - โครงสร้างฐานข้อมูล
|
||||
- [API Design](../02-architecture/02-02-api-design.md) - การออกแบบ API
|
||||
- [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md) - มาตรฐานการพัฒนา Backend
|
||||
- [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md) - มาตรฐานการพัฒนา Frontend
|
||||
|
||||
---
|
||||
|
||||
@@ -356,5 +356,5 @@ graph TB
|
||||
|
||||
---
|
||||
|
||||
**Version:** 1.6.0
|
||||
**Last Review:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Review:** 2025-12-18
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Development Tasks
|
||||
|
||||
**Project:** LCBP3-DMS (Laem Chabang Port Phase 3 - Document Management System)
|
||||
**Version:** 1.5.1
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
---
|
||||
|
||||
@@ -128,7 +128,7 @@ graph TB
|
||||
|
||||
| ID | Task | Priority | Effort | Status | Dependencies |
|
||||
| ---------------------------------------------- | --------------------------- | -------- | -------- | ------------- | ------------ |
|
||||
| [BE-001](./TASK-BE-001-database-migrations.md) | Database Setup & Migrations | P0 | 2-3 days | 🔴 Not Started | None |
|
||||
| [BE-001](TASK-BE-015-schema-v160-migration.md) | Database Setup & Migrations | P0 | 2-3 days | 🔴 Not Started | None |
|
||||
| [BE-002](./TASK-BE-002-auth-rbac.md) | Auth & RBAC Module | P0 | 5-7 days | 🔴 Not Started | BE-001 |
|
||||
|
||||
### Phase 2: Core Infrastructure (3-4 weeks)
|
||||
@@ -160,7 +160,7 @@ graph TB
|
||||
|
||||
| ID | Task | Priority | Effort | Status | Dependencies |
|
||||
| --------------------------------------------- | ------------------------ | -------- | -------- | ------------- | -------------- |
|
||||
| [BE-011](./TASK-BE-011-notification-audit.md) | Notification & Audit Log | P3 | 3-5 days | 🔴 Not Started | BE-001, BE-002 |
|
||||
| [BE-011](README.md) | Notification & Audit Log | P3 | 3-5 days | 🔴 Not Started | BE-001, BE-002 |
|
||||
|
||||
---
|
||||
|
||||
@@ -289,9 +289,9 @@ graph TB
|
||||
- Comprehensive error handling (4 scenarios)
|
||||
- Monitoring & alerting (Prometheus + Grafana)
|
||||
- **Documentation:**
|
||||
- 📋 [Requirements](../01-requirements/03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/document-numbering-operations.md)
|
||||
- 📋 [Requirements](../01-requirements/01-03.11-document-numbering.md)
|
||||
- 📘 [Implementation Guide](../03-implementation/03-04-document-numbering.md)
|
||||
- 📗 [Operations Guide](../04-operations/04-08-document-numbering-operations.md)
|
||||
- **Related ADR:** [ADR-002](../05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
- **Task Details:** [TASK-BE-004](./TASK-BE-004-document-numbering.md)
|
||||
|
||||
@@ -398,7 +398,7 @@ BE-001 (Database)
|
||||
|
||||
### Code Quality
|
||||
|
||||
- ✅ Code เป็นไปตาม [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
- ✅ Code เป็นไปตาม [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
- ✅ No `any` types (TypeScript Strict Mode)
|
||||
- ✅ ESLint และ Prettier passed
|
||||
- ✅ No console.log (use Logger)
|
||||
@@ -448,14 +448,14 @@ Track potential blockers:
|
||||
|
||||
### Architecture
|
||||
|
||||
- [System Architecture](../02-architecture/system-architecture.md)
|
||||
- [Data Model](../02-architecture/data-model.md)
|
||||
- [API Design](../02-architecture/api-design.md)
|
||||
- [System Architecture](../02-architecture/02-01-system-architecture.md)
|
||||
- [Data Model](../02-architecture/02-03-data-model.md)
|
||||
- [API Design](../02-architecture/02-02-api-design.md)
|
||||
|
||||
### Guidelines
|
||||
|
||||
- [Backend Guidelines](../03-implementation/backend-guidelines.md)
|
||||
- [Testing Strategy](../03-implementation/testing-strategy.md)
|
||||
- [Backend Guidelines](../03-implementation/03-02-backend-guidelines.md)
|
||||
- [Testing Strategy](../03-implementation/03-05-testing-strategy.md)
|
||||
|
||||
### Decisions
|
||||
|
||||
@@ -619,5 +619,5 @@ Add these features when:
|
||||
|
||||
---
|
||||
|
||||
**Version:** 1.5.1
|
||||
**Last Updated:** 2025-12-02
|
||||
**Version:** 1.7.0
|
||||
**Last Updated:** 2025-12-18
|
||||
|
||||
@@ -458,7 +458,7 @@ describe('SearchService', () => {
|
||||
|
||||
## 📚 Related Documents
|
||||
|
||||
- [System Architecture - Search](../02-architecture/system-architecture.md#elasticsearch)
|
||||
- [System Architecture - Search](../02-architecture/02-01-system-architecture.md#elasticsearch)
|
||||
- [ADR-005: Technology Stack](../05-decisions/ADR-005-technology-stack.md)
|
||||
|
||||
---
|
||||
|
||||
@@ -161,6 +161,6 @@ stateDiagram-v2
|
||||
|
||||
## References
|
||||
|
||||
- [Requirements v1.6.2](file:///d:/nap-dms.lcbp3/specs/01-requirements/03.11-document-numbering.md)
|
||||
- [Implementation Guide v1.6.2](file:///d:/nap-dms.lcbp3/specs/03-implementation/document-numbering.md)
|
||||
- [ADR-002](file:///d:/nap-dms.lcbp3/specs/05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
- [Requirements v1.6.2](../01-requirements/01-03.11-document-numbering.md)
|
||||
- [Implementation Guide v1.6.2](../03-implementation/03-04-document-numbering.md)
|
||||
- [ADR-002](../05-decisions/ADR-002-document-numbering-strategy.md)
|
||||
|
||||
@@ -187,6 +187,6 @@ interface AuditQueryParams {
|
||||
|
||||
## References
|
||||
|
||||
- [Requirements v1.6.2](file:///d:/nap-dms.lcbp3/specs/01-requirements/03.11-document-numbering.md)
|
||||
- [Frontend Guidelines](file:///d:/nap-dms.lcbp3/specs/03-implementation/frontend-guidelines.md)
|
||||
- [REQ-009 Original Task](file:///d:/nap-dms.lcbp3/specs/06-tasks/REQ-009-DocumentNumbering.md)
|
||||
- [Requirements v1.6.2](../01-requirements/01-03.11-document-numbering.md)
|
||||
- [Frontend Guidelines](../03-implementation/03-03-frontend-guidelines.md)
|
||||
- [REQ-009 Original Task](REQ-009-DocumentNumbering.md)
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
# **ตารางฐานข้อมูล (Data Dictionary) - LCBP3-DMS (V1.6.0)**
|
||||
# **ตารางฐานข้อมูล (Data Dictionary) - LCBP3-DMS (V1.7.0)**
|
||||
|
||||
เอกสารนี้สรุปโครงสร้างตาราง,
|
||||
FOREIGN KEYS (FK),
|
||||
และ Constraints ที่สำคัญทั้งหมดในฐานข้อมูล LCBP3 - DMS (v1.6.0) เพื่อใช้เป็นเอกสารอ้างอิงสำหรับทีมพัฒนา Backend (NestJS) และ Frontend (Next.js) โดยอิงจาก Requirements และ SQL Script ล่าสุด ** สถานะ: ** FINAL GUIDELINE ** วันที่: ** 2025 -12 -13 ** อ้างอิง: ** Requirements v1.6.0 & FullStackJS Guidelines v1.6.0 ** Classification: ** Internal Technical Documentation ## 📝 สรุปรายการปรับปรุง (Summary of Changes in v1.6.0)
|
||||
1.** Schema Refactoring **: ปรับโครงสร้างตาราง `correspondences`, `correspondence_revisions`, `rfas`, `rfa_revisions` ให้เป็นมาตรฐานเดียวกัน
|
||||
2.** Shared PK Pattern **: ตาราง `rfas` ใช้ ID ร่วมกับ `correspondences` (FK Reference แทน AUTO_INCREMENT)
|
||||
3.** Column Rename **: เปลี่ยน `title` เป็น `subject` ในตาราง revision และเพิ่ม `body`, `remarks`
|
||||
4.** Virtual Columns **: เพิ่ม Virtual Columns สำหรับ Index ข้อมูลจาก JSON details
|
||||
5.** FK Updates **: `correspondence_recipients` FK ชี้ไป `correspondences(id)` แทน `correspondence_revisions` ---
|
||||
และ Constraints ที่สำคัญทั้งหมดในฐานข้อมูล LCBP3 - DMS (v1.7.0) เพื่อใช้เป็นเอกสารอ้างอิงสำหรับทีมพัฒนา Backend (NestJS) และ Frontend (Next.js) โดยอิงจาก Requirements และ SQL Script ล่าสุด ** สถานะ: ** FINAL GUIDELINE ** วันที่: ** 2025 -12 -18 ** อ้างอิง: ** Requirements v1.7.0 & FullStackJS Guidelines v1.7.0 ** Classification: ** Internal Technical Documentation ## 📝 สรุปรายการปรับปรุง (Summary of Changes in v1.7.0)
|
||||
1. **Document Numbering Overhaul**: ปรับปรุงโครงสร้าง `document_number_counters` เปลี่ยน PK เป็น Composite 8 columns และใช้ `reset_scope` แทน `current_year`
|
||||
2. **Audit & Error Logging**: ปรับปรุงตาราง `document_number_audit`, `document_number_errors` และเพิ่ม `document_number_reservations`
|
||||
3. **JSON Schemas**: เพิ่ม columns `version`, `table_name`, `ui_schema`, `virtual_columns`, `migration_script` ในตาราง `json_schemas`
|
||||
4. **Schema Cleanup**: ลบ `correspondence_id` ออกจาก `rfa_revisions` และปรับปรุง Virtual Columns ใน `correspondence_revisions` ---
|
||||
|
||||
## **1. 🏢 Core & Master Data Tables (องค์กร, โครงการ, สัญญา)**
|
||||
|
||||
@@ -252,7 +251,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
---
|
||||
|
||||
### 3.3 correspondences (UPDATE v1.5.1)
|
||||
### 3.3 correspondences (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Master table for correspondence documents (non-revisioned data)
|
||||
|
||||
@@ -289,7 +288,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
---
|
||||
|
||||
### 3.4 correspondence_revisions (UPDATE v1.5.1)
|
||||
### 3.4 correspondence_revisions (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Child table storing revision history of correspondences (1:N)
|
||||
|
||||
@@ -312,7 +311,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
| created_by | INT | NULL, FK | User who created revision |
|
||||
| updated_by | INT | NULL, FK | User who last updated |
|
||||
| v_ref_project_id | INT | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column ดึง Project ID จาก JSON details เพื่อทำ Index |
|
||||
| v_ref_type | VARCHAR(50) | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column ดึง Type จาก JSON details |
|
||||
|
||||
| v_doc_subtype | VARCHAR(50) | GENERATED ALWAYS AS (...) VIRTUAL | Virtual Column ดึง Type จาก JSON details |
|
||||
| schema_version | INT | DEFAULT 1 | Version of the schema used with this details |
|
||||
|
||||
@@ -330,7 +329,6 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
* INDEX (document_date)
|
||||
* INDEX (issued_date)
|
||||
* INDEX (v_ref_project_id)
|
||||
* INDEX (v_ref_type)
|
||||
* INDEX (v_doc_subtype)
|
||||
|
||||
---
|
||||
@@ -429,25 +427,26 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
## **4. 📐 approval: RFA Tables (เอกสารขออนุมัติ, Workflows)**
|
||||
|
||||
### 4.1 rfa_types
|
||||
### 4.1 rfa_types (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Master table for RFA (Request for Approval) types
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ----------- | ------------ | --------------------------- | ------------------------------- |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier |
|
||||
| type_code | VARCHAR(20) | NOT NULL, UNIQUE | Type code (DWG, DOC, MAT, etc.) |
|
||||
| type_name | VARCHAR(100) | NOT NULL | Full type name |
|
||||
| description | TEXT | NULL | Type description |
|
||||
| sort_order | INT | DEFAULT 0 | Display order |
|
||||
| is_active | TINYINT(1) | DEFAULT 1 | Active status |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :----------- | :----------- | :-------------------------- | :------------------------------ |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique identifier |
|
||||
| contract_id | INT | NOT NULL, FK | Contract reference |
|
||||
| type_code | VARCHAR(20) | NOT NULL | Type code (DWG, DOC, MAT, etc.) |
|
||||
| type_name_th | VARCHAR(100) | NOT NULL | Full type name (TH) |
|
||||
| type_name_en | VARCHAR(100) | NOT NULL | Full type name (EN) |
|
||||
| remark | TEXT | NULL | Remark |
|
||||
| is_active | TINYINT(1) | DEFAULT 1 | Active status |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* UNIQUE (type_code)
|
||||
* UNIQUE (contract_id, type_code)
|
||||
* FOREIGN KEY (contract_id) REFERENCES contracts(id) ON DELETE CASCADE
|
||||
* INDEX (is_active)
|
||||
* INDEX (sort_order)
|
||||
|
||||
**Relationships**:
|
||||
|
||||
@@ -507,43 +506,42 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
---
|
||||
|
||||
### 4.4 rfas (UPDATE v1.5.1)
|
||||
### 4.4 rfas (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Master table for RFA documents (non-revisioned data)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ----------------- | --------- | --------------------------- | --------------------------- |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Master RFA ID |
|
||||
| rfa_type_id | INT | NOT NULL, FK | Reference to rfa_types |
|
||||
| **discipline_id** | **INT** | **NULL, FK** | **[NEW] สาขางาน (ถ้ามี)** |
|
||||
| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp |
|
||||
| created_by | INT | NULL, FK | User who created the record |
|
||||
| deleted_at | DATETIME | NULL | Soft delete timestamp |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------- | :-------- | :------------------------ | :------------------------------------------ |
|
||||
| id | INT | PK, FK | Master RFA ID (Shared with correspondences) |
|
||||
| rfa_type_id | INT | NOT NULL, FK | Reference to rfa_types |
|
||||
| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp |
|
||||
| created_by | INT | NULL, FK | User who created the record |
|
||||
| deleted_at | DATETIME | NULL | Soft delete timestamp |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (id) REFERENCES correspondences(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (rfa_type_id) REFERENCES rfa_types(id)
|
||||
* **FOREIGN KEY (discipline_id) REFERENCES disciplines(id) ON DELETE SET NULL**
|
||||
* FOREIGN KEY (created_by) REFERENCES users(user_id) ON DELETE SET NULL
|
||||
* INDEX (rfa_type_id)
|
||||
* INDEX (deleted_at)
|
||||
|
||||
**Relationships**:
|
||||
|
||||
* Parent: rfa_types, **disciplines**, users
|
||||
* Parent: correspondences, rfa_types, users
|
||||
* Children: rfa_revisions
|
||||
|
||||
---
|
||||
|
||||
### 4.5 rfa_revisions (UPDATE v1.5.1)
|
||||
### 4.5 rfa_revisions (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Child table storing revision history of RFAs (1:N)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ------------------- | ------------ | --------------------------------- | ----------------------------------------------------------- |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique revision ID |
|
||||
| correspondence_id | INT | NOT NULL, FK | Link to correspondence (RFA as correspondence) |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ----------- | --------- | --------------------------- | ------------------ |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique revision ID |
|
||||
|
||||
| rfa_id | INT | NOT NULL, FK | Master RFA ID |
|
||||
| revision_number | INT | NOT NULL | Revision sequence (0, 1, 2...) |
|
||||
| revision_label | VARCHAR(10) | NULL | Display revision (A, B, 1.1...) |
|
||||
@@ -566,7 +564,6 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (correspondence_id) REFERENCES correspondences(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (rfa_id) REFERENCES rfas(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (rfa_status_code_id) REFERENCES rfa_status_codes(id)
|
||||
* FOREIGN KEY (rfa_approve_code_id) REFERENCES rfa_approve_codes(id) ON DELETE SET NULL
|
||||
@@ -582,7 +579,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
**Relationships**:
|
||||
|
||||
* Parent: correspondences, rfas, rfa_status_codes, rfa_approve_codes, users
|
||||
* Children: rfa_items, rfa_workflows
|
||||
* Children: rfa_items
|
||||
|
||||
---
|
||||
|
||||
@@ -590,15 +587,15 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
**Purpose**: Junction table linking RFA revisions to shop drawing revisions (M:N)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ------------------------ | --------- | --------------- | ------------------------------ |
|
||||
| rfarev_correspondence_id | INT | PRIMARY KEY, FK | RFA revision correspondence ID |
|
||||
| shop_drawing_revision_id | INT | PRIMARY KEY, FK | Shop drawing revision ID |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :----------------------- | :-------- | :-------------- | :----------------------- |
|
||||
| rfa_revision_id | INT | PRIMARY KEY, FK | RFA Revision ID |
|
||||
| shop_drawing_revision_id | INT | PRIMARY KEY, FK | Shop drawing revision ID |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (rfarev_correspondence_id, shop_drawing_revision_id)
|
||||
* FOREIGN KEY (rfarev_correspondence_id) REFERENCES rfa_revisions(correspondence_id) ON DELETE CASCADE
|
||||
* PRIMARY KEY (rfa_revision_id, shop_drawing_revision_id)
|
||||
* FOREIGN KEY (rfa_revision_id) REFERENCES rfa_revisions(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (shop_drawing_revision_id) REFERENCES shop_drawing_revisions(id) ON DELETE CASCADE
|
||||
* INDEX (shop_drawing_revision_id)
|
||||
|
||||
@@ -614,45 +611,6 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
---
|
||||
|
||||
### 4.7 rfa_workflows
|
||||
|
||||
**Purpose**: Transaction log table tracking actual RFA approval workflow execution
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| --------------- | --------- | ----------------------------------- | ------------------------------------------------- |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique workflow log ID |
|
||||
| rfa_revision_id | INT | NOT NULL, FK | Reference to RFA revision |
|
||||
| step_number | INT | NOT NULL | Current step number |
|
||||
| organization_id | INT | NOT NULL, FK | Organization responsible |
|
||||
| assigned_to | INT | NULL, FK | Assigned user ID |
|
||||
| action_type | ENUM | NULL | Action type: REVIEW, APPROVE, ACKNOWLEDGE |
|
||||
| status | ENUM | NULL | Status: PENDING, IN_PROGRESS, COMPLETED, REJECTED |
|
||||
| comments | TEXT | NULL | Comments/remarks |
|
||||
| completed_at | DATETIME | NULL | Completion timestamp |
|
||||
| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Record creation timestamp |
|
||||
| updated_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP ON UPDATE | Last update timestamp |
|
||||
| state_context | JSON\* | NULL | เก็บข้อมูล Context ของ Workflow ณ ขณะนั้น (Snapshot) |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (rfa_revision_id) REFERENCES rfa_revisions(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (organization_id) REFERENCES organizations(id)
|
||||
* FOREIGN KEY (assigned_to) REFERENCES users(user_id)
|
||||
* INDEX (rfa_revision_id, step_number)
|
||||
* INDEX (assigned_to, status)
|
||||
* INDEX (status)
|
||||
|
||||
**Relationships**:
|
||||
|
||||
* Parent: rfa_revisions, organizations, users
|
||||
|
||||
**Business Rules**:
|
||||
|
||||
* Records actual workflow execution history
|
||||
* Tracks who did what and when
|
||||
* Multiple records per RFA revision (one per step)
|
||||
* Status changes tracked via updated_at
|
||||
|
||||
---
|
||||
|
||||
@@ -1344,85 +1302,154 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
---
|
||||
|
||||
### 9.2 document_number_counters (UPDATE v1.5.1)
|
||||
### 9.2 document_number_counters (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Transaction table tracking running numbers (High Concurrency)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| -------------------------- | --------- | ------------- | -------------------------------------------- |
|
||||
| project_id | INT | PK, NOT NULL | โครงการ |
|
||||
| originator_organization_id | INT | PK, NOT NULL | องค์กรผู้ส่ง |
|
||||
| recipient_organization_id | INT | PK, NOT NULL | [NEW] องค์กรผู้รับ (-1 = ทุกองค์กร) |
|
||||
| correspondence_type_id | INT | PK, NOT NULL | ประเภทเอกสาร |
|
||||
| sub_type_id | INT | PK, DEFAULT 0 | [NEW] ประเภทย่อย สำหรับ TRANSMITTAL (0 = ไม่ระบุ) |
|
||||
| rfa_type_id | INT | PK, DEFAULT 0 | [NEW] ประเภท RFA (0 = ไม่ใช่ RFA) |
|
||||
| discipline_id | INT | PK, DEFAULT 0 | [NEW] สาขางาน (0 = ไม่ระบุ) |
|
||||
| current_year | INT | PK, NOT NULL | ปี ค.ศ. ของตัวนับ (auto-reset ทุกปี) |
|
||||
| last_number | INT | DEFAULT 0 | เลขล่าสุดที่ถูกใช้งานไปแล้ว |
|
||||
| updated_at | TIMESTAMP | ON UPDATE | เวลาที่อัปเดตล่าสุด |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| -------------------------- | ----------- | ------------- | ----------------------------------------------- |
|
||||
| project_id | INT | PK, NOT NULL | โครงการ |
|
||||
| originator_organization_id | INT | PK, NOT NULL | องค์กรผู้ส่ง |
|
||||
| recipient_organization_id | INT | PK, NOT NULL | องค์กรผู้รับ (0 = no recipient / RFA) |
|
||||
| correspondence_type_id | INT | PK, NULL | ประเภทเอกสาร (NULL = default) |
|
||||
| sub_type_id | INT | PK, DEFAULT 0 | ประเภทย่อย สำหรับ TRANSMITTAL (0 = ไม่ระบุ) |
|
||||
| rfa_type_id | INT | PK, DEFAULT 0 | ประเภท RFA (0 = ไม่ใช่ RFA) |
|
||||
| discipline_id | INT | PK, DEFAULT 0 | สาขางาน (0 = ไม่ระบุ) |
|
||||
| reset_scope | VARCHAR(20) | PK, NOT NULL | Scope of reset (YEAR_2024, MONTH_2024_01, NONE) |
|
||||
| last_number | INT | DEFAULT 0 | เลขล่าสุดที่ถูกใช้งานไปแล้ว |
|
||||
| version | INT | DEFAULT 0 | Optimistic Lock Version |
|
||||
| updated_at | DATETIME(6) | ON UPDATE | เวลาที่อัปเดตล่าสุด |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* **PRIMARY KEY (project_id, originator_organization_id, recipient_organization_id, correspondence_type_id, sub_type_id, rfa_type_id, discipline_id, current_year)**
|
||||
* **PRIMARY KEY (project_id, originator_organization_id, recipient_organization_id, correspondence_type_id, sub_type_id, rfa_type_id, discipline_id, reset_scope)**
|
||||
* INDEX idx_counter_lookup (project_id, correspondence_type_id, reset_scope)
|
||||
* INDEX idx_counter_org (originator_organization_id, reset_scope)
|
||||
|
||||
**Business Rules**:
|
||||
|
||||
* **Composite Primary Key 8 Columns**: เพื่อรองรับการรันเลขที่ซับซ้อนตาม Req 6B
|
||||
* **Concurrency Control**: ใช้ Redis Lock หรือ Optimistic Locking ในการอัปเดต `last_number`
|
||||
* **Reset Rule**: `current_year` เปลี่ยน -> เริ่มนับ 1 ใหม่
|
||||
* **Composite Primary Key 8 Columns**: เพื่อรองรับการรันเลขที่ซับซ้อนและ Reset Scope ที่หลากหลาย
|
||||
* **Concurrency Control**: ใช้ Redis Lock หรือ Optimistic Locking (version)
|
||||
* **Reset Scope**: ใช้ Field `reset_scope` ควบคุมการ Reset แทน `current_year` แบบเดิม
|
||||
|
||||
---
|
||||
|
||||
### 9.3 document_number_audit (NEW v1.5.1)
|
||||
### 9.3 document_number_audit (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Audit log for document number generation (Debugging & Tracking)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------------- | :----------- | :---------- | :---------------------------------- |
|
||||
| id | BIGINT | PK, AI | Unique ID |
|
||||
| transaction_id | VARCHAR(36) | NOT NULL | UUID ของ Transaction การขอเลข |
|
||||
| counter_key_json | JSON | NOT NULL | ค่า Key ที่ใช้ในการ Query (เก็บเป็น JSON) |
|
||||
| generated_number | VARCHAR(100) | NOT NULL | เลขที่ได้ |
|
||||
| requested_by | INT | FK | User ที่ขอเลข |
|
||||
| requested_at | TIMESTAMP | DEFAULT NOW | เวลาที่ขอ |
|
||||
| execution_time_ms | INT | NULL | เวลาที่ใช้ในการประมวลผล (ms) |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------------------- | :----------- | :----------------- | :-------------------------------------- |
|
||||
| id | INT | PK, AI | ID ของ audit record |
|
||||
| document_id | INT | NOT NULL, FK | ID ของเอกสารที่สร้างเลขที่ |
|
||||
| document_type | VARCHAR(50) | NULL | ประเภทเอกสาร |
|
||||
| document_number | VARCHAR(100) | NOT NULL | เลขที่เอกสารที่สร้าง (ผลลัพธ์) |
|
||||
| operation | ENUM | DEFAULT 'CONFIRM' | RESERVE, CONFIRM, MANUAL_OVERRIDE, etc. |
|
||||
| status | ENUM | DEFAULT 'RESERVED' | RESERVED, CONFIRMED, CANCELLED, VOID |
|
||||
| counter_key | JSON | NOT NULL | Counter key ที่ใช้ (JSON 8 fields) |
|
||||
| reservation_token | VARCHAR(36) | NULL | Token การจอง |
|
||||
| originator_organization_id | INT | NULL | องค์กรผู้ส่ง |
|
||||
| recipient_organization_id | INT | NULL | องค์กรผู้รับ |
|
||||
| template_used | VARCHAR(200) | NOT NULL | Template ที่ใช้ในการสร้าง |
|
||||
| user_id | INT | NOT NULL, FK | ผู้ขอสร้างเลขที่ |
|
||||
| is_success | BOOLEAN | DEFAULT TRUE | สถานะความสำเร็จ |
|
||||
| created_at | TIMESTAMP | DEFAULT NOW | วันที่/เวลาที่สร้าง |
|
||||
| total_duration_ms | INT | NULL | เวลารวมทั้งหมดในการสร้าง (ms) |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (document_id) REFERENCES correspondences(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||
* INDEX (document_id)
|
||||
* INDEX (user_id)
|
||||
* INDEX (status)
|
||||
* INDEX (operation)
|
||||
* INDEX (document_number)
|
||||
* INDEX (reservation_token)
|
||||
* INDEX (created_at)
|
||||
|
||||
---
|
||||
|
||||
### 9.4 document_number_errors (NEW v1.5.1)
|
||||
### 9.4 document_number_errors (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Error log for failed document number generation
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :--------------- | :---------- | :---------- | :------------------------------- |
|
||||
| id | BIGINT | PK, AI | Unique ID |
|
||||
| transaction_id | VARCHAR(36) | NOT NULL | UUID ของ Transaction |
|
||||
| error_code | VARCHAR(50) | NOT NULL | รหัส Error (เช่น ERR_LOCK_TIMEOUT) |
|
||||
| error_message | TEXT | NOT NULL | รายละเอียด Error |
|
||||
| counter_key_json | JSON | NULL | ค่า Key ที่พยายามใช้ |
|
||||
| occurred_at | TIMESTAMP | DEFAULT NOW | เวลาที่เกิด Error |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------ | :-------- | :---------- | :--------------------------------------------- |
|
||||
| id | INT | PK, AI | ID ของ error record |
|
||||
| error_type | ENUM | NOT NULL | LOCK_TIMEOUT, VERSION_CONFLICT, DB_ERROR, etc. |
|
||||
| error_message | TEXT | NULL | ข้อความ error |
|
||||
| stack_trace | TEXT | NULL | Stack trace สำหรับ debugging |
|
||||
| context_data | JSON | NULL | Context ของ request |
|
||||
| user_id | INT | NULL | ผู้ที่เกิด error |
|
||||
| created_at | TIMESTAMP | DEFAULT NOW | วันที่เกิด error |
|
||||
| resolved_at | TIMESTAMP | NULL | วันที่แก้ไขแล้ว |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* INDEX (error_type)
|
||||
* INDEX (created_at)
|
||||
* INDEX (user_id)
|
||||
* INDEX (resolved_at)
|
||||
|
||||
---
|
||||
|
||||
## **10. ⚙️ Unified Workflow Engine Tables (NEW v1.5.1)**
|
||||
### 9.5 document_number_reservations (NEW v1.7.0)
|
||||
|
||||
**Purpose**: Two-Phase Commit table for document number reservation
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :--------------------- | :----------- | :--------------- | :----------------------------------- |
|
||||
| id | INT | PK, AI | Unique ID |
|
||||
| token | VARCHAR(36) | UNIQUE, NOT NULL | UUID v4 Reservation Token |
|
||||
| document_number | VARCHAR(100) | UNIQUE, NOT NULL | เลขที่เอกสารที่จอง |
|
||||
| document_number_status | ENUM | DEFAULT RESERVED | RESERVED, CONFIRMED, CANCELLED, VOID |
|
||||
| document_id | INT | NULL, FK | ID ของเอกสาร (เมื่อ Confirm แล้ว) |
|
||||
| expires_at | DATETIME(6) | NOT NULL | เวลาหมดอายุการจอง |
|
||||
| project_id | INT | NOT NULL, FK | Project Context |
|
||||
| user_id | INT | NOT NULL, FK | User Context |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (document_id) REFERENCES correspondence_revisions(id) ON DELETE SET NULL
|
||||
* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE
|
||||
* FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||
* INDEX idx_token (token)
|
||||
* INDEX idx_status (document_number_status)
|
||||
* INDEX idx_status_expires (document_number_status, expires_at)
|
||||
* INDEX idx_document_id (document_id)
|
||||
* INDEX idx_user_id (user_id)
|
||||
* INDEX idx_reserved_at (reserved_at)
|
||||
|
||||
---
|
||||
|
||||
## **10. ⚙️ Unified Workflow Engine Tables (UPDATE v1.7.0)**
|
||||
|
||||
### 10.1 workflow_definitions
|
||||
|
||||
**Purpose**: เก็บแม่แบบ (Template) ของ Workflow (Req 3.6)
|
||||
**Purpose**: เก็บแม่แบบ (Template) ของ Workflow (Definition / DSL)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------ | :----------- | :----------- | :--------------------------------------------- |
|
||||
| id | INT | PK, AI | Unique ID |
|
||||
| workflow_code | VARCHAR(50) | UNIQUE | รหัส Workflow (เช่น WF-RFA-GENERIC) |
|
||||
| workflow_name | VARCHAR(255) | NOT NULL | ชื่อ Workflow |
|
||||
| description | TEXT | NULL | คำอธิบาย |
|
||||
| module | VARCHAR(50) | NOT NULL | ใช้กับ Module ไหน (RFA, CORRESPONDENCE) |
|
||||
| steps_config | JSON | NOT NULL | การตั้งค่า Step (Sequence, Approvers, Conditions) |
|
||||
| is_active | BOOLEAN | DEFAULT TRUE | สถานะการใช้งาน |
|
||||
| version | INT | DEFAULT 1 | เวอร์ชันของ Definition |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------ | :---------- | :----------- | :------------------------------------- |
|
||||
| id | CHAR(36) | PK, UUID | Unique Workflow Definition ID |
|
||||
| workflow_code | VARCHAR(50) | NOT NULL | รหัส Workflow (เช่น RFA_FLOW_V1) |
|
||||
| version | INT | DEFAULT 1 | หมายเลข Version |
|
||||
| description | TEXT | NULL | คำอธิบาย Workflow |
|
||||
| dsl | JSON | NOT NULL | นิยาม Workflow ต้นฉบับ (YAML/JSON Format) |
|
||||
| compiled | JSON | NOT NULL | โครงสร้าง Execution Tree ที่ Compile แล้ว |
|
||||
| is_active | BOOLEAN | DEFAULT TRUE | สถานะการใช้งาน |
|
||||
| created_at | TIMESTAMP | DEFAULT NOW | วันที่สร้าง |
|
||||
| updated_at | TIMESTAMP | ON UPDATE | วันที่แก้ไขล่าสุด |
|
||||
|
||||
**Business Rules**:
|
||||
* `steps_config` เก็บ Logic ของ Workflow ทั้งหมดในรูปแบบ JSON เพื่อความยืดหยุ่น
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* UNIQUE KEY (workflow_code, version)
|
||||
* INDEX (is_active)
|
||||
|
||||
---
|
||||
|
||||
@@ -1430,16 +1457,24 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
**Purpose**: เก็บสถานะของ Workflow ที่กำลังรันอยู่จริง (Runtime)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :--------------------- | :----------- | :----------- | :----------------------------------------- |
|
||||
| id | BIGINT | PK, AI | Unique ID |
|
||||
| workflow_definition_id | INT | FK, NOT NULL | อ้างอิง Definition |
|
||||
| business_key | VARCHAR(100) | INDEX | ID ของเอกสารที่ผูกกับ Workflow นี้ (เช่น RFA-001) |
|
||||
| current_step_name | VARCHAR(100) | NOT NULL | ชื่อ Step ปัจจุบัน |
|
||||
| status | ENUM | NOT NULL | IN_PROGRESS, COMPLETED, TERMINATED |
|
||||
| context_data | JSON | NULL | ข้อมูลประกอบการตัดสินใจ (Variables) |
|
||||
| started_at | TIMESTAMP | DEFAULT NOW | เวลาที่เริ่ม |
|
||||
| completed_at | TIMESTAMP | NULL | เวลาที่จบ |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------ | :---------- | :--------------- | :--------------------------------------------- |
|
||||
| id | CHAR(36) | PK, UUID | Unique Instance ID |
|
||||
| definition_id | CHAR(36) | FK, NOT NULL | อ้างอิง Definition ที่ใช้ |
|
||||
| entity_type | VARCHAR(50) | NOT NULL | ประเภทเอกสาร (rfa_revision, correspondence...) |
|
||||
| entity_id | VARCHAR(50) | NOT NULL | ID ของเอกสาร |
|
||||
| current_state | VARCHAR(50) | NOT NULL | สถานะปัจจุบัน |
|
||||
| status | ENUM | DEFAULT 'ACTIVE' | ACTIVE, COMPLETED, CANCELLED, TERMINATED |
|
||||
| context | JSON | NULL | ตัวแปร Context สำหรับตัดสินใจ |
|
||||
| created_at | TIMESTAMP | DEFAULT NOW | เวลาที่สร้าง |
|
||||
| updated_at | TIMESTAMP | ON UPDATE | เวลาที่อัปเดตล่าสุด |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (definition_id) REFERENCES workflow_definitions(id) ON DELETE CASCADE
|
||||
* INDEX (entity_type, entity_id)
|
||||
* INDEX (current_state)
|
||||
|
||||
---
|
||||
|
||||
@@ -1447,86 +1482,102 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
**Purpose**: เก็บประวัติการดำเนินการในแต่ละ Step (Audit Trail)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :------------------- | :----------- | :----------- | :--------------------------------- |
|
||||
| id | BIGINT | PK, AI | Unique ID |
|
||||
| workflow_instance_id | BIGINT | FK, NOT NULL | อ้างอิง Instance |
|
||||
| step_name | VARCHAR(100) | NOT NULL | ชื่อ Step |
|
||||
| action | VARCHAR(50) | NOT NULL | การกระทำ (APPROVE, REJECT, COMMENT) |
|
||||
| actor_id | INT | FK, NULL | User ที่กระทำ |
|
||||
| comments | TEXT | NULL | ความเห็นเพิ่มเติม |
|
||||
| performed_at | TIMESTAMP | DEFAULT NOW | เวลาที่กระทำ |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------------- | :---------- | :----------- | :-------------------- |
|
||||
| id | CHAR(36) | PK, UUID | Unique ID |
|
||||
| instance_id | CHAR(36) | FK, NOT NULL | อ้างอิง Instance |
|
||||
| from_state | VARCHAR(50) | NOT NULL | สถานะต้นทาง |
|
||||
| to_state | VARCHAR(50) | NOT NULL | สถานะปลายทาง |
|
||||
| action | VARCHAR(50) | NOT NULL | Action ที่กระทำ |
|
||||
| action_by_user_id | INT | FK, NULL | User ID ผู้กระทำ |
|
||||
| comment | TEXT | NULL | ความเห็น |
|
||||
| metadata | JSON | NULL | Snapshot ข้อมูล ณ ขณะนั้น |
|
||||
| created_at | TIMESTAMP | DEFAULT NOW | เวลาที่กระทำ |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id)
|
||||
* FOREIGN KEY (instance_id) REFERENCES workflow_instances(id) ON DELETE CASCADE
|
||||
* INDEX (instance_id)
|
||||
* INDEX (action_by_user_id)
|
||||
|
||||
---
|
||||
|
||||
## **11. 🖥️ System & Logs Tables (ระบบ, บันทึก)**
|
||||
|
||||
### 11.1 json_schemas (NEW v1.5.1)
|
||||
### 11.1 json_schemas (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: เก็บ Schema สำหรับ Validate JSON Columns (Req 3.12)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------- | :---------- | :----------- | :------------------------------------- |
|
||||
| id | INT | PK, AI | Unique ID |
|
||||
| schema_code | VARCHAR(50) | UNIQUE | รหัส Schema (เช่น RFA_DETAILS_V1) |
|
||||
| schema_body | JSON | NOT NULL | JSON Schema Draft 7/2020-12 definition |
|
||||
| description | TEXT | NULL | คำอธิบาย |
|
||||
| is_active | BOOLEAN | DEFAULT TRUE | สถานะ |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------------- | :----------- | :----------- | :------------------------------- |
|
||||
| id | INT | PK, AI | Unique ID |
|
||||
| schema_code | VARCHAR(100) | NOT NULL | รหัส Schema (เช่น RFA_DWG) |
|
||||
| version | INT | DEFAULT 1 | เวอร์ชันของ Schema |
|
||||
| table_name | VARCHAR(100) | NOT NULL | ชื่อตารางเป้าหมาย |
|
||||
| schema_definition | JSON | NOT NULL | JSON Schema Definition |
|
||||
| ui_schema | JSON | NULL | โครงสร้าง UI Schema สำหรับ Frontend |
|
||||
| virtual_columns | JSON | NULL | Config สำหรับสร้าง Virtual Columns |
|
||||
| migration_script | JSON | NULL | Script สำหรับแปลงข้อมูล |
|
||||
| is_active | BOOLEAN | DEFAULT TRUE | สถานะการใช้งาน |
|
||||
|
||||
|
||||
---
|
||||
|
||||
### 11.2 audit_logs (UPDATE v1.5.1)
|
||||
### 11.2 audit_logs (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: Centralized audit logging for all system actions
|
||||
**Purpose**: Centralized audit logging for all system actions (Req 6.1)
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ----------- | ------------ | --------------------------- | ----------------------------------------- |
|
||||
| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT | Unique log ID |
|
||||
| user_id | INT | NULL, FK | User who performed action |
|
||||
| action | VARCHAR(50) | NOT NULL | Action name (CREATE, UPDATE, DELETE, etc) |
|
||||
| module | VARCHAR(50) | NOT NULL | Module name (USERS, RFA, etc) |
|
||||
| entity_id | VARCHAR(50) | NULL | ID of affected entity |
|
||||
| old_values | JSON | NULL | Data before change |
|
||||
| new_values | JSON | NULL | Data after change |
|
||||
| ip_address | VARCHAR(45) | NULL | User IP address |
|
||||
| user_agent | VARCHAR(255) | NULL | User browser/client info |
|
||||
| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Log timestamp |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :----------- | :----------- | :------------------------ | :------------------------------------------- |
|
||||
| audit_id | BIGINT | PK, AI | Unique log ID |
|
||||
| request_id | VARCHAR(100) | NULL | Trace ID linking to app logs |
|
||||
| user_id | INT | NULL, FK | User who performed action |
|
||||
| action | VARCHAR(100) | NOT NULL | Action name (e.g. rfa.create) |
|
||||
| severity | ENUM | DEFAULT 'INFO' | INFO, WARN, ERROR, CRITICAL |
|
||||
| entity_type | VARCHAR(50) | NULL | Module/Table name (e.g. rfa, correspondence) |
|
||||
| entity_id | VARCHAR(50) | NULL | ID of affected entity |
|
||||
| details_json | JSON | NULL | Context data / Old & New values |
|
||||
| ip_address | VARCHAR(45) | NULL | User IP address |
|
||||
| user_agent | VARCHAR(255) | NULL | User browser/client info |
|
||||
| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Log timestamp |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id, created_at) -- **Partition Key**
|
||||
* INDEX (user_id)
|
||||
* INDEX (module)
|
||||
* INDEX (action)
|
||||
* INDEX (created_at)
|
||||
* INDEX (entity_id)
|
||||
* PRIMARY KEY (audit_id, created_at) -- **Partition Key**
|
||||
* INDEX idx_audit_user (user_id)
|
||||
* INDEX idx_audit_action (action)
|
||||
* INDEX idx_audit_entity (entity_type, entity_id)
|
||||
* INDEX idx_audit_created (created_at)
|
||||
|
||||
**Partitioning**:
|
||||
* **PARTITION BY RANGE (YEAR(created_at))**: แบ่ง Partition รายปี เพื่อประสิทธิภาพในการเก็บข้อมูลระยะยาว
|
||||
|
||||
---
|
||||
|
||||
### 11.3 notifications (UPDATE v1.5.1)
|
||||
### 11.3 notifications (UPDATE v1.7.0)
|
||||
|
||||
**Purpose**: System notifications for users
|
||||
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| ----------- | ------------ | --------------------------- | ----------------------------------- |
|
||||
| id | BIGINT | PRIMARY KEY, AUTO_INCREMENT | Unique notification ID |
|
||||
| user_id | INT | NOT NULL, FK | Recipient user ID |
|
||||
| title | VARCHAR(255) | NOT NULL | Notification title |
|
||||
| message | TEXT | NOT NULL | Notification body |
|
||||
| link | VARCHAR(500) | NULL | Action link URL |
|
||||
| type | VARCHAR(50) | DEFAULT ' INFO ' | Type: INFO, WARNING, ERROR, SUCCESS |
|
||||
| is_read | BOOLEAN | DEFAULT FALSE | Read status |
|
||||
| created_at | TIMESTAMP | DEFAULT CURRENT_TIMESTAMP | Notification timestamp |
|
||||
| Column Name | Data Type | Constraints | Description |
|
||||
| :---------------- | :----------- | :-------------------------- | :------------------------ |
|
||||
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique notification ID |
|
||||
| user_id | INT | NOT NULL, FK | Recipient user ID |
|
||||
| title | VARCHAR(255) | NOT NULL | Notification title |
|
||||
| message | TEXT | NOT NULL | Notification body |
|
||||
| notification_type | ENUM | NOT NULL | Type: EMAIL, LINE, SYSTEM |
|
||||
| is_read | BOOLEAN | DEFAULT FALSE | Read status |
|
||||
| entity_type | VARCHAR(50) | NULL | Related Entity Type |
|
||||
| entity_id | INT | NULL | Related Entity ID |
|
||||
| created_at | DATETIME | DEFAULT CURRENT_TIMESTAMP | Notification timestamp |
|
||||
|
||||
**Indexes**:
|
||||
|
||||
* PRIMARY KEY (id, created_at) -- **Partition Key**
|
||||
* FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||
* INDEX (user_id, is_read)
|
||||
* INDEX (created_at)
|
||||
* INDEX idx_notif_user (user_id)
|
||||
* INDEX idx_notif_type (notification_type)
|
||||
* INDEX idx_notif_read (is_read)
|
||||
* INDEX idx_notif_created (created_at)
|
||||
|
||||
**Partitioning**:
|
||||
* **PARTITION BY RANGE (YEAR(created_at))**: แบ่ง Partition รายปี
|
||||
@@ -1535,58 +1586,33 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
|
||||
|
||||
## **12. 🔍 Views (มุมมองข้อมูล)**
|
||||
|
||||
### 12.1 v_correspondence_details
|
||||
### 12.1 v_current_correspondences
|
||||
|
||||
**Purpose**: Denormalized view for correspondence listing and searching
|
||||
**Purpose**: แสดงข้อมูล Correspondence Revision ล่าสุด (is_current = TRUE)
|
||||
|
||||
```sql
|
||||
CREATE VIEW v_correspondence_details AS
|
||||
SELECT
|
||||
c.id,
|
||||
c.correspondence_number,
|
||||
c.correspondence_type_id,
|
||||
ct.type_name,
|
||||
c.project_id,
|
||||
p.project_code,
|
||||
c.originator_id,
|
||||
org.organization_code AS originator_code,
|
||||
cr.title,
|
||||
cr.revision_number,
|
||||
cr.correspondence_status_id,
|
||||
cs.status_name,
|
||||
cr.document_date,
|
||||
cr.created_at
|
||||
FROM correspondences c
|
||||
JOIN correspondence_revisions cr ON c.id = cr.correspondence_id AND cr.is_current = 1
|
||||
JOIN correspondence_types ct ON c.correspondence_type_id = ct.id
|
||||
JOIN projects p ON c.project_id = p.id
|
||||
LEFT JOIN organizations org ON c.originator_id = org.id
|
||||
LEFT JOIN correspondence_status cs ON cr.correspondence_status_id = cs.id;
|
||||
```
|
||||
### 12.2 v_current_rfas
|
||||
|
||||
### 12.2 v_rfa_details
|
||||
**Purpose**: แสดงข้อมูล RFA Revision ล่าสุด พร้อม Status และ Approve Code
|
||||
|
||||
**Purpose**: Denormalized view for RFA listing and searching
|
||||
### 12.3 v_user_tasks (Unified Workflow)
|
||||
|
||||
```sql
|
||||
CREATE VIEW v_rfa_details AS
|
||||
SELECT
|
||||
r.id,
|
||||
c.correspondence_number AS rfa_number,
|
||||
rt.type_code AS rfa_type,
|
||||
rr.title,
|
||||
rr.revision_number,
|
||||
rsc.status_name AS rfa_status,
|
||||
rac.approve_name AS approval_result,
|
||||
rr.document_date,
|
||||
rr.due_date
|
||||
FROM rfas r
|
||||
JOIN correspondences c ON r.id = c.id -- Assuming 1:1 mapping logic or shared ID
|
||||
JOIN rfa_revisions rr ON r.id = rr.rfa_id AND rr.is_current = 1
|
||||
JOIN rfa_types rt ON r.rfa_type_id = rt.id
|
||||
JOIN rfa_status_codes rsc ON rr.rfa_status_code_id = rsc.id
|
||||
LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
```
|
||||
**Purpose**: รวมรายการงานที่ยังค้างอยู่ (Status = ACTIVE) จากทุกระบบ (RFA, Circulation, Correspondence) เพื่อนำไปแสดงใน Dashboard
|
||||
|
||||
### 12.4 v_audit_log_details
|
||||
|
||||
**Purpose**: แสดง audit_logs พร้อมข้อมูล username และ email ของผู้กระทำ
|
||||
|
||||
### 12.5 v_user_all_permissions
|
||||
|
||||
**Purpose**: รวมสิทธิ์ทั้งหมด (Global + Project + Organization) ของผู้ใช้ทุกคน
|
||||
|
||||
### 12.6 v_documents_with_attachments
|
||||
|
||||
**Purpose**: แสดงเอกสารทั้งหมดที่มีไฟล์แนบ (Correspondence, Circulation, Drawings)
|
||||
|
||||
### 12.7 v_document_statistics
|
||||
|
||||
**Purpose**: แสดงสถิติเอกสารตามประเภทและสถานะ
|
||||
|
||||
---
|
||||
|
||||
@@ -1594,21 +1620,21 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
|
||||
### 13.1 Performance Indexes
|
||||
|
||||
| Table Name | Index Columns | Purpose |
|
||||
| :----------------------- | :------------------------------------------------- | :----------------------------- |
|
||||
| correspondences | (project_id, correspondence_number) | Fast lookup by document number |
|
||||
| correspondences | (correspondence_type_id) | Filter by type |
|
||||
| correspondence_revisions | (correspondence_id, is_current) | Get current revision |
|
||||
| rfas | (rfa_type_id) | Filter by RFA type |
|
||||
| rfa_revisions | (rfa_id, is_current) | Get current RFA revision |
|
||||
| rfa_revisions | (rfa_status_code_id) | Filter by status |
|
||||
| audit_logs | (created_at) | Date range queries |
|
||||
| audit_logs | (user_id) | User activity history |
|
||||
| audit_logs | (module, action) | Action type analysis |
|
||||
| notifications | (user_id, is_read) | Unread notifications query |
|
||||
| document_number_counters | (project_id, correspondence_type_id, current_year) | Running number generation |
|
||||
| workflow_instances | (business_key) | Workflow lookup by document ID |
|
||||
| workflow_instances | (status) | Monitor active workflows |
|
||||
| Table Name | Index Columns | Purpose |
|
||||
| :----------------------- | :------------------------------------------------ | :----------------------------- |
|
||||
| correspondences | (project_id, correspondence_number) | Fast lookup by document number |
|
||||
| correspondences | (correspondence_type_id) | Filter by type |
|
||||
| correspondence_revisions | (correspondence_id, is_current) | Get current revision |
|
||||
| rfas | (rfa_type_id) | Filter by RFA type |
|
||||
| rfa_revisions | (rfa_id, is_current) | Get current RFA revision |
|
||||
| rfa_revisions | (rfa_status_code_id) | Filter by status |
|
||||
| audit_logs | (created_at) | Date range queries |
|
||||
| audit_logs | (user_id) | User activity history |
|
||||
| audit_logs | (module, action) | Action type analysis |
|
||||
| notifications | (user_id, is_read) | Unread notifications query |
|
||||
| document_number_counters | (project_id, correspondence_type_id, reset_scope) | Running number generation |
|
||||
| workflow_instances | (entity_type, entity_id) | Workflow lookup by document ID |
|
||||
| workflow_instances | (current_state) | Monitor active workflows |
|
||||
|
||||
### 13.2 Unique Constraints
|
||||
|
||||
@@ -1620,9 +1646,9 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
| projects | (project_code) | Unique project code |
|
||||
| contracts | (contract_code) | Unique contract code |
|
||||
| correspondences | (project_id, correspondence_number) | Unique document number per project |
|
||||
| rfas | (drawing_number) | Unique shop drawing number |
|
||||
| shop_drawings | (drawing_number) | Unique shop drawing number |
|
||||
| document_number_formats | (project_id, correspondence_type_id) | One format per type per project |
|
||||
| workflow_definitions | (workflow_code) | Unique workflow code |
|
||||
| workflow_definitions | (workflow_code, version) | Unique workflow code per version |
|
||||
|
||||
---
|
||||
|
||||
@@ -1671,7 +1697,7 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
|
||||
## **16. 🔄 Data Migration & Seeding (การย้ายข้อมูล)**
|
||||
|
||||
### 16.1 Initial Seeding (V1.5.1)
|
||||
### 16.1 Initial Seeding (V1.7.0)
|
||||
|
||||
1. **Master Data**:
|
||||
* `organizations`: Owner, Consultant, Contractor
|
||||
@@ -1679,7 +1705,7 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
* `correspondence_types`: LETTER, MEMO, TRANSMITTAL, RFA
|
||||
* `rfa_types`: DWG, MAT, DOC, RFI
|
||||
* `rfa_status_codes`: DFT, PEND, APPR, REJ
|
||||
* `disciplines`: GEN, STR, ARC, MEP (New V1.5.1)
|
||||
* `disciplines`: GEN, STR, ARC, MEP
|
||||
2. **System Users**:
|
||||
* `admin`: Super Admin
|
||||
* `system`: System Bot for automated tasks
|
||||
@@ -1688,11 +1714,11 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
|
||||
* **Schema Migration**: Use TypeORM Migrations or raw SQL scripts (versioned).
|
||||
* **Data Migration**:
|
||||
* **V1.4.5 -> V1.5.1**:
|
||||
* Run SQL script `8_lcbp3_v1_5_1.sql`
|
||||
* Populate `disciplines` table.
|
||||
* Update `document_number_counters` PK (Requires careful migration of existing counters).
|
||||
* Initialize `workflow_definitions`.
|
||||
* **V1.6.0 -> V1.7.0**:
|
||||
* Run SQL script `9_lcbp3_v1_7_0.sql`
|
||||
* Migrate `document_number_counters` to 8-col composite PK.
|
||||
* Initialize `document_number_reservations`.
|
||||
* Update `json_schemas` with new columns.
|
||||
|
||||
---
|
||||
|
||||
@@ -1726,4 +1752,4 @@ LEFT JOIN rfa_approve_codes rac ON rr.rfa_approve_code_id = rac.id;
|
||||
|
||||
---
|
||||
|
||||
**End of Data Dictionary V1.5.1**
|
||||
**End of Data Dictionary V1.7.0**
|
||||
@@ -66,6 +66,8 @@ DROP TABLE IF EXISTS document_number_errors;
|
||||
|
||||
DROP TABLE IF EXISTS document_number_audit;
|
||||
|
||||
DROP TABLE IF EXISTS document_number_reservations;
|
||||
|
||||
-- ============================================================
|
||||
-- ส่วนที่ 2: ตาราง Junction (เชื่อมโยงข้อมูล M:N)
|
||||
-- ============================================================
|
||||
@@ -995,74 +997,58 @@ CREATE TABLE document_number_formats (
|
||||
CREATE TABLE document_number_counters (
|
||||
-- [v1.5.1] Composite Primary Key Columns (8 columns total)
|
||||
project_id INT NOT NULL COMMENT 'โครงการ',
|
||||
correspondence_type_id INT NULL COMMENT 'ประเภทเอกสาร (LETTER, RFA, TRANSMITTAL, etc.) NULL = default format for project',
|
||||
originator_organization_id INT NOT NULL COMMENT 'องค์กรผู้ส่ง',
|
||||
-- เปลี่ยนจาก NULL เป็น DEFAULT -1
|
||||
recipient_organization_id INT NOT NULL DEFAULT -1 COMMENT '[v1.5.1 NEW] องค์กรผู้รับ (-1 = ทุกองค์กร)',
|
||||
-- recipient_organization_id INT NULL COMMENT '[v1.5.1 NEW] องค์กรผู้รับ (NULL = ทุกองค์กร)',
|
||||
correspondence_type_id INT NOT NULL COMMENT 'ประเภทเอกสาร (LETTER, RFA, TRANSMITTAL, etc.)',
|
||||
-- เปลี่ยนจาก NULL เป็น DEFAULT 0
|
||||
recipient_organization_id INT NOT NULL DEFAULT 0 COMMENT '[v1.7.0] องค์กรผู้รับ 0 = no recipient (RFA)',
|
||||
sub_type_id INT DEFAULT 0 COMMENT '[v1.5.1 NEW] ประเภทย่อย สำหรับ TRANSMITTAL (0 = ไม่ระบุ)',
|
||||
rfa_type_id INT DEFAULT 0 COMMENT '[v1.5.1 NEW] ประเภท RFA เช่น SHD, RPT, MAT (0 = ไม่ใช่ RFA)',
|
||||
discipline_id INT DEFAULT 0 COMMENT 'สาขางาน เช่น TER, STR, GEO (0 = ไม่ระบุ)',
|
||||
current_year INT NOT NULL COMMENT 'ปี ค.ศ. ของตัวนับ (auto-reset ทุกปี)',
|
||||
reset_scope VARCHAR(20) NOT NULL COMMENT 'Scope of reset (PROJECT, ORGANIZATION, etc.)',
|
||||
-- Counter Data
|
||||
last_number INT DEFAULT 0 NOT NULL COMMENT 'เลขที่ล่าสุดที่ใช้ไปแล้ว (auto-increment)',
|
||||
version INT DEFAULT 0 NOT NULL COMMENT 'Optimistic Lock Version (TypeORM @VersionColumn)',
|
||||
last_number INT DEFAULT 0 COMMENT 'เลขที่ล่าสุดที่ใช้ไปแล้ว (auto-increment)',
|
||||
-- [v1.5.1 UPDATE] Primary Key: 5 columns -> 8 columns
|
||||
-- ใช้ COALESCE เพื่อรองรับ NULL ใน recipient_organization_id
|
||||
-- Metadata
|
||||
created_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
updated_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
|
||||
-- [v1.7.0 UPDATE] Primary Key: 5 columns -> 8 columns
|
||||
PRIMARY KEY (
|
||||
project_id,
|
||||
originator_organization_id,
|
||||
recipient_organization_id,
|
||||
-- [v1.5.1 NEW] Handle NULL values
|
||||
correspondence_type_id,
|
||||
sub_type_id,
|
||||
-- [v1.5.1 NEW]
|
||||
rfa_type_id,
|
||||
-- [v1.5.1 NEW]
|
||||
discipline_id,
|
||||
current_year
|
||||
reset_scope
|
||||
),
|
||||
-- Foreign Keys
|
||||
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (originator_organization_id) REFERENCES organizations (id) ON DELETE CASCADE,
|
||||
-- NOTE: recipient_organization_id uses -1 as sentinel for "all organizations"
|
||||
-- Therefore NO FK constraint is applied here (would fail for -1)
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types (id) ON DELETE CASCADE,
|
||||
-- [v1.5.1 NEW] Performance Indexes
|
||||
INDEX idx_counter_lookup (
|
||||
project_id,
|
||||
correspondence_type_id,
|
||||
current_year
|
||||
),
|
||||
INDEX idx_counter_org (
|
||||
originator_organization_id,
|
||||
current_year
|
||||
),
|
||||
-- [v1.5.1 NEW] Data Validation Constraints
|
||||
-- CONSTRAINT chk_last_number_positive CHECK (last_number >= 0),
|
||||
-- CONSTRAINT chk_current_year_valid CHECK (current_year BETWEEN 2020 AND 2100)
|
||||
-- Performance Indexes
|
||||
INDEX idx_counter_lookup (project_id, correspondence_type_id, reset_scope),
|
||||
INDEX idx_counter_org (originator_organization_id, reset_scope),
|
||||
-- Constraints
|
||||
CONSTRAINT chk_last_number_positive CHECK (last_number >= 0),
|
||||
CONSTRAINT chk_current_year CHECK (
|
||||
current_year BETWEEN 2020 AND 2100
|
||||
),
|
||||
CONSTRAINT chk_recipient_special CHECK (
|
||||
recipient_organization_id = -1
|
||||
OR recipient_organization_id > 0
|
||||
)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '[v1.5.1 UPDATE] ตารางเก็บ Running Number Counters - รองรับ 8-column composite PK';
|
||||
CONSTRAINT chk_reset_scope_format CHECK (
|
||||
reset_scope IN ('NONE')
|
||||
OR reset_scope LIKE 'YEAR_%'
|
||||
OR reset_scope LIKE 'MONTH_%'
|
||||
OR reset_scope LIKE 'CONTRACT_%')
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'ตารางเก็บ Running Number Counters - รองรับ 8-column composite PK';
|
||||
|
||||
-- ==========================================================
|
||||
-- [v1.5.1 NEW] ตารางเก็บ Audit Trail สำหรับการสร้างเลขที่เอกสาร
|
||||
-- ตารางเก็บ Audit Trail สำหรับการสร้างเลขที่เอกสาร
|
||||
-- เพิ่มตาราง: document_number_audit
|
||||
-- เหตุผล: บันทึกประวัติการสร้างเลขที่ รองรับ audit requirement ≥ 7 ปี
|
||||
-- รองรับ: Req 3.11.8, Backend Plan T2.8
|
||||
-- ==========================================================
|
||||
CREATE TABLE document_number_audit (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'ID ของ audit record',
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'ID ของ audit record',
|
||||
-- Document Info
|
||||
document_id INT NOT NULL COMMENT 'ID ของเอกสารที่สร้างเลขที่ (correspondences.id)',
|
||||
generated_number VARCHAR(100) NOT NULL COMMENT 'เลขที่เอกสารที่สร้าง (ผลลัพธ์)',
|
||||
document_type VARCHAR(50),
|
||||
document_number VARCHAR(100) NOT NULL COMMENT 'เลขที่เอกสารที่สร้าง (ผลลัพธ์)',
|
||||
operation ENUM(
|
||||
'RESERVE',
|
||||
'CONFIRM',
|
||||
@@ -1070,24 +1056,42 @@ CREATE TABLE document_number_audit (
|
||||
'VOID_REPLACE',
|
||||
'CANCEL'
|
||||
) NOT NULL DEFAULT 'CONFIRM' COMMENT 'ประเภทการดำเนินการ',
|
||||
status ENUM(
|
||||
'RESERVED',
|
||||
'CONFIRMED',
|
||||
'CANCELLED',
|
||||
'VOID',
|
||||
'MANUAL'
|
||||
) NOT NULL DEFAULT 'RESERVED' COMMENT 'สถานะเลขที่เอกสาร',
|
||||
counter_key JSON NOT NULL COMMENT 'Counter key ที่ใช้ (JSON format) - 8 fields',
|
||||
metadata JSON COMMENT 'Additional context data',
|
||||
reservation_token VARCHAR(36) NULL,
|
||||
originator_organization_id INT NULL,
|
||||
recipient_organization_id INT NULL,
|
||||
|
||||
template_used VARCHAR(200) NOT NULL COMMENT 'Template ที่ใช้ในการสร้าง',
|
||||
old_value TEXT NULL,
|
||||
new_value TEXT NULL,
|
||||
-- User Info
|
||||
user_id INT NOT NULL COMMENT 'ผู้ขอสร้างเลขที่',
|
||||
ip_address VARCHAR(45) COMMENT 'IP address ของผู้ขอ (IPv4/IPv6)',
|
||||
user_agent TEXT COMMENT 'User agent string (browser info)',
|
||||
is_success BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT 'วันที่/เวลาที่สร้าง',
|
||||
-- Performance & Error Tracking
|
||||
retry_count INT DEFAULT 0 COMMENT 'จำนวนครั้งที่ retry ก่อนสำเร็จ',
|
||||
lock_wait_ms INT COMMENT 'เวลารอ Redis lock (milliseconds)',
|
||||
total_duration_ms INT COMMENT 'เวลารวมทั้งหมดในการสร้าง (milliseconds)',
|
||||
fallback_used ENUM('NONE', 'DB_LOCK', 'RETRY') DEFAULT 'NONE' COMMENT 'Fallback strategy ที่ถูกใช้ (NONE=normal, DB_LOCK=Redis down, RETRY=conflict)',
|
||||
metadata JSON COMMENT 'Additional context data',
|
||||
|
||||
-- Indexes for performance
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_operation (operation),
|
||||
INDEX idx_document_number (document_number),
|
||||
INDEX idx_reservation_token (reservation_token),
|
||||
INDEX idx_created_at (created_at),
|
||||
INDEX idx_generated_number (generated_number),
|
||||
-- Foreign Keys
|
||||
FOREIGN KEY (document_id) REFERENCES correspondences (id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users (user_id)
|
||||
@@ -1100,7 +1104,7 @@ CREATE TABLE document_number_audit (
|
||||
-- รองรับ: Req 3.11.6, Ops monitoring requirements
|
||||
-- ==========================================================
|
||||
CREATE TABLE document_number_errors (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT 'ID ของ error record',
|
||||
id INT AUTO_INCREMENT PRIMARY KEY COMMENT 'ID ของ error record',
|
||||
-- Error Classification
|
||||
error_type ENUM(
|
||||
'LOCK_TIMEOUT',
|
||||
@@ -1130,6 +1134,43 @@ CREATE TABLE document_number_errors (
|
||||
INDEX idx_unresolved (resolved_at) -- Find unresolved errors
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '[v1.5.1 NEW] Error Log สำหรับ Document Numbering System';
|
||||
|
||||
-- =====================================================
|
||||
CREATE TABLE document_number_reservations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
-- Reservation Details
|
||||
token VARCHAR(36) NOT NULL UNIQUE COMMENT 'UUID v4',
|
||||
document_number VARCHAR(100) NOT NULL UNIQUE,
|
||||
document_number_status ENUM('RESERVED', 'CONFIRMED', 'CANCELLED', 'VOID') NOT NULL DEFAULT 'RESERVED',
|
||||
-- Linkage
|
||||
document_id INT NULL COMMENT 'FK to documents (NULL until confirmed)',
|
||||
-- Context (for debugging)
|
||||
project_id INT NOT NULL,
|
||||
correspondence_type_id INT NOT NULL,
|
||||
originator_organization_id INT NOT NULL,
|
||||
recipient_organization_id INT DEFAULT 0,
|
||||
user_id INT NOT NULL,
|
||||
-- Timestamps
|
||||
reserved_at DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6),
|
||||
expires_at DATETIME(6) NOT NULL,
|
||||
confirmed_at DATETIME(6) NULL,
|
||||
cancelled_at DATETIME(6) NULL,
|
||||
-- Audit
|
||||
ip_address VARCHAR(45),
|
||||
user_agent TEXT,
|
||||
metadata JSON NULL COMMENT 'Additional context',
|
||||
-- Indexes
|
||||
INDEX idx_token (token),
|
||||
INDEX idx_status (document_number_status),
|
||||
INDEX idx_status_expires (document_number_status, expires_at),
|
||||
INDEX idx_document_id (document_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_reserved_at (reserved_at),
|
||||
-- Foreign Keys
|
||||
FOREIGN KEY (document_id) REFERENCES correspondence_revisions(id) ON DELETE SET NULL,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'Document Number Reservations - Two-Phase Commit';
|
||||
-- =====================================================
|
||||
-- 10. ⚙️ System & Logs (ระบบและ Log)
|
||||
-- =====================================================
|
||||
@@ -1391,8 +1432,6 @@ CREATE INDEX idx_document_number_counters_org ON document_number_counters (origi
|
||||
|
||||
CREATE INDEX idx_document_number_counters_type ON document_number_counters (correspondence_type_id);
|
||||
|
||||
CREATE INDEX idx_document_number_counters_year ON document_number_counters (current_year);
|
||||
|
||||
-- Indexes for tags
|
||||
CREATE INDEX idx_tags_name ON tags (tag_name);
|
||||
|
||||
@@ -1443,12 +1482,6 @@ CREATE INDEX idx_backup_logs_completed_at ON backup_logs (completed_at);
|
||||
-- Additional Composite Indexes for Performance
|
||||
-- =====================================================
|
||||
-- Composite index for document_number_counters for faster lookups
|
||||
CREATE INDEX idx_doc_counter_composite ON document_number_counters (
|
||||
project_id,
|
||||
originator_organization_id,
|
||||
correspondence_type_id,
|
||||
current_year
|
||||
);
|
||||
|
||||
-- Composite index for notifications for user-specific queries
|
||||
CREATE INDEX idx_notifications_user_unread ON notifications (user_id, is_read, created_at);
|
||||
@@ -2169,3 +2169,48 @@ VALUES (
|
||||
NOW()
|
||||
);
|
||||
|
||||
INSERT INTO `document_number_formats` (
|
||||
`id`,
|
||||
`project_id`,
|
||||
`correspondence_type_id`,
|
||||
`discipline_id`,
|
||||
`format_template`,
|
||||
`reset_sequence_yearly`,
|
||||
`example_number`,
|
||||
`padding_length`,
|
||||
`reset_annually`,
|
||||
`is_active`,
|
||||
`description`,
|
||||
`created_at`,
|
||||
`updated_at`
|
||||
)
|
||||
VALUES (
|
||||
1,
|
||||
1,
|
||||
NULL,
|
||||
0,
|
||||
'{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}',
|
||||
1,
|
||||
NULL,
|
||||
4,
|
||||
1,
|
||||
1,
|
||||
NULL,
|
||||
'2025-12-16 09:33:36',
|
||||
'2025-12-16 09:33:36'
|
||||
),
|
||||
(
|
||||
2,
|
||||
2,
|
||||
NULL,
|
||||
0,
|
||||
'{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}',
|
||||
1,
|
||||
NULL,
|
||||
4,
|
||||
1,
|
||||
1,
|
||||
NULL,
|
||||
'2025-12-16 09:34:10',
|
||||
'2025-12-16 09:34:10'
|
||||
);
|
||||
55
specs/09-history/2025-12-18-refactor-document-numbering.md
Normal file
55
specs/09-history/2025-12-18-refactor-document-numbering.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Document Numbering Refactoring - 2025-12-18
|
||||
|
||||
## Overview
|
||||
Refactored the `DocumentNumberingService` in the backend to split responsibilities into dedicated services (`CounterService`, `ReservationService`) and updated the `DocumentNumberCounter` entity to match the v1.7.0 schema.
|
||||
|
||||
## Changes
|
||||
|
||||
### 1. Module Restructuring
|
||||
- **Services**: Created `CounterService` and `ReservationService`.
|
||||
- **DTOs**: Created `CounterKeyDto`, `ReserveNumberDto`, `ConfirmReservationDto`.
|
||||
- **Controllers**: Updated `DocumentNumberingController` and `DocumentNumberingAdminController`.
|
||||
|
||||
### 2. Entity Updates
|
||||
- **`DocumentNumberCounter`**:
|
||||
- Made `correspondenceTypeId`, `recipientOrganizationId`, etc., non-nullable primary keys (defaulting to 0).
|
||||
- Added `resetScope` with length 20.
|
||||
- **`DocumentNumberReservation`**: Created for two-phase commit reservation logic.
|
||||
|
||||
### 3. Service Logic
|
||||
- **`CounterService`**:
|
||||
- Handles atomic counter increment.
|
||||
- Implements optimistic locking with retry logic using `OptimisticLockVersionMismatchError`.
|
||||
- **`ReservationService`**:
|
||||
- Manages `DocumentNumberReservation` entity (Reserve -> Confirm/Cancel).
|
||||
- Removes unused `userId` from confirmation/cancellation logic.
|
||||
- **`DocumentNumberingService`**:
|
||||
- Delegates counter logic to `CounterService`.
|
||||
- Delegates reservation logic to `ReservationService`.
|
||||
- Corrected property mapping (e.g., `originatorOrganizationId`).
|
||||
- Fixed `resolveDisciplineCode` to use `disciplineCode` column.
|
||||
|
||||
## Verification Results
|
||||
|
||||
### Automated Tests
|
||||
Ran unit tests for `DocumentNumberingService`:
|
||||
```bash
|
||||
npm test modules/document-numbering/document-numbering.service.spec.ts
|
||||
```
|
||||
|
||||
**Result:**
|
||||
```
|
||||
PASS src/modules/document-numbering/document-numbering.service.spec.ts
|
||||
DocumentNumberingService
|
||||
√ should be defined (13 ms)
|
||||
generateNextNumber
|
||||
√ should generate a new number successfully (6 ms)
|
||||
√ should throw error when increment fails (12 ms)
|
||||
|
||||
Test Suites: 1 passed, 1 total
|
||||
Tests: 3 passed, 3 total
|
||||
```
|
||||
|
||||
### Manual Verification Steps
|
||||
1. **Generate Number**: Call `POST /document-numbering/preview` (mapped to `previewNumber`).
|
||||
2. **Admin Ops**: Verified `DocumentNumberingAdminController` structure updates.
|
||||
Reference in New Issue
Block a user