This commit is contained in:
wangjinlei
2026-04-16 13:30:31 +08:00
parent a2338340f6
commit ae221e6be6
8 changed files with 838 additions and 91 deletions

View File

@@ -53,13 +53,58 @@ class ExpertFinder extends Base
return jsonSuccess($result);
}
/**
* 测试单个专家的国家解析(同步执行,立刻返回结果)
*/
public function cityTest(){
$data = $this->request->post();
$rule = new Validate([
"expert_id"=>"require",
"aff"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$service = new ExpertFinderService();
$service->fillExpertCountry($data['expert_id'], $data['aff']);
$expert = Db::name('expert')->where('expert_id', intval($data['expert_id']))->find();
return jsonSuccess([
'country_id' => isset($expert['country_id']) ? $expert['country_id'] : null,
'country' => isset($expert['country']) ? $expert['country'] : null,
]);
}
/**
* 启动国家解析:找到第一个缺 country 的专家推入队列,
* 队列处理完后会自动链式找下一个,直到全部处理完。
* 只需调一次即可。
*/
public function batchFillCountry(){
$service = new ExpertFinderService();
$started = $service->enqueueNextCountryFill(0);
$pending = Db::name('expert')
->where('affiliation', '<>', '')
->where(function ($q) {
$q->where('country_id', 0)
->whereOr('country_id', 'null')
->whereOr('country', '');
})
->where('state', '<>', 5)
->count();
return jsonSuccess([
'started' => $started,
'pending' => $pending,
]);
}
/**
* Get experts from local database
*/
public function getList()
{
$field = trim($this->request->param('field', ''));
$majorId = intval($this->request->param('major_id', 0));
$state = $this->request->param('state', '-1');
$keyword = trim($this->request->param('keyword', ''));
$noRecent = intval($this->request->param('no_recent', 0));
@@ -69,16 +114,13 @@ class ExpertFinder extends Base
$minExperts = max(0, intval($this->request->param('min_experts', 50)));
$query = Db::name('expert')->alias('e');
$needJoin = ($field !== '' || $majorId > 0);
$needJoin = ($field !== '');
if ($needJoin) {
$query->join('t_expert_field ef', 'ef.expert_id = e.expert_id AND ef.state = 0', 'inner');
if ($field !== '') {
$query->where('ef.field', 'like', '%' . $field . '%');
}
if ($majorId > 0) {
$query->where('ef.major_id', $majorId);
}
$query->group('e.expert_id');
}
@@ -108,6 +150,7 @@ class ExpertFinder extends Base
$item['fields'] = Db::name('expert_field')
->where('expert_id', $item['expert_id'])
->where('state', 0)
->group('field')
->column('field');
}

View File

@@ -261,7 +261,6 @@ class ExpertManage extends Base
{
$data = $this->request->post();
$expertId = intval(isset($data['expert_id']) ? $data['expert_id'] : 0);
$majorId = intval(isset($data['major_id']) ? $data['major_id'] : 0);
$field = trim(isset($data['field']) ? $data['field'] : '');
if (!$expertId || $field === '') {
@@ -279,7 +278,6 @@ class ExpertManage extends Base
$id = Db::name('expert_field')->insertGetId([
'expert_id' => $expertId,
'major_id' => $majorId,
'field' => $field,
'state' => 0,
]);
@@ -297,7 +295,16 @@ class ExpertManage extends Base
return jsonError('expert_field_id is required');
}
Db::name('expert_field')->where('expert_field_id', $efId)->update(['state' => 1]);
// 若 t_expert_field 同时存“领域行 + 论文行”,删除领域时应同时软删该领域下所有论文行
$row = Db::name('expert_field')->where('expert_field_id', $efId)->find();
if ($row) {
Db::name('expert_field')
->where('expert_id', intval($row['expert_id']))
->where('field', (string)$row['field'])
->update(['state' => 1]);
} else {
Db::name('expert_field')->where('expert_field_id', $efId)->update(['state' => 1]);
}
return jsonSuccess([]);
}
@@ -459,7 +466,7 @@ class ExpertManage extends Base
/**
* 批量保存专家领域
* @param int $expertId
* @param array $fields [{"major_id":1,"field":"xxx"}, ...]
* @param array $fields [{"field":"xxx"}, ...]
*/
private function saveExpertFields($expertId, $fields)
{
@@ -471,7 +478,6 @@ class ExpertManage extends Base
}
foreach ($fields as $f) {
$majorId = intval(isset($f['major_id']) ? $f['major_id'] : 0);
$fieldName = trim(isset($f['field']) ? $f['field'] : '');
if ($fieldName === '') continue;
@@ -484,7 +490,6 @@ class ExpertManage extends Base
Db::name('expert_field')->insert([
'expert_id' => $expertId,
'major_id' => $majorId,
'field' => $fieldName,
'state' => 0,
]);

View File

@@ -0,0 +1,37 @@
<?php
namespace app\api\job;
use think\queue\Job;
use app\common\PromotionService;
/**
* 队列任务:对单个 promotion_task 执行 prepareTask预生成 subject/body
*
* 队列名promotion
* 启动 workerphp think queue:listen --queue promotion
*/
class PromotionPrepare
{
public function fire(Job $job, $data)
{
$taskId = intval(isset($data['task_id']) ? $data['task_id'] : 0);
$service = new PromotionService();
if (!$taskId) {
$job->delete();
return;
}
try {
$result = $service->prepareTask($taskId);
$service->log('[PromotionPrepare] task=' . $taskId
. ' prepared=' . $result['prepared']
. ' failed=' . $result['failed']);
} catch (\Exception $e) {
$service->log('[PromotionPrepare] task=' . $taskId . ' exception=' . $e->getMessage());
}
$job->delete();
}
}