CaiWuXiTong/app/Console/Commands/SyncSupplierPayableForecastMirror.php
苏木 cae8f769c9 fix(供应商对账): 合入线上热修复并发布货款预估汇总 (#1562)
Co-authored-by: 苏木 <594326199@qq.com>
Co-committed-by: 苏木 <594326199@qq.com>
2026-11-30 14:10:29 +08:00

54 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository;
use Modules\EcommerceFinance\Services\BusinessMirrorSynchronizer;
use Throwable;
class SyncSupplierPayableForecastMirror extends Command
{
protected $signature = 'business-mirror:sync-supplier-payable-forecast
{--batch= : 每批最多读取行数}
{--incremental : 只执行增量同步;默认完整校正采购入库头表和明细}';
protected $description = '完整校正供应商货款预估使用的聚水潭采购入库镜像';
public function handle(BusinessMirrorSynchronizer $synchronizer): int
{
$datasets = [
SupplierPayableForecastRepository::HEAD_DATASET => '采购入库头表',
SupplierPayableForecastRepository::ITEM_DATASET => '采购入库明细',
];
$full = ! (bool) $this->option('incremental');
$batchSize = $this->option('batch') === null ? null : (int) $this->option('batch');
foreach ($datasets as $dataset => $label) {
try {
$result = $synchronizer->sync($dataset, $full, $batchSize, 0);
} catch (Throwable) {
$this->error($label . ':同步失败,已保留上一版镜像数据。');
return self::FAILURE;
}
if ($result['status'] !== 'succeeded') {
$this->error($label . ':未完成同步。');
return self::FAILURE;
}
$this->info(sprintf(
'%s:%s,本轮 %d 批,累计处理 %d 行。',
$label,
$full ? '完整校正完成' : '增量同步完成',
$result['batches'],
$result['rows'],
));
}
return self::SUCCESS;
}
}