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:
69
backend/insert_system_functions_data.py
Normal file
69
backend/insert_system_functions_data.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
插入 system_functions 預設資料
|
||||
"""
|
||||
import psycopg2
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
conn = psycopg2.connect(
|
||||
host="10.1.0.20",
|
||||
port=5433,
|
||||
database="hr_portal",
|
||||
user="admin",
|
||||
password="DC1qaz2wsx"
|
||||
)
|
||||
conn.autocommit = False
|
||||
cur = conn.cursor()
|
||||
|
||||
try:
|
||||
print("Inserting system_functions default data...")
|
||||
|
||||
# 預設資料
|
||||
data = [
|
||||
(10, 'system_managements', 0, '系統管理後台', 1, 100, '', '', [], '', True, True, 1),
|
||||
(11, 'system_settings', 10, '系統資料設定', 2, 10010, '', 'system_settings', ['View', 'Create', 'Read', 'Update', 'Delete'], '', True, True, 1),
|
||||
(12, 'system_codes', 10, '系統代碼設定', 2, 10020, '', 'system_codes', ['View', 'Create', 'Read', 'Update', 'Delete'], '', True, True, 1),
|
||||
(13, 'system_notifications', 10, '系統通知設定', 2, 10030, '', 'system_notifications', ['View', 'Create', 'Read', 'Update', 'Delete'], '', True, True, 1),
|
||||
(14, 'system_logs', 10, '系統紀錄查詢', 2, 10040, '', 'system_logs', ['View', 'Create', 'Read'], '', True, True, 1),
|
||||
(15, 'system_functions', 0, '系統功能設定', 2, 10050, '', 'system_functions', ['View', 'Create', 'Read', 'Update', 'Delete'], '', True, True, 1),
|
||||
(16, 'init_tenants', 0, '租戶初始資料建檔', 2, 10, '', 'init_tenants', ['View', 'Create', 'Read', 'Update', 'Delete'], '', True, True, 1),
|
||||
(17, 'tenant', 0, '公司資料維護', 2, 20, '', 'tenant', ['Read', 'Update'], '', False, True, 1),
|
||||
(18, 'tenant_departments', 0, '部門資料維護', 2, 30, '', 'tenant_departments', ['Create', 'Read', 'Update', 'Delete'], '', False, True, 1),
|
||||
(19, 'tenant_user_roles', 0, '角色設定作業', 2, 40, '', 'tenant_user_roles', ['Create', 'Read', 'Update', 'Delete'], '', False, True, 1),
|
||||
(20, 'tenant_role_rights', 0, '角色權限設定作業', 2, 50, '', 'tenant_role_rights', ['Create', 'Read', 'Update', 'Delete'], '', False, True, 1),
|
||||
(21, 'tenant_emp_resumes', 0, '人員履歷維護', 2, 60, '', 'tenant_emp_resumes', ['Create', 'Read', 'Update', 'Delete'], '', False, True, 1),
|
||||
(22, 'tenant_emp_settings', 0, '人員任用設定作業', 2, 70, '', 'tenant_emp_settings', ['Create', 'Read', 'Update', 'Delete'], '', False, True, 1),
|
||||
]
|
||||
|
||||
for row in data:
|
||||
(id, code, upper_function_id, name, function_type, order, function_icon,
|
||||
module_code, module_functions, description, is_mana, is_active, edit_by) = row
|
||||
|
||||
# 轉換 module_functions 為 JSON
|
||||
module_functions_json = json.dumps(module_functions)
|
||||
|
||||
cur.execute("""
|
||||
INSERT INTO system_functions
|
||||
(id, code, upper_function_id, name, function_type, "order", function_icon,
|
||||
module_code, module_functions, description, is_mana, is_active, edit_by, created_at, updated_at)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
""", (id, code, upper_function_id, name, function_type, order, function_icon,
|
||||
module_code if module_code else None, module_functions_json, description,
|
||||
is_mana, is_active, edit_by))
|
||||
|
||||
conn.commit()
|
||||
|
||||
# 驗證
|
||||
cur.execute("SELECT COUNT(*) FROM system_functions;")
|
||||
count = cur.fetchone()[0]
|
||||
print(f"[OK] Inserted {count} records into system_functions")
|
||||
|
||||
except Exception as e:
|
||||
conn.rollback()
|
||||
print(f"ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
cur.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user