CaiWuXiTong/app/Console/Commands/SyncDingPayableWorkflowMirror.php

48 lines
1.7 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 Illuminate\Support\Facades\Log;
use Modules\EcommerceFinance\Services\DingPayableWorkflowMirrorSynchronizer;
use Throwable;
class SyncDingPayableWorkflowMirror extends Command
{
protected $signature = 'business-mirror:sync-ding-payable-workflows
{--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->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;
}
}