Update README.md to include comprehensive documentation for ThinkPHP 8, featuring installation instructions, new features, sponsorship details, and links to resources.
This commit is contained in:
66
app/controller/MatchController.php
Normal file
66
app/controller/MatchController.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user