补全job文件
This commit is contained in:
@@ -183,11 +183,18 @@ class Plagiarism extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* 取在线查看 URL;过期则自动刷新
|
||||
* 取在线查看 URL(Turnitin 一次性会话链接,关闭报告页后勿复用旧 URL)
|
||||
*
|
||||
* 入参:
|
||||
* check_id 必填
|
||||
* editor_id 选填,当前打开报告的编辑 user_id(与 viewer_user_id 对应,避免 session 认证失败)
|
||||
* reuse 选填,1=在未过期时复用库内缓存;默认 0,每次调用重新向 Turnitin 申请
|
||||
*/
|
||||
public function getReportUrl()
|
||||
{
|
||||
$checkId = intval($this->request->param('check_id', 0));
|
||||
$editorId = intval($this->request->param('editor_id', 0));
|
||||
$reuse = intval($this->request->param('reuse', 0)) === 1;
|
||||
if ($checkId <= 0) {
|
||||
return jsonError('check_id required');
|
||||
}
|
||||
@@ -199,25 +206,37 @@ class Plagiarism extends Base
|
||||
if ($row['state'] != 3) {
|
||||
return jsonError('check not completed yet, state=' . $row['state']);
|
||||
}
|
||||
$needRefresh = empty($row['view_only_url'])
|
||||
$viewerContext = [];
|
||||
if ($editorId > 0) {
|
||||
$viewerContext['editor_id'] = $editorId;
|
||||
}
|
||||
$needRefresh = !$reuse
|
||||
|| empty($row['view_only_url'])
|
||||
|| intval($row['view_only_url_expire']) < time() + 60;
|
||||
|
||||
$usageHint = '每次打开请先调用本接口获取新链接;勿收藏或再次打开旧链接。请在新标签页打开,并允许 Turnitin 域名 Cookie。';
|
||||
|
||||
if ($needRefresh) {
|
||||
$svc = new PlagiarismService();
|
||||
$info = $svc->refreshViewerUrlFor($checkId);
|
||||
$info = $svc->refreshViewerUrlFor($checkId, $viewerContext);
|
||||
if ($info['url'] === '') {
|
||||
return jsonError('Turnitin returned empty viewer_url');
|
||||
}
|
||||
return jsonSuccess([
|
||||
'view_only_url' => $info['url'],
|
||||
'expire' => $info['expire'],
|
||||
'has_pdf' => !empty($info['local_pdf']),
|
||||
'view_only_url' => $info['url'],
|
||||
'expire' => $info['expire'],
|
||||
'has_pdf' => !empty($info['local_pdf']),
|
||||
'viewer_user_id' => $info['viewer_user_id'],
|
||||
'refreshed' => true,
|
||||
'usage_hint' => $usageHint,
|
||||
]);
|
||||
}
|
||||
return jsonSuccess([
|
||||
'view_only_url' => $row['view_only_url'],
|
||||
'expire' => intval($row['view_only_url_expire']),
|
||||
'has_pdf' => !empty($row['pdf_local_path']),
|
||||
'view_only_url' => $row['view_only_url'],
|
||||
'expire' => intval($row['view_only_url_expire']),
|
||||
'has_pdf' => !empty($row['pdf_local_path']),
|
||||
'refreshed' => false,
|
||||
'usage_hint' => $usageHint,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
if (!empty($row['pdf_local_path'])) {
|
||||
|
||||
85
application/api/job/AiCheckReferByDoi.php
Normal file
85
application/api/job/AiCheckReferByDoi.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use think\Db;
|
||||
class AiCheckReferByDoi
|
||||
{
|
||||
private $oQueueJob;
|
||||
private $QueueRedis;
|
||||
private $completedExprie = 3600;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob;
|
||||
$this->QueueRedis = QueueRedis::getInstance();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
//任务开始判断
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
// 获取 Redis 任务的原始数据
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
|
||||
// 获取生产文章ID
|
||||
$iPArticleId = empty($data['p_article_id']) ? 0 : $data['p_article_id'];
|
||||
if (empty($iPArticleId)) {
|
||||
$this->oQueueJob->log("无效的p_article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
// 获取参考文献ID
|
||||
$iPReferId = empty($data['p_refer_id']) ? 0 : $data['p_refer_id'];
|
||||
if (empty($iPArticleId)) {
|
||||
$this->oQueueJob->log("无效的p_article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
// 生成Redis键并尝试获取锁
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$iPArticleId}:{$iPReferId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return; // 未获取到锁,已处理
|
||||
}
|
||||
|
||||
//生成内容
|
||||
$oProductionArticleRefer = new \app\api\controller\References;
|
||||
$response = $oProductionArticleRefer->getCheckByAiResult($data);
|
||||
// 验证API响应
|
||||
if (empty($response)) {
|
||||
throw new \RuntimeException("OpenAI API返回空结果");
|
||||
}
|
||||
// 检查JSON解析错误
|
||||
$aResult = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException("解析OpenAI响应失败: " . json_last_error_msg() . " | 原始响应: {$response}");
|
||||
}
|
||||
$sMsg = empty($aResult['msg']) ? 'success' : $aResult['msg'];
|
||||
//更新完成标识
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie,$sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | 执行日志:{$sMsg}");
|
||||
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\LogicException $e) {
|
||||
$this->oQueueJob->handleNonRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
92
application/api/job/ArticleReferDetailQueue.php
Normal file
92
application/api/job/ArticleReferDetailQueue.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use app\common\ProductionArticleRefer;
|
||||
use think\Db;
|
||||
class ArticleReferDetailQueue
|
||||
{
|
||||
private $oQueueJob;
|
||||
private $QueueRedis;
|
||||
private $completedExprie = 3600;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob;
|
||||
$this->QueueRedis = QueueRedis::getInstance();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
//任务开始判断
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
// 获取 Redis 任务的原始数据
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
// // 获取文章ID
|
||||
// $iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
// if (empty($iArticleId)) {
|
||||
// $this->oQueueJob->log("无效的article_id,删除任务");
|
||||
// $job->delete();
|
||||
// return;
|
||||
// }
|
||||
// 获取生产文章ID
|
||||
$iPArticleId = empty($data['p_article_id']) ? 0 : $data['p_article_id'];
|
||||
if (empty($iPArticleId)) {
|
||||
$this->oQueueJob->log("无效的p_article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
// 获取生产文章ID
|
||||
$iPReferId = empty($data['p_refer_id']) ? 0 : $data['p_refer_id'];
|
||||
if (empty($iPReferId)) {
|
||||
$this->oQueueJob->log("无效的p_refer_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
// 生成Redis键并尝试获取锁
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$iPArticleId}:{$iPReferId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return; // 未获取到锁,已处理
|
||||
}
|
||||
|
||||
//生成内容
|
||||
$oProductionArticleRefer = new ProductionArticleRefer;
|
||||
$response = $oProductionArticleRefer->get($data);
|
||||
// 验证API响应
|
||||
if (empty($response)) {
|
||||
throw new \RuntimeException("返回空结果");
|
||||
}
|
||||
// 检查JSON解析错误
|
||||
$aResult = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException("解析响应失败: " . json_last_error_msg() . " | 原始响应: {$response}");
|
||||
}
|
||||
$sMsg = empty($aResult['msg']) ? 'success' : $aResult['msg'];
|
||||
//更新完成标识
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie,$sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | 执行日志:{$sMsg}");
|
||||
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\LogicException $e) {
|
||||
$this->oQueueJob->handleNonRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
85
application/api/job/ArticleReferQueue.php
Normal file
85
application/api/job/ArticleReferQueue.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use app\common\ProductionArticleRefer;
|
||||
use think\Db;
|
||||
class ArticleReferQueue
|
||||
{
|
||||
private $oQueueJob;
|
||||
private $QueueRedis;
|
||||
private $completedExprie = 180;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob;
|
||||
$this->QueueRedis = QueueRedis::getInstance();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
//任务开始判断
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
// 获取 Redis 任务的原始数据
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
// 获取文章ID
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
if (empty($iArticleId)) {
|
||||
$this->oQueueJob->log("无效的article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
// 获取生产文章ID
|
||||
$iPArticleId = empty($data['p_article_id']) ? 0 : $data['p_article_id'];
|
||||
if (empty($iPArticleId)) {
|
||||
$this->oQueueJob->log("无效的p_article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
|
||||
// 生成Redis键并尝试获取锁
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$iArticleId}:{$iPArticleId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return; // 未获取到锁,已处理
|
||||
}
|
||||
|
||||
//生成内容
|
||||
$oProductionArticleRefer = new ProductionArticleRefer;
|
||||
$response = $oProductionArticleRefer->top($data);
|
||||
// 验证API响应
|
||||
if (empty($response)) {
|
||||
throw new \RuntimeException("OpenAI API返回空结果");
|
||||
}
|
||||
// 检查JSON解析错误
|
||||
$aResult = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException("解析OpenAI响应失败: " . json_last_error_msg() . " | 原始响应: {$response}");
|
||||
}
|
||||
$sMsg = empty($aResult['msg']) ? 'success' : $aResult['msg'];
|
||||
//更新完成标识
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie,$sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | 执行日志:{$sMsg}");
|
||||
|
||||
} catch (\RuntimeException $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\LogicException $e) {
|
||||
$this->oQueueJob->handleNonRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
101
application/api/job/ReminderEmailToReviewer.php
Normal file
101
application/api/job/ReminderEmailToReviewer.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use app\api\controller\Cronreview;
|
||||
class ReminderEmailToReviewer
|
||||
{
|
||||
//审稿邮件提醒
|
||||
private $oQueueJob;
|
||||
private $QueueRedis;
|
||||
private $completedExprie = 3600; // 完成状态过期时间
|
||||
public function __construct()
|
||||
{
|
||||
$this->oQueueJob = new QueueJob;
|
||||
$this->QueueRedis = QueueRedis::getInstance();
|
||||
}
|
||||
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
//任务开始判断
|
||||
$this->oQueueJob->init($job);
|
||||
|
||||
// 获取 Redis 任务的原始数据
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
try {
|
||||
|
||||
// 验证任务数据完整性
|
||||
// 获取文章ID
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
//审稿记录表主键ID
|
||||
$art_rev_id = empty($data['art_rev_id']) ? 0 : $data['art_rev_id'];
|
||||
//审稿人ID
|
||||
$reviewer_id = empty($data['reviewer_id']) ? 0 : $data['reviewer_id'];
|
||||
//邮件类型
|
||||
$email_type = empty($data['email_type']) ? 0 : $data['email_type'];
|
||||
if (empty($iArticleId)) {
|
||||
$this->oQueueJob->log("无效的article_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
if (empty($art_rev_id)) {
|
||||
$this->oQueueJob->log("无效的art_rev_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
if (empty($reviewer_id)) {
|
||||
$this->oQueueJob->log("无效的reviewer_id,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
if (empty($email_type)) {
|
||||
$this->oQueueJob->log("无效的email_type,删除任务");
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
// 生成唯一任务标识
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$iArticleId}:{$reviewer_id}:{$art_rev_id}:{$email_type}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return; // 未获取到锁,已处理
|
||||
}
|
||||
|
||||
// 执行核心任务
|
||||
//查询是否发送过邮件
|
||||
$oCronreview = new Cronreview;
|
||||
$response = $oCronreview->reminder($data);
|
||||
// 验证API响应
|
||||
if (empty($response)) {
|
||||
throw new \RuntimeException("OpenAI API返回空结果");
|
||||
}
|
||||
// 检查JSON解析错误
|
||||
$aResult = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \RuntimeException("解析OpenAI响应失败: " . json_last_error_msg() . " | 原始响应: {$response}");
|
||||
}
|
||||
$sMsg = empty($aResult['msg']) ? 'success' : $aResult['msg'];
|
||||
//更新完成标识
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie,$sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey} | 执行日志:{$sMsg}");
|
||||
|
||||
} catch (RuntimeException $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (LogicException $e) {
|
||||
$this->oQueueJob->handleNonRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} catch (Exception $e) {
|
||||
$this->oQueueJob->handleRetryableException($e,$sRedisKey,$sRedisValue, $job);
|
||||
} finally {
|
||||
$this->oQueueJob->finnal();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user