42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Business\SystemizationTodoWorkbookImporter;
|
||
use Illuminate\Console\Command;
|
||
use Throwable;
|
||
|
||
class ImportSystemizationTodos extends Command
|
||
{
|
||
protected $signature = 'systemization-todos:import
|
||
{file : 待办 Excel 文件路径}
|
||
{--company=1 : 写入的 company_id}
|
||
{--user= : 操作人用户 ID}';
|
||
|
||
protected $description = '导入财务系统化待办清单';
|
||
|
||
public function handle(SystemizationTodoWorkbookImporter $importer): int
|
||
{
|
||
try {
|
||
$result = $importer->import(
|
||
(string) $this->argument('file'),
|
||
max((int) $this->option('company'), 1),
|
||
$this->option('user') !== null ? (int) $this->option('user') : null,
|
||
);
|
||
} catch (Throwable $exception) {
|
||
$this->error($exception->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$this->info(sprintf(
|
||
'工作表 %s:新增 %d 条,跳过已存在 %d 条。',
|
||
$result['sheet'],
|
||
$result['created'],
|
||
$result['skipped'],
|
||
));
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|