This commit is contained in:
128
app/Controller/DeptController.php
Normal file
128
app/Controller/DeptController.php
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Author: ykxiao
|
||||||
|
* Date: 2025/7/14
|
||||||
|
* Time: 下午1:59
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* (c) ykxiao <yk_9001@hotmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\JsonRpc\DeptServiceInterface;
|
||||||
|
use App\Request\DeptRequest;
|
||||||
|
use Exception;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Hyperf\HttpMessage\Server\Response;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
|
class DeptController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Inject]
|
||||||
|
protected DeptServiceInterface $deptServiceInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加部门.
|
||||||
|
*/
|
||||||
|
#[Scene(scene: 'addDept', argument: 'request')]
|
||||||
|
public function addDept(DeptRequest $request): Response
|
||||||
|
{
|
||||||
|
// 微服务接口
|
||||||
|
$params = $request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
|
||||||
|
$rpcDept = $this->deptServiceInterface->addDept($params);
|
||||||
|
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
$deptInfo = $rpcDept['result'];
|
||||||
|
$this->opLogs('[添加部门]' . $deptInfo['name'] ?? '');
|
||||||
|
|
||||||
|
return $this->apiResponse->success($deptInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门列表.
|
||||||
|
* @return Response
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function deptList(): Response
|
||||||
|
{
|
||||||
|
$params = $this->request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
$rpcDept = $this->deptServiceInterface->deptList($params);
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
return $this->apiResponse->success($rpcDept['result']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除部门.
|
||||||
|
*/
|
||||||
|
#[Scene(scene: 'delDept', argument: 'request')]
|
||||||
|
public function delDept(DeptRequest $request): Response
|
||||||
|
{
|
||||||
|
$params = $request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
$rpcDept = $this->deptServiceInterface->delDept($params);
|
||||||
|
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
$this->opLogs('[删除部门]' . $rpcDept['result']['dept_name'] ?? '');
|
||||||
|
return $this->apiResponse->success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取部门.
|
||||||
|
*/
|
||||||
|
public function getDeptInfo(): Response
|
||||||
|
{
|
||||||
|
$params = $this->request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
$rpcDept = $this->deptServiceInterface->getDeptInfo($params);
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
return $this->apiResponse->success($rpcDept['result']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门活动列表.
|
||||||
|
*/
|
||||||
|
public function deptListActive(): Response
|
||||||
|
{
|
||||||
|
$params = $this->request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
$rpcDept = $this->deptServiceInterface->getActiveDeptList($params);
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
return $this->apiResponse->success($rpcDept['result']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新部门状态.
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function updateDeptStatus(): Response
|
||||||
|
{
|
||||||
|
$params = $this->request->all();
|
||||||
|
$params['token'] = $this->token();
|
||||||
|
$rpcDept = $this->deptServiceInterface->updateDeptStatus($params);
|
||||||
|
if (empty($rpcDept['result'])) {
|
||||||
|
return $this->apiResponse->error($rpcDept['message']);
|
||||||
|
}
|
||||||
|
$this->opLogs('[部门状态更新]' . $rpcDept['result']['name']);
|
||||||
|
return $this->apiResponse->success($rpcDept['result']);
|
||||||
|
}
|
||||||
|
}
|
77
app/JsonRpc/DeptServiceConsumer.php
Normal file
77
app/JsonRpc/DeptServiceConsumer.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Author: ykxiao
|
||||||
|
* Date: 2025/7/14
|
||||||
|
* Time: 下午2:04
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* (c) ykxiao <yk_9001@hotmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\JsonRpc;
|
||||||
|
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Hyperf\RpcClient\AbstractServiceClient;
|
||||||
|
|
||||||
|
class DeptServiceConsumer extends AbstractServiceClient implements DeptServiceInterface
|
||||||
|
{
|
||||||
|
#[Inject]
|
||||||
|
protected DeptServiceInterface $deptServiceInterface;
|
||||||
|
|
||||||
|
protected string $serviceName = 'DeptService';
|
||||||
|
|
||||||
|
protected string $protocol = 'jsonrpc-http';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function addDept(array $data): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('data'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function delDept(array $params): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('params'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getDeptInfo(array $params = []): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('params'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function deptList(array $params = []): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('params'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getActiveDeptList(array $params = []): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('params'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function updateDeptStatus(array $data): array
|
||||||
|
{
|
||||||
|
return $this->__request(__FUNCTION__, compact('data'));
|
||||||
|
}
|
||||||
|
}
|
61
app/JsonRpc/DeptServiceInterface.php
Normal file
61
app/JsonRpc/DeptServiceInterface.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Author: ykxiao
|
||||||
|
* Date: 2025/7/14
|
||||||
|
* Time: 下午2:04
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* (c) ykxiao <yk_9001@hotmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\JsonRpc;
|
||||||
|
|
||||||
|
interface DeptServiceInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Desc 新增部门
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addDept(array $data): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Desc 删除部门
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function delDept(array $params): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Desc 获取部门信息
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDeptInfo(array $params = []): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Desc 获取部门列表
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function deptList(array $params = []): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Desc 获取活动的部门列表
|
||||||
|
* @param array $params
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getActiveDeptList(array $params = []): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Desc 修改部门状态
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function updateDeptStatus(array $data): array;
|
||||||
|
}
|
58
app/Request/DeptRequest.php
Normal file
58
app/Request/DeptRequest.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Author: ykxiao
|
||||||
|
* Date: 2025/7/14
|
||||||
|
* Time: 下午2:16
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* (c) ykxiao <yk_9001@hotmail.com>
|
||||||
|
*
|
||||||
|
* This source file is subject to the MIT license that is bundled
|
||||||
|
* with this source code in the file LICENSE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Request;
|
||||||
|
|
||||||
|
class DeptRequest extends AbstractRequest
|
||||||
|
{
|
||||||
|
public array $scenes = [
|
||||||
|
'addDept' => ['name', 'active_status', 'remark'],
|
||||||
|
'updateDept' => ['id', 'name', 'active_status', 'remark'],
|
||||||
|
'delDept' => ['ids'],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => 'required|integer|min:1',
|
||||||
|
'ids' => 'required|array|min:1',
|
||||||
|
'ids.*' => 'required|integer|min:1',
|
||||||
|
'name' => 'required|string|max:45',
|
||||||
|
'remark' => 'string|max:255',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributes(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => '部门名称',
|
||||||
|
'remark' => '备注',
|
||||||
|
'id' => '记录ID',
|
||||||
|
'ids' => '记录ID列表',
|
||||||
|
'ids.*' => '记录ID',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ declare(strict_types=1);
|
|||||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use App\JsonRpc\DeptServiceConsumer;
|
||||||
|
use App\JsonRpc\DeptServiceInterface;
|
||||||
use App\JsonRpc\EasyAppServiceConsumer;
|
use App\JsonRpc\EasyAppServiceConsumer;
|
||||||
use App\JsonRpc\EasyAppServiceInterface;
|
use App\JsonRpc\EasyAppServiceInterface;
|
||||||
use App\JsonRpc\InventoryServiceConsumer;
|
use App\JsonRpc\InventoryServiceConsumer;
|
||||||
@ -27,4 +29,5 @@ return [
|
|||||||
EasyAppServiceInterface::class => EasyAppServiceConsumer::class,
|
EasyAppServiceInterface::class => EasyAppServiceConsumer::class,
|
||||||
InventoryServiceInterface::class => InventoryServiceConsumer::class,
|
InventoryServiceInterface::class => InventoryServiceConsumer::class,
|
||||||
RoleServiceInterface::class => RoleServiceConsumer::class,
|
RoleServiceInterface::class => RoleServiceConsumer::class,
|
||||||
|
DeptServiceInterface::class => DeptServiceConsumer::class,
|
||||||
];
|
];
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use App\JsonRpc\DeptServiceInterface;
|
||||||
use App\JsonRpc\EasyAppServiceInterface;
|
use App\JsonRpc\EasyAppServiceInterface;
|
||||||
use App\JsonRpc\InventoryServiceInterface;
|
use App\JsonRpc\InventoryServiceInterface;
|
||||||
use App\JsonRpc\RoleServiceInterface;
|
use App\JsonRpc\RoleServiceInterface;
|
||||||
@ -25,6 +26,7 @@ return [
|
|||||||
'EasyAppService' => EasyAppServiceInterface::class,
|
'EasyAppService' => EasyAppServiceInterface::class,
|
||||||
'InventoryService' => InventoryServiceInterface::class,
|
'InventoryService' => InventoryServiceInterface::class,
|
||||||
'RoleService' => RoleServiceInterface::class,
|
'RoleService' => RoleServiceInterface::class,
|
||||||
|
'DeptService' => DeptServiceInterface::class,
|
||||||
];
|
];
|
||||||
foreach ($services as $name => $interface) {
|
foreach ($services as $name => $interface) {
|
||||||
$consumers[] = [
|
$consumers[] = [
|
||||||
|
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Controller\CompanyController;
|
use App\Controller\CompanyController;
|
||||||
|
use App\Controller\DeptController;
|
||||||
use App\Controller\FirstCompanyController;
|
use App\Controller\FirstCompanyController;
|
||||||
use App\Controller\PurchaseController;
|
use App\Controller\PurchaseController;
|
||||||
use App\Controller\RoleController;
|
use App\Controller\RoleController;
|
||||||
@ -58,6 +59,14 @@ Router::addGroup('/api/v1', function () {
|
|||||||
Router::post('assign.role.auth', [RoleController::class, 'assignRolePermissions']); # 角色授权
|
Router::post('assign.role.auth', [RoleController::class, 'assignRolePermissions']); # 角色授权
|
||||||
Router::post('role.permission.checked', [RoleController::class, 'roleChecked']); # 角色权限选择列表
|
Router::post('role.permission.checked', [RoleController::class, 'roleChecked']); # 角色权限选择列表
|
||||||
|
|
||||||
|
// 部门管理
|
||||||
|
Router::post('dept.add', [DeptController::class, 'addDept']); # 新增部门
|
||||||
|
Router::post('dept.list', [DeptController::class, 'deptList']); # 部门列表
|
||||||
|
Router::post('dept.delete', [DeptController::class, 'delDept']); # 删除部门
|
||||||
|
Router::post('dept.info', [DeptController::class, 'getDeptInfo']); # 部门信息
|
||||||
|
Router::post('dept.list.active', [DeptController::class, 'deptListActive']); # 部门列表(活动)
|
||||||
|
Router::post('dept.update.status', [DeptController::class, 'updateDeptStatus']); # 部门状态
|
||||||
|
|
||||||
// 平台公司管理
|
// 平台公司管理
|
||||||
Router::post('company.module.add', [RoleController::class, 'addCompanyModule']); # 公司模块授权
|
Router::post('company.module.add', [RoleController::class, 'addCompanyModule']); # 公司模块授权
|
||||||
Router::post('company.permission.checked', [RoleController::class, 'companyChecked']); # 公司模块选择列表
|
Router::post('company.permission.checked', [RoleController::class, 'companyChecked']); # 公司模块选择列表
|
||||||
|
Reference in New Issue
Block a user