git лет назад: 2
Родитель
Сommit
ea5f3f3850

+ 4 - 4
Home/Lib/Action/CronAction.class.php

@@ -23,12 +23,12 @@ class CronAction extends Action {
 				echo $tagetDat.PHP_EOL;
 				$datRes = Zmcoding\FtpFile::getInstance($config)->up_file($locDat, $tagetDat);
 				if($datRes){
+					$md5Res = Zmcoding\FtpFile::getInstance($config)->up_file($v,  $targetDir.'/'. $path_parts['basename']);//md5文件
+					if($md5Res){
+						debug_log('upload_info',json_encode($targetDir.'/'. $path_parts['basename'],JSON_UNESCAPED_UNICODE));
+					}
 					debug_log('upload_info',json_encode($tagetDat,JSON_UNESCAPED_UNICODE));
 				}
-				$md5Res = Zmcoding\FtpFile::getInstance($config)->up_file($v,  $targetDir.'/'. $path_parts['basename']);//md5文件
-				if($md5Res){
-					debug_log('upload_info',json_encode($targetDir.'/'. $path_parts['basename'],JSON_UNESCAPED_UNICODE));
-				}
 			}
 			sleep(3);
 		}

+ 1 - 0
Home/Lib/Action/ListeningFileCreateAction.class.php

@@ -68,6 +68,7 @@ class ListeningFileCreateAction extends Action {
 					$res1=str_replace(".dat.redis",".md5",$res);
 					unlink($res);
 					unlink($res1);
+				}
 					
 	}
 	

+ 36 - 19
Home/Lib/Action/RouteRfidKafkaAction.class.php

@@ -10,6 +10,7 @@ class RouteRfidKafkaAction extends Action {
 	private  function addRfidDataToNingbo( $data, $conn ){
 		//{"methond":"track","mac":"ffc10063","gps":{"locationState":"A","lat":0,"latType":"N","lng":0,"lngType":"E"},"labels":[{"id":"01000423","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"160621112931"},{"id":"01000424","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"160621113202"},{"id":"01000422","event":{"dec":20,"lowBattery":0,"entry":1,"leave":0,"in":1},"time":"160621113303"}]}
 		//var_dump($data);
+		
 		if($data['methond']=='login'){
 			return array('success'=>false,'message'=>'addRfidDataToNingbo failed,methond  login!');
 		}
@@ -21,15 +22,17 @@ class RouteRfidKafkaAction extends Action {
 		if(!$device_name){
 			return array('success'=>false,'message'=>'addRfidDataToNingbo failed,station not existed!');
 		}
-		if($data['time']<(time()-180)){
-			$onlinetime=time();
-		}else{
-			$onlinetime=$data['time'];
+		if($data['methond']=='heartbeat'){
+			if( ($data['time']<(time()-3600) ) || ($data['time']>(time()+3600) ) ){
+				$this->debug_log( 'heartbeat_abnormal', $data );
+				return array('success'=>false,'message'=>'heartbeat time abnormal !');
+			}
+			$save_data=array(
+					'online_time'=>date('Y-m-d H:i:s',$onlinetime)
+			);
+			M('stations')->createSave($station_cond,$save_data);
 		}
-		$save_data=array(
-				'online_time'=>date('Y-m-d H:i:s',$onlinetime)
-		);
-		M('stations')->createSave($station_cond,$save_data);
+		
 		if($data['methond']!='track'){
 			return array('success'=>false,'message'=>'addRfidDataToNingbo failed,methond not track!');
 		}
@@ -44,9 +47,14 @@ class RouteRfidKafkaAction extends Action {
 		//oci_execute($stid);
 		//oci_fetch($stid);
 		
-		
+		$updateStationTime=true;
 		
 		foreach($data['labels'] as $val){
+			if( ($val['time']<(time()-3600*24*10) ) || ($val['time']>(time()+3600*24*10) ) ){
+				$updateStationTime=false;
+				$this->debug_log( 'abnormal_labels', $val );
+				continue;
+			}
 			$RF_STAT=0;
 			$plate_no='';
 			if($val['event']['entry']==1){
@@ -55,7 +63,10 @@ class RouteRfidKafkaAction extends Action {
 				$RF_STAT=2;
 			}
 			$RF_FLAGID=strtoupper($val['id']);
-			
+			if($RF_FLAGID=='00000000'){
+				$this->debug_log( 'abnormal_labels', $val );
+				continue;
+			}
 			$RF_DATE=date('Y-m-d H:i:s',$val['time']);
 			$sql = 'INSERT INTO "DSSC2"."W_DW_RF_RECORD"("ID", "RF_ID", "RF_FLAGID", "RF_DATE", "RF_STAT") VALUES (DSSC2.SEQ_W_DW_RF_RECORD.nextval, \''.$RF_ID.'\', \''.$RF_FLAGID.'\', TO_DATE(\''.$RF_DATE.'\', \'SYYYY-MM-DD HH24:MI:SS\'), \''.$RF_STAT.'\')';
 		 	//var_dump($sql); 
@@ -63,9 +74,11 @@ class RouteRfidKafkaAction extends Action {
 			$stid = oci_parse($conn, $sql);
 			
 		   $r = oci_execute($stid);
+			echo 111;
+			throw new \Exception('insert data to oracle false');
 			if(!$r){
 				$this->debug_log( 'insert_oracle_error', $val );
-				throw new \Exception('insert data to oracle false');
+				return array('success'=>false,'message'=>'addRfidDataToNingbo failed,insert_oracle_error!');
 			}
 			
 		
@@ -74,7 +87,7 @@ class RouteRfidKafkaAction extends Action {
 			oci_define_by_name($stid, 'PLATE_NO', $plate_no);
 			oci_execute($stid);
 			oci_fetch($stid);
-			var_dump($plate_no);
+		
 			
 			$handle_data=array(
 				'RF_STAT'=>$RF_STAT,
@@ -95,9 +108,12 @@ class RouteRfidKafkaAction extends Action {
 			//违规行驶检测  超速逆行检测
 			$this->checkIllegalDriving($handle_data);
 		
-			
-		
-		
+		}
+		if($updateStationTime){
+			$save_data=array(
+				'online_time'=>date('Y-m-d H:i:s',time())
+			);
+			M('stations')->createSave($station_cond,$save_data);
 		}
 		
 		oci_free_statement($stid);
@@ -195,8 +211,10 @@ class RouteRfidKafkaAction extends Action {
 						 $data = json_decode($message->payload,true);
 						 if( $data ){
 							
-							$this->addRfidDataToNingbo($data,$conn);
-							
+							$res=$this->addRfidDataToNingbo($data,$conn);
+							if(!$res['success']){
+								echo $res['message'].PHP_EOL;
+							}
 		
 							 //$this->addRfidDataToRenlian($data);
 						 }
@@ -211,7 +229,6 @@ class RouteRfidKafkaAction extends Action {
 					    echo "default break";
 						$this->debug_log( 'default_Log', $message->errstr() );
 						$this->debug_log( 'default_Log', $message->err );
-		            throw new \Exception($message->errstr(), $message->err);
 		            break;
 		    }
 		}
@@ -482,7 +499,7 @@ class RouteRfidKafkaAction extends Action {
 				//$rk->setLogLevel(LOG_DEBUG);
 				$rk->addBrokers(C('KAFKA_BROKER_LIST'));
 				$topic = $rk->newTopic($topic);
-				$res='{"methond":"track","mac":"FF0435EE","gps":{"locationState":"A","lat":0,"latType":"N","lng":0,"lngType":"E"},"labels":[{"id":"0308EC58","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"'.time().'"},{"id":"01000424","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"1667529922"},{"id":"01000422","event":{"dec":20,"lowBattery":0,"entry":1,"leave":0,"in":1},"time":"1667529922"}]}';
+				$res='{"methond":"track","mac":"FF0435EE","gps":{"locationState":"A","lat":0,"latType":"N","lng":0,"lngType":"E"},"labels":[{"id":"0308EC58","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"'.time().'"},{"id":"01000424","event":{"dec":8,"lowBattery":0,"entry":0,"leave":1,"in":0},"time":"1670294864"},{"id":"01000422","event":{"dec":20,"lowBattery":0,"entry":1,"leave":0,"in":1},"time":"1670294864"}]}';
 							
 		
 				$topic->produce(RD_KAFKA_PARTITION_UA, 0,$res);	

+ 9 - 9
Home/Lib/Action/V1Action.class.php

@@ -8,6 +8,7 @@ class V1Action extends Action {
 
  
 	public  function kafka2createFile(  ){
+		ini_set("memory_limit", "1024M");
 		
 		$broker_list = C('KAFKA_BROKER_LIST');
 		
@@ -94,11 +95,12 @@ class V1Action extends Action {
 					$fileName = $localDir . '/HC_' . $createTime . '.dat';
 					$runTime = time() - $timeFram;
 					$sum++;
-					echo $sum . PHP_EOL;
+					//echo $sum . PHP_EOL;
 		
 					if ($runTime < $fileTimeInterval) {
-						if ($sum % 10000 == 0) {
-							echo 'start write routefile...' . PHP_EOL;
+						if ($sum % 50000 == 0) {
+							//echo 'start write routefile...' . PHP_EOL;
+							echo 'locationPack length  ' .strlen($locationPack).PHP_EOL;
 							$datRes = $this->writeRouteFile($fileName, $locationPack);
 							if ($datRes) {
 								$locationPack = '';
@@ -145,9 +147,7 @@ class V1Action extends Action {
 		
 		debug_log('route_info', $data);
 		
-		$writeData = utf8_encode($data);
-		
-		$res = Zmcoding\FtpFile::getInstance($config)->writeFile($fileName, $writeData);
+		$res = Zmcoding\FtpFile::getInstance($config)->writeFile($fileName, $data);
 		
 		return $res;
 	}
@@ -163,14 +163,14 @@ class V1Action extends Action {
 			return false;
 		}
 		$config = C('FTP_CONFIG');
-		$writeData = md5_file($fileName);
+		//$writeData = md5_file($fileName);
 		
 		$pathInfo = pathinfo($fileName);
 		$md5File = $pathInfo['dirname'].'/'.$pathInfo['filename'].'.md5';
 		
-		$writeData = $writeData. '  '. $pathInfo['basename'];
+		//$writeData = $writeData. '  '. $pathInfo['basename'];
 		
-		$res = Zmcoding\FtpFile::getInstance($config)->writeFile($md5File, $writeData);
+		$res = Zmcoding\FtpFile::getInstance($config)->writeFile($md5File, '');
 		
 		return $res;
 	}