ServerInformationController.php
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?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);
}
}