Files
hr-portal/backend/scripts/README_ADD_DEPARTMENTS.md
Porsche Chen 360533393f 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>
2026-02-23 20:12:43 +08:00

75 lines
2.0 KiB
Markdown

# 新增/修正「部門資料維護」系統功能
## 功能說明
部門資料維護功能,支援樹狀組織架構管理。
## 執行步驟
### 檢查現況
先檢查 id=18 的記錄:
```sql
SELECT id, code, name FROM system_functions WHERE id = 18;
```
### 執行 SQL
執行 `add_departments_function.sql`:
```bash
# 方法一: psql (Linux/Mac)
PGPASSWORD=DC1qaz2wsx psql -h 10.1.0.20 -p 5433 -U admin -d hr_portal -f add_departments_function.sql
# 方法二: 手動執行 SQL
# 連線到資料庫後,執行 add_departments_function.sql 中的 SQL
```
腳本會自動判斷:
- 如果 id=18 存在且為 `tenant_departments`,會修正為 `departments`
- 如果 id=18 不存在,會新增記錄
### 確認結果
```sql
SELECT id, code, name, function_type, module_code, module_functions
FROM system_functions
WHERE code = 'departments';
```
應該顯示:
```
id | code | name | function_type | module_code | module_functions
---+-------------+--------------+---------------+-------------+--------------------
18 | departments | 部門資料維護 | 2 | departments | ["View","Create","Read","Update","Delete"]
```
## 功能配置
- **功能代碼**: departments
- **功能名稱**: 部門資料維護
- **功能類型**: FUNCTION (2)
- **上層功能**: 根層 (0) - 人資功能區
- **圖示**: 🏢
- **操作權限**: View, Create, Read, Update, Delete (完整 CRUD)
- **功能定位**: 人資資料維護功能 (is_mana = false)
## 前後端對應
- **前端路徑**: `/departments`
- **後端 API**:
- GET `/api/v1/departments` - 取得部門列表
- GET `/api/v1/departments/{id}` - 取得部門詳情
- POST `/api/v1/departments` - 新增部門
- PUT `/api/v1/departments/{id}` - 更新部門
- DELETE `/api/v1/departments/{id}` - 刪除部門
- GET `/api/v1/departments/tree` - 取得樹狀結構
## 特殊說明
部門採用樹狀結構:
- **第一層** (depth=0): 可設定 email_domain
- **子層** (depth>=1): 繼承上層的 email_domain
- 支援多層級組織架構