| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Module\System\AdminControllers;
- use App\Module\System\Models\FailedJob;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Spatie\RouteAttributes\Attributes\Resource;
- use UCore\DcatAdmin\AdminController;
- use UCore\DcatAdmin\FilterHelper;
- use UCore\DcatAdmin\GridHelper;
- use UCore\DcatAdmin\ShowHelper;
- /**
- * 失败队列任务管理控制器
- */
- #[Resource('failed-jobs', names: 'dcat.admin.failed-jobs')]
- class FailedJobController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '失败队列任务管理';
- /**
- * 列表页面
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new FailedJob(), function (Grid $grid) {
- $helper = new GridHelper($grid, $this);
-
- $helper->columnId();
-
- $grid->column('uuid', 'UUID')->copyable();
-
- $grid->column('queue', '队列名称')->label('primary');
-
- $grid->column('connection', '连接名称')->label('info');
-
- $grid->column('job_class', '任务类')->display(function ($value) {
- if (!$value) return '';
- $parts = explode('\\', $value);
- return end($parts);
- });
-
- $grid->column('exception_class', '异常类')->display(function ($value) {
- if (!$value) return '';
- $parts = explode('\\', $value);
- return end($parts);
- })->label('danger');
-
- $grid->column('exception_message', '异常消息')->limit(50);
-
- $grid->column('failed_at_formatted', '失败时间')->sortable();
-
- // 筛选器
- $grid->filter(function (Grid\Filter $filter) {
- $helper = new FilterHelper($filter, $this);
- $filter->like('queue', '队列名称');
- $filter->like('connection', '连接名称');
- $filter->like('uuid', 'UUID');
- $filter->between('failed_at', '失败时间')->datetime();
- $filter->like('exception', '异常信息');
- });
-
- // 禁用新增、编辑
- $grid->disableCreateButton();
- $grid->disableEditButton();
-
- // 排序
- $grid->model()->orderBy('id', 'desc');
-
- // 分页
- $grid->paginate(20);
- });
- }
- /**
- * 详情页面
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new FailedJob(), function (Show $show) {
- $helper = new ShowHelper($show, $this);
- $show->field('id', 'ID');
- $show->field('uuid', 'UUID');
- $show->field('queue', '队列名称');
- $show->field('connection', '连接名称');
- $show->field('job_class', '任务类');
- $show->field('exception_class', '异常类');
- $show->field('exception_message', '异常消息');
- $show->field('failed_at_formatted', '失败时间');
- $show->field('payload', '任务载荷')->json();
- $show->field('exception', '完整异常信息')->code();
- // 禁用编辑
- $show->disableEditButton();
- });
- }
- }
|