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