47 lines
1.6 KiB
PHP
47 lines
1.6 KiB
PHP
<?php
|
|
namespace app\command;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use app\model\BalanceLog;
|
|
|
|
class BalanceLogTask extends Command
|
|
{
|
|
protected static $defaultName = 'balance:log-task';
|
|
protected static $defaultDescription = 'balance:log-task';
|
|
protected function configure()
|
|
{
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output):int
|
|
{
|
|
// 1. 确保索引存在
|
|
$output->writeln('Creating indexes...');
|
|
$indexResults = BalanceLog::createAllIndexes();
|
|
foreach ($indexResults as $currency => $messages) {
|
|
$output->writeln("[$currency]");
|
|
foreach ($messages as $message) {
|
|
$output->writeln(" - $message");
|
|
}
|
|
}
|
|
|
|
// 2. 执行数据归档
|
|
$output->writeln('Archiving old data...');
|
|
$archiveResults = BalanceLog::archiveData(3); // 归档3天前的数据
|
|
foreach ($archiveResults as $currency => $result) {
|
|
$output->writeln("[$currency]");
|
|
$output->writeln(" - Table: {$result['table']}");
|
|
$output->writeln(" - Archived: {$result['archived']} records");
|
|
foreach ($result['messages'] as $message) {
|
|
$output->writeln(" - $message");
|
|
}
|
|
}
|
|
|
|
$output->writeln('All tasks completed!');
|
|
return self::SUCCESS;
|
|
}
|
|
} |