看看代码写的怎么样(非高手勿入)

pythonnohtyp 2019-02-06 09:27:56
如题,请客观评价,新手慎评,因内容字符数量限制,贴出部分源代码
<?php
ini_set('memory_limit','2048M');
set_time_limit(0);
require_once 'include/common.php';
if(!$_user_login) {
if(array_key_exists('ajax',$_GET)) {
echo '{code:1000,msg:"未登录"}';
} else {
header("Location: index.php");
}
exit;
}
$action = isset($_GET['ajax'])?$_GET['ajax']:false;
if($action == 'list') {
$orgid = isset($_REQUEST['orgid'])?$_REQUEST['orgid']:'';
$monitorType = isset($_REQUEST['monitorType'])?$_REQUEST['monitorType']:'';
$area = isset($_REQUEST['area'])?$_REQUEST['area']:'';
$latitude = isset($_REQUEST['latitude'])?$_REQUEST['latitude']:'';
$longitude = isset($_REQUEST['longitude'])?$_REQUEST['longitude']:'';
$distance = isset($_REQUEST['distance'])?$_REQUEST['distance']:'';
$_returnJson = $_api->getMonitor($_token, $orgid, $monitorType,$area,$longitude,$latitude,$distance);
echo json_encode($_returnJson);
exit;
}
if($action == 'getMonitorInfo') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$_returnJson = $_api->getMonitor($_token);
echo json_encode($_returnJson);
exit;
}
if($action == 'realTime') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$_returnJson = $_api->getMonitorSensor($_token, $monitorid);
echo json_encode($_returnJson);
exit;
}
if($action == 'chartData') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$timeType =isset($_REQUEST['monitorid'])?intval($_REQUEST['timeType']):0;
$beginTime = time()-86400*$timeType*$timeType*$timeType;
$endTime = time();
$sersorType = ''; //$_REQUEST['sersorType'];
$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType);
foreach($_returnJson['data']['rows'] as $key=>$item) {
$_returnJson['data']['rows'][$key] = $item;
}
//var_export($_returnJson);
echo json_encode($_returnJson);
exit;
}
if($action == 'timePlay') {
$monitorid = isset($_REQUEST['monitorids'])?$_REQUEST['monitorids']:'';
$timeType = trim($_REQUEST['timeType'])=='天'?3:2;
$beginTime = strtotime($_REQUEST['time']);
$endTime = $beginTime;
$sersorType = isset($_REQUEST['sersorType'])?$_REQUEST['sersorType']:'';
$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType);
$_returnJson['REQUEST'] = $_REQUEST;
//var_export($_returnJson);
echo json_encode($_returnJson);
exit;
}
if($action == 'getMonitorSwitch') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$_returnJson = $_api->getMonitorSwitch($_token, $monitorid);
echo json_encode($_returnJson);
exit;
}
if($action == 'getMonitorCamera') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$_returnJson = $_api->getMonitorCamera($_token, $monitorid);
echo json_encode($_returnJson);
exit;
}
if($action == 'setSwitchName') {
$id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
$switchName = isset($_REQUEST['switchName'])?$_REQUEST['switchName']:'';
$_returnJson = $_api->setSwitchName($_token, $id, $switchName);
echo json_encode($_returnJson);
exit;
}
if($action == 'setSwitchCondition') {
$id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
$comandStatus = trim($_REQUEST['comandStatus']);
$linksensorid = trim($_REQUEST['linksensorid']);
$level = trim($_REQUEST['level']);
$mode = trim($_REQUEST['mode']);
$maxval = trim($_REQUEST['maxval']);
$minval = trim($_REQUEST['minval']);
$tolerance = trim($_REQUEST['tolerance']);
$remark = isset($_REQUEST['id'])?trim($_REQUEST['remark']):'';
$_returnJson = $_api->setSwitchCondition($_token, $id, $comandStatus, $linksensorid, $level, $mode, $maxval, $minval, $tolerance, $remark);
echo json_encode($_returnJson);
exit;
}
if($action == 'setAppointmentControl') {
$id = trim($_REQUEST['id']);
$comandStatus = trim($_REQUEST['comandStatus']);
$beginTime = trim($_REQUEST['beginTime']);
$endTime = trim($_REQUEST['endTime']);
$_returnJson = $_api->setAppointmentControl($_token, $id, $comandStatus, $beginTime, $endTime);
echo json_encode($_returnJson);
exit;
}
if($action == 'setManualControl') {
$id = trim($_REQUEST['id']);
$comandStatus = trim($_REQUEST['comandStatus']);
$_returnJson = $_api->setManualControl($_token, $id, $comandStatus);
echo json_encode($_returnJson);
exit;
}

if($action == 'getMonitorAlarm') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$_returnJson = $_api->getMonitorAlarm($_token, $monitorid);
echo json_encode($_returnJson);
exit;
}
if($action == 'setAlarmCondition') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$linksensorid = trim($_REQUEST['linksensorid']);
$frequency = intval($_REQUEST['frequency']);
$data = array(
'id' => trim($_REQUEST['id']),
'mode' => trim($_REQUEST['mode']),
'maxval' => intval($_REQUEST['maxval']),
'minval' => intval($_REQUEST['minval']),
'frequency' => $frequency?$frequency:300,
'issms' => trim($_REQUEST['issms']),
'smsname' => trim($_REQUEST['smsname']),
'smsvalue' => trim($_REQUEST['smsvalue']),
'isemail' => trim($_REQUEST['isemail']),
'emailname' => trim($_REQUEST['emailname']),
'emailvalue' => trim($_REQUEST['emailvalue']),
'isvideo' => trim($_REQUEST['isvideo']),
'ispic' => trim($_REQUEST['ispic']),
'remark' => trim($_REQUEST['remark']),
);
$_returnJson = $_api->setAlarmCondition($_token, $monitorid, $linksensorid, $data);
echo json_encode($_returnJson);
exit;
}
if($action == 'getMonitorRank') {
$beginTime = strtotime(trim($_REQUEST['beginTime']));
$endTime = strtotime(trim($_REQUEST['endTime'].' 23:59:59'));
$monitorType = '';
$sersorType = trim($_REQUEST['sersorType']);
$asc = trim($_REQUEST['asc']);
$timeType = trim($_REQUEST['timeType']);
$size = trim($_REQUEST['size']);

$tbFields = array(
'name' => '点位',
'area' => '区域',
'address' => '地址',
'sensor' => '参数',
'val' => '值',
'level' => '等级',
);
$_returnJson = $_api->getMonitorRank($_token, $beginTime, $endTime, $monitorType, $sersorType, $asc, $timeType, $size);
$resdd = $_api->getDicData($_token);
$dd = array();
foreach($resdd['data'] as $item) {
$dd[$item['category']][$item['value']] = array('name'=>$item['name'],'value'=>$item['value'],);
}
$rows = array();
$levelDD = $sersorType==10000?$dd['AQILegend']:$dd['Level'.$sersorType];
$levelDD = array_values($levelDD);
$levelDir = (count($levelDD)>1 && $levelDD[0]['value']<$levelDD[1]['value'])?0:1;
foreach($_returnJson['data'] as $item) {
$key = $item['sensorid'];
$sensorName = isset($dd['sensor'][$key])?$dd['sensor'][$key]['name']:($dd['sensorV'][$key]?$dd['sensorV'][$key]['name']:$key);
$sensorUnit = isset($dd['sensorUnit'][$key]) && $dd['sensorUnit'][$key]!='-'?' '.$dd['sensorUnit'][$key]['name']:'';
$item['sensor'] = $sensorName;
$item['level'] = '';
foreach($levelDD as $levelIndex => $levelItem) {
if($levelDir == 1) {
if(($item['val'] <= $levelItem['value'])) {
$item['level'] = $levelItem['name'];
break;
}
} else {
if(($item['val'] >= $levelItem['value'])) {
$item['level'] = $levelItem['name'];
break;
}
}
}
$rows[] = $item;
}
$_returnJson['data'] = array();
$_returnJson['data']['rows'] = $rows;
$_returnJson['data']['fields'] = $tbFields;
if(isset($_REQUEST['page']) && $_REQUEST['page'] == 'export') {
$title = date('Y-m-d',$beginTime).'至'.date('Y-m-d',$endTime).' '.($asc==1?'由低到高':'由高到低');
$_returnJson['data'] = exportExcel($rows, $tbFields, $title);
}
echo json_encode($_returnJson);
exit;
}

if($action == 'monitorData') {
$monitorid = isset($_REQUEST['monitorid'])?$_REQUEST['monitorid']:'';
$timeType = intval($_REQUEST['timeType']);
$beginTime = isset($_REQUEST['beginTime'])?strtotime(trim($_REQUEST['beginTime'])):time()-86400;
$endTime = isset($_REQUEST['endTime'])?strtotime(trim($_REQUEST['endTime'].' 23:59:59')):time();
$sersorType = isset($_REQUEST['sersorType'])?$_REQUEST['sersorType']:'';
$mode = isset($_REQUEST['mode'])?$_REQUEST['mode']:'';
$pollution = isset($_REQUEST['pollution'])?$_REQUEST['pollution']:'';
$AQIOpen = isset($_REQUEST['AQIOpen'])?$_REQUEST['AQIOpen']:'';
$dic = 1;
$size = isset($_REQUEST['size'])?$_REQUEST['size']:-1;
$page = isset($_REQUEST['page'])?intval($_REQUEST['page']):-1;

$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType,$mode,$pollution,$size,$page,1);

$dd = array();
foreach($_returnJson['data']['dickList'] as $item) {
$dd[$item['category']][$item['value']] = array('name'=>$item['name'],'value'=>$item['value'],);
}
$aqiSensor = array("17","18","19","20","21","27","10000","10001","10002","10003","10004");
$aqiSensorF = array("17","18","19","20","21","27","10002","10003","10004");
$tbFields = array(
'time' => '时间',
);
$rows = array();
foreach($_returnJson['data']['rows'] as $key => $item) {
foreach($item as $field => $val) {
$item[$field] = $val=='-9999.99'?'-':$val;
if($field=='10001' && $val!='-') $item[$field] = $dd['sensor'][intval($val)]?$dd['sensor'][intval($val)]['name']:$val;
else if($field=='38' && $val!='-') $item[$field] = $dd['windDir'][intval($val)]?$dd['windDir'][intval($val)]['name']:$val;

if($key == 0) {
if($field == 'time' || $field == 'monitorid') continue;
if($AQIOpen) {
if(!in_array($field,$aqiSensor)) continue;
} else {
if(strstr($field,'f-') || $field=="10001") continue;
}
$sensorName = isset($dd['sensor'][$field])?$dd['sensor'][$field]['name']:(isset($dd['sensorV'][$field])?$dd['sensorV'][$field]['name']:$field);
$sensorUnit = isset($dd['sensorUnit'][$field]) && $dd['sensorUnit'][$field]!='-'?' '.$dd['sensorUnit'][$field]['name']:'';
$tbFields[$field] = $sensorName;//.$sensorUnit;
if(in_array($field,$aqiSensorF)) $tbFields['f-'.$field] = $sensorName.' 分指数';
}
}
$rows[] = $item;
}


...全文
1154 点赞 收藏 18
写回复
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_44665465 2019-03-14
代码规范性问题大吗
回复
EnjoyDay1 2019-02-28
你觉得呢,先不说有没有oop思想,毫无注释。别说高手,新手看了也很难受。
回复
weixin_44665465 2019-02-25
原来的程序是怎么样的
回复
引用 3 楼 xuzuning 的回复:
不怎么样,乱七八糟的 一行注释都没有,看不出你要做什么,无法给出建设性意见
大哥,不能这么直接嘛,这样会打击人的, 其实个人觉得还阔以,如果在加上语法上在严谨一点,在优化一点,注释写的更清晰一点就好了
回复
weixin_44665465 2019-02-20
我水平有限,看不太懂,是有规范性方面的问题吗,影响大不大
回复
Douglas Lee 2019-02-19
高手就不要评价了,代码有点惨不忍睹,看了怕做噩梦,我给你简单优化下部分代码。注意代码的命名规范、关键注释、安全检测、异常处理、重复调用、低耦合的原则!如果能面向OOP开发最好,所有成员封装起来,易于维护和扩展。比如通过继承来实现子承父业,减少代码的冗余,接口规范等。 当然,像这种规模不大的小规模程序面向过程即可。
<?php
require_once 'include/common.php';
if(!$_user_login) {
	exit(header('Location: index.php'));
}
//首先,增加三个请求类方法,也可以封装到静态类中
function req_pos( $name ) {
	return isset($_POST[$name]) ? $_POST[$name] : '';
}
function req_get( $name ) {
	return isset($_GET[$name]) ? $_GET[$name] : '';
}
function req_all($name) {
	return isset($_REQUEST[$name]) ? $_POST[$name] : '';
}
//然后,通过 switch 判断,而不是大量的 if 
switch (req_get('ajax')) {
	//Get and print the result value of api.getMonitor.responseJSON ...
	case 'list': exit(json_encode($_api->getMonitor($_token
			, req_all('orgid')
			, req_all('monitorType')
			, req_all('area')
			, req_all('latitude')
			, req_all('longitude')
			, req_all('distance')
		)));
	case 'getMonitorInfo':
		exit(json_encode($_api->getMonitor($_token)));
	case 'realTime':
		exit(json_encode($_api->getMonitorSensor($_token, req_all('monitorid'))));
	case 'chartData':
		$timestamp = time();
		$_returnJson = $_api->getMonitorData($_token
			, req_all('monitorid')
			, intval(req_all('timeType'))
			, ($timestamp - 86400 * $timeType * $timeType * $timeType) // start time
			, $timestamp // end time
			, req_all('sersorType')
			, '' //pollution
		);
		foreach($_returnJson['data']['rows'] as $key => $item ) {
			$_returnJson['data']['rows'][$key] = $item;
		}
		exit(json_encode($_returnJson));
	case 'timePlay':
		// do something...
	default : exit( 'invalid request' );
}
回复
MK965 2019-02-19
switch的效率比ifelse高太多了
回复
weixin_44665465 2019-02-17
水平不够,有高手给看看学习学习
回复
黄袍披身 2019-02-17
不是高手,看着很累,如果代码里同个变量有多个IF 那我就觉得不是好代码...
回复
猪八不戒 2019-02-16
代码太原生了,不规范,无注释。耦合太高
回复
SHANDIANDIAN 2019-02-15
说实话这么多if 可以用switch 优化,其次 不建议用$_REQUEST
回复
子蛟 2019-02-14
null合并运算符 ?? 应该在7.0已上才支持语法糖吧
回复
天使的恩惠 2019-02-09
就这还新手误入,你可能是对你的实力有误解
回复
无涯大者 2019-02-09
代码缺乏规范,有待夯实基础,加强code...
回复
okgef 2019-02-09
至少在
$action = isset($_GET['ajax'])?$_GET['ajax']:false;
我会用
$action = $_GET['ajax'] ?? null;
回复
xuzuning 2019-02-07
不怎么样,乱七八糟的
一行注释都没有,看不出你要做什么,无法给出建设性意见
回复
pythonnohtyp 2019-02-06
function ecmsExcel($rows, $tbFields, $title, $filename){
	require_once 'include/PHPExcel.php';
	$charColumn = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ','CA','CB','CC','CD','CE','CF','CG','CH','CI','CJ','CK','CL','CM','CN','CO','CP','CQ','CR','CS','CT','CU','CV','CW','CX','CY','CZ');
	$objPHPExcel = new PHPExcel();
	$objPHPExcel->setActiveSheetIndex(0);
	$objPHPExcel->getActiveSheet()->setTitle($title);

	$indexFields = 0;
	foreach($tbFields as $field => $fieldName) {
		$cellName = $charColumn[$indexFields++];
		$objPHPExcel->getActiveSheet()->getColumnDimension($cellName)->setWidth(30);
		//echo $cellName." | ";
	}
	//echo '<br>';

	$indexFields = 0;
	foreach($tbFields as $field => $fieldName) {
		$cellName = $charColumn[$indexFields++].'1';
		$objPHPExcel->getActiveSheet()->setCellValue($cellName, $fieldName);
		//echo "$cellName, $fieldName | ";
	}
	//echo '<br>';

	$line = 1;
	foreach($rows as $key => $item) {
		$indexFields = 0;
		$line++;
		
		foreach($tbFields as $field => $fieldName) {
			$cellName = $charColumn[$indexFields++].$line;
			$cellValue = stripSlashes($item[$field]);
			$objPHPExcel->getActiveSheet()->setCellValue($cellName, "".$cellValue);
			//echo "$cellName, $cellValue | ";
		}
	//echo '<br>';
	}
	
	header("Pragma: public");
	header("Expires: 0");
	header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
	header("Content-Type:application/force-download");
	header("Content-Type:application/vnd.ms-execl");
	header("Content-Type:application/octet-stream");
	header("Content-Type:application/download");;
	header('Content-Disposition:attachment;filename="'.$filename.'"');
	header("Content-Transfer-Encoding:binary");
	//echo $filename;  exit;
	//$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
	//$objWriter->save('php://output');
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	$objWriter->save('php://output');
	exit;
}
回复
pythonnohtyp 2019-02-06
<?php
require_once 'include/common.php';
if(!$_user_login) {
	header("Location: index.php");
	exit;
}

if($_GET['ajax'] == 'list') {
	$orgid = $_REQUEST['orgid'];
	$monitorType = $_REQUEST['monitorType'];
	$area = $_REQUEST['area'];
	$latitude = $_REQUEST['latitude'];
	$longitude = $_REQUEST['longitude'];
	$distance = $_REQUEST['distance'];
	$_returnJson = $_api->getMonitor($_token, $orgid, $monitorType,$area,$longitude,$latitude,$distance);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'getMonitorInfo') {
	$monitorid = $_REQUEST['monitorid'];
	$_returnJson = $_api->getMonitor($_token);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'realTime') {
	$monitorid = $_REQUEST['monitorid'];
	$_returnJson = $_api->getMonitorSensor($_token, $monitorid);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'chartData') {
	$monitorid = $_REQUEST['monitorid'];
	$timeType =intval($_REQUEST['timeType']);
	$beginTime = time()-86400*$timeType*$timeType*$timeType;
	$endTime = time();
	$pollution = '';
	$sersorType = $_REQUEST['sersorType'];
	$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType,$pollution);
	foreach($_returnJson['data']['rows'] as $key=>$item) {
		$_returnJson['data']['rows'][$key] = $item;
	}
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'timePlay') {
	$monitorid = $_REQUEST['monitorids'];
	$timeType =trim($_REQUEST['timeType'])=='天'?3:2;
	$beginTime = strtotime($_REQUEST['time']);
	$endTime = $beginTime;
	$sersorType = '';
	$pollution = '';
	$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType,$pollution);
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'getMonitorSwitch') {
	$monitorid = $_REQUEST['monitorid'];
	$_returnJson = $_api->getMonitorSwitch($_token, $monitorid);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'getMonitorCamera') {
	$monitorid = $_REQUEST['monitorid'];
	$_returnJson = $_api->getMonitorCamera($_token, $monitorid);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setSwitchName') {
	$id = $_REQUEST['id'];
	$switchName = $_REQUEST['switchName'];
	$_returnJson = $_api->setSwitchName($_token, $id, $switchName);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setSwitchCondition') {
	$id = trim($_REQUEST['id']);
	$comandStatus = trim($_REQUEST['comandStatus']);
	$linksensorid = trim($_REQUEST['linksensorid']);
	$level = trim($_REQUEST['level']);
	$mode = trim($_REQUEST['mode']);
	$maxval = trim($_REQUEST['maxval']);
	$minval = trim($_REQUEST['minval']);
	$tolerance = trim($_REQUEST['tolerance']);
	$remark = trim($_REQUEST['remark']);
	$_returnJson = $_api->setSwitchCondition($_token, $id, $comandStatus, $linksensorid, $level, $mode, $maxval, $minval, $tolerance, $remark);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setAppointmentControl') {
	$id = trim($_REQUEST['id']);
	$comandStatus = trim($_REQUEST['comandStatus']);
	$beginTime = trim($_REQUEST['beginTime']);
	$endTime = trim($_REQUEST['endTime']);
	$_returnJson = $_api->setAppointmentControl($_token, $id, $comandStatus, $beginTime, $endTime);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setManualControl') {
	$id = trim($_REQUEST['id']);
	$comandStatus = trim($_REQUEST['comandStatus']);
	$_returnJson = $_api->setManualControl($_token, $id, $comandStatus);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'getMonitorAlarm') {
	$monitorid = trim($_REQUEST['monitorid']);
	$_returnJson = $_api->getMonitorAlarm($_token, $monitorid);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setAlarmCondition') {
	$monitorid = trim($_REQUEST['monitorid']);
	$linksensorid = trim($_REQUEST['linksensorid']);
	$data = array( 
		'id' => trim($_REQUEST['id']),
		'mode' => trim($_REQUEST['mode']),
		'maxval' => trim($_REQUEST['maxval']),
		'minval' => trim($_REQUEST['minval']),
		'frequency' => trim($_REQUEST['frequency']),
		'issms' => trim($_REQUEST['issms']),
		'smsname' => trim($_REQUEST['smsname']),
		'smsvalue' => trim($_REQUEST['smsvalue']),
		'isemail' => trim($_REQUEST['isemail']),
		'emailname' => trim($_REQUEST['emailname']),
		'emailvalue' => trim($_REQUEST['emailvalue']),
		'isvideo' => trim($_REQUEST['isvideo']),
		'ispic' => trim($_REQUEST['ispic']),
		'remark' => trim($_REQUEST['remark']),
	);
	$_returnJson = $_api->setAlarmCondition($_token, $monitorid, $linksensorid, $data);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'getMonitorRank') {
	$beginTime = strtotime(trim($_REQUEST['beginTime']));
	$endTime = strtotime(trim($_REQUEST['endTime']));
	$monitorType = '';
	$sersorType = trim($_REQUEST['sersorType']);
	$asc = trim($_REQUEST['asc']);
	$timeType = trim($_REQUEST['timeType']);
	$size = trim($_REQUEST['size']);
	$_returnJson = $_api->getMonitorRank($_token, $beginTime, $endTime, $monitorType, $sersorType, $asc, $timeType, $size);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'monitorData') {
	$monitorid = $_REQUEST['monitorid'];
	$timeType =intval($_REQUEST['timeType']);
	$beginTime = $_REQUEST['beginTime']?strtotime(trim($_REQUEST['beginTime'])):time()-86400;
	$endTime = $_REQUEST['endTime']?strtotime(trim($_REQUEST['endTime'])):time();
	$sersorType = $_REQUEST['sersorType'];
	$pollution = $_REQUEST['pollution'];
	$size = $_REQUEST['size']?$_REQUEST['size']:-1;
	$page = $_REQUEST['page']?$_REQUEST['page']:-1;
	$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,$sersorType,$pollution,$size,$page);
	//var_export($_returnJson);
	$times = ($endTime-$beginTime)/60;
	if($_returnJson['code']==0) {
		if($timeType == 1) {
			$_returnJson['data']['times'] = intval($times/15);
		} else if($timeType == 2) {
			$_returnJson['data']['times'] = intval($times/60);
		} else if($timeType == 3) {
			$_returnJson['data']['times'] = intval($times/60/24);
		} else if($timeType == 4) {
			$_returnJson['data']['times'] = intval($times/60/24/7);
		} else if($timeType == 5) {
			$_returnJson['data']['times'] = intval($times/60/24/30);
		}
	}
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'monitorPollutionRankRatio') {
	$monitorid = $_REQUEST['monitorid'];
	$timeType =intval($_REQUEST['timeType']);
	$beginTime = $_REQUEST['beginTime']?strtotime(trim($_REQUEST['beginTime'])):time()-86400*30;
	$endTime = $_REQUEST['endTime']?strtotime(trim($_REQUEST['endTime'])):time();
	$_returnJson = $_api->getMonitorPollutionRankRatio($_token, $monitorid, $beginTime, $endTime);
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'monitorMainPollutionRatio') {
	$monitorid = $_REQUEST['monitorid'];
	$timeType =intval($_REQUEST['timeType']);
	$beginTime = $_REQUEST['beginTime']?strtotime(trim($_REQUEST['beginTime'])):time()-86400*30;
	$endTime = $_REQUEST['endTime']?strtotime(trim($_REQUEST['endTime'])):time();
	$_returnJson = $_api->getMonitorMainPollutionRatio($_token, $monitorid, $beginTime, $endTime);
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'monitorDataTongbi') {
	$monitorid = $_REQUEST['monitorid'];
	$sersorType = $_REQUEST['sersorType'];
	$timeType =5;
	$beginTime = strtotime("-3 year");
	$endTime = time();
	$pollution = '';
	$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,'',$pollution);
	$list = array('legend'=>array(),'xAxis'=>array('01月','02月','03月','04月','05月','06月','07月','08月','09月','10月','11月','12月'),'series'=>array(),);
	if($_returnJson['code'] == 0) {
		$data = $_returnJson['data']['rows'];
		foreach($data as $item) {
			$ym = explode('-',$item['time']);
			if(!$list['series'][$ym[0]]) {
				foreach($list['xAxis'] as $mon) {
					$list['series'][$ym[0]][$mon] = 0;
				}
			}
			$list['series'][$ym[0]][$ym[1]] = $item[$sersorType]=='-9999.99'?0:$item[$sersorType];
		}
		foreach($list['series'] as $y=>$items) {
			$list['series'][$y] = array_values($list['series'][$y]);
		}
		$list['legend'] = array_keys($list['series']);
	}
	$_returnJson['data'] = $list;
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'monitorDataHuanbi') {
	$monitorid = $_REQUEST['monitorid'];
	$sersorType = $_REQUEST['sersorType'];
	$timeType =5;
	$beginTime = strtotime("-1 year");
	$endTime = time();
	$pollution = '';
	$_returnJson = $_api->getMonitorData($_token, $monitorid,$timeType,$beginTime,$endTime,'',$pollution);
	$list = array();
	if($_returnJson['code'] == 0) {
		$data = $_returnJson['data']['rows'];
		foreach($data as $item) {
			$list[] = array('time'=>$item['time'],'val'=>$item[$sersorType]=='-999.99'?'0':$item[$sersorType]);
		}
	}
	$_returnJson['data'] = $list;
	//var_export($_returnJson);
	echo json_encode($_returnJson);
	exit;
}

if($_GET['ajax'] == 'getProject') {
	$monitorid = $_REQUEST['monitorid'];
	$_returnJson = $_api->getProject($_token, $monitorid);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'setProject') {
	$_returnJson = $_api->setProject($_token, $_POST);
	echo json_encode($_returnJson);
	exit;
}
if($_GET['ajax'] == 'getAlarmHistoryList') {
	$monitorid = $_REQUEST['monitorid'];
	$alarmType = $_REQUEST['alarmType'];
	$beginTime = $_REQUEST['beginTime']?strtotime(trim($_REQUEST['beginTime'])):time()-86400*30;
	$endTime = $_REQUEST['endTime']?strtotime(trim($_REQUEST['endTime'])):time();
	$size = $_REQUEST['size']?$_REQUEST['size']:10;
	$page = $_REQUEST['page']?$_REQUEST['page']:1;
	$_returnJson = $_api->getAlarmHistoryList($_token, $monitorid, $alarmType, $beginTime, $endTime, $page, $size);
	echo json_encode($_returnJson);
	exit;
}
回复
发帖
Framework
创建于2008-08-27

4243

社区成员

国内外优秀PHP框架讨论学习
申请成为版主
帖子事件
创建了帖子
2019-02-06 09:27
社区公告
暂无公告