新增设备暂停/继续命令

This commit is contained in:
Yu Sun
2022-08-19 17:06:18 +08:00
parent 69173cb7a1
commit a01cf0b232

View File

@@ -11,9 +11,10 @@ class ECommand {
$command2API = [
'server_restart' => '/Admin/ServerCloseAndRestart',
'server_close' => '/Admin/ServerClose',
'device_stop' => '/Edge/DeviceStopRequest',
'device_continue' => 'Edge/DeviceContinueRequest'
];
if (str_starts_with($this -> post -> command, 'server')) {
$res = pg_query($this -> dbconn, sprintf(
"SELECT url, port
FROM hf_mes_scada_edgeserver_controller_server
@@ -22,12 +23,25 @@ class ECommand {
));
$server_info = pg_fetch_row($res);
if (str_starts_with($this -> post -> command, 'server'))
$ch = curl_init(
$server_info[0]
. ":"
. $server_info[1]
. $command2API[$this -> post -> command]
);
else if (str_starts_with($this -> post -> command, 'device'))
$ch = curl_init(
$server_info[0]
. ":"
. $server_info[1]
. $command2API[$this -> post -> command]
. '?data='
. $this -> post -> device_id
);
else
return;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
@@ -49,13 +63,13 @@ class ECommand {
['id' => $this -> post -> server_id]
);
}
}
pg_insert(
$this -> dbconn,
'hf_mes_scada_edgeserver_controller_command',
[
'server_id' => $this -> post -> server_id,
'device_id' => $this -> post -> server_id ?? NULL,
'command' => $this -> post -> command,
'success' => $return
],