request->param(); $position = $input['position'] ?? []; $resume = $input['resume'] ?? []; // 如果是JSON请求,尝试从JSON中获取 if (empty($position) && empty($resume)) { $jsonData = json_decode($this->request->getContent(), true); if (is_array($jsonData)) { $position = $jsonData['position'] ?? []; $resume = $jsonData['resume'] ?? []; } } // 参数验证 if (empty($position) || empty($resume)) { return json([ 'code' => 400, 'msg' => '参数错误:岗位信息和简历信息不能为空', 'data' => null ]); } // 计算匹配度 $matchService = new MatchService(); $score = $matchService->calculateMatchScore($position, $resume); return json([ 'code' => 200, 'msg' => '计算成功', 'data' => [ 'match_score' => $score ] ]); } catch (\Exception $e) { return json([ 'code' => 500, 'msg' => '计算失败:' . $e->getMessage(), 'data' => null ]); } } /** * 批量匹配查询(基于数据库) * @return Json */ public function batchMatch(): Json { try { // 获取请求参数 $input = $this->request->param(); $userId = $input['user_id'] ?? 0; // 如果是JSON请求,尝试从JSON中获取 if (empty($userId)) { $jsonData = json_decode($this->request->getContent(), true); if (is_array($jsonData)) { $userId = $jsonData['user_id'] ?? 0; } } // 参数验证 if (empty($userId) || !is_numeric($userId)) { return json([ 'code' => 400, 'msg' => '参数错误:user_id不能为空且必须为数字', 'data' => null ]); } // 分页参数 $page = (int)($input['page'] ?? $jsonData['page'] ?? 1); $pageSize = (int)($input['page_size'] ?? $jsonData['page_size'] ?? 20); $filterZero = (bool)($input['filter_zero'] ?? $jsonData['filter_zero'] ?? false); // 验证分页参数 if ($page < 1) $page = 1; if ($pageSize < 1 || $pageSize > 100) $pageSize = 20; // 限制每页最多100条 // 批量匹配查询 $matchService = new MatchService(); $result = $matchService->batchMatchFromDb((int)$userId, $page, $pageSize, $filterZero); return json([ 'code' => 200, 'msg' => '查询成功', 'data' => $result ]); } catch (\Exception $e) { return json([ 'code' => 500, 'msg' => '查询失败:' . $e->getMessage(), 'data' => null ]); } } }