diff --git a/EdgeManager.php b/EdgeManager.php index 465a932..9d85985 100644 --- a/EdgeManager.php +++ b/EdgeManager.php @@ -175,6 +175,15 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) { 'errmsg' => '节点编码和数值类型不匹配!' ))); $connection -> send($response); + } else if ($data_capture -> check_res === 'NO_DEVICE_CODE') { + $response = new Response(200, [ + 'Content-Type' => 'application/json;charset=utf-8', + ], json_encode(array( + 'action' => 'result_set_node_data', + 'errcode' => 4002, + 'errmsg' => 'device_code为必填字段!' + ))); + $connection -> send($response); } $res = $data_capture -> set_node_data(); if ($res === true) { diff --git a/EdgeManager/EDataCapture/EDataCapture.php b/EdgeManager/EDataCapture/EDataCapture.php index 447f1f2..d6e311f 100644 --- a/EdgeManager/EDataCapture/EDataCapture.php +++ b/EdgeManager/EDataCapture/EDataCapture.php @@ -51,13 +51,18 @@ class EDataCapture { if (!$check_func($row -> value)) { $this -> check_res = 'MISMATCH_TYPE'; return; - } else { - $this -> data[$row -> code][] = [ - 'value' => $row -> value, - 'device_code' => $row -> device_code ?? NULL, - 'batch' => $row -> batch ?? NULL - ]; } + + if (!isset($row -> device_code)) { + $this -> check_res = 'NO_DEVICE_CODE'; + return; + } + $this -> data[$row -> code][] = [ + 'value' => $row -> value, + 'device_code' => $row -> device_code, + 'parent_code' => $row -> parent_code ?? NULL, + 'batch' => $row -> batch ?? NULL + ]; } unset($row); } @@ -78,7 +83,8 @@ class EDataCapture { "('%s', '%s', '%s', '%s')", $code, $row['value'] === false ? 'f' : $row['value'], - $row['device_code'] ?? NULL, + $row['device_code'], + $row['parent_code'] ?? NULL, $row['batch'] ?? NULL ); } diff --git a/EdgeManager/EDataCapture/ENodeConfigure.php b/EdgeManager/EDataCapture/ENodeConfigure.php index e651da4..5d56c38 100644 --- a/EdgeManager/EDataCapture/ENodeConfigure.php +++ b/EdgeManager/EDataCapture/ENodeConfigure.php @@ -38,12 +38,13 @@ class ENodeConfigure { $res[] = pg_query($this -> dbconn, sprintf( 'CREATE TABLE IF NOT EXISTS "%s" ( id serial8, - code text, + code text NOT NULL, v_string text, v_int int, v_float float8, v_bool bool, - device_code text, + device_code text NOT NULL, + parent_code text, batch text, capture_time timestamp NOT NULL DEFAULT NOW() )', $table_name diff --git a/README.md b/README.md index 611112a..5657ce6 100644 --- a/README.md +++ b/README.md @@ -32,19 +32,21 @@ { "action": "set_node_data", "param": { - "working_subclass": , + "working_subclass": , // 可选 "data": [ { "code": , // value的类型需与type对应 "value": , - "device_code": [string], - "batch": [string] + "device_code": [string], // 必需字段 + "parent_code": [string], // 可选字段,对应MES中的code + "batch": [string] // 可选字段 }, { "code": , "value": , "device_code": [string], + "parent_code": [string], "batch": [string] }, ...