统一web入口
This commit is contained in:
145
EdgeManager.php
145
EdgeManager.php
@@ -53,92 +53,89 @@ $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 (isset($post -> action)) {
|
||||||
if (is_array($post) and isset($post['action'])) {
|
if (str_ends_with($post -> action, 'node')) {
|
||||||
if (str_ends_with($post['action'], 'node')) {
|
// 用这种方式自动匹配调用和action相对应的方法
|
||||||
// 用这种方式自动匹配调用和action相对应的方法
|
// 因为pg_insert()不需要action字段
|
||||||
$action = $post['action'];
|
$action = $post -> action;
|
||||||
unset($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)
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => 'Success'
|
'msg' => 'Success'
|
||||||
)));
|
)));
|
||||||
else if ($res === "REPLICATED")
|
else if ($res === "REPLICATED")
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => '节点编码不可重复!'
|
'msg' => '节点编码不可重复!'
|
||||||
)));
|
)));
|
||||||
else if ($res === false) {
|
else if ($res === false) {
|
||||||
$connection -> send(json_encode(array(
|
$connection -> send(json_encode(array(
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
} else if ($post -> action === 'set_node_data') {
|
||||||
|
$data_capture = new EDataCapture($dbconn, post: $post);
|
||||||
|
if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') {
|
||||||
|
$response = new Response(200, [
|
||||||
|
'Content-Type' => 'application/json;charset=utf-8',
|
||||||
|
], json_encode(array(
|
||||||
|
'action' => 'result_set_node_data',
|
||||||
|
'errcode' => 4002,
|
||||||
|
'errmsg' => '未登记过的工序单元!'
|
||||||
|
)));
|
||||||
|
$connection -> send($response);
|
||||||
|
} else if ($data_capture -> check_res === 'MISMATCH_TYPE') {
|
||||||
|
$response = new Response(200, [
|
||||||
|
'Content-Type' => 'application/json;charset=utf-8',
|
||||||
|
], json_encode(array(
|
||||||
|
'action' => 'result_set_node_data',
|
||||||
|
'errcode' => 4002,
|
||||||
|
'errmsg' => '节点编码和数值类型不匹配!'
|
||||||
|
)));
|
||||||
|
$connection -> send($response);
|
||||||
|
}
|
||||||
|
$res = $data_capture -> set_node_data();
|
||||||
|
if ($res === true) {
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'action' => 'result_set_node_data',
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => ''
|
||||||
|
)));
|
||||||
|
} else {
|
||||||
|
$connection -> send(json_encode(array(
|
||||||
|
'action' => 'result_set_node_data',
|
||||||
|
'errcode' => 4002,
|
||||||
|
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (isset($post -> action)) {
|
|
||||||
if ($post -> action === 'set_node_data') {
|
|
||||||
$data_capture = new EDataCapture($dbconn, post: $post);
|
|
||||||
if ($data_capture -> check_res === 'WRONG_WORKING_SUBCLASS') {
|
|
||||||
$response = new Response(200, [
|
|
||||||
'Content-Type' => 'application/json;charset=utf-8',
|
|
||||||
], json_encode(array(
|
|
||||||
'action' => 'result_set_node_data',
|
|
||||||
'errcode' => 4002,
|
|
||||||
'errmsg' => '未登记过的工序单元!'
|
|
||||||
)));
|
|
||||||
$connection -> send($response);
|
|
||||||
} else if ($data_capture -> check_res === 'MISMATCH_TYPE') {
|
|
||||||
$response = new Response(200, [
|
|
||||||
'Content-Type' => 'application/json;charset=utf-8',
|
|
||||||
], json_encode(array(
|
|
||||||
'action' => 'result_set_node_data',
|
|
||||||
'errcode' => 4002,
|
|
||||||
'errmsg' => '节点编码和数值类型不匹配!'
|
|
||||||
)));
|
|
||||||
$connection -> send($response);
|
|
||||||
}
|
|
||||||
$res = $data_capture -> set_node_data();
|
|
||||||
if ($res === true) {
|
|
||||||
$connection -> send(json_encode(array(
|
|
||||||
'action' => 'result_set_node_data',
|
|
||||||
'errcode' => 0,
|
|
||||||
'errmsg' => ''
|
|
||||||
)));
|
|
||||||
} else {
|
} else {
|
||||||
$connection -> send(json_encode(array(
|
// 有action,但是不知道是什么鬼动作
|
||||||
'action' => 'result_set_node_data',
|
$response = new Response(200, [
|
||||||
|
'Content-Type' => 'application/json;charset=utf-8',
|
||||||
|
], json_encode(array(
|
||||||
|
'action' => $post -> action,
|
||||||
'errcode' => 4002,
|
'errcode' => 4002,
|
||||||
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
'errmsg' => '乜Q action吖?同朕check check佢'
|
||||||
)));
|
)));
|
||||||
|
$connection -> send($response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 有action,但是不知道是什么鬼动作
|
// action都无
|
||||||
$response = new Response(200, [
|
$response = new Response(200, [
|
||||||
'Content-Type' => 'application/json;charset=utf-8',
|
'Content-Type' => 'application/json;charset=utf-8',
|
||||||
], json_encode(array(
|
], json_encode(array(
|
||||||
'action' => $post -> action,
|
'action' => '缺少action字段',
|
||||||
'errcode' => 4002,
|
'errcode' => 4001,
|
||||||
'errmsg' => '同朕check check佢'
|
'errmsg' => '你请求紧乜撚动作吖?'
|
||||||
)));
|
)));
|
||||||
$connection -> send($response);
|
$connection -> send($response);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// action都无
|
|
||||||
$response = new Response(200, [
|
|
||||||
'Content-Type' => 'application/json;charset=utf-8',
|
|
||||||
], json_encode(array(
|
|
||||||
'action' => '缺少action字段',
|
|
||||||
'errcode' => 4001,
|
|
||||||
'errmsg' => '你请求紧乜撚动作吖?'
|
|
||||||
)));
|
|
||||||
$connection -> send($response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$get = $request -> get();
|
$get = $request -> get();
|
||||||
|
|||||||
@@ -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]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user