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.
335 lines
11 KiB
PHTML
335 lines
11 KiB
PHTML
2 years ago
|
<?php
|
||
|
|
||
|
include('config.henan.inc.php');
|
||
|
|
||
|
$result = array('res' => 0, 'data' => array());
|
||
|
|
||
|
if (!isset($_GET['act']))
|
||
|
{
|
||
|
echo json_encode($result);
|
||
|
exit();
|
||
|
}
|
||
|
$actiontype = $_GET['act'];
|
||
|
if ($actiontype != 'meteo' && $actiontype != 'ice_weight')
|
||
|
{
|
||
|
echo json_encode($result);
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
$latest = (isset($_GET['latest']) && $_GET['latest'] != 0) ? true : false;
|
||
|
if ($latest && $actiontype == 'meteo')
|
||
|
{
|
||
|
unset($_GET['beginTime']);
|
||
|
unset($_GET['endTime']);
|
||
|
}
|
||
|
$exp = ($actiontype == 'ice_weight' && isset($_GET['exp']) && $_GET['exp'] == 'xls');
|
||
|
if ($exp)
|
||
|
{
|
||
|
unset($_GET['p']);
|
||
|
$_GET['ps'] = intval(PHP_INT_MAX / 2);
|
||
|
}
|
||
|
|
||
|
$page = isset($_GET['p']) ? intval($_GET['p']) : 1;
|
||
|
$pageSize = isset($_GET['ps']) ? intval($_GET['ps']) : 20;
|
||
|
if ($pageSize <= 0) $pageSize = 20;
|
||
|
$beginTime = isset($_GET['beginTime']) ? intval($_GET['beginTime']) : 0;
|
||
|
$endTime = isset($_GET['endTime']) ? intval($_GET['endTime']) : 0;
|
||
|
|
||
|
$queryTypes = array('all', 'line', 'tower', 'terminal');
|
||
|
$queryType = isset($_GET['qt']) ? $_GET['qt'] : 'all';
|
||
|
if (!in_array($queryType, $queryTypes))
|
||
|
{
|
||
|
$queryType = 'all';
|
||
|
}
|
||
|
|
||
|
$beginTime = isset($_GET['bt']) ? intval($_GET['bt']) : 0;
|
||
|
$endTime = isset($_GET['et']) ? intval($_GET['et']) : 0;
|
||
|
if ($beginTime > 946656000000) // 2000-1-1 ms to second
|
||
|
{
|
||
|
$beginTime = floor($beginTime / 1000);
|
||
|
}
|
||
|
if ($endTime > 946656000000) // 2000-1-1
|
||
|
{
|
||
|
$endTime = floor($endTime / 1000);
|
||
|
}
|
||
|
|
||
|
$condition = '';
|
||
|
if ($queryType == 'all')
|
||
|
{
|
||
|
if ($beginTime != 0 && $endTime != 0)
|
||
|
{
|
||
|
$condition = 't1.update_time BETWEEN ' . $beginTime . ' AND ' . $endTime;
|
||
|
}
|
||
|
}
|
||
|
else if ($queryType == 'line')
|
||
|
{
|
||
|
$condition = ' t4.`id`=' . intval($_GET['id']);
|
||
|
if ($beginTime != 0 && $endTime != 0)
|
||
|
{
|
||
|
$condition .= ' AND t1.update_time BETWEEN ' . $beginTime . ' AND ' . $endTime;
|
||
|
}
|
||
|
}
|
||
|
else if ($queryType == 'tower')
|
||
|
{
|
||
|
$condition = ' t3.`id`=' . intval($_GET['id']);
|
||
|
if ($beginTime != 0 && $endTime != 0)
|
||
|
{
|
||
|
$condition .= ' AND t1.update_time BETWEEN ' . $beginTime . ' AND ' . $endTime;
|
||
|
}
|
||
|
}
|
||
|
else if ($queryType == 'terminal')
|
||
|
{
|
||
|
if ($latest && $actiontype == 'meteo')
|
||
|
{
|
||
|
$condition = ' t2.`id`=' . intval($_GET['id']);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$condition = ' t1.`term_id`=' . intval($_GET['id']);
|
||
|
}
|
||
|
|
||
|
if ($beginTime != 0 && $endTime != 0)
|
||
|
{
|
||
|
$condition .= ' AND t1.update_time BETWEEN ' . $beginTime . ' AND ' . $endTime;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$tableName = '';
|
||
|
$fields = '';
|
||
|
$joinClause = ' terminals AS t2 ON t1.term_id=t2.`id` JOIN `towers` AS t3 ON t2.tower_id=t3.`id` JOIN `lines` AS t4 ON t3.`line_id`=t4.`id`';
|
||
|
$commonFields = 't2.`id` AS termId,t2.cmdid,t2.phase,t3.name AS towerName,t3.line_id as lineId,t4.name AS lineName,t4.dy_level_id AS dyLevel';
|
||
|
if ($actiontype == 'meteo')
|
||
|
{
|
||
|
$fields = "t1.update_time AS updateTime,t1.`air_temperature` AS temperature,t1.`humidity`,t1.`standard_wind_speed` AS windSpeed,t1.wind_direction AS windDirection,t1.precipitation,t1.air_pressure AS airPressure,t1.radiation_Intensity AS radiationIntensity,t1.avg_wind_speed_1min AS avgWindSpeed1Min,t1.avg_wind_dir_1min AS avgWindDir1Min,t1.avg_wind_speed_10min AS avgWindSpeed10Min,t1.avg_wind_dir_10min AS avgWindDir10Min,t1.max_wind_speed AS maxSpeed10Min";
|
||
|
$tableName = 'weathers';
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$fields = "t1.update_time AS updateTime,t1.func_code AS funcCode, t1.`maxpull_pull` AS maxPull,t1.`maxpull_wind` AS maxPullWind,t1.`maxpull_tilt` AS maxPullTilt,t1.`minpull_pull` AS minPull,t1.`minpull_wind` AS minPullWind,t1.`minpull_tilt` AS minPullTilt,t1.`maxwind_wind` AS maxWind,t1.`maxwind_pull` AS maxWindPull,t1.`maxwind_tilt` AS maxWindTilt,t1.`maxwind_tilt` AS maxWindTilt,t1.`minwind_wind` AS minWind,t1.`minwind_pull` AS minWindPull,t1.`minwind_tilt` AS minWindTilt";
|
||
|
$tableName = 'lead_pulls';
|
||
|
}
|
||
|
|
||
|
if (!empty($condition))
|
||
|
{
|
||
|
$condition = ' WHERE ' . $condition;
|
||
|
}
|
||
|
|
||
|
$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'"
|
||
|
]);
|
||
|
|
||
|
if ($latest && $actiontype == 'meteo')
|
||
|
{
|
||
|
$sql = 'SELECT count(*) AS cnt FROM terminals AS t2 JOIN `towers` AS t3 ON t2.tower_id=t3.`id` JOIN `lines` AS t4 ON t3.`line_id`=t4.`id`';
|
||
|
if (!empty($condition))
|
||
|
{
|
||
|
$sql .= $condition . " AND t2.`status`=1 AND t3.`status`=1 AND t4.`status`=1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$sql .= " WHERE t2.`status`=1 AND t3.`status`=1 AND t4.`status`=1";
|
||
|
}
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
header ('SqlCnt: ' . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$row = $stmt->fetch();
|
||
|
$stmt = null;
|
||
|
if (!$row)
|
||
|
{
|
||
|
header ('SqlCnt: ' . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
$numberOfRows = $row['cnt'];
|
||
|
$numberOfPages = ceil(($numberOfRows + $pageSize - 1) / $pageSize);
|
||
|
if ($page > $numberOfPages)
|
||
|
{
|
||
|
$page = $numberOfPages;
|
||
|
}
|
||
|
|
||
|
$result['page'] = array('page' => 1, 'pageSize' => $pageSize, "totalPages" => $numberOfPages, "totalRecords" => $numberOfRows);
|
||
|
|
||
|
header ('Sql' . $numberOfRows . ': ' . $sql);
|
||
|
|
||
|
if ($numberOfRows > 0)
|
||
|
{
|
||
|
$sql = 'SELECT ' . $commonFields . ' FROM terminals AS t2 JOIN `towers` AS t3 ON t2.tower_id=t3.`id` JOIN `lines` AS t4 ON t3.`line_id`=t4.`id`';
|
||
|
if (!empty($condition))
|
||
|
{
|
||
|
$sql .= $condition . " AND t2.`status`=1 AND t3.`status`=1 AND t4.`status`=1";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$sql .= " WHERE t2.`status`=1 AND t3.`status`=1 AND t4.`status`=1";
|
||
|
}
|
||
|
$sql .= ' LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize;
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
header ('Sql: ' . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$rows = $stmt->fetchAll();
|
||
|
$stmt = null;
|
||
|
if (!$rows)
|
||
|
{
|
||
|
// echo $sql;
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$terms = array();
|
||
|
$termIds = array();
|
||
|
foreach ($rows as $row)
|
||
|
{
|
||
|
$terms[$row['termId']] = $row;
|
||
|
$termIds[] = $row['termId'];
|
||
|
}
|
||
|
|
||
|
$subSql = 'SELECT MAX(t1.id) AS `uid` ' . ' FROM ' . $tableName . ' AS t1 WHERE t1.`term_id` IN(' . implode(',', $termIds) . ') GROUP BY t1.`term_id`';
|
||
|
$sql = 'SELECT t1.`term_id` AS termId,' . $fields . ' FROM ' . $tableName . ' AS t1 JOIN (' . $subSql . ') AS tt ON t1.`id`=tt.`uid` ORDER BY t1.`id` DESC';
|
||
|
|
||
|
header("SQL: " . $sql);
|
||
|
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
$rows = $stmt->fetchAll();
|
||
|
foreach ($rows as $row)
|
||
|
{
|
||
|
$terms[$row['termId']] = array_merge($terms[$row['termId']], $row);
|
||
|
}
|
||
|
|
||
|
$result['data'] = array_values($terms);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$functionCodes = array();
|
||
|
$sql = 'SELECT term_id,func_code,`name` FROM terminal_function_codes';
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
header("SQL: " . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
$rows = $stmt->fetchAll();
|
||
|
foreach ($rows as $row)
|
||
|
{
|
||
|
$functionCodes[$row['term_id']][$row['func_code']] = $row['name'];
|
||
|
}
|
||
|
|
||
|
$sql = 'SELECT count(*) AS cnt FROM ' . $tableName . ' AS t1 JOIN ' . $joinClause . $condition;
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
// echo $sql;
|
||
|
header("SQLCnt: " . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$row = $stmt->fetch();
|
||
|
$stmt = null;
|
||
|
if (!$row)
|
||
|
{
|
||
|
// echo $sql;
|
||
|
header("SQLCnt: " . $sql);
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
// header("SQLCnt: " . $sql);
|
||
|
$numberOfRows = $row['cnt'];
|
||
|
$numberOfPages = ceil(($numberOfRows + $pageSize - 1) / $pageSize);
|
||
|
if ($page > $numberOfPages)
|
||
|
{
|
||
|
$page = $numberOfPages;
|
||
|
}
|
||
|
|
||
|
$result['page'] = array('page' => $page, 'pageSize' => $pageSize, "totalPages" => $numberOfPages, "totalRecords" => $numberOfRows);
|
||
|
$sql = 'SELECT ' . $fields . ',' . $commonFields . ' FROM ' . $tableName . ' AS t1 JOIN ' . $joinClause . $condition . ' ORDER BY t1.`id` DESC LIMIT ' . (($page - 1) * $pageSize) . ',' . $pageSize;
|
||
|
|
||
|
header("SQL: " . $sql);
|
||
|
|
||
|
$stmt = $db->prepare($sql);
|
||
|
$res = $stmt->execute();
|
||
|
if (!$res)
|
||
|
{
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
$result['data'] = $stmt->fetchAll();
|
||
|
|
||
|
foreach ($result['data'] as &$row)
|
||
|
{
|
||
|
$row['funcCodeHex'] = isset($row['funcCode']) ? sprintf('%02X', $row['funcCode']) : '';
|
||
|
|
||
|
if (isset($row['funcCode']) && isset($functionCodes[$row['termId']][$row['funcCode']]))
|
||
|
{
|
||
|
$row['funcCodeName'] = $functionCodes[$row['termId']][$row['funcCode']];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$row['funcCodeName'] = '';
|
||
|
}
|
||
|
|
||
|
if ($exp)
|
||
|
{
|
||
|
$row['updateTime'] = date('Y-m-d H:i:s', $row['updateTime']);
|
||
|
$row['funcCodeName'] .= '(' . $row['funcCodeHex'] . ')';
|
||
|
}
|
||
|
}
|
||
|
unset($row);
|
||
|
}
|
||
|
|
||
|
if ($actiontype == 'ice_weight' && isset($_GET['exp']) && $_GET['exp'] == 'xls')
|
||
|
{
|
||
|
// 监测终端编号 时间 功能单元识别码 最大拉力(Kg) 最大拉力时风偏角(°) 最大拉力时倾斜角(°) 最小拉力(Kg) 最小拉力时风偏角(°) 最小拉力时倾斜角(°) 最大风偏角(°) 最大风偏角时倾斜角(°) 最大风偏角时拉力(Kg) 最小风偏角(°) 最小风偏角时倾斜角(°) 最小风偏角时拉力(Kg)
|
||
|
|
||
|
include ('lib/expxls.inc.php');
|
||
|
|
||
|
$columns = array(
|
||
|
array('name' => 'cmdid', 'title' => '监测终端编号', 'width' => 15),
|
||
|
array('name' => 'updateTime', 'title' => '时间', 'width' => 20),
|
||
|
array('name' => 'funcCodeName', 'title' => '功能单元识别码', 'width' => 16),
|
||
|
array('name' => 'maxPull', 'title' => '最大拉力(Kg)', 'width' => 14),
|
||
|
array('name' => 'maxPullWind', 'title' => '最大拉力时风偏角(°)', 'fmt' => '%0.01f', 'width' => 20),
|
||
|
array('name' => 'maxPullTilt', 'title' => '最大拉力时倾斜角(°)', 'fmt' => '%0.01f', 'width' => 20),
|
||
|
array('name' => 'minPull', 'title' => '最小拉力(Kg)', 'width' => 14),
|
||
|
array('name' => 'minPullWind', 'title' => '最小拉力时风偏角(°)', 'fmt' => '%0.01f', 'width' => 20),
|
||
|
array('name' => 'minPullTilt', 'title' => '最小拉力时倾斜角(°)', 'fmt' => '%0.01f', 'width' => 20),
|
||
|
array('name' => 'maxWind', 'title' => '最大风偏角(°)', 'fmt' => '%0.01f', 'width' => 14),
|
||
|
array('name' => 'maxWindTilt', 'title' => '最大风偏角时倾斜角(°)', 'fmt' => '%0.01f', 'width' => 22),
|
||
|
array('name' => 'maxWindPull', 'title' => '最大风偏角时拉力(Kg)', 'width' => 21),
|
||
|
array('name' => 'minWind', 'title' => '最小风偏角(°)', 'fmt' => '%0.01f', 'width' => 14),
|
||
|
array('name' => 'minWindTilt', 'title' => '最小风偏角时倾斜角(°)', 'fmt' => '%0.01f', 'width' => 22),
|
||
|
array('name' => 'minWindPull', 'title' => '最小风偏角时拉力(Kg)', 'width' => 21)
|
||
|
);
|
||
|
|
||
|
exportOrderExcel($columns, $result['data']);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// header ('Access-Control-Allow-Origin: *');
|
||
|
header ('Content-type: application/json; charset=utf-8');
|
||
|
echo json_encode($result, JSON_UNESCAPED_UNICODE);
|
||
|
}
|