470 lines
17 KiB
PHP
470 lines
17 KiB
PHP
<?php
|
|
session_start();
|
|
if( !defined('IN') ) die('bad request!');
|
|
include_once( AROOT . 'controller' . DS . 'app.class.php');
|
|
header("Content-Type: text/html; charset=utf-8");
|
|
date_default_timezone_set('PRC');
|
|
class stationController extends appController
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
// 发送错误结果集
|
|
public function send_error($number,$msg)
|
|
{
|
|
$obj = array();
|
|
$obj['code'] = intval($number);
|
|
$obj['result'] = $msg;
|
|
|
|
if( g('API_EMBED_MODE') == 1 ){
|
|
return json_encode($obj);
|
|
}else{
|
|
header("Content-Type: application/json");
|
|
die(json_encode($obj));
|
|
}
|
|
}
|
|
|
|
// 发送结果集
|
|
public function send_result($total,$data)
|
|
{
|
|
$obj = array();
|
|
$obj['rows'] = $data;
|
|
// $obj['result'] = 'success';
|
|
$obj['total'] = $total;
|
|
|
|
if( g('API_EMBED_MODE') == 1 ){
|
|
return json_encode($obj);
|
|
}else{
|
|
header("Content-Type: application/json");
|
|
die(json_encode($obj));
|
|
}
|
|
}
|
|
|
|
|
|
// 发送结果集
|
|
public function send_resu($data)
|
|
{
|
|
$obj = array();
|
|
$obj['code'] = 0;
|
|
$obj['message'] = 'success';
|
|
$obj['data'] = $data;
|
|
|
|
if( g('API_EMBED_MODE') == 1 ){
|
|
return json_encode($obj);
|
|
}else{
|
|
header("Content-Type: application/json");
|
|
die(json_encode($obj));
|
|
}
|
|
}
|
|
|
|
//设备类型占比
|
|
public function DeviceTypePie()
|
|
{
|
|
|
|
$default_id = v("id");
|
|
|
|
$project_id = $_SESSION['project_id'];
|
|
|
|
if($_SESSION['project_id'] == '0')
|
|
{
|
|
if(empty($default_id)){
|
|
$sql_deviceType = "select CASE WHEN type = 1 THEN '控制柜' WHEN type = 2 THEN '曝气机' WHEN type = 3 THEN '管网监测' else '摄像头' END as name,count(id) as value from device group by type";
|
|
}else{
|
|
$sql_deviceType = prepare("select CASE WHEN type = 1 THEN '控制柜' WHEN type = 2 THEN '曝气机' WHEN type = 3 THEN '管网监测' else '摄像头' END as name,count(id) as value from device where project_id=?i group by type",array($default_id));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(empty($default_id)){
|
|
$sql_deviceType = prepare("select CASE WHEN type = 1 THEN '控制柜' WHEN type = 2 THEN '曝气机' WHEN type = 3 THEN '管网监测' else '摄像头' END as name,count(id) as value from device where project_id=?i group by type",array($project_id));
|
|
}else{
|
|
$sql_deviceType = prepare("select CASE WHEN type = 1 THEN '控制柜' WHEN type = 2 THEN '曝气机' WHEN type = 3 THEN '管网监测' else '摄像头' END as name,count(id) as value from device where project_id=?i group by type",array($default_id));
|
|
}
|
|
|
|
}
|
|
|
|
$deviceType = get_data($sql_deviceType);
|
|
|
|
return self::send_resu($deviceType);
|
|
}
|
|
|
|
// 场站列表
|
|
public function getDataTable()
|
|
{
|
|
$default_id = v("id");
|
|
$terminal = v("terminal");
|
|
$area = v("area");
|
|
|
|
if($_SESSION['project_id'] == '0')
|
|
{
|
|
|
|
if(empty($default_id))
|
|
{
|
|
if(empty($terminal) && empty($area))
|
|
{
|
|
$sql = "select terminal.id,project.name as project_name,area.note as area,terminal.name as terminal_name,terminal.address,terminal.head,terminal.mobile from terminal,project,area where terminal.project_id=project.id and terminal.area_id = area.id";
|
|
|
|
$data = get_data($sql);
|
|
|
|
$total = count($data);
|
|
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
$terminal_name = $data[$i]['terminal_name'];
|
|
|
|
$sql_1 = prepare("select count(id) from device where type=1 and terminal_id=?i",array($id));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(id) from device where type=2 and terminal_id=?i",array($id));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(id) from device where type=3 and terminal_id=?i",array($id));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(id) from device where type=4 and terminal_id=?i",array($id));
|
|
$count_4 = get_var($sql_4);
|
|
|
|
$data[$i]['terminal'] = $terminal_name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
}
|
|
|
|
}
|
|
else if(empty($terminal) && !empty($area))
|
|
{
|
|
$sql = prepare("select terminal.id,project.name as project_name,area.note as area,terminal.name as terminal_name,terminal.address,terminal.head,terminal.mobile from terminal,project,area where terminal.project_id=project.id and terminal.area_id = area.id and area.note=?s",array($area));
|
|
|
|
$data = get_data($sql);
|
|
|
|
$total = count($data);
|
|
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
$terminal_name = $data[$i]['terminal_name'];
|
|
|
|
$sql_1 = prepare("select count(device.id) from device,terminal where device.type=1 and device.terminal_id=terminal.id and terminal.id=?i and terminal.area=?s",array($id,$area));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(device.id) from device,terminal where device.type=2 and device.terminal_id=terminal.id and terminal.id=?i and terminal.area=?s",array($id,$area));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(device.id) from device,terminal where device.type=3 and device.terminal_id=terminal.id and terminal.id=?i and terminal.area=?s",array($id,$area));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(device.id) from device,terminal where device.type=4 and device.terminal_id=terminal.id and terminal.id=?i and terminal.area=?s",array($id,$area));
|
|
$count_4 = get_var($sql_4);
|
|
|
|
$data[$i]['terminal'] = $terminal_name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
}
|
|
|
|
}
|
|
else if(!empty($terminal) && empty($area))
|
|
{
|
|
$sql = prepare("select terminal.id,project.name as project_name,area.note as area,terminal.name as terminal_name,terminal.address,terminal.head,terminal.mobile from terminal,project,area where terminal.project_id=project.id and terminal.area_id = area.id and terminal.name=?s",array($terminal));
|
|
|
|
$data = get_data($sql);
|
|
|
|
$total = count($data);
|
|
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
$terminal_name = $data[$i]['terminal_name'];
|
|
|
|
$sql_1 = prepare("select count(device.id) from device,terminal where device.type=1 and device.terminal_id=terminal.id and terminal.name=?s",array($terminal));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(device.id) from device,terminal where device.type=2 and device.terminal_id=terminal.id and terminal.name=?s",array($terminal));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(device.id) from device,terminal where device.type=3 and device.terminal_id=terminal.id and terminal.name=?s",array($terminal));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(device.id) from device,terminal where device.type=4 and device.terminal_id=terminal.id and terminal.name=?s",array($terminal));
|
|
$count_4 = get_var($sql_4);
|
|
|
|
$data[$i]['terminal'] = $terminal_name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
}
|
|
|
|
}else{
|
|
$sql = prepare("select terminal.id,project.name as project_name,area.note as area,terminal.name as terminal_name,terminal.address,terminal.head,terminal.mobile from terminal,project,area where terminal.project_id=project.id and terminal.area_id = area.id and terminal.name=?s and area.note=?s",array($terminal,$area));
|
|
|
|
$data = get_data($sql);
|
|
|
|
$total = count($data);
|
|
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
|
|
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
$terminal_name = $data[$i]['terminal_name'];
|
|
|
|
$sql_1 = prepare("select count(device.id) from device,terminal where device.type=1 and device.terminal_id=terminal.id and terminal.name=?s and terminal.area=?s",array($terminal,$area));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(device.id) from device,terminal where device.type=2 and device.terminal_id=terminal.id and terminal.name=?s and terminal.area=?s",array($terminal,$area));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(device.id) from device,terminal where device.type=3 and device.terminal_id=terminal.id and terminal.name=?s and terminal.area=?s",array($terminal,$area));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(device.id) from device,terminal where device.type=4 and device.terminal_id=terminal.id and terminal.name=?s and terminal.area=?s",array($terminal,$area));
|
|
$count_4 = get_var($sql_4);
|
|
|
|
$data[$i]['terminal'] = $terminal_name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
}
|
|
}
|
|
|
|
}else{
|
|
|
|
$sql = prepare("select terminal.id,area.note as area,terminal.name,terminal.address,terminal.head,terminal.mobile,project.name as project_name from terminal,area,project where terminal.project_id=?i and area.id = terminal.area_id and project.id = terminal.project_id",array($default_id));
|
|
$data = get_data($sql);
|
|
$total = count($data);
|
|
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
|
|
$sql_1 = prepare("select count(id) from device where type=1 and project_id=?i and terminal_id=?i",array($default_id,$id));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(id) from device where type=2 and project_id=?i and terminal_id=?i",array($default_id,$id));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(id) from device where type=3 and project_id=?i and terminal_id=?i",array($default_id,$id));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(id) from device where type=4 and project_id=?i and terminal_id=?i",array($default_id,$id));
|
|
$count_4 = get_var($sql_4);
|
|
$data[$i]['terminal'] = $name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
$project_id = $_SESSION['project_id'];
|
|
$sql = prepare("select terminal.id,area.note as area,terminal.name,terminal.address,terminal.head,terminal.mobile,project.name as project_name from terminal,area,project where terminal.project_id=?i and area.id = terminal.area_id and project.id = terminal.project_id",array($project_id));
|
|
$data = get_data($sql);
|
|
$total = count($data);
|
|
for($i=0;$i<$total;$i++)
|
|
{
|
|
|
|
$id = $data[$i]['id'];
|
|
$name = $data[$i]['name'];
|
|
$project_name = $data[$i]['project_name'];
|
|
|
|
$sql_1 = prepare("select count(id) from device where type=1 and project_id=?i and terminal_id=?i",array($project_id,$id));
|
|
$count_1 = get_var($sql_1);
|
|
|
|
$sql_2 = prepare("select count(id) from device where type=2 and project_id=?i and terminal_id=?i",array($project_id,$id));
|
|
$count_2 = get_var($sql_2);
|
|
|
|
$sql_3 = prepare("select count(id) from device where type=3 and project_id=?i and terminal_id=?i",array($project_id,$id));
|
|
$count_3 = get_var($sql_3);
|
|
|
|
$sql_4 = prepare("select count(id) from device where type=4 and project_id=?i and terminal_id=?i",array($project_id,$id));
|
|
$count_4 = get_var($sql_4);
|
|
|
|
$data[$i]['terminal'] = $name;
|
|
$data[$i]['project'] = $project_name;
|
|
$data[$i]['controlBox'] = $count_1;
|
|
$data[$i]['Bqmachine'] = $count_2;
|
|
$data[$i]['Gwdevice'] = $count_3;
|
|
$data[$i]['Camera'] = $count_4;
|
|
}
|
|
}
|
|
|
|
return self::send_result($total,$data);
|
|
}
|
|
|
|
//场站详情列表
|
|
public function detailsDataTable(){
|
|
$id = v("id");
|
|
$sql = prepare("select elec_conductivity_data,elec_resistivity_data,elec_conductivity_tds_data,rainfall_data,rainsnow,level_data,ph_data,ammonia_data,created_at from data where device_id = (select id from device where terminal_id = ?i limit 1) order by created_at desc limit 200",array($id));
|
|
$data = get_data($sql);
|
|
$total = count($data);
|
|
return self::send_result($total,$data);
|
|
}
|
|
|
|
//场站详情折线图
|
|
public function getdatadetailsline(){
|
|
$id = v('id');
|
|
$time = v('time');//周 月 年
|
|
|
|
// $time = '本年';
|
|
switch($time){
|
|
case 'week':
|
|
// 获取当前日期
|
|
$endtime = date('Y-m-d');
|
|
|
|
// 获取当前日期是星期几
|
|
$dayOfWeek = date('N', strtotime($today)) -1;
|
|
|
|
// 计算距离本周一的天数差
|
|
$daysToMonday = $dayOfWeek - 1;
|
|
|
|
// 获取本周星期一的日期
|
|
$starttime = date('Y-m-d', strtotime("-$daysToMonday days", strtotime($endtime)));
|
|
|
|
$weeks = $this -> getDateFromRange($starttime,$endtime);
|
|
//获取指定日期之间的日期
|
|
$times = $this -> getDate($starttime,$endtime);
|
|
$data['times'] = $weeks;
|
|
$start = ' 00:00:00';
|
|
$end = ' 23:59:59';
|
|
for($i=0;$i<count($times);$i++){
|
|
$created_at_start = $times[$i].$start;
|
|
$created_at_end = $times[$i].$end;
|
|
//调控次数
|
|
$sql_event = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count+gate_up_count+gate_down_count) as control_count from data where device_id = (select id from device where terminal_id = ?i limit 1) and created_at >= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end));
|
|
$event = get_var($sql_event);
|
|
$data['event'][] = $event;
|
|
//能耗统计
|
|
$data['plc'][] = 0;
|
|
}
|
|
|
|
break;
|
|
|
|
case 'month':
|
|
// 获取当前日期
|
|
$endtime = date('Y-m-d');
|
|
$starttime = date("Y-m-01");
|
|
//获取指定日期之间的日期
|
|
$times = $this -> getDate($starttime,$endtime);
|
|
$data['times'] = $times;
|
|
$start = ' 00:00:00';
|
|
$end = ' 23:59:59';
|
|
for($i=0;$i<count($times);$i++){
|
|
$created_at_start = $times[$i].$start;
|
|
$created_at_end = $times[$i].$end;
|
|
//调控次数
|
|
$sql_event = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count+gate_up_count+gate_down_count) as control_count from data where device_id = (select id from device where terminal_id = ?i limit 1) and created_at >= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end));
|
|
$event = get_var($sql_event);
|
|
$data['event'][] = $event;
|
|
//能耗统计
|
|
$data['plc'][] = 0;
|
|
}
|
|
break;
|
|
|
|
case 'year':
|
|
// 获取当前日期
|
|
$endtime = date('Y-01-01');
|
|
$starttime = date("Y-12-31");
|
|
$yearmonth = $this -> getYearDate();
|
|
//获取指定日期之间的日期
|
|
// $times = $this -> getYearDate($starttime,$endtime);
|
|
$data['times'] = $yearmonth;
|
|
$start = ' 00:00:00';
|
|
$end = ' 23:59:59';
|
|
for($k=0;$k<12;$k++){
|
|
$firstday = date($yearmonth[$k].'-01', strtotime($date));
|
|
$lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
|
|
$created_at_start = $firstday.$start;
|
|
$created_at_end = $lastday.$end;
|
|
//调控次数
|
|
$sql_event = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count+gate_up_count+gate_down_count) as control_count from data where device_id = (select id from device where terminal_id = ?i limit 1) and created_at >= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end));
|
|
$event = get_var($sql_event);
|
|
$data['event'][] = $event;
|
|
//能耗统计
|
|
$data['plc'][] = 0;
|
|
}
|
|
break;
|
|
|
|
}
|
|
$data['time'] = $time;
|
|
return self::send_resu($data);
|
|
}
|
|
|
|
//获取指定日期是星期几
|
|
public function getDateFromRange($startdate, $enddate){
|
|
$stimestamp = strtotime($startdate);
|
|
$etimestamp = strtotime($enddate);
|
|
$days = ($etimestamp-$stimestamp)/86400+1;//计算日期段内有多少天
|
|
//保存每天日期
|
|
$weekArray = array("日","一","二","三","四","五","六");
|
|
for($i = 0; $i < $days; $i++){
|
|
// $currentDate = date('m月d', $stimestamp+(86400*$i));
|
|
$currentDate_1 = date('Y-m-d', $stimestamp+(86400*$i));
|
|
$currentWeek = "周".$weekArray[date("w",strtotime($currentDate_1))];
|
|
$date[] = $currentWeek;
|
|
}
|
|
return $date;
|
|
}
|
|
|
|
|
|
// 获取指定日期之间的所有日期
|
|
public function getDate($startdate,$enddate){
|
|
$stimestamp = strtotime($startdate);
|
|
$etimestamp = strtotime($enddate);
|
|
// 计算日期段内有多少天
|
|
$days = ($etimestamp-$stimestamp)/86400+1;
|
|
// 保存每天日期
|
|
$date = array();
|
|
for($i=0; $i<$days; $i++){
|
|
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
|
|
}
|
|
return $date;
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取本年的12个月
|
|
*/
|
|
public function getYearDate()
|
|
{
|
|
|
|
for ($i=1; $i < 13; $i++) {
|
|
|
|
$month = date("Y",time())."-".$i;
|
|
|
|
$array[] = date("Y-m",strtotime($month));
|
|
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
} |