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.
39 lines
1.8 KiB
PHP
39 lines
1.8 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'] : '';
|
|
|
|
if ($_GET['act'] == 'list')
|
|
{
|
|
$lineId = isset($_GET['lineId']) ? intval($_GET['lineId']) : 0;
|
|
|
|
$lineCondtion = $lineId ? ' WHERE t3.`id`=' . $lineId : '';
|
|
$sql = "SELECT t1.id, t1.cmdid,t1.`display_name`,t1.`protocol`,t2.`name` AS tower_name,t3.`name` AS line_name, FROM_UNIXTIME(t4.last_heartbeat) AS last_heartbeat,FROM_UNIXTIME(t4.boot_time) AS boot_time";
|
|
$sql .= ",t4.battery_voltage,t4.op_temperature,t4.battery_capacity,t4.floating_charge,t4.total_working_time,t4.working_time,t4.connection_state,FROM_UNIXTIME(t4.ws_update_time) AS ws_update_time";
|
|
$sql .= " FROM terminals AS t1 JOIN towers AS t2 ON t1.tower_id=t2.id JOIN `lines` AS t3 ON t2.line_id=t3.id";
|
|
$sql .= " LEFT JOIN terminal_status AS t4 ON t1.id=t4.term_id " . $lineCondtion . " ORDER BY t2.line_id,t1.cmdid";
|
|
$stmt = $db->query($sql);
|
|
|
|
$rows = $stmt->fetchAll();
|
|
$result['data'] = $rows;
|
|
$stmt = null;
|
|
}
|
|
else
|
|
{
|
|
$termId = intval($_GET['termid']);
|
|
$stmt = $db->query("SELECT term_id,battery_voltage,op_temperature,battery_capacity,floating_charge,total_working_time,working_time,connection_state,FROM_UNIXTIME(ws_update_time) AS ws_update_time FROM terminal_working_status_history WHERE term_id=" . $termId . " ORDER BY ws_update_time desc LIMIT 100");
|
|
$result['data'] = $stmt->fetchAll();
|
|
|
|
}
|
|
|
|
header ('Content-type: application/json; charset=utf-8');
|
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|