From a948c11eb917ea15ec04de31cca6a5ee76f73109 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Sat, 20 Aug 2022 14:18:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E9=9B=86=E6=95=B0=E6=8D=AE=E6=97=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AAparent=5Fcode=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E5=90=8C=E6=97=B6device=5Fcode=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EdgeManager.php | 9 +++++++++ EdgeManager/EDataCapture/EDataCapture.php | 20 +++++++++++++------- EdgeManager/EDataCapture/ENodeConfigure.php | 5 +++-- README.md | 8 +++++--- 4 files changed, 30 insertions(+), 12 deletions(-) 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] }, ...