This commit is contained in:
wangjinlei
2026-04-16 16:16:08 +08:00
parent 87d815dc17
commit e9a354c663
3 changed files with 27 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ namespace app\api\controller;
use think\Cache; use think\Cache;
use think\Db; use think\Db;
use think\Queue;
use think\Validate; use think\Validate;
use app\common\ExpertFinderService; use app\common\ExpertFinderService;
@@ -65,6 +66,15 @@ class ExpertFinder extends Base
if(!$rule->check($data)){ if(!$rule->check($data)){
return jsonError($rule->getError()); return jsonError($rule->getError());
} }
$data1 = [
'expert_id' => intval($data['expert_id']),
'affiliation' => trim((string)$data['aff']),
];
// Queue::push('app\api\job\FillExpertCountry@fire', $data1, 'FetchExpertCity');
$service = new ExpertFinderService(); $service = new ExpertFinderService();
$service->fillExpertCountry($data['expert_id'], $data['aff']); $service->fillExpertCountry($data['expert_id'], $data['aff']);
$expert = Db::name('expert')->where('expert_id', intval($data['expert_id']))->find(); $expert = Db::name('expert')->where('expert_id', intval($data['expert_id']))->find();
@@ -85,11 +95,7 @@ class ExpertFinder extends Base
$pending = Db::name('expert') $pending = Db::name('expert')
->where('affiliation', '<>', '') ->where('affiliation', '<>', '')
->where(function ($q) { ->where('country_id', 0)
$q->where('country_id', 0)
->whereOr('country_id', 'null')
->whereOr('country', '');
})
->where('state', '<>', 5) ->where('state', '<>', 5)
->count(); ->count();

View File

@@ -16,6 +16,9 @@ class FillExpertCountry
{ {
public function fire(Job $job, $data) public function fire(Job $job, $data)
{ {
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0); $expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
$affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : ''; $affiliation = isset($data['affiliation']) ? trim((string)$data['affiliation']) : '';

View File

@@ -593,11 +593,7 @@ class ExpertFinderService
{ {
$row = Db::name('expert') $row = Db::name('expert')
->where('affiliation', '<>', '') ->where('affiliation', '<>', '')
->where(function ($q) { ->where('country_id', 0)
$q->where('country_id', 0)
->whereOr('country_id', 'null')
->whereOr('country', '');
})
->where('state', '<>', 5) ->where('state', '<>', 5)
->field('expert_id, affiliation') ->field('expert_id, affiliation')
->order('expert_id asc') ->order('expert_id asc')
@@ -614,9 +610,9 @@ class ExpertFinderService
]; ];
if ($delay > 0) { if ($delay > 0) {
Queue::later($delay, 'app\api\job\FillExpertCountry@fire', $data, 'FetchExperts'); Queue::later($delay, 'app\api\job\FillExpertCountry@fire', $data, 'FetchExpertCity');
} else { } else {
Queue::push('app\api\job\FillExpertCountry@fire', $data, 'FetchExperts'); Queue::push('app\api\job\FillExpertCountry@fire', $data, 'FetchExpertCity');
} }
return true; return true;
@@ -628,7 +624,10 @@ class ExpertFinderService
public function fillExpertCountry($expertId, $affiliation) public function fillExpertCountry($expertId, $affiliation)
{ {
$affiliation = trim((string)$affiliation); $affiliation = trim((string)$affiliation);
if ($affiliation === '') return; if ($affiliation === '') {
Db::name('expert')->where('expert_id', intval($expertId))->update(['country_id' => -1]);
return;
}
$resolver = new CountryResolverService([ $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' => trim((string)Env::get('expert_country_chat_url', Env::get('citation_chat_url', 'http://chat.taimed.cn/v1/chat/completions'))),
@@ -638,7 +637,6 @@ class ExpertFinderService
]); ]);
$result = $resolver->resolve($affiliation); $result = $resolver->resolve($affiliation);
if (empty($result)) return;
$countryId = 0; $countryId = 0;
$enName = ''; $enName = '';
@@ -666,6 +664,12 @@ class ExpertFinderService
'country_id' => $countryId, 'country_id' => $countryId,
'country' => $enName, 'country' => $enName,
]); ]);
} else {
// country_id = -1 表示「已尝试但未识别」,避免链式执行时反复卡在同一条
Db::name('expert')->where('expert_id', intval($expertId))->update([
'country_id' => -1,
]);
$this->log('[CountryFill] expert_id=' . $expertId . ' unresolved, code=' . ($result['code'] ?? '') . ' en_name=' . ($result['en_name'] ?? ''));
} }
} }