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']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user