You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
include('config.inc.php');
|
|
|
|
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
|
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
|
|
]);
|
|
// $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE , PDO::FETCH_ASSOC );
|
|
|
|
$result = array('res' => 0, 'data' => array());
|
|
$action = isset($_GET['act']) ? $_GET['act'] : '';
|
|
$lineId = isset($_GET['lineId']) ? intval($_GET['lineId']) : 0;
|
|
|
|
$ts = time() - 86400 * 30;
|
|
$sql = 'SELECT t1.`id`, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name FROM terminals AS t1 JOIN towers AS t2 ON t1.tower_id=t2.id JOIN `lines` AS t3 ON t2.line_id=t3.id';
|
|
if ($lineId != 0)
|
|
{
|
|
$sql .= ' WHERE t2.line_id=' . $lineId;
|
|
}
|
|
$stmt = $db->query($sql);
|
|
$terminals = $stmt->fetchAll();
|
|
|
|
$sql = 'SELECT term_id,battery_voltage,battery_capacity,FROM_UNIXTIME(ws_update_time) AS ws_update_time FROM terminal_working_status_history WHERE term_id=:term_id AND ws_update_time>=' . $ts . ' ORDER BY ws_update_time';
|
|
header('SQL: ' . $sql);
|
|
$stmt = $db->prepare($sql);
|
|
|
|
$values['term_id'] = 0;
|
|
foreach ($terminals as &$terminal)
|
|
{
|
|
|
|
$terminal['records'] = 0;
|
|
$terminal['bc'] = '';
|
|
$terminal['bcTime'] = '';
|
|
$terminal['bv'] = '';
|
|
$terminal['bvTime'] = '';
|
|
$terminal['validBv'] = 0;
|
|
$terminal['lowBv'] = 0;
|
|
$terminal['validBc'] = 0;
|
|
|
|
$values['term_id'] = $terminal['id'];
|
|
$stmt->execute($values);
|
|
$rows = $stmt->fetchAll();
|
|
|
|
foreach ($rows as &$row)
|
|
{
|
|
$terminal['records'] += 1;
|
|
if ($row['battery_voltage'] > 0)
|
|
{
|
|
$terminal['bv'] = $row['battery_voltage'];
|
|
$terminal['bvTime'] = $row['ws_update_time'];
|
|
$terminal['validBv'] += 1;
|
|
if ($row['battery_voltage'] < 13)
|
|
{
|
|
$terminal['lowBv'] += 1;
|
|
}
|
|
}
|
|
|
|
if ($row['battery_capacity'] > 0)
|
|
{
|
|
$terminal['bc'] = $row['battery_capacity'];
|
|
$terminal['bcTime'] = $row['ws_update_time'];
|
|
$terminal['validBc'] += 1;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$result['data'] = $terminals;
|
|
header ('Content-type: application/json; charset=utf-8');
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|