luck 4 years ago
parent
commit
8495b45fc0

+ 82 - 669
application/web/controller/IndexController.php

@@ -9,6 +9,7 @@
 // | Author: 小夏 < 449134904@qq.com>
 // +----------------------------------------------------------------------
 namespace app\web\controller;
+
 use think\Db;
 use app\common\plugin\Varbinary;
 use PhpOffice\PhpSpreadsheet\IOFactory;
@@ -16,691 +17,103 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Border;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+
 //产品类
+
 /**
  * @author lyuis
- *	小程序首页相应功能类
+ *    小程序首页相应功能类
  */
 class IndexController extends MainController
 {
-	private $pages=15;
+    private $pages = 15;
 
-	//首页信息
-	public function index(){
-	    //站点信息
-        $primarydev=Db::table('primarydev')->select();
 
+    /*
+     * @name 站点列表
+     *
+     * */
+    public function index()
+    {
+        //站点信息
+        $index = Db::table('primarydev')->select();
 
-        $this->api_return_json(compact('primarydev'),1);
-
-    }
-    //报警设备
-    public function reportdata(){
-        $PRIMARYADDR=$this->request->param('primaryaddr');
-        if($PRIMARYADDR){
-            //报警设备 reportdata
-            $reportdata=Db::table('reportdata')->where(array(array('ALARMENDTIME','=',''),array('PRIMARYADDR','=',$PRIMARYADDR)))->select();
-            $this->api_return_json(compact('reportdata'),1);
+        foreach ($index as $k => &$v) {
+            $res = $this->bd_decrypt($v['DVICLONGITUDE'], $v['DVICLATITUDE']);
+            $v['DVICLONGITUDE'] = $res['gg_lon'];
+            $v['DVICLATITUDE'] = $res['gg_lat'];
         }
 
-        //$this->api_return_json(array('msg'=>'请选择一个站点'));
+        $this->api_return_json(compact('index'), 1);
+
     }
 
+    /*
+     *
+     * @name 报警设备
+     * */
+    public function reportdata()
+    {
+        $PRIMARYADDR = $this->request->param('PRIMARYADDR');
+        if (isset($PRIMARYADDR) && intval($PRIMARYADDR)) {
+            //报警设备 查站点id下的
+            $reportdata = Db::table('reportdata')
+                ->alias('rp')
+                ->where(array(array('rp.ALARMENDTIME', '=', ''), array('rp.PRIMARYADDR', '=', $PRIMARYADDR)))
+                ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
+                ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                ->select();
 
+        } else {
+            //报警设备 查所有
+            $reportdata = Db::table('reportdata')
+                ->alias('rp')
+                ->where(array(array('rp.ALARMENDTIME', '=', '')))
+                ->join('realtimedata rt', 'rt.DEVICEID=rp.DEVICEID and rt.PRIMARYADDR=rp.PRIMARYADDR', 'left')
+                ->field('rp.*,rt.STATUS,rt.LASTTRANSDATE')
+                ->select();
 
+        }
+        $arr = array(1 => '80℃', 2 => '2:100℃', 3 => '130℃');
+        $sta = array('在线', '报警', '不在线', '未配置');
+        foreach ($reportdata as &$v) {
+            $v['TEMPERTHRESHOLD'] = $arr[$v['TEMPERTHRESHOLD']];
+            $v['STATUS'] = $sta[$v['STATUS']];
+            $v['ADDRESS'] = $v['STATIONNAME'] . $v['POWERDISCABNAME'] . $v['CELLNAME'];
+            $v['DEVICENAME']=$v['DEVICENAME']?$v['DEVICENAME']:'未命名';
+        }
+        $this->api_return_json(compact('reportdata'), 1);
+    }
 
-	/**
-	 * 旁路电缆首页接口s
-	 */
-	public function deviceList(){
-		$page=$this->request->param('page',1);
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		$deviceList=Db::name('device')
-		->alias('u')
-		->field('u.DeviceID as id,u.DeviceName as name,u.DeviceType as type,u.DeviceAddress as address,r.TestTime')
-		->join('Result_Last r','r.DeviceID=u.DeviceID','left')
-		->limit(($page-1)*$this->pages,$this->pages)
-		->select();
-		foreach($deviceList as &$v){
-			$v['type_text']=$v['type']==1 ? '电流巡检设备':'温度巡检设备';
-				
-			if(!empty($v['TestTime'])&&strtotime($v['TestTime'])>time()-600)
-				$v['online']=1;
-			else 
-				$v['online']=0;
-		};
-		if(!empty($collect)){
-			if(!is_array($collect))
-				$collect=json_decode($collect,true);
-			$collect_ids=array_column($collect, 'id');
-		}else 
-			$collect_ids=array();
-		foreach ($deviceList as &$val){
-			if(!empty($collect_ids)){
-				if(in_array($val['id'],$collect_ids)){
-					$val['is_collect']=1;
-				}else
-					$val['is_collect']=0;
-				}
-			else 
-				$val['is_collect']=0;
-		}
-		$pages=$this->pages;
-		$user_id=$this->userid;
-		$this->api_return_json(compact('deviceList','pages','collect','user_id'),1);
-	}
-	
-	public function collectDevice(){
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-		$collect=json_decode($collect,true);
-		if(!empty($collect))
-		array_multisort(array_column($collect,'num'), SORT_ASC, $collect);
-		$deviceId=empty($collect) ? array() :array_column($collect, 'id');
-		$collcetDevice=Db::table('Result_Last')->where(array(array('DeviceID','in',$deviceId)))->field('TestTime,DeviceID')->select();
-		foreach($collect as &$val){
-			foreach ($collcetDevice as $v){
-				if($val['id']==$v['DeviceID']){
-					if(!empty($v['TestTime'])&&strtotime($v['TestTime'])>time()-300)
-						$val['online']=1;
-					else
-						$val['online']=0;
-				}
-			}
-			
-		};
-		$user_id=$this->userid;
-		$this->api_return_json(compact('collect','user_id'),1);
-	}
-	
-	//旁路电缆实时数据接口
-	public function dataRealTime(){
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$deviceId=empty($collect) ? array() :array_column($collect, 'id');
-		$deviceName=empty($collect) ? array() :array_column($collect, 'name','id');
-		$dataRealTime=Db::table('Result_Last')
-		->alias('u')
-		->where(array(array('u.DeviceID','in',$deviceId)))
-		->field('u.*,r.DeviceName as name,r.DeviceType as type,(u.Result_1+u.Result_2+u.Result_3)/3 as avg')
-		->join('device r','r.DeviceID=u.DeviceID','left')
-		->order('avg desc')
-		->select();
-		$dianliu=$wendu=array();
-		foreach ($dataRealTime as $key=>&$val){
-			if(!empty($val['TestTime'])&&strtotime($val['TestTime'])<time()-900){
-				unset($dataRealTime[$key]);
-				continue;
-			}
-			$val['Result_1']=sprintf('%.1f',$val['Result_1']);
-			$val['Result_2']=sprintf('%.1f',$val['Result_2']);
-			$val['Result_3']=sprintf('%.1f',$val['Result_3']);
-			$val['Result_4']=sprintf('%.1f',$val['Result_4']);
-			$val['Result_5']=sprintf('%.1f',$val['Result_5']);
-			if(!empty($deviceName[$val['DeviceID']]))
-			$val['name']=$deviceName[$val['DeviceID']];
-			if($val['type']==1)//1电流2温度
-				array_push($dianliu,$val);
-			else{
-				array_push($wendu,$val);
-			}
-		}
-		$dataRealTimes=array($wendu,$dianliu);
-		$data=array();
-		foreach ($dataRealTimes as $key=>$v){
-			if(empty($v))
-				continue;
-			$data[$key][0]=array('name'=>'A相','xAxis'=>array_column($v, 'name'),'resData'=>array_column($v, 'Result_1'));
-			$data[$key][1]=array('name'=>'B相','xAxis'=>array_column($v, 'name'),'resData'=>array_column($v, 'Result_2'));
-			$data[$key][2]=array('name'=>'C相','xAxis'=>array_column($v, 'name'),'resData'=>array_column($v, 'Result_3'));
-		}
-		$tem=array('dianliu0'=>0.1,'dianliu1'=>10,'wendu0'=>50,'wendu1'=>100);
-		if(!file_exists(CMF_ROOT . 'public/userConfig.json'))
-			file_put_contents(CMF_ROOT . 'public/userConfig.json',json_encode($tem),LOCK_EX);
-		$userConfig=file_get_contents(CMF_ROOT . 'public/userConfig.json');
-		$userConfig=empty($userConfig) ? array():json_decode($userConfig,true);
-		$this->api_return_json(compact('dataRealTime','data','userConfig'),1);
-	}
-	
-	public function dataDay(){
-		$device_id=$this->request->param('device_id');
-		$sdate=$this->request->param('sdate');
-		$edate=$this->request->param('edate');
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$elecDeviceId=0;
-		foreach ($collect as $v){
-			if($v['type']==1&&$v['id']!=$device_id)
-				$elecDeviceId=$v['id'];
-		}
-		if(empty($device_id))
-			$this->api_return_json(array('msg'=>'设备参数异常'));
-		if(empty($sdate)||empty($edate))
-			$this->api_return_json(array('msg'=>'时间参数异常'));
-		$type=Db::name('device')->field('DeviceType')->where(array('DeviceId'=>$device_id))->find()['DeviceType'];
-		$where=array(array('DeviceId','=',$device_id),array('TestTime','between',array($sdate,$edate)));
-		$dataDay=Db::name('result_day')
-		->where($where)
-		->order('TestTime asc')
-		->select();
-		foreach ($dataDay as &$val){
-			$val['time']=date('H:i:s',strtotime($val['TestTime']));
-			$val['type']=$type;
-				$val['Result_1']=sprintf('%.1f',$val['Result_1']);
-				$val['Result_2']=sprintf('%.1f',$val['Result_2']);
-				$val['Result_3']=sprintf('%.1f',$val['Result_3']);
-				$val['Result_4']=sprintf('%.1f',$val['Result_4']);
-				$val['Result_5']=sprintf('%.1f',$val['Result_5']);
-		}
-		$data=array();
-		$data['xAxis']=array_column($dataDay, 'time');
-		$data['a']=array_column($dataDay, 'Result_1');
-		$data['b']=array_column($dataDay, 'Result_2');
-		$data['c']=array_column($dataDay, 'Result_3');
-		array_multisort(array_column($dataDay,'ResultID'), SORT_DESC, $dataDay);
-		$elecData=array();
-		if($elecDeviceId){
-			$where=array(array('DeviceId','=',$elecDeviceId),array('TestTime','between',array($sdate,$edate)));
-			$dataDayElec=Db::name('result_day')
-			->where($where)
-			->order('TestTime asc')
-			->select();
-			foreach ($dataDayElec as &$val){
-				$val['time']=date('H:i:s',strtotime($val['TestTime']));
-				$val['type']=1;
-				$val['Result_1']=sprintf('%.1f',$val['Result_1']);
-				$val['Result_2']=sprintf('%.1f',$val['Result_2']);
-				$val['Result_3']=sprintf('%.1f',$val['Result_3']);
-				$val['Result_4']=sprintf('%.1f',$val['Result_4']);
-				$val['Result_5']=sprintf('%.1f',$val['Result_5']);
-			}
-			$elecData['xAxis']=array_column($dataDayElec, 'time');
-			$elecData['a']=array_column($dataDayElec, 'Result_1');
-			$elecData['b']=array_column($dataDayElec, 'Result_2');
-			$elecData['c']=array_column($dataDayElec, 'Result_3');
-		}
-		$tem=array('dianliu0'=>0.1,'dianliu1'=>10,'wendu0'=>50,'wendu1'=>100);
-		if(!file_exists(CMF_ROOT . 'public/userConfig.json'))
-			file_put_contents(CMF_ROOT . 'public/userConfig.json',json_encode($tem),LOCK_EX);
-		$userConfig=file_get_contents(CMF_ROOT . 'public/userConfig.json');
-		$userConfig=empty($userConfig) ? array():json_decode($userConfig,true);
-		$this->api_return_json(compact('dataDay','data','type','elecData','userConfig'),1);
-	}
-	
-	public function dataDevice(){
-		/* $num=$this->request->param('num',1);
-		if(!in_array($num,array(1,2,3)))
-			$this->api_return_json(array('msg'=>'参数异常')); */
-		$item=array(1,2,3);
-		$itemName=array('1'=>'A相','2'=>'B相','3'=>'C相');
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$deviceId=empty($collect) ? array() :array_column($collect, 'id');
-		$deviceName=empty($collect) ? array() :array_column($collect, 'name','id');
-		$deviceType=empty($collect) ? array() :array_column($collect, 'type','id');
-		$xTime=array();
-		$yDevice=array();
-		$dealdata=array();
-		$maxCount=array();
-		$dataDevice=array();
-			foreach ($deviceId as $k=>$v){
-				$where=array(array('DeviceId','=',$v),array('TestTime','between',array(date('Y-m-d'.' 00:00:00'),date('Y-m-d H:i:s'))));
-				$dataDay=Db::name('result_day')
-				->field('Result_1,Result_2,Result_3,Result_5,TestTime')
-				->where($where)
-				->limit(200)
-				->order('TestTime desc')
-				->select();
-				if(empty($dataDay))
-					continue;
-				$itStatus=$this->resReturnStatus($deviceType[$v],array($dataDay[0]['Result_1'],$dataDay[0]['Result_2'],$dataDay[0]['Result_3']));
-				$vStatus=$dataDay[0]['Result_5']<=6.5 ? 1 : 0;
-				$dataTem=array('name'=>$deviceName[$v],'vStatus'=>$vStatus,'itStatus'=>$itStatus,'id'=>$v,'type'=>$deviceType[$v]);
-				array_push($dataDevice,$dataTem);
-				
-				foreach ($item as $i=>$n){
-					array_push($yDevice,$deviceName[$v].$itemName[$n]);
-					
-					$tem=array();
-					foreach ($dataDay as $key=>&$val){
-						if($n==1)
-						$val['TestTime']=strtotime($val['TestTime']);
-						$zVal=sprintf('%.1f',($val['Result_'.$n]));
-						array_push($tem,array(count($dataDay)<200 ? count($dataDay)-1-$key:199-$key,count($yDevice)-1,$zVal));
-					}
-					if($n==1)
-					if(max(array_column($dataDay,'TestTime'))>=(empty($maxCount) ?0 :max(array_column($maxCount,'TestTime')))){
-						$maxCount=$dataDay;
-					}
-					array_push($dealdata,$tem);
-				}
-			}
-			foreach ($maxCount as $vmax){
-				array_unshift($xTime,date('H:i',$vmax['TestTime']));
-			}
-			$lineWidth=5;
-		$this->api_return_json(compact('xTime','yDevice','dealdata','dataDevice','lineWidth'),1);
-	}
-	
-	public function resReturnStatus($type,$data){
-		$tem=array('dianliu0'=>0.1,'dianliu1'=>10,'wendu0'=>50,'wendu1'=>100);
-		if(!file_exists(CMF_ROOT . 'public/userConfig.json')||empty(file_get_contents(CMF_ROOT . 'public/userConfig.json')))
-			file_put_contents(CMF_ROOT . 'public/userConfig.json',json_encode($tem),LOCK_EX);
-		$userConfig=file_get_contents(CMF_ROOT . 'public/userConfig.json');
-		$userConfig=empty($userConfig) ? $tem:json_decode($userConfig,true);
-		if($type==1){
-			//电流设备判断
-			$temData=array();
-			foreach($data as $d){
-				if($d>=$userConfig['dianliu1'])
-					array_push($temData,2);
-				elseif($d>=$userConfig['dianliu0'])
-					array_push($temData,1);
-				else 
-					array_push($temData,0);
-			}
-			return $temData;
-		}else{
-			//温度设备判断
-			$temData=array();
-			foreach($data as $d){
-				if($d>=$userConfig['wendu1'])
-					array_push($temData,2);
-				elseif($d>=$userConfig['wendu0'])
-					array_push($temData,1);
-				else 
-					array_push($temData,0);
-			}
-			return $temData;
-		}
-	}
-	
-	public function dataHistory(){
-		
-		$device_id=$this->request->param('device_id');
-		$sdate=$this->request->param('sdate');
-		$edate=$this->request->param('edate');
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$elecDeviceId=0;
-		foreach ($collect as $v){
-			if($v['type']==1&&$v['id']!=$device_id)
-				$elecDeviceId=$v['id'];
-		}
-		if(empty($device_id))
-			$this->api_return_json(array('msg'=>'设备参数异常'));
-		if(empty($sdate)||empty($edate))
-			$this->api_return_json(array('msg'=>'时间参数异常'));
-		$type=Db::name('device')->field('DeviceType')->where(array('DeviceId'=>$device_id))->find()['DeviceType'];
-		$where=array(array('Device_Id','=',$device_id),array('TestTime_Day','=',date('Y-m-d',strtotime($sdate))));
-		$dataHistorySql=Db::name('result_list')
-		->where($where)
-		->find();
-		$dataHistory=array();
-		$data=array();
-		if(!empty($dataHistorySql)){
-			$dataHistorySql['type']=$type;
-			$dataHistorySql['Result_1']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_1']));
-			$dataHistorySql['Result_2']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_2']));
-			$dataHistorySql['Result_3']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_3']));
-			$dataHistorySql['Result_4']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_4']));
-			$dataHistorySql['Result_5']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_5']));
-			$dataHistorySql['TestTime']=Varbinary::byteArrayTodatetimeArray(($dataHistorySql['TestTime']));
-			foreach ($dataHistorySql['TestTime'] as $key=>$val){
-				if($val<$sdate||$val>$edate)
-					continue;
-				$dataHistoryTmp['Result_1']=$dataHistorySql['Result_1'][$key];
-				$dataHistoryTmp['Result_2']=$dataHistorySql['Result_2'][$key];
-				$dataHistoryTmp['Result_3']=$dataHistorySql['Result_3'][$key];
-				$dataHistoryTmp['Result_4']=$dataHistorySql['Result_4'][$key];;
-				$dataHistoryTmp['Result_5']=$dataHistorySql['Result_5'][$key];;
-				$dataHistoryTmp['time']=$val;
-				$dataHistoryTmp['type']=$type;
-					$dataHistoryTmp['Result_1']=sprintf('%.1f',$dataHistoryTmp['Result_1']);
-					$dataHistoryTmp['Result_2']=sprintf('%.1f',$dataHistoryTmp['Result_2']);
-					$dataHistoryTmp['Result_3']=sprintf('%.1f',$dataHistoryTmp['Result_3']);
-					$dataHistoryTmp['Result_4']=sprintf('%.1f',$dataHistoryTmp['Result_4']);
-					$dataHistoryTmp['Result_5']=sprintf('%.1f',$dataHistoryTmp['Result_5']);
-				$dataHistory[]=$dataHistoryTmp;
-			}
-		$data['xAxis']=array_column($dataHistory, 'time');
-		$data['a']=array_column($dataHistory, 'Result_1');
-		$data['b']=array_column($dataHistory, 'Result_2');
-		$data['c']=array_column($dataHistory, 'Result_3');
-		}
-		array_multisort(array_column($dataHistory,'time'), SORT_DESC, $dataHistory);
-		$elecData=array();
-		if($elecDeviceId){
-			$dataHistoryElec=array();
-			$where=array(array('Device_Id','=',$elecDeviceId),array('TestTime_Day','=',date('Y-m-d',strtotime($sdate))));
-			$dataHistorySqlElec=Db::name('result_list')
-			->where($where)
-			->find();
-			if(!empty($dataHistorySqlElec)){
-				$dataHistorySqlElec['type']=1;
-				$dataHistorySqlElec['Result_1']=Varbinary::byteArrayTofloatArray(($dataHistorySqlElec['Result_1']));
-				$dataHistorySqlElec['Result_2']=Varbinary::byteArrayTofloatArray(($dataHistorySqlElec['Result_2']));
-				$dataHistorySqlElec['Result_3']=Varbinary::byteArrayTofloatArray(($dataHistorySqlElec['Result_3']));
-				$dataHistorySqlElec['Result_4']=Varbinary::byteArrayTofloatArray(($dataHistorySqlElec['Result_4']));
-				$dataHistorySqlElec['Result_5']=Varbinary::byteArrayTofloatArray(($dataHistorySqlElec['Result_5']));
-				$dataHistorySqlElec['TestTime']=Varbinary::byteArrayTodatetimeArray(($dataHistorySqlElec['TestTime']));
-				foreach ($dataHistorySqlElec['TestTime'] as $key=>$val){
-					if($val<$sdate||$val>$edate)
-						continue;
-					$dataHistoryTmpElec['Result_1']=$dataHistorySqlElec['Result_1'][$key];
-					$dataHistoryTmpElec['Result_2']=$dataHistorySqlElec['Result_2'][$key];
-					$dataHistoryTmpElec['Result_3']=$dataHistorySqlElec['Result_3'][$key];
-					$dataHistoryTmpElec['Result_4']=$dataHistorySqlElec['Result_4'][$key];;
-					$dataHistoryTmpElec['Result_5']=$dataHistorySqlElec['Result_5'][$key];;
-					$dataHistoryTmpElec['time']=$val;
-					$dataHistoryTmpElec['type']=$type;
-					$dataHistoryTmpElec['Result_1']=sprintf('%.1f',$dataHistoryTmpElec['Result_1']);
-					$dataHistoryTmpElec['Result_2']=sprintf('%.1f',$dataHistoryTmpElec['Result_2']);
-					$dataHistoryTmpElec['Result_3']=sprintf('%.1f',$dataHistoryTmpElec['Result_3']);
-					$dataHistoryTmpElec['Result_4']=sprintf('%.1f',$dataHistoryTmpElec['Result_4']);
-					$dataHistoryTmpElec['Result_5']=sprintf('%.1f',$dataHistoryTmpElec['Result_5']);
-					$dataHistoryElec[]=$dataHistoryTmpElec;
-				}
-				$elecData['xAxis']=array_column($dataHistoryElec, 'time');
-				$elecData['a']=array_column($dataHistoryElec, 'Result_1');
-				$elecData['b']=array_column($dataHistoryElec, 'Result_2');
-				$elecData['c']=array_column($dataHistoryElec, 'Result_3');
-			}
-		}
-		$tem=array('dianliu0'=>0.1,'dianliu1'=>10,'wendu0'=>50,'wendu1'=>100);
-		if(!file_exists(CMF_ROOT . 'public/userConfig.json'))
-			file_put_contents(CMF_ROOT . 'public/userConfig.json',json_encode($tem),LOCK_EX);
-		$userConfig=file_get_contents(CMF_ROOT . 'public/userConfig.json');
-		$userConfig=empty($userConfig) ? array():json_decode($userConfig,true);
-		$this->api_return_json(compact('dataHistory','data','type','elecData','userConfig'),1);
-	}
-	
-	public function exportDay(){
-		$device_id=$this->request->param('device_id');
-		$sdate=$this->request->param('sdate');
-		$edate=$this->request->param('edate');
-		if(empty($device_id))
-			$this->api_return_json(array('msg'=>'设备参数异常'));
-		if(empty($sdate)||empty($edate))
-			$this->api_return_json(array('msg'=>'时间参数异常'));
-		$type=Db::name('device')->field('DeviceType')->where(array('DeviceId'=>$device_id))->find()['DeviceType'];
-		$where=array(array('DeviceId','=',$device_id),array('TestTime','between',array($sdate,$edate)));
-		$dataDay=Db::name('result_day')
-		->where($where)
-		->order('TestTime asc')
-		->select();
-		foreach ($dataDay as &$val){
-			$val['time']=date('H:i:s',strtotime($val['TestTime']));
-			$val['type']=$type;
-			$val['Result_1']=sprintf('%.1f',$val['Result_1']).($type==1 ? 'A':'℃');
-			$val['Result_2']=sprintf('%.1f',$val['Result_2']).($type==1 ? 'A':'℃');
-			$val['Result_3']=sprintf('%.1f',$val['Result_3']).($type==1 ? 'A':'℃');
-			$val['Result_4']=sprintf('%.1f',$val['Result_4']).($type==1 ? 'V':'℃');
-			$val['Result_5']=sprintf('%.1f',$val['Result_5']).'V';
-		}
-		array_multisort(array_column($dataDay,'ResultID'), SORT_DESC, $dataDay);
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$name='当日数据';
-		foreach ($collect as $v){
-			if($v['id']==$device_id)
-				$name=$v['name'].$name;
-		}
-		$file=$this->export($dataDay,$name,$type);
-		$this->api_return_json(array('path'=>'excel/'.$file,'file_name'=>$file),1);
-	}
-	
-	public function exportHistory(){
-		$device_id=$this->request->param('device_id');
-		$sdate=$this->request->param('sdate');
-		$edate=$this->request->param('edate');
-		if(empty($device_id))
-			$this->api_return_json(array('msg'=>'设备参数异常'));
-		if(empty($sdate)||empty($edate))
-			$this->api_return_json(array('msg'=>'时间参数异常'));
-		$type=Db::name('device')->field('DeviceType')->where(array('DeviceId'=>$device_id))->find()['DeviceType'];
-		$where=array(array('Device_Id','=',$device_id),array('TestTime_Day','=',date('Y-m-d',strtotime($sdate))));
-		$dataHistorySql=Db::name('result_list')
-		->where($where)
-		->find();
-		$dataHistory=array();
-		if(empty($dataHistorySql)){
-			$this->api_return_json(array('msg'=>'历史数据异常'));
-		}
-			$dataHistorySql['type']=$type;
-			$dataHistorySql['Result_1']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_1']));
-			$dataHistorySql['Result_2']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_2']));
-			$dataHistorySql['Result_3']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_3']));
-			$dataHistorySql['Result_4']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_4']));
-			$dataHistorySql['Result_5']=Varbinary::byteArrayTofloatArray(($dataHistorySql['Result_5']));
-			$dataHistorySql['TestTime']=Varbinary::byteArrayTodatetimeArray(($dataHistorySql['TestTime']));
-			foreach ($dataHistorySql['TestTime'] as $key=>$val){
-				if($val<$sdate||$val>$edate)
-					continue;
-				$dataHistoryTmp['Result_1']=$dataHistorySql['Result_1'][$key];
-				$dataHistoryTmp['Result_2']=$dataHistorySql['Result_2'][$key];
-				$dataHistoryTmp['Result_3']=$dataHistorySql['Result_3'][$key];
-				$dataHistoryTmp['Result_4']=$dataHistorySql['Result_4'][$key];;
-				$dataHistoryTmp['Result_5']=$dataHistorySql['Result_5'][$key];;
-				$dataHistoryTmp['time']=$val;
-				$dataHistoryTmp['type']=$type;
-				$dataHistoryTmp['Result_1']=sprintf('%.1f',$dataHistoryTmp['Result_1']).($type==1 ? 'A':'℃');
-				$dataHistoryTmp['Result_2']=sprintf('%.1f',$dataHistoryTmp['Result_2']).($type==1 ? 'A':'℃');
-				$dataHistoryTmp['Result_3']=sprintf('%.1f',$dataHistoryTmp['Result_3']).($type==1 ? 'A':'℃');
-				$dataHistoryTmp['Result_4']=sprintf('%.1f',$dataHistoryTmp['Result_4']).($type==1 ? 'V':'℃');
-				$dataHistoryTmp['Result_5']=sprintf('%.1f',$dataHistoryTmp['Result_5']).'V';
-				$dataHistory[]=$dataHistoryTmp;
-			}
+    /*
+     *
+     * @name 添加设备
+     * */
+    public function addequipment()
+    {
+        $param = $this->request->param();
+        if (!isset($param['PRIMARYADDR']) || empty($param['PRIMARYADDR'])) {
+            $this->api_return_json(array('msg' => '请填写中继器ID'));
+        }
+        if (!isset($param['REPEATERNAME']) || empty($param['REPEATERNAME'])) {
+            $this->api_return_json(array('msg' => '请填写中继器名称'));
+        }
+        if (!isset($param['STATIONNAME']) || empty($param['STATIONNAME'])) {
+            $this->api_return_json(array('msg' => '请填写站点名称'));
+        }
+        if (!isset($param['DVICLONGITUDE']) || empty($param['DVICLONGITUDE'])) {
+            $this->api_return_json(array('msg' => '请填写经度'));
+        }
+        if (!isset($param['DVICLATITUDE']) || empty($param['DVICLATITUDE'])) {
+            $this->api_return_json(array('msg' => '请填写纬度'));
+        }
 
-		array_multisort(array_column($dataHistory,'time'), SORT_DESC, $dataHistory);
-		$collect=empty(file_get_contents(CMF_ROOT . 'public/collect.json')) ? array():json_decode(file_get_contents(CMF_ROOT . 'public/collect.json'),true);
-		if(empty($collect))
-			$collect=array();
-		if(!is_array($collect))
-			$collect=json_decode($collect,true);
-		$name='历史数据';
-		foreach ($collect as $v){
-			if($v['id']==$device_id)
-				$name=$v['name'].$name;
-		}
-		$file=$this->export($dataHistory,$name,$type);
-		$this->api_return_json(array('path'=>'excel/'.$file,'file_name'=>$file),1);
-	}
-	
-	//导出数据
-	public function export($result,$name,$type){//导出Excel
-		set_time_limit(0);
-		$xlsName  = $name;
-		$xlsCell  = array(
-				array('time','时间','20'),//字段,名称,样式,图片
-				array('Result_1','A相'.($type==1 ? '电流':'温度'),'20'),
-				array('Result_2','B相'.($type==1 ? '电流':'温度'),'20'),
-				array('Result_3','C相'.($type==1 ? '电流':'温度'),'20'),
-				array('Result_4',$type==1 ? '充电电压':'地表温度','20'),
-				array('Result_5','电池电压','20')
-	
-		);
-		$file=$this->exportExcel($xlsName,$xlsCell,$result);
-		return $file;
-	}
-	
-	/**
-	 * @param $expTitle 名称
-	 * @param $expCellName 参数
-	 * @param $expTableData 内容
-	 * @throws \PHPExcel_Exception
-	 * @throws \PHPExcel_Reader_Exception
-	 */
-	public function exportExcel($expTitle,$expCellName,$expTableData){
-		set_time_limit(0);
-		$xlsTitle = $expTitle;//iconv('utf-8', 'gb2312', $expTitle);//文件名称
-		$fileName = date('YmdHis');//or $xlsTitle 文件名称可根据自己情况设定
-		$cellNum = count($expCellName);
-		$dataNum = count($expTableData);
-		 
-		$objPHPExcel = new  Spreadsheet();
-		$styleArray = [
-	
-		'borders' => [
-	
-		'allBorders' => [
-	
-		'borderStyle' => Border::BORDER_THIN //细边框
-	
-		]
-	
-		]
-	
-		];
-		$cellName = 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');
-		$cellName=array_slice($cellName, 0,$cellNum);
-		foreach ($cellName as $val){
-			//垂直左右居中
-			$objPHPExcel->setActiveSheetIndex(0)->getStyle($val)->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-			$objPHPExcel->getActiveSheet()->getStyle($val)->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
-			$objPHPExcel->getActiveSheet()->getStyle($val)->getAlignment()->setWrapText(true);
-		}
-		 
-		//        $objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格
-		//         $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle.'  Export time:'.date('Y-m-d H:i:s'));
-		for($i=0;$i<$cellNum;$i++){
-			$objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'1', $expCellName[$i][1]);
-			if(!empty($expCellName[$i][2]))//表示有样式
-				$objPHPExcel->getActiveSheet()->getColumnDimension($cellName[$i])->setWidth($expCellName[$i][2]);
-		}
-		//var_dump($expTableData);exit;
-		// Miscellaneous glyphs, UTF-8
-		for($i=0;$i<$dataNum;$i++){
-			for($j=0;$j<$cellNum;$j++){
-				$objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+2), $expTableData[$i][$expCellName[$j][0]]);
-			}
-		}
-		$objPHPExcel->getActiveSheet()->getStyle('A1:'.$cellName[$cellNum-1].'1')->applyFromArray($styleArray);
-		$objWriter=new Xlsx($objPHPExcel);
-		$file=$xlsTitle.'.xlsx';
-		$objWriter->save(CMF_ROOT . 'public/upload/excel/'.$file);
-		return $file;
-	}
-	
-	
-	
-	public function checkTime($ar){
-		$current=(int)date('H')*60+(int)date('i');
-		if(count($ar)!=4)
-			return false;
-		$ar_begin=explode(':',$ar[0]);
-		$ar_end=explode(':',$ar[1]);
-		$b=intval($ar_begin[0])*60+intval($ar_begin[1]);
-		$e=intval($ar_end[0])*60+intval($ar_end[1]);
-	
-		$ar_begin_1=explode(':',$ar[2]);
-		$ar_end_1=explode(':',$ar[3]);
-		$b_1=intval($ar_begin_1[0])*60+intval($ar_begin_1[1]);
-		$e_1=intval($ar_end_1[0])*60+intval($ar_end_1[1]);
-	
-		if($current>=$b&&$current<=$e)
-			return true;
-		else if($current>=$b_1&&$current<=$e_1)
-			return true;
-		return false;
-	}
-	
-	/**
-	 * 视频时间处理时分秒
-	 */
-	protected static function videoTimeDeal($time){
-		if($time<=60)
-			return $time.'秒';
-		elseif($time<3600)
-			return intval($time/60).'分'.$time%60 .'秒';
-		else
-			return intval($time/3600).'时'.intval(($time%3600)/60).'分'.($time%3600)%60 .'秒';
-	}
-	
-	public function shouzimu(){
-		echo $this->Getzimu($this->request->param('str'));
-	}
-	
-	public function Getzimu($str)
-	{
-		if(empty($str)){return '';}
-	
-		$fchar=ord($str{0});
-	
-		if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{0});
-	
-		$s1=iconv('UTF-8','gb2312',$str);
-	
-		$s2=iconv('gb2312','UTF-8',$s1);
-	
-		$s=$s2==$str?$s1:$str;
-	
-		$asc=ord($s{0})*256+ord($s{1})-65536;
-	
-		if($asc>=-20319&&$asc<=-20284) return 'A';
-	
-		if($asc>=-20283&&$asc<=-19776) return 'B';
-	
-		if($asc>=-19775&&$asc<=-19219) return 'C';
-	
-		if($asc>=-19218&&$asc<=-18711) return 'D';
-	
-		if($asc>=-18710&&$asc<=-18527) return 'E';
-	
-		if($asc>=-18526&&$asc<=-18240) return 'F';
-	
-		if($asc>=-18239&&$asc<=-17923) return 'G';
-	
-		if($asc>=-17922&&$asc<=-17418) return 'H';
-	
-		if($asc>=-17417&&$asc<=-16475) return 'J';
-	
-		if($asc>=-16474&&$asc<=-16213) return 'K';
-	
-		if($asc>=-16212&&$asc<=-15641) return 'L';
-	
-		if($asc>=-15640&&$asc<=-15166) return 'M';
-	
-		if($asc>=-15165&&$asc<=-14923) return 'N';
-	
-		if($asc>=-14922&&$asc<=-14915) return 'O';
-	
-		if($asc>=-14914&&$asc<=-14631) return 'P';
-	
-		if($asc>=-14630&&$asc<=-14150) return 'Q';
-	
-		if($asc>=-14149&&$asc<=-14091) return 'R';
-	
-		if($asc>=-14090&&$asc<=-13319) return 'S';
-	
-		if($asc>=-13318&&$asc<=-12839) return 'T';
-	
-		if($asc>=-12838&&$asc<=-12557) return 'W';
-	
-		if($asc>=-12556&&$asc<=-11848) return 'X';
-	
-		if($asc>=-11847&&$asc<=-11056) return 'Y';
-	
-		if($asc>=-11055&&$asc<=-10247) return 'Z';
-	
-		return "#";
-	}
+        $res = Db::name('device')->insertGetId($param);
+        if ($res) {
+            $this->api_return_json(array('msg' => '添加成功'), 1);
+        }
+    }
 }
 
+
+

+ 2 - 2
application/web/controller/MainController.php

@@ -46,11 +46,11 @@ class MainController extends Controller
         $action=request()->action();
         $token='lyuis';
         if($token=='lyuis'){
-        	$this->userid=5;
+        	$this->userid=7;
         	return;
         }
 
-        if (end($s) != 'ArController'&& end($s) != 'NotifyController'&& end($s) != 'LoginController' && $module!="admin"&&$action!='login'&&$action!='datarealtime'&&$action!='home' ) {
+        if (end($s) != 'LoginController' && $module!="admin"&&$action!='login'&&$action!='datarealtime'&&$action!='home' ) {
             if(empty($token)){
                 $this->api_return_json(['msg'=>'请先登录。']);
             }

File diff suppressed because it is too large
+ 588 - 555
application/web/controller/UserController.php


+ 1 - 1
public/collect.json

@@ -1 +1 @@
-[{"id":"3","name":"3号接头","type":"2","address":"3","TestTime":"2020-08-15 09:35:00.0000000","ROW_NUMBER":"1","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"3"},{"id":"4","name":"4号接头","type":"2","address":"4","TestTime":"2020-08-15 09:35:00.0000000","ROW_NUMBER":"2","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"4"},{"id":"6","name":"6号接头","type":"2","address":"6","TestTime":"2020-08-15 09:35:00.0000000","ROW_NUMBER":"4","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"6"},{"id":"7","name":"7号接头","type":"2","address":"7","TestTime":"2020-08-17 08:12:00.0000000","ROW_NUMBER":"5","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"7"},{"id":"8","name":"8号接头","type":"2","address":"8","TestTime":"2020-08-17 08:11:00.0000000","ROW_NUMBER":"6","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"8"},{"id":"2","name":"2号接头","type":"2","address":"2","TestTime":"2020-08-17 08:12:00.0000000","ROW_NUMBER":"8","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"2"},{"id":"5","name":"5号接头","type":"2","address":"5","TestTime":"2020-09-07 10:55:00.0000000","ROW_NUMBER":"3","type_text":"温度巡检设备","online":1,"is_collect":0,"num":"5"},{"id":"11","name":"1号电流设备","type":"1","address":"11","TestTime":"2020-09-29 15:51:00.0000000","ROW_NUMBER":"9","type_text":"电流巡检设备","online":1,"is_collect":0,"num":"1"}]
+{"5":["3348"],"6":["3348"],"7":["3349","3348"]}

Some files were not shown because too many files changed in this diff