You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
command代码
setDescription('同步PLM物料'); } public function handle() { $this->info('同步PLM物料开始'); $service = $this->container->get(MaterialService::class); $totalPages = $service->asyncPLMWithCoroutine(); $this->info("同步完成,共处理 {$totalPages} 页"); $this->info('同步PLM物料结束'); } } ` service代码: ` public function asyncPLMWithCoroutine(int $pageSize = 500, array $where = [], int $concurrency = 5): void { MaterialNew::truncate(); // 获取全部公司 $companyIds = [ 7343700558009602052, 7343700558009602058, 7343700558009602071 ]; foreach ($companyIds as $companyId) { // 获取第一页数据 $firstPage = $this->plmService->getMaterialListList([ 'page' => 1, 'pageSize' => $pageSize, 'sort_field' => '', 'sort_asc' => true, ]); if (empty($firstPage['list'])) { continue; } $this->insertRecords($firstPage['list'], $companyId); $total = $firstPage['total'] ?? 0; $totalPages = (int) ceil($total / $pageSize); // 构建分页任务 $parallel = new Parallel($concurrency); for ($page = 2; $page <= $totalPages; $page++) { $parallel->add(function () use ($page, $pageSize, $companyId) { $param = [ 'page' => $page, 'pageSize' => $pageSize, 'sort_field' => '', 'sort_asc' => true, ]; $data = $this->plmService->getMaterialListList($param); if (!empty($data['list'])) { $this->insertRecords($data['list'], $companyId); } }); } // 等待所有并发任务执行完成 $parallel->wait(); } } ``
Beta Was this translation helpful? Give feedback.
All reactions