50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Log;
|
||
use Modules\EcommerceFinance\Services\DingPayableWorkflowMirrorSynchronizer;
|
||
use Throwable;
|
||
|
||
class SyncDingOnlineDaifaPrice extends Command
|
||
{
|
||
protected $signature = 'business-mirror:sync-ding-online-daifa-price
|
||
{--full : 执行或继续首次全量同步}
|
||
{--batch= : 每批流程数量}
|
||
{--max-batches= : 本轮最多批次数,0 表示直到完成}';
|
||
|
||
protected $description = '同步钉钉线上代发业务报销流程到共享业务镜像库';
|
||
|
||
public function handle(DingPayableWorkflowMirrorSynchronizer $synchronizer): int
|
||
{
|
||
if (! (bool) config('upstream_mirrors.refresh_enabled', false) && ! $this->option('full')) {
|
||
return self::SUCCESS;
|
||
}
|
||
|
||
try {
|
||
$result = $synchronizer
|
||
->forConfigKey('ding_online_daifa_price')
|
||
->sync(
|
||
(bool) $this->option('full'),
|
||
$this->option('batch') === null ? null : (int) $this->option('batch'),
|
||
$this->option('max-batches') === null ? null : (int) $this->option('max-batches'),
|
||
);
|
||
} catch (Throwable $exception) {
|
||
Log::error('钉钉线上代发价格流程镜像同步失败。', ['exception' => $exception::class]);
|
||
$this->error('钉钉线上代发价格流程同步失败,已保留上一版共享数据。');
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'%s:本轮 %d 批,累计处理 %d 条明细。',
|
||
$result['status'] === 'succeeded' ? '同步完成' : '同步进行中',
|
||
$result['batches'],
|
||
$result['rows'],
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|