From 2d5ce87605a3ed2f510dcff79bc170a980eda2b6 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 16 Mar 2025 00:55:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81AI=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Report.php | 19 ++++++++++++++++ app/Tasks/BotReceiveMsgTask.php | 40 +++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/app/Models/Report.php b/app/Models/Report.php index 8c5f23951..458bfb998 100644 --- a/app/Models/Report.php +++ b/app/Models/Report.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Exceptions\ApiException; +use App\Module\Base; use Carbon\Carbon; use Carbon\Traits\Creator; use Illuminate\Database\Eloquent\Builder; @@ -95,6 +96,24 @@ class Report extends AbstractModel return $this->appendattrs['receives']; } + /** + * 获取汇报内容 + * @param $id + * @return self|null + */ + public static function idOrCodeToContent($id) + { + if (Base::isNumber($id)) { + return self::find($id); + } elseif ($id) { + $reportLink = ReportLink::whereCode($id)->first(); + if ($reportLink) { + return self::find($reportLink->rid); + } + } + return null; + } + /** * 获取单条记录 * @param $id diff --git a/app/Tasks/BotReceiveMsgTask.php b/app/Tasks/BotReceiveMsgTask.php index 5567e3674..df3dbe82a 100644 --- a/app/Tasks/BotReceiveMsgTask.php +++ b/app/Tasks/BotReceiveMsgTask.php @@ -5,6 +5,7 @@ namespace App\Tasks; use App\Models\FileContent; use App\Models\Project; use App\Models\ProjectTask; +use App\Models\Report; use App\Models\User; use App\Models\UserBot; use App\Models\UserDepartment; @@ -606,22 +607,37 @@ class BotReceiveMsgTask extends AbstractTask $original = str_replace($match[0][$index], "'{$taskName}' (see below for task_content tag)", $original); } } - if (preg_match_all("/]*?>(.*?)<\/a>/", $original, $match)) { - $filePaths = $match[1]; - foreach ($filePaths as $index => $filePath) { - if (preg_match("/single\/file\/(.*?)$/", $filePath, $fileMatch)) { - $fileName = addslashes($match[2][$index]); - $fileContent = "文件状态:不存在或已删除"; + if (preg_match_all("/]*?>[~%]([^>]*)<\/a>/", $original, $match)) { + $urlPaths = $match[2]; + foreach ($urlPaths as $index => $urlPath) { + $pathTag = null; + $pathName = null; + $pathContent = null; + if (preg_match("/single\/file\/(.*?)$/", $urlPath, $fileMatch)) { + $pathTag = "file_content"; + $pathName = addslashes($match[3][$index]); + $pathContent = "文件状态:不存在或已删除"; $fileInfo = FileContent::idOrCodeToContent($fileMatch[1]); if ($fileInfo && isset($fileInfo->content['url'])) { - $filePath = public_path($fileInfo->content['url']); - if (file_exists($filePath)) { - $fileName .= " (ID:{$fileInfo->id})"; - $fileContent = TextExtractor::getFileContent($filePath); + $urlPath = public_path($fileInfo->content['url']); + if (file_exists($urlPath)) { + $pathName .= " (ID:{$fileInfo->id})"; + $pathContent = TextExtractor::getFileContent($urlPath); } } - $aiContents[] = "\n{$fileContent}\n"; - $original = str_replace($match[0][$index], "'{$fileName}' (see below for file_content tag)", $original); + } elseif (preg_match("/single\/report\/detail\/(.*?)$/", $urlPath, $reportMatch)) { + $pathTag = "report_content"; + $pathName = addslashes($match[3][$index]); + $pathContent = "报告状态:不存在或已删除"; + $reportInfo = Report::idOrCodeToContent($reportMatch[1]); + if ($reportInfo) { + $pathName .= " (ID:{$reportInfo->id})"; + $pathContent = $reportInfo->content; + } + } + if ($pathTag) { + $aiContents[] = "<{$pathTag} path=\"{$pathName}\">\n{$pathContent}\n"; + $original = str_replace($match[0][$index], "'{$pathName}' (see below for {$pathTag} tag)", $original); } } }