getPdo(); $chk = $pdo->prepare("SELECT COUNT(*) FROM persons WHERE id = ?"); $chk->execute([$personId]); if ((int)$chk->fetchColumn() === 0) { Response::error('人员不存在'); } $where = ['pwe.person_id = ?', 'pwe.is_active = 1']; $params = [$personId]; if (isset($_REQUEST['is_current']) && $_REQUEST['is_current'] !== '') { $where[] = 'pwe.is_current = ?'; $params[] = (int)$_REQUEST['is_current'] ? 1 : 0; } $whereSql = implode(' AND ', $where); $stmt = $pdo->prepare( "SELECT COUNT(*) FROM person_work_experiences pwe INNER JOIN companies c ON c.id = pwe.company_id WHERE $whereSql" ); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT pwe.id AS work_id, pwe.company_id, CASE WHEN c.name_zh IS NOT NULL AND c.name_zh <> '' THEN c.name_zh ELSE COALESCE(c.name_en, c.display_name) END AS company_name, c.industry, pwe.department, pwe.position, pwe.job_level, pwe.start_date, pwe.end_date, pwe.is_current FROM person_work_experiences pwe INNER JOIN companies c ON c.id = pwe.company_id WHERE $whereSql ORDER BY pwe.is_current DESC, pwe.start_date DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);