diff --git a/EdgeManager.php b/EdgeManager.php index 05e7ce1..febaa18 100644 --- a/EdgeManager.php +++ b/EdgeManager.php @@ -71,7 +71,7 @@ $worker -> onMessage = function(TcpConnection $connection, Request $request) { else if ($res === "REPLICATED") $connection -> send(json_encode(array( 'code' => 1, - 'msg' => '节点编码不可重复!' + 'msg' => '同一工序单元内的节点编码不可重复!' ))); else if ($res === false) { $connection -> send(json_encode(array( diff --git a/EdgeManager/EDataCapture/EDataCapture.php b/EdgeManager/EDataCapture/EDataCapture.php index c73a3b5..b9b86d8 100644 --- a/EdgeManager/EDataCapture/EDataCapture.php +++ b/EdgeManager/EDataCapture/EDataCapture.php @@ -22,10 +22,12 @@ class EDataCapture { $this -> working_subclass = $this -> post -> param -> working_subclass; } - $res = pg_fetch_all(pg_query($this -> dbconn, + $res = pg_fetch_all(pg_query($this -> dbconn, sprintf( "SELECT code, type - FROM hf_mes_scada_data_capture_node_configure" - )); + FROM hf_mes_scada_data_capture_node_configure + WHERE working_subclass = '%s'", + $this -> post -> param -> working_subclass + ))); $code_type = &$this -> code_type; array_walk($res, function(&$v, $k) use (&$code_type) { diff --git a/EdgeManager/EDataCapture/ENodeConfigure.php b/EdgeManager/EDataCapture/ENodeConfigure.php index eadd182..ba6de1f 100644 --- a/EdgeManager/EDataCapture/ENodeConfigure.php +++ b/EdgeManager/EDataCapture/ENodeConfigure.php @@ -11,8 +11,10 @@ class ENodeConfigure { function add_node() { $exists = pg_query($this -> dbconn, sprintf( "SELECT EXISTS( - SELECT 1 FROM hf_mes_scada_data_capture_node_configure WHERE code='%s' - )", $this -> post -> code + SELECT 1 FROM hf_mes_scada_data_capture_node_configure + WHERE code = '%s' + AND working_subclass = '%s' + )", $this -> post -> code, $this -> post -> working_subclass )); if (pg_fetch_assoc($exists)['exists'] == 't') { return "REPLICATED"; @@ -23,7 +25,7 @@ class ENodeConfigure { $res[] = pg_query($this -> dbconn, sprintf( 'CREATE TABLE IF NOT EXISTS "%s" ( id serial8, - code text references hf_mes_scada_data_capture_node_configure(code), + code text, v_string text, v_int int, v_float float8, diff --git a/EdgeManager/Init.php b/EdgeManager/Init.php index 305926f..baeb86d 100644 --- a/EdgeManager/Init.php +++ b/EdgeManager/Init.php @@ -11,8 +11,8 @@ function init_db($server_name, $user, $password) { // 全局未启用TSDB的时候在这里对scada数据库启用就好 pg_query($dbconn, "CREATE EXTENSION IF NOT EXISTS timescaledb"); pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_data_capture_node_configure ( - id serial2, - code text primary key NOT NULL, + id serial2 primary key, + code text, name text NOT NULL, type text NOT NULL, flow_code text, @@ -21,5 +21,24 @@ function init_db($server_name, $user, $password) { create_date timestamp NOT NULL DEFAULT NOW(), note text )"); + pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_server ( + id serial2 primary key, + code text, + name text NOT NULL, + ip text NOT NULL, + port int2 NOT NULL, + sync_addr text NOT NULL, + create_date timestamp NOT NULL DEFAULT NOW(), + note text + )"); + pg_query($dbconn, "CREATE TABLE IF NOT EXISTS hf_mes_scada_edgeserver_controller_command ( + id serial8 primary key, + server_id serial2 references hf_mes_scada_edgeserver_controller_server(id), + device_id text, + node text, + command text, + create_date timestamp NOT NULL DEFAULT NOW(), + update_status bool + )"); pg_close($dbconn); }