node configure增改接近完成,删除后端还没做
This commit is contained in:
8
app/EDataCapture/EDataCapture.php
Normal file
8
app/EDataCapture/EDataCapture.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace EdgeManager\EDataCapture;
|
||||
|
||||
class EDataCapture {
|
||||
private function set_data() {
|
||||
|
||||
}
|
||||
}
|
||||
64
app/EDataCapture/ENodeConfigure.php
Normal file
64
app/EDataCapture/ENodeConfigure.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace EdgeManager\EDataCapture;
|
||||
|
||||
class ENodeConfigure {
|
||||
function __construct(
|
||||
protected $dbconn,
|
||||
protected $post = NULL,
|
||||
protected $get = NULL
|
||||
) {}
|
||||
|
||||
function add_node() {
|
||||
$table_name = "hf_mes_scada_data_capture_node_data_" . $this -> post['process_code'];
|
||||
|
||||
pg_query($this -> dbconn, "BEGIN");
|
||||
$res1 = pg_query($this -> dbconn, sprintf(
|
||||
"CREATE TABLE IF NOT EXISTS %s(
|
||||
id serial8,
|
||||
code text references hf_mes_scada_data_capture_node_configure(code),
|
||||
v_string text,
|
||||
v_int int,
|
||||
v_float float8,
|
||||
v_bool bool,
|
||||
device_code text,
|
||||
batch text,
|
||||
create_date timestamp
|
||||
)", $table_name
|
||||
));
|
||||
$res2 = pg_insert(
|
||||
$this -> dbconn,
|
||||
'hf_mes_scada_data_capture_node_configure',
|
||||
$this -> post
|
||||
);
|
||||
|
||||
if ($res1 and $res2)
|
||||
pg_query($this -> dbconn, "COMMIT");
|
||||
else
|
||||
pg_query($this -> dbconn, "ROLLBACK");
|
||||
|
||||
pg_query($this -> dbconn, sprintf("SELECT create_hypertable('%s','create_date')", $table_name));
|
||||
pg_query($this -> dbconn, sprintf(
|
||||
"CREATE INDEX ON %s (v_string, v_int, v_float, v_bool, create_date DESC)
|
||||
WHERE COALESCE(v_string, v_int::text, v_float::text, v_bool::text) IS NOT NULL
|
||||
", $table_name
|
||||
));
|
||||
}
|
||||
|
||||
function remove_node() {
|
||||
|
||||
}
|
||||
|
||||
function update_node() {
|
||||
return pg_update(
|
||||
$this -> dbconn,
|
||||
'hf_mes_scada_data_capture_node_configure',
|
||||
$this -> post,
|
||||
['code' => $this -> post['code']]
|
||||
);
|
||||
}
|
||||
|
||||
function get_nodes() {
|
||||
$res = pg_query($this -> dbconn, "SELECT * FROM hf_mes_scada_data_capture_node_configure");
|
||||
return pg_fetch_all($res);
|
||||
}
|
||||
}
|
||||
22
app/Init.php
Normal file
22
app/Init.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
function init_db($server_name, $user, $password) {
|
||||
$dbconn = pg_connect(sprintf("host=%s user=%s password=%s", $server_name, $user, $password));
|
||||
$res = pg_query("select datname from pg_database");
|
||||
if (find_key_value(pg_fetch_assoc($res), 'datname', 'scada'))
|
||||
pg_query("CREATE DATABASE scada");
|
||||
pg_close($dbconn);
|
||||
|
||||
$dbconn = pg_connect(sprintf("host=%s dbname=scada user=%s password=%s", $server_name, $user, $password));
|
||||
pg_query("CREATE TABLE IF NOT EXISTS hf_mes_scada_data_capture_node_configure (
|
||||
id serial2,
|
||||
code text primary key,
|
||||
name text,
|
||||
type text,
|
||||
flow_code text,
|
||||
process_code text,
|
||||
workstation text,
|
||||
create_date timestamp,
|
||||
note text
|
||||
)");
|
||||
pg_close($dbconn);
|
||||
}
|
||||
11
app/Utils.php
Normal file
11
app/Utils.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
function find_key_value($array, $key, $val) {
|
||||
foreach ($array as $item)
|
||||
{
|
||||
if (is_array($item) && find_key_value($item, $key, $val))
|
||||
return true;
|
||||
if (isset($item[$key]) && $item[$key] == $val)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user