已经完成一个文章校对了,但换个文章id就报错了,排查前备份
This commit is contained in:
@@ -6641,8 +6641,9 @@ class Article extends Base
|
||||
}
|
||||
}
|
||||
public function checkOne(){
|
||||
$articleId = intval($this->request->param('article_id', 7414));
|
||||
$svc = new ReferenceCheckService();
|
||||
$svc->checkOne();
|
||||
return jsonSuccess($svc->enqueueSecondPassByArticle($articleId));
|
||||
}
|
||||
public function referenceCheckEnqueueArticleMain(){
|
||||
$amId = 127448;
|
||||
@@ -6792,7 +6793,7 @@ class Article extends Base
|
||||
$citeStart = intval(isset($row['cite_tag_start']) ? $row['cite_tag_start'] : 0);
|
||||
$rowStatus = intval($row['status']);
|
||||
return array(
|
||||
'check_id' => intval($row['check_id']),
|
||||
'check_id' => intval(isset($row['id']) ? $row['id'] : (isset($row['check_id']) ? $row['check_id'] : 0)),
|
||||
'article_id' => intval(isset($row['article_id']) ? $row['article_id'] : 0),
|
||||
'am_id' => $amId,
|
||||
'cite_group_key' => $amId . '_' . $citeStart,
|
||||
@@ -6806,7 +6807,8 @@ class Article extends Base
|
||||
'text_end' => intval(isset($row['text_end']) ? $row['text_end'] : 0),
|
||||
'status' => isset($statusMap[$rowStatus]) ? $statusMap[$rowStatus] : 'unknown',
|
||||
'is_match' => intval($row['is_match']),
|
||||
'is_reasonable' => intval($row['is_match']) === 1,
|
||||
'can_support' => intval(isset($row['can_support']) ? $row['can_support'] : $row['is_match']),
|
||||
'is_reasonable' => intval(isset($row['can_support']) ? $row['can_support'] : $row['is_match']) === 1,
|
||||
'confidence' => floatval($row['confidence']),
|
||||
'reason' => isset($row['reason']) ? $row['reason'] : '',
|
||||
'error_msg' => isset($row['error_msg']) ? $row['error_msg'] : '',
|
||||
|
||||
@@ -36,6 +36,9 @@ class ReferenceCheck
|
||||
|
||||
try {
|
||||
$checkId = intval(isset($data['check_id']) ? $data['check_id'] : 0);
|
||||
if ($checkId <= 0 && !empty($jobData['data']['check_id'])) {
|
||||
$checkId = intval($jobData['data']['check_id']);
|
||||
}
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job:{$sClassName}:{$checkId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
@@ -61,45 +64,47 @@ class ReferenceCheck
|
||||
}
|
||||
|
||||
try {
|
||||
$mainInfo = Db::name('article_main')->where('am_id', $row['am_id'])->find();
|
||||
$contentA = trim($mainInfo['content']);//trim((string)(isset($row['origin_text']) ? $row['origin_text'] : ''));
|
||||
if ($contentA === '' && !empty($row['content_a'])) {
|
||||
$contentA = trim((string)$row['content_a']);
|
||||
}
|
||||
$contentB = trim((string)(isset($row['refer_text']) ? $row['refer_text'] : ''));
|
||||
$svc = new ReferenceCheckService();
|
||||
|
||||
if ($contentB === '' && intval($row['p_refer_id']) > 0) {
|
||||
$contentA = $svc->resolveMainContentForJob($row);
|
||||
$contentB = trim((string)(isset($row['refer_text']) ? $row['refer_text'] : ''));
|
||||
$refer = null;
|
||||
|
||||
if (intval($row['p_refer_id']) > 0) {
|
||||
$refer = Db::name('production_article_refer')
|
||||
->where('p_refer_id', intval($row['p_refer_id']))
|
||||
->where('status', 0)
|
||||
->where('state', 0)
|
||||
->find();
|
||||
if ($refer) {
|
||||
$contentB = (new ReferenceCheckService())->formatReferForLlm($refer);
|
||||
if ($refer && $contentB === '') {
|
||||
$contentB = $svc->formatReferForLlm($refer);
|
||||
}
|
||||
}
|
||||
|
||||
if ($contentA === '' || $contentB === '') {
|
||||
$this->markFailed($checkId, 'Missing content_a or reference text');
|
||||
$this->markFailed($checkId, 'Missing article_main.content or refer_text');
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$llm = new LLMService();
|
||||
$llmResult = $llm->checkReference($contentA, $contentB);
|
||||
$isMatch = !empty($llmResult['is_match']);
|
||||
$llmResult = $llm->checkReference($contentA, $contentB, false);
|
||||
$canSupport = $svc->parseLlmCanSupport($llmResult);
|
||||
$confidence = floatval($llmResult['confidence']);
|
||||
|
||||
Db::name('article_reference_check_result')->where('id', $checkId)->update([
|
||||
'is_match' => $isMatch ? 1 : 0,
|
||||
'confidence' => $llmResult['confidence'],
|
||||
'reason' => $llmResult['reason'],
|
||||
$svc->updateCheckResult($checkId, [
|
||||
'can_support' => $canSupport ? 1 : 0,
|
||||
'is_match' => $canSupport ? 1 : 0,
|
||||
'confidence' => $confidence,
|
||||
'reason' => isset($llmResult['reason']) ? $llmResult['reason'] : '',
|
||||
'status' => 1,
|
||||
'error_msg' => '',
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
|
||||
$svc->maybeEnqueueSecondPass($checkId, $confidence);
|
||||
|
||||
$amId = intval(isset($row['am_id']) ? $row['am_id'] : 0);
|
||||
if ($amId > 0) {
|
||||
(new ReferenceCheckService())->syncAmRefCheckStatus($amId);
|
||||
$svc->syncAmRefCheckStatus($amId);
|
||||
}
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie, $sRedisValue);
|
||||
$job->delete();
|
||||
@@ -127,11 +132,14 @@ class ReferenceCheck
|
||||
private function markFailed($checkId, $msg)
|
||||
{
|
||||
$row = Db::name('article_reference_check_result')->where('id', $checkId)->find();
|
||||
Db::name('article_reference_check_result')->where('id', $checkId)->update([
|
||||
'status' => 2,
|
||||
'error_msg' => mb_substr($msg, 0, 500),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
try {
|
||||
(new ReferenceCheckService())->updateCheckResult($checkId, [
|
||||
'status' => 2,
|
||||
'error_msg' => $msg,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\think\Log::error('ReferenceCheck markFailed: ' . $e->getMessage());
|
||||
}
|
||||
$amId = empty($row) ? 0 : intval(isset($row['am_id']) ? $row['am_id'] : 0);
|
||||
if ($amId > 0) {
|
||||
(new ReferenceCheckService())->syncAmRefCheckStatus($amId);
|
||||
|
||||
150
application/api/job/ReferenceCheckTwo.php
Normal file
150
application/api/job/ReferenceCheckTwo.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
namespace app\api\job;
|
||||
|
||||
use think\Db;
|
||||
use think\queue\Job;
|
||||
use app\common\QueueJob;
|
||||
use app\common\QueueRedis;
|
||||
use app\common\ReferenceCheckService;
|
||||
use app\common\service\LLMService;
|
||||
|
||||
class ReferenceCheckTwo
|
||||
{
|
||||
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);
|
||||
|
||||
$rawBody = empty($job->getRawBody()) ? '' : $job->getRawBody();
|
||||
$jobData = empty($rawBody) ? [] : json_decode($rawBody, true);
|
||||
$jobId = empty($jobData['id']) ? 'unknown' : $jobData['id'];
|
||||
|
||||
$sRedisKey = '';
|
||||
$sRedisValue = '';
|
||||
|
||||
$this->oQueueJob->log("-----------队列任务开始-----------");
|
||||
$this->oQueueJob->log("当前任务ID: {$jobId}, 尝试次数: {$job->attempts()}");
|
||||
|
||||
try {
|
||||
$checkId = intval(isset($data['check_id']) ? $data['check_id'] : 0);
|
||||
if ($checkId <= 0 && !empty($jobData['data']['check_id'])) {
|
||||
$checkId = intval($jobData['data']['check_id']);
|
||||
}
|
||||
$sClassName = get_class($this);
|
||||
$sRedisKey = "queue_job_two:{$sClassName}:{$checkId}";
|
||||
$sRedisValue = uniqid() . '_' . getmypid();
|
||||
|
||||
if (!$this->oQueueJob->acquireLock($sRedisKey, $sRedisValue, $job)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($checkId <= 0) {
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
$row = Db::name('article_reference_check_result')->where('id', $checkId)->find();
|
||||
if (empty($row)) {
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
|
||||
// if (intval($row['status']) === 1) {
|
||||
// $job->delete();
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
$svc = new ReferenceCheckService();
|
||||
|
||||
$contentA = $svc->resolveMainContentForJob($row);
|
||||
$referText = trim((string)(isset($row['refer_text']) ? $row['refer_text'] : ''));
|
||||
$refer = null;
|
||||
|
||||
if (intval($row['p_refer_id']) > 0) {
|
||||
$refer = Db::name('production_article_refer')
|
||||
->where('p_refer_id', intval($row['p_refer_id']))
|
||||
->where('state', 0)
|
||||
->find();
|
||||
}
|
||||
|
||||
$payload = $svc->prepareRecheckPayload(is_array($refer) ? $refer : [], $referText);
|
||||
$doiBlock = $payload['doi_block'];
|
||||
|
||||
if ($contentA === '' || $referText === '') {
|
||||
$this->markFailed($checkId, 'Missing article_main.content or refer_text');
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
$llm = new LLMService();
|
||||
$llmResult = $llm->checkReference($contentA, $referText, true, $doiBlock);
|
||||
|
||||
$canSupport = $svc->parseLlmCanSupport($llmResult);
|
||||
$tag = $payload['has_abstract']
|
||||
? ('[Crossref复核' . ($payload['doi_used'] !== '' ? ' ' . $payload['doi_used'] : '') . ']')
|
||||
: '[Crossref复核-无摘要]';
|
||||
$reason = $tag . ' ' . (isset($llmResult['reason']) ? $llmResult['reason'] : '');
|
||||
|
||||
$affected = $svc->updateCheckResult($checkId, [
|
||||
'can_support' => $canSupport ? 1 : 0,
|
||||
'is_match' => $canSupport ? 1 : 0,
|
||||
'confidence' => floatval($llmResult['confidence']),
|
||||
'reason' => $reason,
|
||||
'status' => 1,
|
||||
'error_msg' => '',
|
||||
]);
|
||||
$this->oQueueJob->log("Crossref复核写入 id={$checkId} affected={$affected} can_support=" . ($canSupport ? 1 : 0) . " confidence=" . floatval($llmResult['confidence']));
|
||||
|
||||
$amId = intval(isset($row['am_id']) ? $row['am_id'] : 0);
|
||||
if ($amId > 0) {
|
||||
$svc->syncAmRefCheckStatus($amId);
|
||||
}
|
||||
$this->QueueRedis->finishJob($sRedisKey, 'completed', $this->completedExprie, $sRedisValue);
|
||||
$job->delete();
|
||||
$this->oQueueJob->log("任务执行成功 | 日志ID: {$sRedisKey}");
|
||||
} catch (\Exception $e) {
|
||||
$this->oQueueJob->log('ReferenceCheckTwo error: ' . $e->getMessage());
|
||||
if ($job->attempts() >= 3) {
|
||||
$this->markFailed($checkId, $e->getMessage());
|
||||
$job->delete();
|
||||
return;
|
||||
}
|
||||
$job->release(30);
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
private function markFailed($checkId, $msg)
|
||||
{
|
||||
$row = Db::name('article_reference_check_result')->where('id', $checkId)->find();
|
||||
try {
|
||||
(new ReferenceCheckService())->updateCheckResult($checkId, [
|
||||
'status' => 2,
|
||||
'error_msg' => $msg,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\think\Log::error('ReferenceCheckTwo markFailed: ' . $e->getMessage());
|
||||
}
|
||||
$amId = empty($row) ? 0 : intval(isset($row['am_id']) ? $row['am_id'] : 0);
|
||||
if ($amId > 0) {
|
||||
(new ReferenceCheckService())->syncAmRefCheckStatus($amId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user