260321:1700 Correct Coresspondence / Doing RFA

This commit is contained in:
admin
2026-03-21 17:00:41 +07:00
parent dcf55f4d08
commit 03d16cfd64
57 changed files with 1923 additions and 663 deletions
@@ -33,6 +33,11 @@ related:
## 3.3.4. การอ้างอิงและจัดกลุ่ม:
- RFA สามารถอ้างถึง (Reference) แบบก่อสร้าง (Shop Drawing) ได้หลายฉบับ
- การสร้าง RFA ต้องสร้างเอกสารแม่ใน `correspondences` โดยใช้ `correspondence_types.type_code = 'RFA'`
- ประเภทย่อยของ RFA ต้องเก็บใน `rfas.rfa_type_id`
- ถ้า `rfa_types.type_code` เป็น `DDW` หรือ `SDW` ระบบต้องบังคับให้เลือกอย่างน้อย 1 `shop_drawing_revision`
- ถ้า `rfa_types.type_code` เป็น `ADW` ระบบต้องบังคับให้เลือกอย่างน้อย 1 `asbuilt_drawing_revision`
- 1 แถวใน `rfa_items` ต้องอ้างอิง Drawing Revision ได้เพียง 1 รายการเท่านั้น โดยเป็น `shop_drawing_revision` หรือ `asbuilt_drawing_revision` อย่างใดอย่างหนึ่ง
## 3.3.5. Workflow (Unified Workflow):
@@ -522,7 +522,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
| :----------- | :----------- | :-------------------------- | :------------------------------ |
| 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_code | VARCHAR(20) | NOT NULL | Type code (DDW, SDW, ADW, 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 |
@@ -653,29 +653,41 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
### 4.6 rfa_items
**Purpose**: Junction table linking RFA revisions to shop drawing revisions (M:N)
**Purpose**: Child table linking RFA revisions to drawing revisions that require approval
| 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 |
| Column Name | Data Type | Constraints | Description |
| :------------------------- | :----------------------- | :------------------- | :--------------------------------- |
| id | INT | PRIMARY KEY, AI | Unique identifier |
| rfa_revision_id | INT | NOT NULL, FK | RFA Revision ID |
| item_type | ENUM('SHOP','AS_BUILT') | NOT NULL | Drawing reference type |
| shop_drawing_revision_id | INT | NULL, FK | Shop drawing revision ID |
| asbuilt_drawing_revision_id| INT | NULL, FK | As-Built drawing revision ID |
**Indexes**:
* PRIMARY KEY (rfa_revision_id, shop_drawing_revision_id)
* PRIMARY KEY (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
* FOREIGN KEY (asbuilt_drawing_revision_id) REFERENCES asbuilt_drawing_revisions(id) ON DELETE CASCADE
* UNIQUE KEY (rfa_revision_id, shop_drawing_revision_id)
* UNIQUE KEY (rfa_revision_id, asbuilt_drawing_revision_id)
* INDEX (item_type)
* INDEX (shop_drawing_revision_id)
* INDEX (asbuilt_drawing_revision_id)
**Relationships**:
* Parent: rfa_revisions, shop_drawing_revisions
* Parent: rfa_revisions, shop_drawing_revisions, asbuilt_drawing_revisions
**Business Rules**:
* Used primarily for RFA type = ' DWG ' (Shop Drawing)
* One RFA can contain multiple shop drawings
* One shop drawing can be referenced by multiple RFAs
* `correspondences.correspondence_type_id` for an RFA must always point to `correspondence_types.type_code = 'RFA'`
* `rfas.rfa_type_id` stores the selected RFA subtype
* `DDW` and `SDW` RFA types must reference `shop_drawing_revisions`
* `ADW` RFA types must reference `asbuilt_drawing_revisions`
* Each `rfa_items` row must reference exactly one drawing revision target according to `item_type`
* One RFA can contain multiple drawing references
* One drawing revision can be referenced by multiple RFAs
---
@@ -1515,7 +1527,8 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
| ---------------------- | ------------ | --------------------------- | -------------------------------------------- |
| id | INT | PRIMARY KEY, AUTO_INCREMENT | Unique format ID |
| project_id | INT | NOT NULL, FK | Reference to projects |
| correspondence_type_id | INT | NOT NULL, FK | Reference to correspondence_types |
| correspondence_type_id | INT | NULL, FK | Reference to correspondence_types |
| discipline_id | INT | DEFAULT 0, FK | Reference to disciplines (0 = all) |
| format_string | VARCHAR(100) | NOT NULL | Format pattern (e.g., {ORG}-{TYPE}-{YYYY}-#) |
| description | TEXT | NULL | Format description |
| reset_annually | BOOLEAN | DEFAULT TRUE | Start sequence new every year |
@@ -1526,7 +1539,7 @@ SET NULL - INDEX (is_active) - INDEX (email) ** Relationships **: - Parent: orga
* PRIMARY KEY (id)
* FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
* FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE
* UNIQUE KEY (project_id, correspondence_type_id)
* UNIQUE KEY (project_id, correspondence_type_id, discipline_id)
* INDEX (is_active)
**Relationships**:
@@ -469,17 +469,22 @@ CREATE TABLE rfa_revisions (
SET NULL
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'ตารางขยายของ correspondence_revisions สำหรับ RFA (1:1)';
-- ตารางเชื่อมระหว่าง rfa_revisions (ที่เป็นประเภท DWG) กับ shop_drawing_revisions (M:N)
-- ตารางรายการอ้างอิง Drawing Revision ของ RFA (รองรับ Shop Drawing และ As-Built Drawing)
CREATE TABLE rfa_items (
rfa_revision_id INT COMMENT 'ID ของ RFA Revision',
shop_drawing_revision_id INT COMMENT 'ID ของ Shop Drawing Revision',
PRIMARY KEY (
rfa_revision_id,
shop_drawing_revision_id
),
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID ของตาราง',
rfa_revision_id INT NOT NULL COMMENT 'ID ของ RFA Revision',
item_type ENUM('SHOP', 'AS_BUILT') NOT NULL COMMENT 'ประเภท Drawing Revision ที่ถูกอ้างอิง',
shop_drawing_revision_id INT NULL COMMENT 'ID ของ Shop Drawing Revision',
asbuilt_drawing_revision_id INT NULL COMMENT 'ID ของ As-Built Drawing Revision',
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
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'ตารางเชื่อมระหว่าง rfa_revisions (ที่เป็นประเภท DWG) กับ shop_drawing_revisions (M :N)';
FOREIGN KEY (shop_drawing_revision_id) REFERENCES shop_drawing_revisions (id) ON DELETE CASCADE,
FOREIGN KEY (asbuilt_drawing_revision_id) REFERENCES asbuilt_drawing_revisions (id) ON DELETE CASCADE,
UNIQUE KEY uq_rfa_items_shop (rfa_revision_id, shop_drawing_revision_id),
UNIQUE KEY uq_rfa_items_asbuilt (rfa_revision_id, asbuilt_drawing_revision_id),
INDEX idx_rfa_items_type (item_type),
INDEX idx_rfa_items_shop (shop_drawing_revision_id),
INDEX idx_rfa_items_asbuilt (asbuilt_drawing_revision_id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'ตารางรายการอ้างอิง Drawing Revision ของ RFA โดย 1 แถวต้องอ้างอิง Shop Drawing Revision หรือ As-Built Drawing Revision อย่างใดอย่างหนึ่ง';
-- =====================================================
-- 5. 📐 Drawings (แบบ, หมวดหมู่)
@@ -222,7 +222,7 @@ INSERT INTO users (
VALUES (
1,
'superadmin',
'$2b$10$MpKnf1UEvlu8hZcqMkhMsuWG3gYD/priWTUr71GpF/uuroaGxtose',
'$2b$10$60HqaxJFZSF8.n.kOPubge2pK3SXbz4tmNTmrQB/coZ8QXrFMcdIK',
'Super',
'Admin',
'superadmin @example.com',
@@ -232,7 +232,7 @@ VALUES (
(
2,
'admin',
'$2b$10$MpKnf1UEvlu8hZcqMkhMsuWG3gYD/priWTUr71GpF/uuroaGxtose',
'$2b$10$60HqaxJFZSF8.n.kOPubge2pK3SXbz4tmNTmrQB/coZ8QXrFMcdIK',
'Admin',
'คคง.',
'admin@example.com',
@@ -242,7 +242,7 @@ VALUES (
(
3,
'editor01',
'$2b$10$MpKnf1UEvlu8hZcqMkhMsuWG3gYD/priWTUr71GpF/uuroaGxtose',
'$2b$10$60HqaxJFZSF8.n.kOPubge2pK3SXbz4tmNTmrQB/coZ8QXrFMcdIK',
'DC',
'C1',
'editor01 @example.com',
@@ -252,7 +252,7 @@ VALUES (
(
4,
'viewer01',
'$2b$10$MpKnf1UEvlu8hZcqMkhMsuWG3gYD/priWTUr71GpF/uuroaGxtose',
'$2b$10$60HqaxJFZSF8.n.kOPubge2pK3SXbz4tmNTmrQB/coZ8QXrFMcdIK',
'Viewer',
'สคฉ.03',
'viewer01@example.com',
@@ -273,7 +273,7 @@ INSERT INTO users (
VALUES (
5,
'migration_bot',
'$2b$10$MpKnf1UEvlu8hZcqMkhMsuWG3gYD/priWTUr71GpF/uuroaGxtose',
'$2b$10$60HqaxJFZSF8.n.kOPubge2pK3SXbz4tmNTmrQB/coZ8QXrFMcdIK',
'Migration',
'Bot',
'migration@system.internal',
@@ -125,16 +125,18 @@ LCBP3-DMS ต้องสร้างเลขที่เอกสารอั
CREATE TABLE document_number_formats (
id INT PRIMARY KEY AUTO_INCREMENT,
project_id INT NOT NULL,
correspondence_type_id INT NULL COMMENT 'Specific Type ID, or NULL for Project Default', -- CHANGED: Allow NULL
correspondence_type_id INT NULL COMMENT 'Specific Type ID, or NULL for Project Default',
discipline_id INT DEFAULT 0 COMMENT 'Specific Discipline ID, or 0 for All',
format_template VARCHAR(100) NOT NULL COMMENT 'e.g. {PROJECT}-{TYPE}-{YEAR}-{SEQ:4}',
description TEXT,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
FOREIGN KEY (correspondence_type_id) REFERENCES correspondence_types(id) ON DELETE CASCADE,
-- Note: Application logic must enforce single default format per project
UNIQUE KEY unique_format (project_id, correspondence_type_id)
-- Note: Application logic uses automated Upsert based on business key
UNIQUE KEY unique_format (project_id, correspondence_type_id, discipline_id)
) ENGINE=InnoDB COMMENT='Template configurations for document numbering';
-- Counter Table with Optimistic Locking
@@ -975,3 +977,4 @@ ensure:
| 1.0 | 2025-11-30 | Initial decision |
| 2.0 | 2025-12-02 | Updated with comprehensive error scenarios, monitoring, security, and all token types |
| 3.0 | 2025-12-17 | Aligned with Requirements v1.6.2: updated counter schema, token definitions, Number State Machine |
| 4.0 | 2026-03-21 | Added discipline_id to formats, implemented automated Upsert logic for template management |