mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-09-05 15:25:31 +08:00
feat(timer): 新增并发数/触发节点/触发时间三字段及幂等分发
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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -13,6 +13,9 @@ use app\common\model\TimeModel;
|
|||||||
* @property string $last_execute_node 最后执行节点ID
|
* @property string $last_execute_node 最后执行节点ID
|
||||||
* @property int $last_execute_time 最后执行时间戳
|
* @property int $last_execute_time 最后执行时间戳
|
||||||
* @property int $manual_trigger 手动触发标记:0=未触发,1=已触发 0:未触发,1:已触发
|
* @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 创建时间
|
* @property int $create_time 创建时间
|
||||||
*/
|
*/
|
||||||
class SystemTimerConfig extends TimeModel
|
class SystemTimerConfig extends TimeModel
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ class SystemTimerConfig extends BaseScheme
|
|||||||
#[Component(type: 'switch', options: ['未触发', '已触发'])]
|
#[Component(type: 'switch', options: ['未触发', '已触发'])]
|
||||||
public $manual_trigger;
|
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)]
|
#[Field(type: 'int', length: 11, comment: '创建时间', unsigned: true)]
|
||||||
#[Component(type: 'date', options: [])]
|
#[Component(type: 'date', options: [])]
|
||||||
public $create_time;
|
public $create_time;
|
||||||
|
|||||||
85
extend/base/admin/service/adminUpdateCodeData/v2.3.0.php
Normal file
85
extend/base/admin/service/adminUpdateCodeData/v2.3.0.php
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @internal-framework
|
||||||
|
*
|
||||||
|
* 此文件为框架内置功能
|
||||||
|
*
|
||||||
|
* 用途:框架版本更新代码(v2.3.0)- system_timer_config 新增定时器动态管控三字段
|
||||||
|
* 维护者:框架维护者
|
||||||
|
*
|
||||||
|
* 变更:
|
||||||
|
* - concurrency INT UNSIGNED NULL 并发数:NULL=继承代码默认
|
||||||
|
* - trigger_node_id VARCHAR(100) NULL 手动触发目标节点ID
|
||||||
|
* - last_trigger_time INT UNSIGNED NULL 手动触发设置时间戳,用于TTL自动复位
|
||||||
|
*
|
||||||
|
* 三字段均允许 NULL,用于区分"继承代码默认"与"显式覆盖"。
|
||||||
|
*
|
||||||
|
* 注意:此文件属于框架内核,业务开发者不应修改
|
||||||
|
*/
|
||||||
|
|
||||||
|
use think\console\Input;
|
||||||
|
use think\console\Output;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
|
class UpdateFunction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Input
|
||||||
|
*/
|
||||||
|
public $input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Output
|
||||||
|
*/
|
||||||
|
public $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 待新增字段定义.
|
||||||
|
*/
|
||||||
|
public $newColumns = [
|
||||||
|
'concurrency' => "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('更新代码完成');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user