feat: HR Portal - Complete Multi-Tenant System with Redis Session Storage
Major Features: - ✅ Multi-tenant architecture (tenant isolation) - ✅ Employee CRUD with lifecycle management (onboarding/offboarding) - ✅ Department tree structure with email domain management - ✅ Company info management (single-record editing) - ✅ System functions CRUD (permission management) - ✅ Email account management (multi-account per employee) - ✅ Keycloak SSO integration (auth.lab.taipei) - ✅ Redis session storage (10.1.0.254:6379) - Solves Cookie 4KB limitation - Cross-system session sharing - Sliding expiration (8 hours) - Automatic token refresh Technical Stack: Backend: - FastAPI + SQLAlchemy - PostgreSQL 16 (10.1.0.20:5433) - Keycloak Admin API integration - Docker Mailserver integration (SSH) - Alembic migrations Frontend: - Next.js 14 (App Router) - NextAuth 4 with Keycloak Provider - Redis session storage (ioredis) - Tailwind CSS Infrastructure: - Redis 7 (10.1.0.254:6379) - Session + Cache - Keycloak 26.1.0 (auth.lab.taipei) - Docker Mailserver (10.1.0.254) Architecture Highlights: - Session管理由 Keycloak + Redis 統一控制 - 支援多系統 (HR/WebMail/Calendar/Drive/Office) 共享 session - Token 自動刷新,異質服務整合 - 未來可無縫遷移到雲端 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
102
backend/insert_dashboard_function.py
Normal file
102
backend/insert_dashboard_function.py
Normal file
@@ -0,0 +1,102 @@
|
||||
"""
|
||||
插入 dashboard 系統功能記錄
|
||||
"""
|
||||
import psycopg2
|
||||
from datetime import datetime
|
||||
|
||||
# 資料庫連線參數
|
||||
DB_CONFIG = {
|
||||
'host': '10.1.0.20',
|
||||
'port': 5433,
|
||||
'database': 'hr_portal',
|
||||
'user': 'admin',
|
||||
'password': 'DC1qaz2wsx'
|
||||
}
|
||||
|
||||
def insert_dashboard_function():
|
||||
"""插入 dashboard 功能記錄"""
|
||||
try:
|
||||
conn = psycopg2.connect(**DB_CONFIG)
|
||||
cursor = conn.cursor()
|
||||
|
||||
today = datetime.now()
|
||||
|
||||
# 插入 SQL
|
||||
insert_sql = """
|
||||
INSERT INTO system_functions (
|
||||
id,
|
||||
code,
|
||||
upper_function_id,
|
||||
name,
|
||||
function_type,
|
||||
"order",
|
||||
module_code,
|
||||
module_functions,
|
||||
description,
|
||||
is_active,
|
||||
edit_by,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
23,
|
||||
'dashboard',
|
||||
0,
|
||||
'系統首頁',
|
||||
2,
|
||||
10,
|
||||
'dashboard',
|
||||
'["Create", "Read"]'::jsonb,
|
||||
'',
|
||||
true,
|
||||
1,
|
||||
%s,
|
||||
%s
|
||||
)
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
code = EXCLUDED.code,
|
||||
upper_function_id = EXCLUDED.upper_function_id,
|
||||
name = EXCLUDED.name,
|
||||
function_type = EXCLUDED.function_type,
|
||||
"order" = EXCLUDED."order",
|
||||
module_code = EXCLUDED.module_code,
|
||||
module_functions = EXCLUDED.module_functions,
|
||||
description = EXCLUDED.description,
|
||||
is_active = EXCLUDED.is_active,
|
||||
edit_by = EXCLUDED.edit_by,
|
||||
updated_at = EXCLUDED.updated_at;
|
||||
"""
|
||||
|
||||
cursor.execute(insert_sql, (today, today))
|
||||
conn.commit()
|
||||
|
||||
print("[OK] Dashboard 功能記錄插入成功")
|
||||
print(f" ID: 23")
|
||||
print(f" Code: dashboard")
|
||||
print(f" Name: 系統首頁")
|
||||
print(f" Module Functions: [Create, Read]")
|
||||
|
||||
# 驗證插入
|
||||
cursor.execute("SELECT id, code, name, module_functions FROM system_functions WHERE id = 23;")
|
||||
result = cursor.fetchone()
|
||||
|
||||
if result:
|
||||
print(f"\n[Verified] 記錄已確認存在:")
|
||||
print(f" ID: {result[0]}")
|
||||
print(f" Code: {result[1]}")
|
||||
print(f" Name: {result[2]}")
|
||||
print(f" Module Functions: {result[3]}")
|
||||
else:
|
||||
print("[WARNING] 記錄插入後查詢不到")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except psycopg2.Error as e:
|
||||
print(f"[ERROR] Database error: {e}")
|
||||
raise
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Unexpected error: {e}")
|
||||
raise
|
||||
|
||||
if __name__ == "__main__":
|
||||
insert_dashboard_function()
|
||||
Reference in New Issue
Block a user