Files
EdgeManager/app/EDataCapture/EDataCapture.php
2022-07-10 22:11:08 +08:00

60 lines
2.0 KiB
PHP

<?php
namespace EdgeManager\EDataCapture;
class EDataCapture {
// 我不主张在构造函数内实现类型检查,因为在请求过于密集、记录较多时会严重影响性能
// 请使用SCADA系统的开发人员自觉遵守文档内规范
function __construct(
protected $dbconn,
protected $post = NULL,
protected $get = NULL
) {}
function set_node_data() {
foreach (array_chunk($this -> post -> param -> data, 6710885, true) as $chunk) {
$sql_head = sprintf(
"INSERT INTO hf_mes_scada_data_capture_node_data_%s (code, v_%s, device_code, batch)
VALUES",
$this -> post -> param -> working_subclass,
$this -> post -> param -> type
);
foreach ($chunk as $row) {
$sql_values[] = sprintf(
"('%s', %s, %s, %s)",
$row -> code,
$row -> value,
$row -> device_code ?? 'DEFAULT',
$row -> batch ?? 'DEFAULT'
);
}
return pg_query($this -> dbconn, $sql_head . implode(',', $sql_values));
}
}
function get_node_data() {
$name_type = pg_fetch_assoc(pg_query($this -> dbconn, sprintf(
"SELECT name, type
FROM hf_mes_scada_data_capture_node_configure
WHERE working_subclass = '%s'
AND code = '%s'",
$this -> get['working_subclass'],
$this -> get['code']
)));
$res = pg_fetch_all(pg_query($this -> dbconn, sprintf(
"SELECT id, v_%s AS value, device_code, batch, capture_time
FROM hf_mes_scada_data_capture_node_data_%s
WHERE code = '%s'",
$name_type['type'],
$this -> get['working_subclass'],
$this -> get['code']
)));
array_walk($res, function(&$v, $k) use ($name_type) {
$v['name'] = $name_type['name'];
});
return $res;
}
}