统一web入口

This commit is contained in:
Yu Sun
2022-07-12 23:26:06 +08:00
parent 3148d70ed6
commit f841787187
2 changed files with 80 additions and 83 deletions

View File

@@ -53,14 +53,14 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
} }
} }
if (isset($post) and is_array($post)) { if (isset($post) and !(is_array($post) and count($post) === 0)) {
if (count($post) !== 0) {
// Axios发送的POST是array // Axios发送的POST是array
if (is_array($post) and isset($post['action'])) { if (isset($post -> action)) {
if (str_ends_with($post['action'], 'node')) { if (str_ends_with($post -> action, 'node')) {
// 用这种方式自动匹配调用和action相对应的方法 // 用这种方式自动匹配调用和action相对应的方法
$action = $post['action']; // 因为pg_insert()不需要action字段
unset($post['action']); $action = $post -> action;
unset($post -> action);
$enode_configure = new ENodeConfigure($dbconn, post: $post); $enode_configure = new ENodeConfigure($dbconn, post: $post);
$res = $enode_configure -> $action(); $res = $enode_configure -> $action();
if ($res === true) if ($res === true)
@@ -79,11 +79,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
'msg' => '服务器内部逻辑错误,请联系开发者!' 'msg' => '服务器内部逻辑错误,请联系开发者!'
))); )));
} }
} } else if ($post -> action === 'set_node_data') {
}
}
} else if (isset($post -> action)) {
if ($post -> action === 'set_node_data') {
$data_capture = new EDataCapture($dbconn, post: $post); $data_capture = new EDataCapture($dbconn, post: $post);
if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') { if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') {
$response = new Response(200, [ $response = new Response(200, [
@@ -125,7 +121,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
], json_encode(array( ], json_encode(array(
'action' => $post -> action, 'action' => $post -> action,
'errcode' => 4002, 'errcode' => 4002,
'errmsg' => '同朕check check佢' 'errmsg' => '乜Q action吖同朕check check佢'
))); )));
$connection -> send($response); $connection -> send($response);
} }
@@ -140,6 +136,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
))); )));
$connection -> send($response); $connection -> send($response);
} }
}
$get = $request -> get(); $get = $request -> get();
if (isset($get['query'])) { if (isset($get['query'])) {

View File

@@ -12,13 +12,13 @@ class ENodeConfigure {
$exists = pg_query(sprintf( $exists = pg_query(sprintf(
"SELECT EXISTS( "SELECT EXISTS(
SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s' SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s'
)", $this -> post['code'] )", $this -> post -> code
)); ));
if (pg_fetch_assoc($exists)['exists'] == 't') { if (pg_fetch_assoc($exists)['exists'] == 't') {
return "REPLICATED"; return "REPLICATED";
} }
$table_name = "hf_mes_scada_data_capture_node_data_" . $this -> post['working_subclass']; $table_name = "hf_mes_scada_data_capture_node_data_" . $this -> post -> working_subclass;
pg_query($this -> dbconn, "BEGIN"); pg_query($this -> dbconn, "BEGIN");
$res[] = pg_query($this -> dbconn, sprintf( $res[] = pg_query($this -> dbconn, sprintf(
@@ -37,7 +37,7 @@ class ENodeConfigure {
$res[] = pg_insert( $res[] = pg_insert(
$this -> dbconn, $this -> dbconn,
'hf_mes_scada_data_capture_node_configure', 'hf_mes_scada_data_capture_node_configure',
$this -> post (array) $this -> post
); );
// 检查一下,如果超表已经有了就不要尝试重复创建了 // 检查一下,如果超表已经有了就不要尝试重复创建了
$table_exists = pg_query(sprintf( $table_exists = pg_query(sprintf(
@@ -69,17 +69,17 @@ class ENodeConfigure {
$res[] = pg_delete( $res[] = pg_delete(
$this -> dbconn, $this -> dbconn,
'hf_mes_scada_data_capture_node_configure', 'hf_mes_scada_data_capture_node_configure',
$this -> post, (array) $this -> post,
); );
$exists = pg_query(sprintf( $exists = pg_query(sprintf(
"SELECT EXISTS( "SELECT EXISTS(
SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s' SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s'
)", $this -> post['working_subclass'] )", $this -> post -> working_subclass
)); ));
if (pg_fetch_assoc($exists)['exists'] == 'f') { if (pg_fetch_assoc($exists)['exists'] == 'f') {
$res[] = pg_query(sprintf( $res[] = pg_query(sprintf(
"DROP TABLE hf_mes_scada_data_capture_node_data_%s", "DROP TABLE hf_mes_scada_data_capture_node_data_%s",
$this -> post['working_subclass'] $this -> post -> working_subclass
)); ));
} }
@@ -96,8 +96,8 @@ class ENodeConfigure {
return pg_update( return pg_update(
$this -> dbconn, $this -> dbconn,
'hf_mes_scada_data_capture_node_configure', 'hf_mes_scada_data_capture_node_configure',
$this -> post, (array) $this -> post,
['code' => $this -> post['code']] ['code' => $this -> post -> code]
); );
} }