setName('knowledge:seed-experts') ->setDescription('为三专家初始化默认知识库(营销/产品/用户)') ->addOption('companyId', null, Option::VALUE_OPTIONAL, '公司 ID', 0) ->addOption('all', null, Option::VALUE_NONE, '为全部公司补建'); } protected function execute(Input $input, Output $output) { $companyId = max(0, (int)$input->getOption('companyId')); $all = (bool)$input->getOption('all'); $ids = []; if ($all) { $ids = Db::name('users')->where('companyId', '>', 0)->group('companyId')->column('companyId'); } elseif ($companyId > 0) { $ids = [$companyId]; } else { $output->writeln('请指定 --companyId 或 --all'); return 1; } $totalCreated = 0; foreach ($ids as $cid) { $cid = (int)$cid; if ($cid <= 0) { continue; } $stats = ExpertKnowledgeSeedService::seedForCompany($cid); $totalCreated += (int)$stats['created']; $output->writeln(sprintf( 'companyId=%d created=%d existing=%d enabled=%d kbIds=%s', $cid, $stats['created'], $stats['existing'], $stats['enabled'], json_encode($stats['kbIds'], JSON_UNESCAPED_UNICODE) )); } $output->writeln("done companies=" . count($ids) . " totalCreated={$totalCreated}"); return 0; } }