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>
83 lines
2.1 KiB
Python
83 lines
2.1 KiB
Python
"""
|
|
建立 tenant_employees 視圖
|
|
整合 tenant_emp_settings 和 tenant_emp_resumes 的資料
|
|
"""
|
|
import psycopg2
|
|
|
|
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("Creating tenant_employees view...")
|
|
|
|
# 先刪除舊的視圖 (如果存在)
|
|
cur.execute("DROP VIEW IF EXISTS tenant_employees CASCADE;")
|
|
|
|
# 建立視圖整合兩個表
|
|
cur.execute("""
|
|
CREATE VIEW tenant_employees AS
|
|
SELECT
|
|
s.id,
|
|
s.tenant_id,
|
|
s.seq_no,
|
|
s.tenant_emp_code AS employee_id,
|
|
s.tenant_keycloak_user_id AS keycloak_user_id,
|
|
r.english_name AS username_base,
|
|
r.legal_name,
|
|
r.english_name,
|
|
r.mobile AS phone,
|
|
r.mobile,
|
|
s.hire_at AS hire_date,
|
|
s.employment_status AS status,
|
|
s.is_active,
|
|
s.edit_by,
|
|
s.created_at,
|
|
s.updated_at
|
|
FROM tenant_emp_settings s
|
|
INNER JOIN tenant_emp_resumes r ON s.tenant_resume_id = r.id;
|
|
""")
|
|
|
|
conn.commit()
|
|
print("SUCCESS: tenant_employees view created")
|
|
|
|
# 驗證視圖
|
|
cur.execute("""
|
|
SELECT column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'tenant_employees'
|
|
ORDER BY ordinal_position;
|
|
""")
|
|
|
|
columns = cur.fetchall()
|
|
print("\nView structure:")
|
|
for col in columns:
|
|
print(f" {col[0]:<25} {col[1]}")
|
|
|
|
# 測試查詢
|
|
cur.execute("SELECT COUNT(*) FROM tenant_employees;")
|
|
count = cur.fetchone()[0]
|
|
print(f"\nTotal employees: {count}")
|
|
|
|
if count > 0:
|
|
cur.execute("SELECT employee_id, legal_name, english_name, status FROM tenant_employees LIMIT 3;")
|
|
employees = cur.fetchall()
|
|
print("\nSample data:")
|
|
for emp in employees:
|
|
print(f" {emp[0]:<15} {emp[1]:<20} {emp[2]:<20} {emp[3]}")
|
|
|
|
except Exception as e:
|
|
conn.rollback()
|
|
print(f"ERROR: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
finally:
|
|
cur.close()
|
|
conn.close()
|