参看文献再次更新

This commit is contained in:
wangjinlei
2026-07-15 13:18:53 +08:00
parent 296294d405
commit 6c43d9b994
3 changed files with 152 additions and 33 deletions

View File

@@ -7,7 +7,8 @@ use think\Env;
use think\Queue;
/**
* 参考文献分流处理:freshRefers 入口之后,按 journal / book / other 三路处理。
* 参考文献分流处理:按 journal / book / other 三路处理。
* 每条文献单独入 ReferenceDispatchQueue由 worker 并行消费。
*
* - journal有 DOI 入 ArticleReferDetailQueue无 DOI 保留原文
* - book填充结构化字段 author/title/joura/dateno/isbn与 Preaccept、References 约定一致)
@@ -24,9 +25,9 @@ class ReferenceDispatchService
}
/**
* 对某篇生产文章全部参考文献按类型分流处理
* 文章全部有效参考文献逐条入队分流HTTP 内只做 push立即返回
*/
public function dispatchRefersByType($pArticleId)
public function enqueueRefersByType($pArticleId)
{
$pArticleId = intval($pArticleId);
if ($pArticleId <= 0) {
@@ -43,43 +44,90 @@ class ReferenceDispatchService
return;
}
foreach ($refers as $refer) {
Queue::push(
'app\api\job\ReferenceDispatchQueue@fire',
$refer,
'ReferenceDispatchQueue'
);
}
}
/**
* 处理单条参考文献分流(由 ReferenceDispatchQueue 调用)
*/
public function dispatchReferByType($pReferId)
{
$pReferId = intval($pReferId);
if ($pReferId <= 0) {
return;
}
$refer = Db::name('production_article_refer')
->where('p_refer_id', $pReferId)
->where('state', 0)
->find();
if (empty($refer)) {
return;
}
$crossref = new CrossrefService([
'mailto' => trim((string)Env::get('crossref_mailto', '')),
]);
foreach ($refers as $refer) {
$summary = null;
$crossrefType = '';
if (trim((string)$refer['refer_doi']) !== '') {
$doiNorm = $this->normalizeDoi($refer['refer_doi']);
if ($doiNorm !== '') {
$summary = $crossref->fetchWorkSummary($doiNorm);
if ($summary && !empty($summary['raw']['type'])) {
$crossrefType = (string)$summary['raw']['type'];
}
$summary = null;
$crossrefType = '';
if (trim((string)$refer['refer_doi']) !== '') {
$doiNorm = $this->normalizeDoi($refer['refer_doi']);
if ($doiNorm !== '') {
$summary = $crossref->fetchWorkSummary($doiNorm);
if ($summary && !empty($summary['raw']['type'])) {
$crossrefType = (string)$summary['raw']['type'];
}
}
}
$typeInfo = $this->classifier->classify((string)$refer['refer_content'], $crossrefType);
$dispatchType = $this->classifier->normalizeDispatchType($typeInfo['type']);
$typeInfo = $this->classifier->classify((string)$refer['refer_content'], $crossrefType);
$dispatchType = $this->classifier->normalizeDispatchType($typeInfo['type']);
Db::name('production_article_refer')->where('p_refer_id', $refer['p_refer_id'])->update([
'refer_type' => $dispatchType,
'update_time' => time(),
]);
$refer['refer_type'] = $dispatchType;
Db::name('production_article_refer')->where('p_refer_id', $refer['p_refer_id'])->update([
'refer_type' => $dispatchType,
'update_time' => time(),
]);
$refer['refer_type'] = $dispatchType;
switch ($dispatchType) {
case ReferenceTypeClassifier::TYPE_BOOK:
$this->processBookRefer($refer, $summary, $crossref);
break;
case ReferenceTypeClassifier::TYPE_OTHER:
$this->processOtherRefer($refer);
break;
default:
$this->processJournalRefer($refer);
break;
}
switch ($dispatchType) {
case ReferenceTypeClassifier::TYPE_BOOK:
$this->processBookRefer($refer, $summary, $crossref);
break;
case ReferenceTypeClassifier::TYPE_OTHER:
$this->processOtherRefer($refer);
break;
default:
$this->processJournalRefer($refer);
break;
}
}
/**
* 同步处理整篇文章(仅供脚本/调试,勿在 HTTP 或单条队列任务中批量调用)
*/
public function dispatchRefersByType($pArticleId)
{
$pArticleId = intval($pArticleId);
if ($pArticleId <= 0) {
return;
}
$refers = Db::name('production_article_refer')
->where('p_article_id', $pArticleId)
->where('state', 0)
->order('index asc, p_refer_id asc')
->column('p_refer_id');
foreach ($refers as $pReferId) {
$this->dispatchReferByType($pReferId);
}
}