backup: 完成 HR_position_ 表格前綴重命名與欄位對照表整理

變更內容:
- 所有資料表加上 HR_position_ 前綴
- 整理完整欄位顯示名稱與 ID 對照表
- 模組化 JS 檔案 (admin.js, ai.js, csv.js 等)
- 專案結構優化 (docs/, scripts/, tests/ 等)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-09 12:05:20 +08:00
parent a068ef9704
commit a6af297623
82 changed files with 8685 additions and 4933 deletions

View File

@@ -10,7 +10,7 @@ USE hr_position_system;
-- ============================================================
-- Table: positions (崗位基礎資料)
-- ============================================================
CREATE TABLE IF NOT EXISTS positions (
CREATE TABLE IF NOT EXISTS HR_position_positions (
id VARCHAR(20) PRIMARY KEY COMMENT '崗位編號',
position_code VARCHAR(20) NOT NULL UNIQUE COMMENT '崗位編號',
position_name VARCHAR(100) NOT NULL COMMENT '崗位名稱',
@@ -59,7 +59,7 @@ CREATE TABLE IF NOT EXISTS positions (
-- ============================================================
-- Table: jobs (職務基礎資料)
-- ============================================================
CREATE TABLE IF NOT EXISTS jobs (
CREATE TABLE IF NOT EXISTS HR_position_jobs (
id VARCHAR(20) PRIMARY KEY COMMENT '職務編號',
job_category_code VARCHAR(4) NOT NULL COMMENT '職務類別編號',
job_category_name VARCHAR(50) COMMENT '職務類別名稱',
@@ -88,7 +88,7 @@ CREATE TABLE IF NOT EXISTS jobs (
-- ============================================================
-- Table: job_descriptions (崗位描述)
-- ============================================================
CREATE TABLE IF NOT EXISTS job_descriptions (
CREATE TABLE IF NOT EXISTS HR_position_job_descriptions (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
emp_no VARCHAR(20) COMMENT '工號',
emp_name VARCHAR(50) COMMENT '姓名',
@@ -126,13 +126,13 @@ CREATE TABLE IF NOT EXISTS job_descriptions (
INDEX idx_emp_no (emp_no),
INDEX idx_position_code (position_code),
INDEX idx_version_date (version_date),
FOREIGN KEY (position_code) REFERENCES positions(position_code) ON DELETE SET NULL
FOREIGN KEY (position_code) REFERENCES HR_position_positions(position_code) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='崗位描述表';
-- ============================================================
-- Table: reference_codes (參照資料代碼表)
-- ============================================================
CREATE TABLE IF NOT EXISTS reference_codes (
CREATE TABLE IF NOT EXISTS HR_position_reference_codes (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
code_type VARCHAR(50) NOT NULL COMMENT '代碼類型',
code_value VARCHAR(10) NOT NULL COMMENT '代碼值',
@@ -152,7 +152,7 @@ CREATE TABLE IF NOT EXISTS reference_codes (
-- ============================================================
-- Table: audit_logs (審計日誌)
-- ============================================================
CREATE TABLE IF NOT EXISTS audit_logs (
CREATE TABLE IF NOT EXISTS HR_position_audit_logs (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
action VARCHAR(20) NOT NULL COMMENT '操作類型(CREATE/UPDATE/DELETE)',
entity_type VARCHAR(50) NOT NULL COMMENT '實體類型',
@@ -174,21 +174,21 @@ CREATE TABLE IF NOT EXISTS audit_logs (
-- ============================================================
-- 崗位類別 (Position Category)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('POSITION_CATEGORY', '01', '技術職', 1),
('POSITION_CATEGORY', '02', '管理職', 2),
('POSITION_CATEGORY', '03', '業務職', 3),
('POSITION_CATEGORY', '04', '行政職', 4);
-- 崗位性質 (Position Nature)
INSERT INTO reference_codes (code_type, code_value, code_name, code_name_en, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, code_name_en, sort_order) VALUES
('POSITION_NATURE', 'FT', '全職', 'Full-time', 1),
('POSITION_NATURE', 'PT', '兼職', 'Part-time', 2),
('POSITION_NATURE', 'CT', '約聘', 'Contract', 3),
('POSITION_NATURE', 'IN', '實習', 'Intern', 4);
-- 崗位級別 (Position Level)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('POSITION_LEVEL', 'L1', '基層員工', 1),
('POSITION_LEVEL', 'L2', '資深員工', 2),
('POSITION_LEVEL', 'L3', '主管', 3),
@@ -198,7 +198,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('POSITION_LEVEL', 'L7', '總經理', 7);
-- 職務類別 (Job Category)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('JOB_CATEGORY', 'MGR', '管理職', 1),
('JOB_CATEGORY', 'TECH', '技術職', 2),
('JOB_CATEGORY', 'SALE', '業務職', 3),
@@ -207,7 +207,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('JOB_CATEGORY', 'PROD', '生產職', 6);
-- 學歷 (Education)
INSERT INTO reference_codes (code_type, code_value, code_name, code_name_en, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, code_name_en, sort_order) VALUES
('EDUCATION', 'HS', '高中', 'High School', 1),
('EDUCATION', 'JC', '專科', 'Junior College', 2),
('EDUCATION', 'BA', '大學', 'Bachelor', 3),
@@ -215,7 +215,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, code_name_en, sor
('EDUCATION', 'PHD', '博士', 'PhD', 5);
-- 薪酬范圍 (Salary Range)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('SALARY_RANGE', 'A', 'A級', 1),
('SALARY_RANGE', 'B', 'B級', 2),
('SALARY_RANGE', 'C', 'C級', 3),
@@ -224,7 +224,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('SALARY_RANGE', 'N', '面議', 6);
-- 任職地點 (Work Location)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('WORK_LOCATION', 'HQ', '總部', 1),
('WORK_LOCATION', 'TPE', '台北辦公室', 2),
('WORK_LOCATION', 'TYC', '桃園廠區', 3),
@@ -233,7 +233,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('WORK_LOCATION', 'SZ', '深圳辦公室', 6);
-- 員工屬性 (Employee Attribute)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('EMP_ATTRIBUTE', 'FT', '正式員工', 1),
('EMP_ATTRIBUTE', 'CT', '約聘人員', 2),
('EMP_ATTRIBUTE', 'PT', '兼職人員', 3),
@@ -241,7 +241,7 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('EMP_ATTRIBUTE', 'DP', '派遣人員', 5);
-- 招聘職位 (Recruit Position)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('RECRUIT_POSITION', 'ENG', '工程師', 1),
('RECRUIT_POSITION', 'MGR', '經理', 2),
('RECRUIT_POSITION', 'AST', '助理', 3),
@@ -249,11 +249,93 @@ INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUE
('RECRUIT_POSITION', 'SAL', '業務', 5);
-- 職稱要求 (Title Requirement)
INSERT INTO reference_codes (code_type, code_value, code_name, sort_order) VALUES
INSERT INTO HR_position_reference_codes (code_type, code_value, code_name, sort_order) VALUES
('TITLE_REQ', 'NONE', '無要求', 1),
('TITLE_REQ', 'CERT', '需證書', 2),
('TITLE_REQ', 'LIC', '需執照', 3);
-- ============================================================
-- Table: business_units (事業體)
-- ============================================================
CREATE TABLE IF NOT EXISTS HR_position_business_units (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
business_code VARCHAR(20) NOT NULL UNIQUE COMMENT '事業體代碼',
business_name VARCHAR(100) NOT NULL COMMENT '事業體名稱',
sort_order INT DEFAULT 0 COMMENT '排序',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否啟用',
remark VARCHAR(500) COMMENT '備註',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間',
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間',
INDEX idx_business_name (business_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='事業體表';
-- ============================================================
-- Table: divisions (處級單位)
-- ============================================================
CREATE TABLE IF NOT EXISTS HR_position_divisions (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
division_code VARCHAR(20) NOT NULL UNIQUE COMMENT '處級單位代碼',
division_name VARCHAR(100) NOT NULL COMMENT '處級單位名稱',
business_id INT COMMENT '所屬事業體ID',
sort_order INT DEFAULT 0 COMMENT '排序',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否啟用',
remark VARCHAR(500) COMMENT '備註',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間',
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間',
INDEX idx_division_name (division_name),
INDEX idx_business_id (business_id),
FOREIGN KEY (business_id) REFERENCES HR_position_business_units(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='處級單位表';
-- ============================================================
-- Table: departments (部級單位)
-- ============================================================
CREATE TABLE IF NOT EXISTS HR_position_departments (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
department_code VARCHAR(20) NOT NULL UNIQUE COMMENT '部級單位代碼',
department_name VARCHAR(100) NOT NULL COMMENT '部級單位名稱',
division_id INT COMMENT '所屬處級單位ID',
sort_order INT DEFAULT 0 COMMENT '排序',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否啟用',
remark VARCHAR(500) COMMENT '備註',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間',
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間',
INDEX idx_department_name (department_name),
INDEX idx_division_id (division_id),
FOREIGN KEY (division_id) REFERENCES HR_position_divisions(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='部級單位表';
-- ============================================================
-- Table: organization_positions (組織崗位關聯)
-- ============================================================
CREATE TABLE IF NOT EXISTS HR_position_organization_positions (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主鍵',
business_id INT NOT NULL COMMENT '事業體ID',
division_id INT NOT NULL COMMENT '處級單位ID',
department_id INT NOT NULL COMMENT '部級單位ID',
position_title VARCHAR(100) NOT NULL COMMENT '崗位名稱',
sort_order INT DEFAULT 0 COMMENT '排序',
is_active BOOLEAN DEFAULT TRUE COMMENT '是否啟用',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間',
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時間',
INDEX idx_business_id (business_id),
INDEX idx_division_id (division_id),
INDEX idx_department_id (department_id),
INDEX idx_position_title (position_title),
UNIQUE KEY uk_org_position (business_id, division_id, department_id, position_title),
FOREIGN KEY (business_id) REFERENCES HR_position_business_units(id) ON DELETE CASCADE,
FOREIGN KEY (division_id) REFERENCES HR_position_divisions(id) ON DELETE CASCADE,
FOREIGN KEY (department_id) REFERENCES HR_position_departments(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='組織崗位關聯表';
-- ============================================================
-- End of Schema
-- ============================================================