54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?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;
|
||
}
|
||
}
|