From 863a4fd31f62b6e892b51f73bf0a4c5dac5ee41a Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Tue, 12 Aug 2025 09:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E8=AF=9D=E8=8E=B7=E5=AE=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/api/config/route.php | 5 + .../controller/CallRecordingController.php | 142 ++++++++++++++++++ .../api/model/CallRecordingModel.php | 11 ++ Server/application/command.php | 1 + .../command/CallRecordingListCommand.php | 57 +++++++ .../application/job/CallRecordingListJob.php | 123 +++++++++++++++ 6 files changed, 339 insertions(+) create mode 100644 Server/application/api/controller/CallRecordingController.php create mode 100644 Server/application/api/model/CallRecordingModel.php create mode 100644 Server/application/command/CallRecordingListCommand.php create mode 100644 Server/application/job/CallRecordingListJob.php diff --git a/Server/application/api/config/route.php b/Server/application/api/config/route.php index 79d3bc47..a71303e1 100644 --- a/Server/application/api/config/route.php +++ b/Server/application/api/config/route.php @@ -97,6 +97,11 @@ Route::group('v1', function () { Route::get('autoCreate', 'app\api\controller\AllotRuleController@autoCreateAllotRules');// 自动创建分配规则 √ }); + // CallRecording控制器路由 + Route::group('call-recording', function () { + Route::get('list', 'app\api\controller\CallRecordingController@getlist'); // 获取通话记录列表 √ + }); + }); }); \ No newline at end of file diff --git a/Server/application/api/controller/CallRecordingController.php b/Server/application/api/controller/CallRecordingController.php new file mode 100644 index 00000000..a8112611 --- /dev/null +++ b/Server/application/api/controller/CallRecordingController.php @@ -0,0 +1,142 @@ +request->header('authorization', $this->authorization)); + if (empty($authorization)) { + if ($isInner) { + return json_encode(['code' => 500, 'msg' => '缺少授权信息']); + } else { + return errorJson('缺少授权信息'); + } + } + + try { + // 构建请求参数 + $params = [ + 'keyword' => $keyword, + 'isCallOut' => $isCallOut, + 'secondMin' => $secondMin, + 'secondMax' => $secondMax, + 'departmentIds' => $departmentIds, + 'pageIndex' => $pageIndex, + 'pageSize' => $pageSize, + 'from' => $from, + 'to' => $to, + 'departmentId' => $departmentId + ]; + + // 设置请求头 + $headerData = ['client:system']; + $header = setHeader($headerData, $authorization, 'plain'); + + // 发送请求获取通话记录列表 + $result = requestCurl($this->baseUrl . 'api/CallRecording/list', $params, 'GET', $header); + $response = handleApiResponse($result); + + // 保存数据到数据库 + if (!empty($response['results'])) { + foreach ($response['results'] as $item) { + $this->saveCallRecording($item); + } + } + + if ($isInner) { + return json_encode(['code' => 200, 'msg' => '获取通话记录列表成功', 'data' => $response]); + } else { + return successJson($response, '获取通话记录列表成功'); + } + } catch (\Exception $e) { + if ($isInner) { + return json_encode(['code' => 500, 'msg' => '获取通话记录列表失败:' . $e->getMessage()]); + } else { + return errorJson('获取通话记录列表失败:' . $e->getMessage()); + } + } + } + + /** + * 保存通话记录数据到数据库 + * @param array $item 通话记录数据 + */ + private function saveCallRecording($item) + { + // 将时间戳转换为秒级时间戳(API返回的是毫秒级) + $beginTime = isset($item['beginTime']) ? intval($item['beginTime'] / 1000) : 0; + $endTime = isset($item['endTime']) ? intval($item['endTime'] / 1000) : 0; + $callBeginTime = isset($item['callBeginTime']) ? intval($item['callBeginTime'] / 1000) : 0; + + // 将日期时间字符串转换为时间戳 + $createTime = isset($item['createTime']) ? strtotime($item['createTime']) : 0; + $lastUpdateTime = isset($item['lastUpdateTime']) ? strtotime($item['lastUpdateTime']) : 0; + + $data = [ + 'id' => isset($item['id']) ? $item['id'] : 0, + 'tenantId' => isset($item['tenantId']) ? $item['tenantId'] : 0, + 'deviceOwnerId' => isset($item['deviceOwnerId']) ? $item['deviceOwnerId'] : 0, + 'userName' => isset($item['userName']) ? $item['userName'] : '', + 'nickname' => isset($item['nickname']) ? $item['nickname'] : '', + 'realName' => isset($item['realName']) ? $item['realName'] : '', + 'deviceMemo' => isset($item['deviceMemo']) ? $item['deviceMemo'] : '', + 'fileName' => isset($item['fileName']) ? $item['fileName'] : '', + 'imei' => isset($item['imei']) ? $item['imei'] : '', + 'phone' => isset($item['phone']) ? $item['phone'] : '', + 'isCallOut' => isset($item['isCallOut']) ? $item['isCallOut'] : false, + 'beginTime' => $beginTime, + 'endTime' => $endTime, + 'audioUrl' => isset($item['audioUrl']) ? $item['audioUrl'] : '', + 'mp3AudioUrl' => isset($item['mp3AudioUrl']) ? $item['mp3AudioUrl'] : '', + 'callBeginTime' => $callBeginTime, + 'callLogId' => isset($item['callLogId']) ? $item['callLogId'] : 0, + 'callType' => isset($item['callType']) ? $item['callType'] : 0, + 'duration' => isset($item['duration']) ? $item['duration'] : 0, + 'skipReason' => isset($item['skipReason']) ? $item['skipReason'] : '', + 'skipUpload' => isset($item['skipUpload']) ? $item['skipUpload'] : false, + 'isDeleted' => isset($item['isDeleted']) ? $item['isDeleted'] : false, + 'createTime' => $createTime, + 'lastUpdateTime' => $lastUpdateTime + ]; + + // 使用id作为唯一性判断 + $callRecording = CallRecordingModel::where('id', $item['id'])->find(); + if ($callRecording) { + $callRecording->save($data); + } else { + CallRecordingModel::create($data); + } + } +} \ No newline at end of file diff --git a/Server/application/api/model/CallRecordingModel.php b/Server/application/api/model/CallRecordingModel.php new file mode 100644 index 00000000..3c7c8e04 --- /dev/null +++ b/Server/application/api/model/CallRecordingModel.php @@ -0,0 +1,11 @@ + 'app\command\WorkbenchTrafficDistributeCommand', // 工作台流量分发任务 'workbench:groupPush' => 'app\command\WorkbenchGroupPushCommand', // 工作台群组同步任务 'switch:friends' => 'app\command\SwitchFriendsCommand', + 'call-recording:list' => 'app\command\CallRecordingListCommand', // 通话记录列表 √ ]; diff --git a/Server/application/command/CallRecordingListCommand.php b/Server/application/command/CallRecordingListCommand.php new file mode 100644 index 00000000..00770833 --- /dev/null +++ b/Server/application/command/CallRecordingListCommand.php @@ -0,0 +1,57 @@ +setName('call-recording:list') + ->setDescription('获取通话记录列表,并根据分页自动处理下一页'); + } + + protected function execute(Input $input, Output $output) + { + $output->writeln('开始处理通话记录列表任务...'); + + try { + // 初始页码 + $pageIndex = 0; + $pageSize = 100; // 每页获取100条记录 + + // 将第一页任务添加到队列 + $this->addToQueue($pageIndex, $pageSize); + + $output->writeln('通话记录列表任务已添加到队列'); + } catch (\Exception $e) { + Log::error('通话记录列表任务添加失败:' . $e->getMessage()); + $output->writeln('通话记录列表任务添加失败:' . $e->getMessage()); + return false; + } + + return true; + } + + /** + * 添加任务到队列 + * @param int $pageIndex 页码 + * @param int $pageSize 每页大小 + */ + protected function addToQueue($pageIndex, $pageSize) + { + $data = [ + 'pageIndex' => $pageIndex, + 'pageSize' => $pageSize + ]; + + // 添加到队列,设置任务名为 call_recording_list + Queue::push(CallRecordingListJob::class, $data, 'call_recording_list'); + } +} diff --git a/Server/application/job/CallRecordingListJob.php b/Server/application/job/CallRecordingListJob.php new file mode 100644 index 00000000..867afd60 --- /dev/null +++ b/Server/application/job/CallRecordingListJob.php @@ -0,0 +1,123 @@ +processCallRecordingList($data, $job->attempts())) { + $job->delete(); + Log::info('通话记录列表任务执行成功,页码:' . $data['pageIndex']); + } else { + if ($job->attempts() > 3) { + // 超过重试次数,删除任务 + Log::error('通话记录列表任务执行失败,已超过重试次数,页码:' . $data['pageIndex']); + $job->delete(); + } else { + // 任务失败,重新放回队列 + Log::warning('通话记录列表任务执行失败,重试次数:' . $job->attempts() . ',页码:' . $data['pageIndex']); + $job->release(Config::get('queue.failed_delay', 10)); + } + } + } catch (\Exception $e) { + // 出现异常,记录日志 + Log::error('通话记录列表任务异常:' . $e->getMessage()); + if ($job->attempts() > 3) { + $job->delete(); + } else { + $job->release(Config::get('queue.failed_delay', 10)); + } + } + } + + /** + * 处理通话记录列表获取 + * @param array $data 任务数据 + * @param int $attempts 重试次数 + * @return bool + */ + protected function processCallRecordingList($data, $attempts) + { + // 获取参数 + $pageIndex = isset($data['pageIndex']) ? $data['pageIndex'] : 0; + $pageSize = isset($data['pageSize']) ? $data['pageSize'] : 100; + + Log::info('开始获取通话记录列表,页码:' . $pageIndex . ',页大小:' . $pageSize); + + // 实例化控制器 + $callRecordingController = new CallRecordingController(); + + // 构建请求参数 + $params = [ + 'pageIndex' => $pageIndex, + 'pageSize' => $pageSize, + 'keyword' => '', + 'isCallOut' => '', + 'secondMin' => 0, + 'secondMax' => 99999, + 'departmentIds' => '', + 'from' => '2016-01-01 00:00:00', + 'to' => '2025-08-31 00:00:00', + 'departmentId' => '' + ]; + + // 设置请求信息 + $request = request(); + $request->withGet($params); + + // 调用通话记录列表获取方法 + $result = $callRecordingController->getlist($params, true); + $response = json_decode($result, true); + + + // 判断是否成功 + if ($response['code'] == 200) { + $data = $response['data']; + + // 判断是否有下一页 + if (!empty($data) && isset($data['results']) && count($data['results']) > 0) { + // 有下一页,将下一页任务添加到队列 + $nextPageIndex = $pageIndex + 1; + $this->addNextPageToQueue($nextPageIndex, $pageSize); + Log::info('添加下一页任务到队列,页码:' . $nextPageIndex); + } + + return true; + } else { + $errorMsg = isset($response['msg']) ? $response['msg'] : '未知错误'; + Log::error('获取通话记录列表失败:' . $errorMsg); + return false; + } + } + + /** + * 添加下一页任务到队列 + * @param int $pageIndex 页码 + * @param int $pageSize 每页大小 + */ + protected function addNextPageToQueue($pageIndex, $pageSize) + { + $data = [ + 'pageIndex' => $pageIndex, + 'pageSize' => $pageSize + ]; + + // 添加到队列,设置任务名为 call_recording_list + Queue::push(self::class, $data, 'call_recording_list'); + } +}