158 lines
5.2 KiB
PHP
158 lines
5.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
namespace App\System\Controller\Tools;
|
|
|
|
use App\System\Request\SettingCrontabRequest;
|
|
use App\System\Service\SettingCrontabLogService;
|
|
use App\System\Service\SettingCrontabService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\DeleteMapping;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Annotation\PostMapping;
|
|
use Hyperf\HttpServer\Annotation\PutMapping;
|
|
use Builder\Annotation\Auth;
|
|
use Builder\Annotation\OperationLog;
|
|
use Builder\Annotation\Permission;
|
|
use Builder\BaseController;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
/**
|
|
* 定时任务控制器
|
|
* Class CrontabController
|
|
* @package App\System\Controller\Tools
|
|
*/
|
|
#[Controller(prefix: "system/setting/crontab"), Auth]
|
|
class CrontabController extends BaseController
|
|
{
|
|
/**
|
|
* 计划任务服务
|
|
*/
|
|
#[Inject]
|
|
protected SettingCrontabService $service;
|
|
|
|
/**
|
|
* 计划任务日志服务
|
|
*/
|
|
#[Inject]
|
|
protected SettingCrontabLogService $logService;
|
|
|
|
/**
|
|
* 获取列表分页数据
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[GetMapping("index"), Permission("setting:crontab, setting:crontab:index")]
|
|
public function index(): ResponseInterface
|
|
{
|
|
return $this->success($this->service->getPageList($this->request->all()));
|
|
}
|
|
|
|
/**
|
|
* 获取日志列表分页数据
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[GetMapping("logPageList")]
|
|
public function logPageList(): ResponseInterface
|
|
{
|
|
return $this->success($this->logService->getPageList($this->request->all()));
|
|
}
|
|
|
|
/**
|
|
* 保存数据
|
|
* @param SettingCrontabRequest $request
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[PostMapping("save"), Permission("setting:crontab:save"), OperationLog]
|
|
public function save(SettingCrontabRequest $request): ResponseInterface
|
|
{
|
|
return $this->success(['id' => $this->service->save($request->all())]);
|
|
}
|
|
|
|
/**
|
|
* 立即执行定时任务
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[PostMapping("run"), Permission("setting:crontab:run"), OperationLog]
|
|
public function run(): ResponseInterface
|
|
{
|
|
$id = $this->request->input('id', null);
|
|
if (is_null($id)) {
|
|
return $this->error();
|
|
} else {
|
|
return $this->service->run($id) ? $this->success() : $this->error();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取一条数据信息
|
|
* @param int $id
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[GetMapping("read/{id}"), Permission("setting:crontab:read")]
|
|
public function read(int $id): ResponseInterface
|
|
{
|
|
return $this->success($this->service->read($id));
|
|
}
|
|
|
|
/**
|
|
* 更新数据
|
|
* @param int $id
|
|
* @param SettingCrontabRequest $request
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[PutMapping("update/{id}"), Permission("setting:crontab:update"), OperationLog]
|
|
public function update(int $id, SettingCrontabRequest $request): ResponseInterface
|
|
{
|
|
return $this->service->update($id, $request->all()) ? $this->success() : $this->error();
|
|
}
|
|
|
|
/**
|
|
* 单个或批量删除
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[DeleteMapping("delete"), Permission("setting:crontab:delete")]
|
|
public function delete(): ResponseInterface
|
|
{
|
|
return $this->service->delete((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
|
|
}
|
|
|
|
/**
|
|
* 删除定时任务日志
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[DeleteMapping("deleteCrontabLog"), Permission("setting:crontab:deleteCrontabLog"), OperationLog("删除定时任务日志")]
|
|
public function deleteCrontabLog(): \Psr\Http\Message\ResponseInterface
|
|
{
|
|
return $this->logService->delete((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
|
|
}
|
|
|
|
/**
|
|
* 更改状态
|
|
* @return ResponseInterface
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
*/
|
|
#[PutMapping("changeStatus"), Permission("setting:crontab:update"), OperationLog]
|
|
public function changeStatus(): ResponseInterface
|
|
{
|
|
return $this->service->changeStatus((int) $this->request->input('id'), (string) $this->request->input('status'))
|
|
? $this->success() : $this->error();
|
|
}
|
|
} |