采集数据时新增一个parent_code字段,同时device_code更改为必填

This commit is contained in:
Yu Sun
2022-08-20 14:18:13 +08:00
parent c33b6b9cd8
commit a948c11eb9
4 changed files with 30 additions and 12 deletions

View File

@@ -175,6 +175,15 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) {
'errmsg' => '节点编码和数值类型不匹配!' 'errmsg' => '节点编码和数值类型不匹配!'
))); )));
$connection -> send($response); $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(); $res = $data_capture -> set_node_data();
if ($res === true) { if ($res === true) {

View File

@@ -51,14 +51,19 @@ class EDataCapture {
if (!$check_func($row -> value)) { if (!$check_func($row -> value)) {
$this -> check_res = 'MISMATCH_TYPE'; $this -> check_res = 'MISMATCH_TYPE';
return; return;
} else { }
if (!isset($row -> device_code)) {
$this -> check_res = 'NO_DEVICE_CODE';
return;
}
$this -> data[$row -> code][] = [ $this -> data[$row -> code][] = [
'value' => $row -> value, 'value' => $row -> value,
'device_code' => $row -> device_code ?? NULL, 'device_code' => $row -> device_code,
'parent_code' => $row -> parent_code ?? NULL,
'batch' => $row -> batch ?? NULL 'batch' => $row -> batch ?? NULL
]; ];
} }
}
unset($row); unset($row);
} }
} }
@@ -78,7 +83,8 @@ class EDataCapture {
"('%s', '%s', '%s', '%s')", "('%s', '%s', '%s', '%s')",
$code, $code,
$row['value'] === false ? 'f' : $row['value'], $row['value'] === false ? 'f' : $row['value'],
$row['device_code'] ?? NULL, $row['device_code'],
$row['parent_code'] ?? NULL,
$row['batch'] ?? NULL $row['batch'] ?? NULL
); );
} }

View File

@@ -38,12 +38,13 @@ class ENodeConfigure {
$res[] = pg_query($this -> dbconn, sprintf( $res[] = pg_query($this -> dbconn, sprintf(
'CREATE TABLE IF NOT EXISTS "%s" ( 'CREATE TABLE IF NOT EXISTS "%s" (
id serial8, id serial8,
code text, code text NOT NULL,
v_string text, v_string text,
v_int int, v_int int,
v_float float8, v_float float8,
v_bool bool, v_bool bool,
device_code text, device_code text NOT NULL,
parent_code text,
batch text, batch text,
capture_time timestamp NOT NULL DEFAULT NOW() capture_time timestamp NOT NULL DEFAULT NOW()
)', $table_name )', $table_name

View File

@@ -32,19 +32,21 @@
{ {
"action": "set_node_data", "action": "set_node_data",
"param": { "param": {
"working_subclass": <string>, "working_subclass": <string>, // 可选
"data": [ "data": [
{ {
"code": <string>, "code": <string>,
// value的类型需与type对应 // value的类型需与type对应
"value": <string | int | float | bool>, "value": <string | int | float | bool>,
"device_code": [string], "device_code": [string], // 必需字段
"batch": [string] "parent_code": [string], // 可选字段对应MES中的code
"batch": [string] // 可选字段
}, },
{ {
"code": <string>, "code": <string>,
"value": <string | int | float | bool>, "value": <string | int | float | bool>,
"device_code": [string], "device_code": [string],
"parent_code": [string],
"batch": [string] "batch": [string]
}, },
... ...