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.

102 lines
3.5 KiB
PHTML

<?php
include('config.henan.inc.php');
$result = array('code' => 400, 'dataList' => array(), 'dataCount' => 0, 'rTime' => date('Y-m-d H:i:s'));
$actionType = isset($_GET['actiontype']) ? $_GET['actiontype'] : (isset($_GET['actionType']) ? $_GET['actionType'] : '');
if (empty($actionType) || !isset($_GET['beginTime']) || !isset($_GET['endTime']))
{
// print_r($_GET);
// echo "param is wrong";
echo json_encode($result);
exit();
}
// http://localhost/xlinez/api/xpai/xline.php?actiontype=ice_weight&timestamp=17008746439186B579774441C58FB0867FF05C8CE2&beginTime=2023-11-25%2009:00:43&endTime=2023-11-25%2009:10:43
$beginTime = date_parse_from_format("Y-m-d H:i:s", $_GET['beginTime']);
$endTime = date_parse_from_format("Y-m-d H:i:s", $_GET['endTime']);
$beginTime = mktime($beginTime['hour'], $beginTime['minute'], $beginTime['second'], $beginTime['month'], $beginTime['day'], $beginTime['year']);
$endTime = mktime($endTime['hour'], $endTime['minute'], $endTime['second'], $endTime['month'], $endTime['day'], $endTime['year']);
if ($actionType != 'meteo' && $actionType != 'ice_weight')
{
// echo "actiontype is wrong";
echo json_encode($result);
exit();
}
$timestamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : '';
if ($actionType == 'meteo')
{
$sql = "SELECT FROM_UNIXTIME(t1.update_time) AS cupdateTime,t1.`air_temperature` AS ctemperature,t1.`humidity` AS chumidity,t1.`standard_wind_speed` AS cwindSpeed,t1.`avg_wind_dir_10min` AS cwindDirection, t1.radiation_Intensity AS csunshine,t1.precipitation AS crainAmount,t2.cmdid AS cmonitorCode";
$sql .= " FROM weathers AS t1 JOIN terminals AS t2 ON t1.term_id=t2.`id` WHERE t1.update_time BETWEEN " . $beginTime . ' AND ' . $endTime;
}
else
{
$sql = "SELECT FROM_UNIXTIME(t1.update_time) AS cupdateTime,t1.`wind_speed` AS cwindAngle,t1.`maxpull_pull` AS cpull,(t1.`maxpull_pull`+t1.`minpull_pull`)/2 AS cpullAngle,t2.cmdid AS cmonitorCode";
$sql .= " FROM lead_pulls AS t1 JOIN terminals AS t2 ON t1.term_id=t2.`id` WHERE t1.update_time BETWEEN " . $beginTime . ' AND ' . $endTime;
}
$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'"
]);
header("SQL: " . $sql);
$stmt = $db->prepare($sql);
$res = $stmt->execute();
if (!$res)
{
header("SQL: " . $sql);
$result['msg'] = 'error on sql';
echo json_encode($result);
exit();
}
$rows = $stmt->fetchAll();
$stmt = null;
if (!$rows)
{
header("SQL: " . $sql);
$result['msg'] = 'error on fetchall';
echo json_encode($result);
exit();
}
if ($actionType == 'meteo')
{
foreach ($rows as &$row)
{
settype($row['ctemperature'], 'float');
settype($row['chumidity'], 'float');
settype($row['cwindSpeed'], 'float');
settype($row['cwindDirection'], 'float');
settype($row['csunshine'], 'float');
settype($row['crainAmount'], 'float');
}
unset($row);
}
else
{
foreach ($rows as &$row)
{
settype($row['cwindAngle'], 'float');
$row['cice'] = 0;
settype($row['cpull'], 'float');
settype($row['cpullAngle'], 'float');
}
unset($row);
}
$result['dataList'] = $rows;
$result['dataCount'] = count($result['dataList']);
$result['code'] = 0;
$result['msg'] = '请求成功';
// header ('Access-Control-Allow-Origin: *');
header ('Content-type: application/json; charset=utf-8');
echo json_encode($result, JSON_UNESCAPED_UNICODE);