feat(timer): 新增定时器配置、日志和主机的后台管理界面

T10: TimerConfig CURD - task management with run_type/status editing,
     manual trigger button, task_name read-only, no add/delete
T11: TimerLog CURD - read-only log viewer with filters and color badges
T12: Host list enhanced - is_master column, setMaster button
This commit is contained in:
augushong
2026-05-26 02:50:40 +08:00
parent 25fab093fa
commit 90e584f5a1
23 changed files with 943 additions and 18 deletions

View File

@@ -0,0 +1,97 @@
<?php
namespace app\admin\controller\system;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use think\App;
/**
* @ControllerAnnotation(title="定时任务协调配置表")
*/
class TimerConfig extends AdminController
{
use \app\admin\traits\Curd;
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\admin\model\SystemTimerConfig();
$this->assign('select_list_run_type', $this->model::SELECT_LIST_RUN_TYPE, true);
$this->assign('select_list_status', $this->model::SELECT_LIST_STATUS, true);
$this->assign('select_list_is_synced', $this->model::SELECT_LIST_IS_SYNCED, true);
$this->assign('select_list_manual_trigger', $this->model::SELECT_LIST_MANUAL_TRIGGER, true);
// 允许通过行内修改的字段
$this->allowModifyFields = [
'status',
'run_type',
];
}
/**
* @NodeAnotation(title="添加")
*/
public function add()
{
$this->error('定时任务配置由系统同步生成,不支持手动添加');
}
/**
* @NodeAnotation(title="删除")
*/
public function delete($id)
{
$this->error('定时任务配置由系统管理,不支持删除');
}
/**
* @NodeAnotation(title="编辑")
*/
public function edit($id)
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
if ($this->request->isPost()) {
$post = $this->request->post();
// 只允许修改 run_type 和 status
$post = array_intersect_key($post, array_flip(['run_type', 'status']));
try {
$save = $row->save($post);
} catch (\Exception $e) {
$this->error('保存失败:' . $e->getMessage());
}
$save ? $this->success('保存成功') : $this->error('保存失败');
}
$this->assign('row', $row);
return $this->fetch();
}
/**
* @NodeAnotation(title="手动触发")
*/
public function trigger($id)
{
$this->checkPostRequest();
$row = $this->model->find($id);
if (!$row) {
$this->error('数据不存在');
}
if ($row->getAttr('run_type') !== 'manual') {
$this->error('只有manual类型的任务支持手动触发');
}
if ($row->getAttr('status') != 1) {
$this->error('任务已停用,请先启用');
}
try {
$row->save(['manual_trigger' => 1]);
} catch (\Exception $e) {
$this->error('触发失败:' . $e->getMessage());
}
$this->success('触发成功,等待定时器执行');
}
}

View File

@@ -0,0 +1,109 @@
<?php
namespace app\admin\controller\system;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnotation;
use think\App;
/**
* @ControllerAnnotation(title="定时器执行日志")
*/
class TimerLog extends AdminController
{
use \app\admin\traits\Curd;
protected $sort = [
'id' => 'desc',
];
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\admin\model\SystemTimerLog();
}
/**
* @NodeAnotation(title="列表")
*/
public function index()
{
if ($this->request->isAjax()) {
if (input('selectFields')) {
return $this->selectList();
}
list($page, $limit, $where, $excludes, $request_options, $group) = $this->buildTableParames();
$count = $this->model
->where($where)
->group($group)
->count();
$list = $this->model
->where($where)
->page($page, $limit)
->order($this->sort)
->group($group)
->select();
$data = [
'code' => 0,
'msg' => '',
'count' => $count,
'data' => $list,
];
return json($data);
}
return $this->fetch();
}
/**
* @NodeAnotation(title="详情")
*/
public function read($id)
{
$row = $this->model->find($id);
empty($row) && $this->error('数据不存在');
$title = $row->title;
$this->assign('row', $row);
$this->assign('title', $title);
return $this->fetch();
}
/**
* @NodeAnotation(title="添加")
*/
public function add()
{
$this->error('日志表不允许手动添加');
}
/**
* @NodeAnotation(title="编辑")
*/
public function edit($id)
{
$this->error('日志表不允许编辑');
}
/**
* @NodeAnotation(title="删除")
*/
public function delete($id)
{
$this->error('日志表不允许删除');
}
/**
* @NodeAnotation(title="属性修改")
*/
public function modify()
{
$this->error('日志表不允许修改');
}
}