基本完成前后端代码
This commit is contained in:
131
EdgeManager.php
131
EdgeManager.php
@@ -24,56 +24,74 @@ $worker -> onWorkerStart = function(Worker $worker) {
|
||||
$worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
global $options, $dbconn;
|
||||
|
||||
$post = $request -> post();
|
||||
if (isset($post['action']) and str_contains($post['action'], 'node')) {
|
||||
$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' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
// 仅供Axios使用
|
||||
if ($request->header('content-type') === 'application/json') {
|
||||
$post = $request -> post();
|
||||
if (isset($post['action']) and str_contains($post['action'], 'node')) {
|
||||
$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 (isset($post['action']) and str_contains($post['action'], 'data')) {
|
||||
$action = $post['action'];
|
||||
unset($post['action']);
|
||||
$data_capture = new EDataCapture($dbconn, $post = $post);
|
||||
$res = $data_capture -> $action();
|
||||
if ($res === true) {
|
||||
} else {
|
||||
$post = json_decode($request -> rawBody());
|
||||
if (json_last_error() !== JSON_ERROR_NONE)
|
||||
dump('fuck');
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'errcode' => 0,
|
||||
'errmsg' => ''
|
||||
'action' => '错得太离谱以至于我也不知道这是什么动作',
|
||||
'errcode' => 4001,
|
||||
'errmsg' => 'POST的内容不是JSON,也并非可按照JSON解析的字符串!'
|
||||
)));
|
||||
dump($post);
|
||||
if ($post -> action === 'set_node_data') {
|
||||
$data_capture = new EDataCapture($dbconn, post: $post);
|
||||
$res = $data_capture -> set_node_data();
|
||||
if ($res === true) {
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'errcode' => 0,
|
||||
'errmsg' => ''
|
||||
)));
|
||||
} else {
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'errcode' => 4002,
|
||||
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
||||
)));
|
||||
}
|
||||
} else {
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'action' => $post -> action,
|
||||
'errcode' => 4002,
|
||||
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
||||
'errmsg' => '请检查传入的字段值!'
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
$get = $request -> get();
|
||||
if (isset($get['query']) and $get['query'] == 'nodes') {
|
||||
$enode_configure = new ENodeConfigure($dbconn, $get = $get);
|
||||
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||
$nodes = $enode_configure -> get_nodes();
|
||||
if (is_null($nodes))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => 'no node data'
|
||||
'msg' => 'no node data yet'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
@@ -81,6 +99,51 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
'data' => $nodes
|
||||
)));
|
||||
}
|
||||
|
||||
if (isset($get['query']) and $get['query'] == 'working_subclasses') {
|
||||
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||
$working_subclasses = $enode_configure -> get_working_subclasses();
|
||||
if (is_null($working_subclasses))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '还没有工序单元!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'data' => $working_subclasses
|
||||
)));
|
||||
}
|
||||
|
||||
if (isset($get['query']) and $get['query'] == 'codes') {
|
||||
$enode_configure = new ENodeConfigure($dbconn, get: $get);
|
||||
$codes = $enode_configure -> get_codes_by_working_subclasses();
|
||||
if (is_null($codes))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'data' => $codes
|
||||
)));
|
||||
}
|
||||
|
||||
if (isset($get['query']) and $get['query'] == 'node_data') {
|
||||
$data_capture = new EDataCapture($dbconn, get: $get);
|
||||
$data = $data_capture -> get_node_data();
|
||||
if (is_null($data))
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
'data' => $data
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
Worker::runAll();
|
||||
|
||||
Reference in New Issue
Block a user