mirror of
https://github.com/henry4682/finance_app.git
synced 2026-07-16 00:10:00 +00:00
feat: 前端分離+功能api化
1. 新增資產管理CRUD、googleOAuth登入 2. 更改原記帳controller
This commit is contained in:
40
app/Console/Commands/RefreshAllAssetPrices.php
Normal file
40
app/Console/Commands/RefreshAllAssetPrices.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\UpdateAssetPriceJob;
|
||||
use App\Models\InvestmentHolding;
|
||||
use App\Models\Security;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class RefreshAllAssetPrices extends Command
|
||||
{
|
||||
// 執行此指令的名稱:php artisan asset:refresh-prices
|
||||
protected $signature = 'asset:refresh-prices';
|
||||
protected $description = '將全系統所有股票與基金的價格更新任務推入 Queue 佇列';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// 🟢 1. 從持倉表中撈出所有使用者「目前有在使用」且「不重複」的股票與基金代號
|
||||
// 這樣能完美確保 2330 只會被爬一次,不會對證交所造成重複負擔
|
||||
$uniqueHoldings = Security::select('code', 'type', 'name')
|
||||
->groupBy('code', 'type', 'name') // 去除重複
|
||||
->get();
|
||||
|
||||
$this->info("全系統共發現 " . $uniqueHoldings->count() . " 檔不重複的現役標的,開始指派更新任務...");
|
||||
|
||||
$delaySeconds = 0;
|
||||
|
||||
foreach ($uniqueHoldings as $holding) {
|
||||
UpdateAssetPriceJob::dispatch(
|
||||
$holding->code,
|
||||
$holding->type,
|
||||
$holding->name
|
||||
)->delay(now()->addSeconds($delaySeconds));
|
||||
|
||||
$delaySeconds += 2;
|
||||
}
|
||||
|
||||
$this->info("所有任務皆已成功排入背景 Queue,預計花費 {$delaySeconds} 秒消化完畢。");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user