完成自动类型检查和查询功能
This commit is contained in:
@@ -13,6 +13,7 @@ init_db($options['server_name'], $options['user'], $options['password']);
|
||||
|
||||
$worker = new Worker('http://0.0.0.0:8888');
|
||||
$worker -> name = 'CaptureWorker';
|
||||
$worker -> count = 200;
|
||||
|
||||
$worker -> onWorkerStart = function(Worker $worker) {
|
||||
global $options, $dbconn;
|
||||
@@ -27,6 +28,9 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
// 先预处理POST内容
|
||||
if ($request->header('content-type') === 'application/json') {
|
||||
$post = $request -> post();
|
||||
if (isset($post['action'])) {
|
||||
$post = json_decode(json_encode($post, JSON_PRESERVE_ZERO_FRACTION));
|
||||
}
|
||||
} else {
|
||||
$body = $request -> rawBody();
|
||||
if ($body === "") {
|
||||
@@ -49,7 +53,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($post)) {
|
||||
if (isset($post) and is_array($post)) {
|
||||
if (count($post) !== 0) {
|
||||
// Axios:发送的POST是array
|
||||
if (is_array($post) and isset($post['action'])) {
|
||||
@@ -90,8 +94,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
'errmsg' => '未登记过的工序单元!'
|
||||
)));
|
||||
$connection -> send($response);
|
||||
}
|
||||
if ($data_capture -> check_res === 'MISMATCH_TYPE') {
|
||||
} else if ($data_capture -> check_res === 'MISMATCH_TYPE') {
|
||||
$response = new Response(200, [
|
||||
'Content-Type' => 'application/json;charset=utf-8',
|
||||
], json_encode(array(
|
||||
@@ -104,13 +107,13 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
$res = $data_capture -> set_node_data();
|
||||
if ($res === true) {
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'action' => 'result_set_node_data',
|
||||
'errcode' => 0,
|
||||
'errmsg' => ''
|
||||
)));
|
||||
} else {
|
||||
$connection -> send(json_encode(array(
|
||||
'action' => 'result_set_data',
|
||||
'action' => 'result_set_node_data',
|
||||
'errcode' => 4002,
|
||||
'errmsg' => 'ROLLBACKed: Bad data received (structure and/or values)'
|
||||
)));
|
||||
@@ -187,6 +190,11 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
|
||||
'code' => 1,
|
||||
'msg' => '服务器内部逻辑错误,请联系开发者!'
|
||||
)));
|
||||
else if ($data === "TOO_MANY")
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 1,
|
||||
'msg' => '结果太多(超过二百万条),请收紧查询条件!'
|
||||
)));
|
||||
else
|
||||
$connection -> send(json_encode(array(
|
||||
'code' => 0,
|
||||
|
||||
Reference in New Issue
Block a user