| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 从计划创建任务Action
- *
- * 用于从清理计划创建执行任务
- */
- class CreateTaskFromPlanAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '创建任务';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $planId = $this->getKey();
- $taskName = $request->input('task_name');
-
- if (empty($taskName)) {
- return $this->response()
- ->error('请输入任务名称');
- }
-
- // 调用服务创建任务
- $result = CleanupService::createTaskFromPlan($planId, $taskName);
-
- if (!$result['success']) {
- return $this->response()
- ->error('创建失败:' . $result['message']);
- }
-
- $task = $result['data'];
-
- return $this->response()
- ->success('任务创建成功!')
- ->detail("
- 任务ID:{$task['id']}<br>
- 任务名称:{$task['task_name']}<br>
- 关联计划:{$task['plan_name']}<br>
- 包含表数:{$task['total_tables']}<br>
- 状态:待执行
- ")
- ->redirect('/admin/cleanup/tasks/' . $task['id']);
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('创建失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认创建任务?',
- '将基于此计划创建一个新的清理任务。',
- [
- 'task_name' => [
- 'type' => 'text',
- 'label' => '任务名称',
- 'placeholder' => '请输入任务名称',
- 'required' => true,
- ]
- ]
- ];
- }
- }
|