feat: add zyt medicine bootstrap
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\pharmacy\EjMedicineBootstrapService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class EjPharmacyBootstrapMedicines extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('ej-pharmacy:bootstrap-medicines')
|
||||
->setDescription('一次性导入并原子替换恩济药房药材目录投影')
|
||||
->addOption('replace', null, Option::VALUE_NONE, '确认替换本地 EJ 药材投影')
|
||||
->addOption('confirm', null, Option::VALUE_OPTIONAL, '破坏性操作确认令牌:RESET_TEST_CATALOG', '')
|
||||
->addOption('batch-size', null, Option::VALUE_OPTIONAL, '远端导入批次大小(1-500)', 100);
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$batchSize = (int) $input->getOption('batch-size');
|
||||
EjMedicineBootstrapService::assertCommandGate(
|
||||
(bool) $input->getOption('replace'),
|
||||
(string) $input->getOption('confirm'),
|
||||
$batchSize
|
||||
);
|
||||
$result = EjMedicineBootstrapService::execute($batchSize);
|
||||
$output->writeln(sprintf(
|
||||
'bootstrap 完成 source=%d batches=%d catalog=%d active_mappings=%d unmapped=%d',
|
||||
$result['source_count'],
|
||||
$result['batch_count'],
|
||||
$result['catalog'],
|
||||
$result['active_mappings'],
|
||||
$result['unmapped']
|
||||
));
|
||||
return 0;
|
||||
} catch (\Throwable $exception) {
|
||||
$output->error($exception->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\service\pharmacy\EjMedicineCatalogSyncService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class EjPharmacySyncCatalog extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('ej-pharmacy:sync-catalog')
|
||||
->setDescription('增量同步洛阳药房 ERP 药材目录')
|
||||
->addOption('limit', 'l', Option::VALUE_OPTIONAL, '每页数量', 200);
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try {
|
||||
$stats = EjMedicineCatalogSyncService::sync(max((int) $input->getOption('limit'), 1));
|
||||
$output->writeln(sprintf(
|
||||
'同步完成 pages=%d pulled=%d created=%d updated=%d deactivated=%d cursor=%d',
|
||||
$stats['pages'],
|
||||
$stats['pulled'],
|
||||
$stats['created'],
|
||||
$stats['updated'],
|
||||
$stats['deactivated'],
|
||||
$stats['cursor']
|
||||
));
|
||||
return 0;
|
||||
} catch (\Throwable $exception) {
|
||||
$output->error($exception->getMessage());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user