新增批量

This commit is contained in:
杨志
2026-01-06 11:23:52 +08:00
parent e41dd33d23
commit cb7ad9a4b7
15 changed files with 1371 additions and 75 deletions

122
app/controller/Match.php Normal file
View File

@@ -0,0 +1,122 @@
<?php
declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\service\MatchService;
use think\response\Json;
/**
* 岗位简历匹配度控制器
*/
class MatchController extends BaseController
{
/**
* 计算岗位和简历的匹配度
* @return Json
*/
public function calculate(): Json
{
try {
// 获取请求参数支持JSON和表单数据
$input = $this->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
]);
}
}
}

View File

@@ -1,66 +0,0 @@
<?php
declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\service\MatchService;
use think\response\Json;
/**
* 岗位简历匹配度控制器
*/
class MatchController extends BaseController
{
/**
* 计算岗位和简历的匹配度
* @return Json
*/
public function calculate(): Json
{
try {
// 获取请求参数支持JSON和表单数据
$input = $this->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
]);
}
}
}