hyperf-view/app/System/Controller/Permission/PostController.php

171 lines
5.8 KiB
PHP

<?php
declare(strict_types = 1);
namespace App\System\Controller\Permission;
use App\System\Request\SystemPostRequest;
use App\System\Service\SystemPostService;
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 PostController
* @package App\System\Controller
*/
#[Controller(prefix: "system/post"), Auth]
class PostController extends BaseController
{
#[Inject]
protected SystemPostService $service;
/**
* 岗位分页列表
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("index"), Permission("system:post, system:post: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("recycle"), Permission("system:post:recycle")]
public function recycle(): ResponseInterface
{
return $this->success($this->service->getPageListByRecycle($this->request->all()));
}
/**
* 获取岗位列表
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("list")]
public function list(): ResponseInterface
{
return $this->success($this->service->getList());
}
/**
* 保存数据
* @param SystemPostRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PostMapping("save"), Permission("system:post:save"), OperationLog]
public function save(SystemPostRequest $request): ResponseInterface
{
return $this->success(['id' => $this->service->save($request->all())]);
}
/**
* 获取一条数据信息
* @param int $id
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("read/{id}"), Permission("system:post:read")]
public function read(int $id): ResponseInterface
{
return $this->success($this->service->read($id));
}
/**
* 更新数据
* @param int $id
* @param SystemPostRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("update/{id}"), Permission("system:post:update"), OperationLog]
public function update(int $id, SystemPostRequest $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("system:post:delete")]
public function delete(): ResponseInterface
{
return $this->service->delete((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
}
/**
* 单个或批量真实删除数据 (清空回收站)
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[DeleteMapping("realDelete"), Permission("system:post:realDelete"), OperationLog]
public function realDelete(): ResponseInterface
{
return $this->service->realDelete((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
}
/**
* 单个或批量恢复在回收站的数据
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("recovery"), Permission("system:post:recovery")]
public function recovery(): ResponseInterface
{
return $this->service->recovery((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
}
/**
* 更改岗位状态
* @param SystemPostRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("changeStatus"), Permission("system:post:changeStatus"), OperationLog]
public function changeStatus(SystemPostRequest $request): ResponseInterface
{
return $this->service->changeStatus((int) $request->input('id'), (string) $request->input('status'))
? $this->success() : $this->error();
}
/**
* 数字运算操作
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("numberOperation"), Permission("system:post:update"), OperationLog]
public function numberOperation(): ResponseInterface
{
return $this->service->numberOperation(
(int) $this->request->input('id'),
(string) $this->request->input('numberName'),
(int) $this->request->input('numberValue', 1),
) ? $this->success() : $this->error();
}
}