作者堆叠 专刊

This commit is contained in:
wyn
2026-07-29 17:05:42 +08:00
parent f583f67e24
commit 1ee795b6b9
10 changed files with 2833 additions and 141 deletions

View File

@@ -246,6 +246,131 @@ class ReferenceReferAuthorService
return $result;
}
/**
* 单条参考文献:外网拉取作者并入库,再返回明细
* 有 DOI → Crossref + OpenAlex失败或无 DOI → 解析 refer.author
*
* @return array{
* p_article_id:int,
* p_refer_id:int,
* reference_no:int,
* doi:string,
* synced:int,
* refer:array|null,
* author_count:int,
* authors:array
* }
*/
public function fetchAuthorsByPReferId($pArticleId, $pReferId)
{
$pArticleId = intval($pArticleId);
$pReferId = intval($pReferId);
if ($pArticleId <= 0 || $pReferId <= 0) {
throw new \InvalidArgumentException('p_article_id and p_refer_id are required');
}
$refer = Db::name('production_article_refer')
->where('p_refer_id', $pReferId)
->where('p_article_id', $pArticleId)
->where('state', 0)
->find();
if (empty($refer)) {
return [
'p_article_id' => $pArticleId,
'p_refer_id' => $pReferId,
'reference_no' => 0,
'doi' => '',
'synced' => 0,
'refer' => null,
'author_count' => 0,
'authors' => [],
];
}
$refUtil = new ReferenceCheckService();
$doi = $refUtil->extractDoiFromRefer($refer);
$syncedCount = $this->syncOneRefer($pReferId, $pArticleId, $refer);
$result = $this->getAuthorsByPReferId($pArticleId, $pReferId);
$result['doi'] = $doi;
$result['synced'] = $syncedCount > 0 ? 1 : 0;
return $result;
}
/**
* 按 p_article_id + p_refer_id 读取作者明细(只读本地库)
*
* @return array{p_article_id:int,p_refer_id:int,reference_no:int,refer:array|null,author_count:int,authors:array}
*/
public function getAuthorsByPReferId($pArticleId, $pReferId)
{
$pArticleId = intval($pArticleId);
$pReferId = intval($pReferId);
if ($pArticleId <= 0 || $pReferId <= 0) {
throw new \InvalidArgumentException('p_article_id and p_refer_id are required');
}
$refer = Db::name('production_article_refer')
->field('p_refer_id,p_article_id,index,author,title,joura,refer_doi,doilink,refer_type')
->where('p_refer_id', $pReferId)
->where('p_article_id', $pArticleId)
->where('state', 0)
->find();
if (empty($refer)) {
return [
'p_article_id' => $pArticleId,
'p_refer_id' => $pReferId,
'reference_no' => 0,
'refer' => null,
'author_count' => 0,
'authors' => [],
];
}
$rows = Db::name('production_article_refer_author')
->where('p_article_id', $pArticleId)
->where('p_refer_id', $pReferId)
->order('author_seq asc, id asc')
->field('author_seq,author_position,is_first_author,family,given,display_name,citation_name,orcid,openalex_id,identity_source')
->select();
$authors = [];
foreach ($rows as $row) {
$authors[] = [
'author_seq' => intval($row['author_seq'] ?? 0),
'author_position' => (string)($row['author_position'] ?? ''),
'is_first_author' => intval($row['is_first_author'] ?? 0),
'family' => (string)($row['family'] ?? ''),
'given' => (string)($row['given'] ?? ''),
'display_name' => (string)($row['display_name'] ?? ''),
'citation_name' => (string)($row['citation_name'] ?? ''),
'orcid' => (string)($row['orcid'] ?? ''),
'openalex_id' => (string)($row['openalex_id'] ?? ''),
'identity_source' => (string)($row['identity_source'] ?? ''),
];
}
return [
'p_article_id' => $pArticleId,
'p_refer_id' => $pReferId,
'reference_no' => intval($refer['index']) + 1,
'refer' => [
'p_refer_id' => $pReferId,
'reference_no' => intval($refer['index']) + 1,
'author' => (string)($refer['author'] ?? ''),
'title' => (string)($refer['title'] ?? ''),
'joura' => (string)($refer['joura'] ?? ''),
'refer_doi' => (string)($refer['refer_doi'] ?? ''),
'doilink' => (string)($refer['doilink'] ?? ''),
'refer_type' => (string)($refer['refer_type'] ?? ''),
],
'author_count' => count($authors),
'authors' => $authors,
];
}
/**
* 读取已入库的作者身份(与 ReferenceAuthorIdentityService 结构兼容)
*