定義
核心維護提醒與業務邏輯
- 關聯調整說明:
- 原規格中的
contact_id 已統一下化為 customers 表格的 customer_id(直接整合了客戶公司名稱、聯絡人姓名、Email 與 Phone 資訊)。
- 在線時數採集:
- PM 登入/登出 時,除了產生
user_sessions 紀錄外,需同步累加線上秒數至 users.total_online_seconds。
- 報表產出數據採集:
- PM 成功生成報表(
status 變更為 GENERATED)時,需自動將 users.generated_report_count 加 1。
- 使用軌跡 (Audit Trail) 數據採集:
- 所有的系統點擊、報表規格修改、下載與匯出操作,皆需經由後端 Middleware 或 API 層寫入
audit_logs 表格。
- 安全與初次登入驗證:
- 預設建立之帳號
is_first_login 為 True,密碼預設為 report24837296。系統需判定首次登入後強制導向修改密碼頁面。
數據庫 Schema 結構總覽
users (PM / 系統帳號表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
user_id | String(36) | Primary Key (UUID) |
name | String(100) | 使用者姓名 |
email | String(100) | 登入 Email (Unique Key) |
password | String(255) | 密碼(預設 report24837296,須經過 Password Hash) |
role | String(20) | 權限角色 (例如: 'PM', 'Admin') |
is_first_login | Boolean | 首次登入標記 (預設 True) |
total_online_seconds | Integer | 【數據指標】 累計登入總秒數 (預設 0) |
generated_report_count | Integer | 【數據指標】 累計產出報表總次數 (預設 0) |
last_login_at | DateTime | 最後登入時間 |
customers (客戶與聯絡人資料表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
customer_id | String(36) | Primary Key (UUID) |
pm_id | String(36) | Foreign Key -> users.user_id (負責 PM) |
company_name | String(150) | 公司名稱 |
customer_name | String(100) | 聯絡人姓名 |
customer_mail | String(100) | 聯絡人 Email |
customer_phone | String(50) | 聯絡人電話 |
reports (報表規格主表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
report_id | String(36) | Primary Key (UUID) |
report_code | String(50) | 報表編號 (Unique Key) |
pm_id | String(36) | Foreign Key -> users.user_id |
customer_id | String(36) | Foreign Key -> customers.customer_id |
status | String(20) | 狀態 (例如: 'DRAFT', 'GENERATED', 'ARCHIVED') |
spec_series | Integer | 串聯數 (預設 6) |
spec_parallel | Integer | 並聯數 |
cell_num | String(50) | 電芯型號 / 料號 |
cell_type | String(50) | 電芯種類 (如 18650, 21700, 磷酸鐵鋰) |
connection_method | String(50) | 串併方式 |
processing_method | String(50) | 加工方式 |
connector_type | String(50) | 連接器類型 |
wire_length | Numeric(10,2) | 線長 (mm/cm) |
outer_casing | String(50) | 外包覆材質 |
array_arrangement | Enum | 排列方式 ('I', 'U', 'II') |
has_bms | Boolean | 是否包含 BMS (預設 True) |
bms_spec_limit | String(50) | BMS 規格限制 (如 '6S?P') |
weight_g | Numeric(10,2) | 估計重量 (g) |
dimensions_mm | String(50) | 尺寸規格 (格式如 L_W_H) |
delivery_days | Integer | 交期天數 |
tiered_pricing | Numeric(12,2) | 報表價格/階梯價格 |
report_histories (歷史版本與快照)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
history_id | String(36) | Primary Key (UUID) |
report_id | String(36) | Foreign Key -> reports.report_id |
version | Integer | 版本號 (1, 2, 3…) |
snapshot_data | JSON | 該版次整份報表與客戶資訊的 JSON 快照 |
created_by | String(36) | Foreign Key -> users.user_id (編輯者) |
user_sessions (登入與時數細節表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
session_id | String(36) | Primary Key (UUID) |
user_id | String(36) | Foreign Key -> users.user_id |
login_at | DateTime | 登入時間 |
logout_at | DateTime | 登出時間 |
duration_seconds | Integer | 該次 Session 線上總秒數 |
audit_logs (系統操作軌跡表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
log_id | String(36) | Primary Key (UUID) |
user_id | String(36) | Foreign Key -> users.user_id (可為 Null) |
action | String(50) | 操作類型 (LOGIN, CREATE_REPORT, EXPORT_PDF, UPDATE_SPEC) |
resource | String(50) | 操作標的 (如 reports, customers) |
details | JSON | 詳細操作參數與欄位變更紀錄 |
ip_address | String(45) | 用戶端 IP 地址 |
user_agent | String(255) | 用戶端瀏覽器/裝置資訊 |
static_report_masters (靜態報表主檔 / 規格範本表)
| 欄位名稱 (Field) | 型態 (Type) | 說明 / 預設值 (Description) |
|---|
master_id | String(36) | Primary Key (UUID) |
template_code | String(50) | 規格範本 / 標準報表編號 (Unique Key) |
spec_series | Integer | 預設串聯數 (S) |
spec_parallel | Integer | 預設並聯數 (P) |
cell_num | String(50) | 推薦/標準電芯型號與料號 |
cell_type | String(50) | 電芯種類 (如 18650, 21700, LFP, NCM) |
connection_method | String(50) | 標準串併與焊接方式 |
processing_method | String(50) | 標準加工方式 |
connector_type | String(50) | 標準連接器規格 |
wire_length | Numeric(10,2) | 標準線長 (mm/cm) |
outer_casing | String(50) | 外包覆材質 (如熱縮套管、PVC、金屬外殼) |
array_arrangement | Enum | 預設排列方式 ('I', 'U', 'II') |
has_bms | Boolean | 預設是否包含 BMS (預設 True) |
bms_spec_limit | String(50) | 搭配之 BMS 規格限制 (如 '6S') |
weight_g | Numeric(10,2) | 標準估計總重量 (g) |
dimensions_mm | String(50) | 標準外觀尺寸 (格式如 L_W_H) |
delivery_days | Integer | 標準基準交期天數 |
tiered_pricing | Numeric(12,2) | 預設階梯定價 / 基礎建議售價 |
is_active | Boolean | 是否啟用此範本 (預設 True) |
created_at | DateTime | 建立時間 |
updated_at | DateTime | 最後異動時間 |