|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Aside\Devops;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Exceptions\AsideGlobalException;
|
|
|
|
use App\Exceptions\BsideGlobalException;
|
|
|
|
use App\Http\Controllers\Aside\BaseController;
|
|
|
|
use App\Http\Logic\Aside\Devops\ServerInformationLogic;
|
|
|
|
use App\Http\Requests\Aside\Devops\ServerInformationRequest;
|
|
|
|
use App\Models\Devops\ServerInformation;
|
|
|
|
use App\Models\Devops\ServerInformationLog;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
|
|
|
|
class ServerInformationController extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @remark :获取服务器列表
|
|
|
|
* @name :lists
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/1 11:19
|
|
|
|
*/
|
|
|
|
public function lists()
|
|
|
|
{
|
|
|
|
if(isset($this->map['title']) && !empty($this->map['title'])){
|
|
|
|
$this->map['title'] = ['like','%'.$this->map['title'],'%'];
|
|
|
|
}
|
|
|
|
$serverInformationModel = new ServerInformation();
|
|
|
|
$lists = $serverInformationModel->lists($this->map,$this->page,$this->row,$this->order);
|
|
|
|
$this->response('success', Code::SUCCESS, $lists);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加
|
|
|
|
* @param ServerInformationRequest $serverInformationRequest
|
|
|
|
* @param ServerInformationLogic $serverInformationLogic
|
|
|
|
* @return void
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
*/
|
|
|
|
public function add(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic)
|
|
|
|
{
|
|
|
|
|
|
|
|
$serverInformationRequest->validated();
|
|
|
|
$serverInformationLogic->create();
|
|
|
|
$this->response('服务器添加成功!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑
|
|
|
|
* @param ServerInformationRequest $serverInformationRequest
|
|
|
|
* @param ServerInformationLogic $serverInformationLogic
|
|
|
|
* @return void
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
*/
|
|
|
|
public function edit(ServerInformationRequest $serverInformationRequest, ServerInformationLogic $serverInformationLogic)
|
|
|
|
{
|
|
|
|
|
|
|
|
$serverInformationRequest->validate([
|
|
|
|
'id' => 'required|integer',
|
|
|
|
], [
|
|
|
|
'id.required' => 'ID不能为空',
|
|
|
|
'id.integer' => 'ID必须为整数',
|
|
|
|
]);
|
|
|
|
$serverInformationLogic->update();
|
|
|
|
$this->response('服务器修改成功!');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除
|
|
|
|
* @param ServerInformationLogic $serverInformationLogic
|
|
|
|
* @return void
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
*/
|
|
|
|
public function delete(ServerInformationLogic $serverInformationLogic)
|
|
|
|
{
|
|
|
|
$serverInformationLogic->get_batch_update();
|
|
|
|
$this->response('服务器删除成功!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 恢复数据
|
|
|
|
* @param ServerInformationLogic $serverInformationLogic
|
|
|
|
* @return void
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
*/
|
|
|
|
public function restore(ServerInformationLogic $serverInformationLogic)
|
|
|
|
{
|
|
|
|
$serverInformationLogic->get_batch_update(ServerInformationLog::ACTION_RECOVER, ServerInformation::DELETED_DELETE);
|
|
|
|
$this->response('服务器恢复成功!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 服务器信息
|
|
|
|
* @param int $deleted
|
|
|
|
* @return JsonResponse
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
public function getServerInfo(int $deleted = ServerInformation::DELETED_NORMAL)
|
|
|
|
{
|
|
|
|
$serverInformationLogic = new ServerInformationLogic();
|
|
|
|
$data = $serverInformationLogic->serverInfo($deleted);
|
|
|
|
if (!$data) {
|
|
|
|
return $this->response('服务器信息不存在', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
return $this->success($data->toArray());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取软删除的服务器信息
|
|
|
|
* @return JsonResponse
|
|
|
|
* @throws AsideGlobalException
|
|
|
|
* @throws BsideGlobalException
|
|
|
|
* @throws ContainerExceptionInterface
|
|
|
|
* @throws NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
public function getDeleteServerInfo()
|
|
|
|
{
|
|
|
|
return $this->getServerInfo(ServerInformation::DELETED_DELETE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |