From 236a343fa95c15ee3f58e0411f0ab04254602328 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 25 Jul 2026 21:57:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(timer):=20=E6=96=B0=E5=A2=9E=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E6=95=B0/=E8=A7=A6=E5=8F=91=E8=8A=82=E7=82=B9/?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E6=97=B6=E9=97=B4=E4=B8=89=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=8F=8A=E5=B9=82=E7=AD=89=E5=88=86=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Scheme 定义 concurrency(nullable)/trigger_node_id/last_trigger_time 三字段,Model 声明属性,v2.3.0 分发代码幂等 ALTER 保证升级自动同步。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- app/admin/model/SystemTimerConfig.php | 3 + app/admin/scheme/SystemTimerConfig.php | 9 ++ .../service/adminUpdateCodeData/v2.3.0.php | 85 +++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 extend/base/admin/service/adminUpdateCodeData/v2.3.0.php diff --git a/app/admin/model/SystemTimerConfig.php b/app/admin/model/SystemTimerConfig.php index 7f2dd3c..b7ffcbd 100644 --- a/app/admin/model/SystemTimerConfig.php +++ b/app/admin/model/SystemTimerConfig.php @@ -13,6 +13,9 @@ use app\common\model\TimeModel; * @property string $last_execute_node 最后执行节点ID * @property int $last_execute_time 最后执行时间戳 * @property int $manual_trigger 手动触发标记:0=未触发,1=已触发 0:未触发,1:已触发 + * @property int|null $concurrency 并发数:NULL=继承代码默认 + * @property string|null $trigger_node_id 手动触发目标节点ID + * @property int|null $last_trigger_time 手动触发设置时间戳,用于TTL自动复位 * @property int $create_time 创建时间 */ class SystemTimerConfig extends TimeModel diff --git a/app/admin/scheme/SystemTimerConfig.php b/app/admin/scheme/SystemTimerConfig.php index 18b4a5e..5c4587d 100644 --- a/app/admin/scheme/SystemTimerConfig.php +++ b/app/admin/scheme/SystemTimerConfig.php @@ -43,6 +43,15 @@ class SystemTimerConfig extends BaseScheme #[Component(type: 'switch', options: ['未触发', '已触发'])] public $manual_trigger; + #[Field(type: 'int', length: 11, nullable: true, unsigned: true, comment: '并发数:NULL=继承代码默认')] + public $concurrency; + + #[Field(type: 'varchar', length: 100, nullable: true, comment: '手动触发目标节点ID')] + public $trigger_node_id; + + #[Field(type: 'int', length: 11, nullable: true, unsigned: true, comment: '手动触发设置时间戳,用于TTL自动复位')] + public $last_trigger_time; + #[Field(type: 'int', length: 11, comment: '创建时间', unsigned: true)] #[Component(type: 'date', options: [])] public $create_time; diff --git a/extend/base/admin/service/adminUpdateCodeData/v2.3.0.php b/extend/base/admin/service/adminUpdateCodeData/v2.3.0.php new file mode 100644 index 0000000..503466f --- /dev/null +++ b/extend/base/admin/service/adminUpdateCodeData/v2.3.0.php @@ -0,0 +1,85 @@ + "ADD COLUMN `concurrency` INT UNSIGNED NULL COMMENT '并发数:NULL=继承代码默认'", + 'trigger_node_id' => "ADD COLUMN `trigger_node_id` VARCHAR(100) NULL COMMENT '手动触发目标节点ID'", + 'last_trigger_time' => "ADD COLUMN `last_trigger_time` INT UNSIGNED NULL COMMENT '手动触发设置时间戳,用于TTL自动复位'", + ]; + + public function update() + { + $this->output->writeln('更新代码'); + + $this->output->info('v2.3.0:为 system_timer_config 表新增定时器动态管控字段(concurrency / trigger_node_id / last_trigger_time)'); + + $table = config('database.connections.mysql.prefix', 'ul_') . 'system_timer_config'; + + // 确认表存在 + $tableExists = Db::query( + "SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?", + [$table] + ); + if (empty($tableExists)) { + $this->output->warning("表 {$table} 不存在,跳过字段新增。请先执行 scheme:sync 或 migrate:run 初始化表结构。"); + + return; + } + + // 幂等:读取现有字段,已存在的跳过 + $columns = Db::query("SHOW COLUMNS FROM `{$table}`"); + $exists = array_column($columns, 'Field'); + + $added = 0; + $skipped = 0; + foreach ($this->newColumns as $field => $sqlFragment) { + if (in_array($field, $exists)) { + $this->output->writeln(" - 字段 {$field} 已存在,跳过"); + ++$skipped; + continue; + } + + Db::execute("ALTER TABLE `{$table}` {$sqlFragment}"); + $this->output->writeln(" - 新增字段 {$field} 完成"); + ++$added; + } + + $this->output->info("本次新增 {$added} 个字段,跳过 {$skipped} 个已存在字段"); + $this->output->writeln('更新代码完成'); + } +}