This commit is contained in:
wangjinlei
2026-04-17 09:51:09 +08:00
parent e9a354c663
commit 4417a7ea28
5 changed files with 314 additions and 41 deletions

View File

@@ -589,7 +589,15 @@ class ExpertFinderService
* @param int $delay 延迟秒数防止打满模型默认1秒
* @return bool 是否成功推入了一条
*/
public function enqueueNextCountryFill($delay = 1)
/**
* 启动国家解析链:找到下一个缺国家的专家推入指定队列。
*
* @param int $delay 延迟秒数
* @param string $queue 队列名(不同队列跑不同 worker互不阻塞
* @param string $chatUrl 该链使用的模型地址(为空则用默认)
* @return bool
*/
public function enqueueNextCountryFill($delay = 1, $queue = 'FetchExperts', $chatUrl = '')
{
$row = Db::name('expert')
->where('affiliation', '<>', '')
@@ -600,19 +608,22 @@ class ExpertFinderService
->find();
if (!$row) {
$this->log('[CountryFill] no more pending experts');
$this->log('[CountryFill] no more pending experts, queue=' . $queue);
return false;
}
$data = [
'expert_id' => intval($row['expert_id']),
'affiliation' => trim((string)$row['affiliation']),
'queue' => $queue,
'chat_url' => $chatUrl,
];
$jobClass = 'app\api\job\FillExpertCountry@fire';
if ($delay > 0) {
Queue::later($delay, 'app\api\job\FillExpertCountry@fire', $data, 'FetchExpertCity');
Queue::later($delay, $jobClass, $data, $queue);
} else {
Queue::push('app\api\job\FillExpertCountry@fire', $data, 'FetchExpertCity');
Queue::push($jobClass, $data, $queue);
}
return true;
@@ -621,7 +632,7 @@ class ExpertFinderService
/**
* 对单个专家执行国家解析(同步),由队列 Job FillExpertCountry 调用,也可直接调用测试。
*/
public function fillExpertCountry($expertId, $affiliation)
public function fillExpertCountry($expertId, $affiliation, $chatUrl = '')
{
$affiliation = trim((string)$affiliation);
if ($affiliation === '') {
@@ -629,8 +640,11 @@ class ExpertFinderService
return;
}
$defaultUrl = trim((string)Env::get('expert_country_chat_url', Env::get('citation_chat_url', 'http://chat.taimed.cn/v1/chat/completions')));
$url = ($chatUrl !== '') ? $chatUrl : $defaultUrl;
$resolver = new CountryResolverService([
'chat_url' => trim((string)Env::get('expert_country_chat_url', Env::get('citation_chat_url', 'http://chat.taimed.cn/v1/chat/completions'))),
'chat_url' => $url,
'chat_model' => trim((string)Env::get('expert_country_chat_model', Env::get('citation_chat_model', 'gpt-4.1'))),
'api_key' => trim((string)Env::get('expert_country_chat_api_key', Env::get('citation_chat_api_key', ''))),
'timeout' => max(20, intval(Env::get('expert_country_chat_timeout', 60))),

View File

@@ -90,16 +90,23 @@ class PromotionService
$body = $logEntry['body_prepared'];
} else {
$journal = Db::name('journal')->where('journal_id', $task['journal_id'])->find();
$expert_fields = Db::name('expert_fields')->where('expert_id', $expert['expert_id'])->select();
$field_str = '';
foreach ($expert_fields as $field){
if($field_str != ''){
$field_str .= ','.$field['field_name'];
}else{
$field_str = $field['field_name'];
$expert_fields = Db::name('expert_field')
->where('expert_id', $expert['expert_id'])
->where('state', 0)
->select();
$fieldSet = [];
$representativeTitle = '';
foreach ($expert_fields as $ef) {
$fn = trim($ef['field']);
if ($fn !== '' && !in_array($fn, $fieldSet)) {
$fieldSet[] = $fn;
}
if ($representativeTitle === '' && !empty($ef['paper_title'])) {
$representativeTitle = trim($ef['paper_title']);
}
}
$expert['fields'] = $field_str;
$expert['fields'] = implode(',', $fieldSet);
$expert['representative_work_title'] = $representativeTitle;
$expertVars = $this->buildExpertVars($expert);
$journalVars = $this->buildJournalVars($journal);
$vars = array_merge($journalVars, $expertVars);
@@ -204,19 +211,27 @@ class PromotionService
]);
$failed++;
continue;
}else{
$expert_fields = Db::name('expert_field')->where('expert_id', $expert['expert_id'])->select();
$field_str = '';
foreach ($expert_fields as $field){
if($field_str != ''){
$field_str .= ','.$field['field'];
}else{
$field_str = $field['field'];
}
}
$expert['fields'] = $field_str;
}
$expert_fields = Db::name('expert_field')
->where('expert_id', $expert['expert_id'])
->where('state', 0)
->select();
$fieldSet = [];
$representativeTitle = '';
foreach ($expert_fields as $ef) {
$fn = trim($ef['field']);
if ($fn !== '' && !in_array($fn, $fieldSet)) {
$fieldSet[] = $fn;
}
if ($representativeTitle === '' && !empty($ef['paper_title'])) {
$representativeTitle = trim($ef['paper_title']);
}
}
$expert['fields'] = implode(',', $fieldSet);
$expert['representative_work_title'] = $representativeTitle;
$expertVars = $this->buildExpertVars($expert);
$vars = array_merge($journalVars, $expertVars);
$rendered = $this->renderFromTemplate(
@@ -477,11 +492,12 @@ class PromotionService
public function buildExpertVars($expert)
{
return [
'expert_title' => "Ph.D",
'expert_title' => "Ph.D",
'expert_name' => $expert['name'] ?? '',
'expert_email' => $expert['email'] ?? '',
'expert_affiliation' => $expert['affiliation'] ?? '',
'expert_field' => $expert['field'] ?? '',
'expert_field' => $expert['fields'] ?? ($expert['field'] ?? ''),
'representative_work_title' => $expert['representative_work_title'] ?? '',
];
}