hyperf-view/app/System/Controller/DataCenter/DictDataController.php

197 lines
6.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\System\Controller\DataCenter;
use App\System\Request\SystemDictDataRequest;
use App\System\Service\SystemDictDataService;
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 LogsController
* @package App\System\Controller\DataCenter
*/
#[Controller(prefix: "system/dataDict"), Auth]
class DictDataController extends BaseController
{
#[Inject]
protected SystemDictDataService $service;
/**
* 列表
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("index"), Permission("system:dict, system:dict: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("list")]
public function list(): ResponseInterface
{
return $this->success($this->service->getList($this->request->all()));
}
/**
* 快捷查询多个字典
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("lists")]
public function lists(): ResponseInterface
{
return $this->success($this->service->getLists($this->request->all()));
}
/**
* 清除字典缓存
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PostMapping("clearCache"), Permission("system:dict:clearCache"), OperationLog]
public function clearCache(): ResponseInterface
{
return $this->service->clearCache() ? $this->success() : $this->error();
}
/**
* 回收站列表
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[GetMapping("recycle"), Permission("system:dict:recycle")]
public function recycle(): ResponseInterface
{
return $this->success($this->service->getPageListByRecycle($this->request->all()));
}
/**
* 新增字典类型
* @param SystemDictDataRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PostMapping("save"), Permission("system:dict:save"), OperationLog]
public function save(SystemDictDataRequest $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:dict:read")]
public function read(int $id): ResponseInterface
{
return $this->success($this->service->read($id));
}
/**
* 更新一个字典类型
* @param int $id
* @param SystemDictDataRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("update/{id}"), Permission("system:dict:update"), OperationLog]
public function update(int $id, SystemDictDataRequest $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:dict: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:dict: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:dict:recovery")]
public function recovery(): ResponseInterface
{
return $this->service->recovery((array) $this->request->input('ids', [])) ? $this->success() : $this->error();
}
/**
* 更改字典状态
* @param SystemDictDataRequest $request
* @return ResponseInterface
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
#[PutMapping("changeStatus"), Permission("system:dict:update"), OperationLog]
public function changeStatus(SystemDictDataRequest $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:dict: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();
}
}