You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
9.2 KiB
280 lines
9.2 KiB
<?php
|
|
//error_reporting(0);
|
|
include 'DB.php';
|
|
|
|
class screen
|
|
{
|
|
|
|
private $conn;
|
|
|
|
// DEMO資料處理,418
|
|
private $_demo_imei_arr = ['861577063344498', '861577063351097', '861577063351113', '861577063351741', '861577063351774', '861577063352293',
|
|
'861577063352749', '861577063352871', '861577063352970', '864442060230983', '864442060231551', '864442060231734',
|
|
'864442060239414', '864442060293510', '864442068257731', '864442068361905', '864442068513299', '864442068513380',
|
|
'864442068537074', '864442068537082', '864442068537207', '864442068537884', '864442068537934'];
|
|
|
|
function __construct($config = array())
|
|
{
|
|
$this->conn = new DB();
|
|
}
|
|
|
|
/**
|
|
* 获取梯龄数据
|
|
*/
|
|
function eleage()
|
|
{
|
|
try {
|
|
$sql = 'select id,takecertificatedate from facility';
|
|
$eleageres = $this->conn->getAll($sql);
|
|
$years5 = 0;
|
|
$years10 = 0;
|
|
$years15 = 0;
|
|
$years20 = 0;
|
|
$years20plus = 0;
|
|
foreach ($eleageres as $k => $v) {
|
|
$startdate = date('Y-m-d');
|
|
$enddate = $v['takecertificatedate'];
|
|
if($enddate==NULL ){continue; }
|
|
$second= strtotime($startdate)- strtotime($enddate);
|
|
$days =$second/86400;
|
|
if ($days < 1825) {
|
|
$years5++;
|
|
} elseif (1825 <= $days || $days < 3650) {
|
|
$years10++;
|
|
} elseif (3650 <= $days || $days < 5475) {
|
|
$years15++;
|
|
} elseif (5475 <= $days || $days < 7300) {
|
|
$years20++;
|
|
} else {
|
|
$years20plus++;
|
|
}
|
|
}
|
|
$result['labels'] = ['5年以内', '5-10年', '10-15年', '15-20年', '20年以上'];
|
|
$result['data'] = [];
|
|
array_push($result['data'], $years5, $years10, $years15, $years20, $years20plus);
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
function eleage_v2()
|
|
{
|
|
try {
|
|
$result['labels'] = ['5年以内', '5-10年', '10-15年', '15-20年', '20年以上'];
|
|
$result['data'] = ['33', '337', '79', '90', '201'];
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取区域数据
|
|
*/
|
|
function area()
|
|
{
|
|
try {
|
|
$sql = 'select area from facility ';
|
|
$areas = $this->conn->getAll($sql);
|
|
$area = array_column($areas, 'area');
|
|
$Statistics = array_count_values($area); //统计结果
|
|
$result['labels'] = array_keys($Statistics);
|
|
$data = array_values($Statistics);
|
|
$result['data'] = $data;
|
|
$sumtai = array_sum($data);
|
|
$result['taisum'] = $sumtai;
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
function area_v2()
|
|
{
|
|
try {
|
|
$data = [198, 136, 7, 37, 33, 48, 293, 15, 6, 8, 28];
|
|
$result['labels'] = ["桃園市", "台北市", "宜蘭市", "新竹縣", "新竹市", "高雄市", "新北市", "台南市", "屏東縣", "台中市", "基隆市"];
|
|
$result['data'] = $data;
|
|
$sumtai = array_sum($data);
|
|
$result['taisum'] = $sumtai;
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据imei值获取电梯信息
|
|
*/
|
|
function imei()
|
|
{
|
|
try {
|
|
$imei = $_REQUEST['imei'];
|
|
$sql = "select facilityno,address from facility where imei='$imei'";
|
|
$areas = $this->conn->getRow($sql);
|
|
echo json_encode($areas);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取实时数据
|
|
*/
|
|
function realtimefail_v2()
|
|
{
|
|
try {
|
|
//$sql = 'select * from fault_log where to_days(create_at) = to_days(now()) and (fault_message !=" ") order by id desc';
|
|
//$sql = 'select * from fault_log where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_at) and (fault_message !=" ") order by id desc';
|
|
// 418,先隱藏無電梯編號的
|
|
$demo_imei_str = implode("','", $this->_demo_imei_arr);
|
|
$sql = "select * from fault_log where facilityno <> '' ";//DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_at) ";
|
|
$sql .= "and to_days(now()) - to_days(create_at) <= 60 and (fault_message !=' ') ";
|
|
$sql .= "and imei not in ('".$demo_imei_str."') ";
|
|
$sql .= "and flag not in ('1106', '1202') ";
|
|
$sql .= "and facilityno not like '22TX000140%' ";
|
|
$sql .= "order by id desc";
|
|
$fault_log = $this->conn->getAll($sql);
|
|
for ($x=0; $x<sizeof($fault_log);$x++) {
|
|
$facilityno=$fault_log[$x]['facilityno'];
|
|
$sqldang="select address from facility where facilityno='$facilityno' ";
|
|
$res=$this->conn->getRow($sqldang);
|
|
if($res['address']==null){
|
|
$address='暂无地址';
|
|
}
|
|
else{
|
|
$address=$res['address'];
|
|
}
|
|
$fault_log[$x]['address']= $address;
|
|
}
|
|
|
|
echo json_encode($fault_log);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
function realtimefail()
|
|
{
|
|
try {
|
|
$sql = "select * from fault_log where to_days(now()) - to_days(create_at) <= 60 and (fault_message !=' ') ";
|
|
$sql .= "order by id desc";
|
|
$fault_log = $this->conn->getAll($sql);
|
|
for ($x=0; $x<sizeof($fault_log);$x++) {
|
|
$facilityno=$fault_log[$x]['facilityno'];
|
|
$sqldang="select address from facility where facilityno='$facilityno' ";
|
|
$res=$this->conn->getRow($sqldang);
|
|
if($res['address']==null){
|
|
$address='暂无地址';
|
|
}
|
|
else{
|
|
$address=$res['address'];
|
|
}
|
|
$fault_log[$x]['address']= $address;
|
|
}
|
|
|
|
echo json_encode($fault_log);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 故障类型
|
|
* [ // 数据数组,name 为数据项名称,value 为数据项值
|
|
// {value:4, name:'急停模式停止:4(50%)'},
|
|
// {value:1, name:'運行中急停(安全回路斷路):1(12.5%)'},
|
|
// {value:1, name:'運行時開門:1(12.5%)'},
|
|
// {value:2, name:'門開時運行:2(25%)'}
|
|
// ]
|
|
*/
|
|
function failturetype_v2()
|
|
{
|
|
try {
|
|
$sql = 'select fault_message from fault_log ';
|
|
$demo_imei_str = implode("','", $this->_demo_imei_arr);
|
|
$sql .= "where imei not in ('".$demo_imei_str."') ";
|
|
$sql .= "and flag not in ('1106', '1202') ";
|
|
$fault_messages = $this->conn->getAll($sql);
|
|
$fault_message= array_column($fault_messages, 'fault_message');
|
|
$Statistics = array_count_values(array_filter($fault_message)); //统计结果
|
|
$va = array_values($Statistics);
|
|
$sumt = array_sum($va);
|
|
|
|
$arr=array();
|
|
foreach ($Statistics as $k => $v) {
|
|
$bili=(floor(($v/$sumt)*100)).'%';
|
|
$data=new class{};
|
|
$data->name=$k.':'.$v.'('.$bili.')';
|
|
$data->value=$v;
|
|
array_push($arr,$data);
|
|
}
|
|
$result['data'] = $arr;
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
function failturetype()
|
|
{
|
|
try {
|
|
$sql = 'select fault_message from fault_log ';
|
|
$fault_messages = $this->conn->getAll($sql);
|
|
$fault_message= array_column($fault_messages, 'fault_message');
|
|
$Statistics = array_count_values(array_filter($fault_message)); //统计结果
|
|
$va = array_values($Statistics);
|
|
$sumt = array_sum($va);
|
|
|
|
$arr=array();
|
|
foreach ($Statistics as $k => $v) {
|
|
$bili=(floor(($v/$sumt)*100)).'%';
|
|
$data=new class{};
|
|
$data->name=$k.':'.$v.'('.$bili.')';
|
|
$data->value=$v;
|
|
array_push($arr,$data);
|
|
}
|
|
$result['data'] = $arr;
|
|
echo json_encode($result);
|
|
} catch (Exception $e) {
|
|
die($e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$m = $_REQUEST['m'];
|
|
$screen = new screen();
|
|
if ($m == 'eleage') {
|
|
$screen->eleage();
|
|
}
|
|
if ($m == 'area') {
|
|
$screen->area();
|
|
}
|
|
if ($m == 'imei') {
|
|
$screen->imei();
|
|
}
|
|
if ($m == 'realtimefail') {
|
|
$screen->realtimefail();
|
|
}
|
|
if ($m == 'failturetype') {
|
|
$screen->failturetype();
|
|
}
|
|
// for 418
|
|
if ($m == 'eleage_v2') {
|
|
$screen->eleage_v2();
|
|
}
|
|
if ($m == 'area_v2') {
|
|
$screen->area_v2();
|
|
}
|
|
if ($m == 'realtimefail_v2') {
|
|
$screen->realtimefail_v2();
|
|
}
|
|
if ($m == 'failturetype_v2') {
|
|
$screen->failturetype_v2();
|
|
}
|
|
|
|
?>
|
|
|
|
|