自动化审稿相关文件提交
This commit is contained in:
81
application/api/job/RecommendReviewer.php
Normal file
81
application/api/job/RecommendReviewer.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\Reviewer;
|
||||
class RecommendReviewer
|
||||
{
|
||||
// 推荐审稿人任务
|
||||
public function fire(Job $job, $data)
|
||||
{
|
||||
|
||||
//获取任务ID
|
||||
$iLogId = 0;
|
||||
try {
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
$sMsg = '获取推荐审稿人信息成功';
|
||||
if(!empty($job->getRawBody())){
|
||||
$aJob = json_decode($job->getRawBody(), true);
|
||||
$aParam = [
|
||||
'job_id' => empty($aJob['id']) ? '' : $aJob['id'],
|
||||
'job_class' => get_class($this),
|
||||
'status' => 0,
|
||||
'create_time' => time(),
|
||||
'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE)
|
||||
];
|
||||
$iLogId = $oQueueJob->addLog($aParam);
|
||||
// 步骤1:上传素材(图片)
|
||||
$iArticleId = empty($data['article_id']) ? 0 : $data['article_id'];
|
||||
if (!empty($iArticleId)) {
|
||||
|
||||
$aParam = ['article_id' => $iArticleId,'page' => 1,'size' => empty($data['size']) ? 5 : $data['size']];
|
||||
//获取推荐审稿人信息
|
||||
$oReviewer = new Reviewer;
|
||||
$aResult = json_decode($oReviewer->recommend($aParam),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '获取推荐审稿人信息失败' : $aResult['msg'];
|
||||
|
||||
//插入审稿人记录表
|
||||
$aResult = empty($aResult['data']['lists']) ? [] : $aResult['data']['lists'];
|
||||
if(empty($aResult)){
|
||||
$sMsg = 'No qualified reviewers were selected';
|
||||
}
|
||||
if(!empty($aResult)){
|
||||
$aParam = ['article_id' => $iArticleId,'reviewer_id' => array_column($aResult, 'reviewer_id')];
|
||||
$aResult = json_decode($oReviewer->add($aParam),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Reviewer data insertion failed' : $aResult['msg'];
|
||||
//发送邀请审稿人审稿邮件
|
||||
if($iStatus == 1){
|
||||
$aResult = json_decode($oReviewer->email($aParam),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? 'Reviewer data insertion failed' : $aResult['msg'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$job->delete();
|
||||
|
||||
//更新任务状态
|
||||
$aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
// // 记录日志
|
||||
// \think\Log::info("RecommendReviewer延迟任务执行成功: ".json_encode($data));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
//实例化
|
||||
$oQueueJob = new QueueJob;
|
||||
//更新任务状态
|
||||
$sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage();
|
||||
$aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg];
|
||||
$oQueueJob->updateLog($aParam);
|
||||
$job->delete();
|
||||
// // 记录错误日志
|
||||
// \think\Log::error("RecommendReviewer延迟任务失败: ".$e->getMessage());
|
||||
}finally {
|
||||
gc_collect_cycles(); // 强制垃圾回收
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user