|
@@ -146,7 +146,6 @@ class Api extends CatchController
|
|
|
}catch(Exception $e){
|
|
|
debug_log("InAndOUT","抛出异常:".$e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
$text=substr($text,24);
|
|
@@ -162,12 +161,6 @@ class Api extends CatchController
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 清除数据
|
|
|
*
|
|
@@ -206,7 +199,7 @@ class Api extends CatchController
|
|
|
$a=$json_data['a'];
|
|
|
//状态
|
|
|
$status=$json_data['status'];
|
|
|
- //进出
|
|
|
+ //是否形成进出考勤
|
|
|
$in_and_out=$json_data["in_and_out"];
|
|
|
|
|
|
//总数
|
|
@@ -224,22 +217,10 @@ class Api extends CatchController
|
|
|
debug_log("clear_label", $item.':'. "标签信号个数等于超过2个,参与计算");
|
|
|
$frist=$a[0]['dirt'];
|
|
|
$end=$a[$count-1]['dirt'];
|
|
|
+
|
|
|
if($frist!=$end){
|
|
|
- $data_array=[];
|
|
|
- $data_array[]=[
|
|
|
- "label"=>$item,
|
|
|
- 'time'=>$a[$count-1]['time'],
|
|
|
- 'dirt'=> $frist==1?1:2 //1是进 2是出
|
|
|
- ];
|
|
|
- $url_data=[
|
|
|
- "mac"=>$station,
|
|
|
- "data"=>$data_array
|
|
|
- ];
|
|
|
debug_log("clear_label", $item.':'. "标签信号个数等于超过2个,参与计算,得出结果:".$frist);
|
|
|
-
|
|
|
- $dispose->set_time_results($station,$item,$a[$count-1]['time'],$frist==1?1:2);
|
|
|
- $dispose->getRemoteData($url_data);
|
|
|
- debug_log("clear_label","发送给远程".json_encode($url_data));
|
|
|
+ $dispose->network_push($station,$item,$a[$count-1]['time'],$frist==1?1:2);
|
|
|
}else{
|
|
|
debug_log("clear_label", $item.':'. "标签信号个数没有超过2个,全部去清除");
|
|
|
}
|
|
@@ -274,31 +255,12 @@ class Api extends CatchController
|
|
|
|
|
|
if($status['dirt']!=$res){
|
|
|
debug_log("clear_label", $item.':'. "最后一个信号,方向相反,得出结果,清除缓存数据");
|
|
|
- $redis->hdel($key,$item);
|
|
|
- $data_array=[];
|
|
|
- $data_array[]=[
|
|
|
- "label"=>$item,
|
|
|
- 'time'=>$a[$count-1]['time'],
|
|
|
- 'dirt'=> $status['dirt']==1?1:2 //1是进 2是出
|
|
|
- ];
|
|
|
- $url_data=[
|
|
|
- "mac"=>$station,
|
|
|
- "data"=>$data_array
|
|
|
- ];
|
|
|
- //设置key
|
|
|
- $dispose->set_time_results($station,$item,$a[$count-1]['time'],$status['dirt']==1?1:2);
|
|
|
- // debug_log("InAndOUT","得出计算结果:".json_encode($arr));
|
|
|
- debug_log("clear_label","发送给远程".json_encode($url_data));
|
|
|
- //远程推送
|
|
|
- $dispose->getRemoteData($url_data);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ $dispose->network_push($station,$item,$a[$count-1]['time'],$status['dirt']==1?1:2);
|
|
|
+
|
|
|
}else{
|
|
|
//上午不做二次计算
|
|
|
if(empty($in_and_out)){
|
|
|
- //二次生成结果
|
|
|
-
|
|
|
-
|
|
|
$res=$dispose->second_create_direction($station,$item);
|
|
|
if(!empty($res)){
|
|
|
$res_time= $dispose->get_time_results($station,$item);
|
|
@@ -308,24 +270,26 @@ class Api extends CatchController
|
|
|
//判断如果结果超过时间
|
|
|
if($diff_time>10){
|
|
|
debug_log("clear_label", $item.':'. "二次生成进出");
|
|
|
- $data_array=[];
|
|
|
- $data_array[]=[
|
|
|
- "label"=>$item,
|
|
|
- 'time'=>$res['time'],
|
|
|
- 'dirt'=>$res['dirt'],
|
|
|
- ];
|
|
|
- $url_data=[
|
|
|
- "mac"=>$station,
|
|
|
- "data"=>$data_array
|
|
|
- ];
|
|
|
- debug_log("clear_label","二次生成发送给远程".json_encode($url_data));
|
|
|
- //远程推送时间
|
|
|
- $dispose->set_time_results($station,$item,$res['time'],$res['dirt']);
|
|
|
- //远程推送
|
|
|
- $dispose->getRemoteData($url_data);
|
|
|
|
|
|
+ $dispose->network_push($station,$item,$res['time'],$res['dirt']);
|
|
|
}
|
|
|
|
|
|
+ }else{
|
|
|
+ //存入没有生成考勤时的初始防线
|
|
|
+ //获取朝前的最大值
|
|
|
+ //获取朝后的最大值
|
|
|
+ $frontMax= $dispose->get_label_history(4,$station,$item);
|
|
|
+ $backMax= $dispose->get_label_history(5,$station,$item);
|
|
|
+ $records=false;
|
|
|
+ if($status['dirt']==1){
|
|
|
+ $records=$frontMax<65;
|
|
|
+ }
|
|
|
+ if($status['dirt']==2){
|
|
|
+ $records=$backMax<65;
|
|
|
+ }
|
|
|
+ if($records){
|
|
|
+ $dispose->no_check_data($station,$item,$status['dirt'],$a[$count-1]['time'],1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -392,14 +356,6 @@ class Api extends CatchController
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public function redis_to_mysql_parea(){
|
|
|
|
|
|
$ues_redis=Cache::store('redis')->handler();
|
|
@@ -426,40 +382,41 @@ class Api extends CatchController
|
|
|
continue;
|
|
|
}
|
|
|
$text = $this->handleMessage($text, $mac, $time, $ues_redis);
|
|
|
+ }
|
|
|
|
|
|
- // foreach ($jsonData as $k => $v) {
|
|
|
- // $data = json_decode($v, true);
|
|
|
- // $config = $this->selectHash("anbang_four_wire",$data['mac']);
|
|
|
- // if(!$config){
|
|
|
- // $config = [
|
|
|
- // "front" => 70,
|
|
|
- // "behind" => 70,
|
|
|
- // "left" => 70,
|
|
|
- // "right" => 70
|
|
|
- // ];
|
|
|
- // }else{
|
|
|
- // $config = json_decode($config);
|
|
|
- // }
|
|
|
- // $field = "";
|
|
|
- // $infos = $ues_redis->hget("parea_rfidinfos",$field);
|
|
|
- // if(!$infos){
|
|
|
-
|
|
|
- // }
|
|
|
- // //判断进出段
|
|
|
- // //1。当前时间 - 上次时间 > 设定时间
|
|
|
- // if( (time() - $v["time"]) > $setInt ){
|
|
|
- // //推送离开
|
|
|
- // }
|
|
|
- // }
|
|
|
- // sleep(2);
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ public function redis_to_mysql_indoor(){
|
|
|
|
|
|
+ $ues_redis=Cache::store('redis')->handler();
|
|
|
+ $text="";
|
|
|
+ $dispose = new dispose($ues_redis);
|
|
|
+ while(1){
|
|
|
+ $jsonData= $ues_redis->lpop("mqtt_data_indoor4rssi");
|
|
|
+ debug_log("indoor_InAndOUT",'mqtt数据redis'.$jsonData);
|
|
|
+
|
|
|
+ if(!$jsonData){
|
|
|
+ debug_log("indoor_InAndOUT",'mqtt没有数据');
|
|
|
+ sleep(1);
|
|
|
+ continue;
|
|
|
+
|
|
|
+ }
|
|
|
+ // debug_log("InAndOUT",$jsonData);
|
|
|
+ $data=json_decode($jsonData,true);
|
|
|
+ // debug_log("InAndOUT",$data['cnt']);
|
|
|
+ $time=$data['time'];
|
|
|
+ $mac=$data['devId'];
|
|
|
+ $text=$text.$data['cnt'];
|
|
|
+
|
|
|
+ if(strlen($text)<24){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // var_dump("before",microtime());
|
|
|
+ $text = $this->handleMessageIndoor($text, $mac, $time, $ues_redis);
|
|
|
+ // var_dump("after",microtime());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- // //http://47.114.185.186:8115/api/areaReport
|
|
|
-// //{“mac”:”013560”,”data”:[{“label”:”258962f”,”time”:1682317268,”dirt”:2},{“label”:”258962f”,”time”:1682317268,”dirt”:1}]
|
|
|
-// }
|
|
|
|
|
|
//打印日志
|
|
|
public function temporary_label_log(){
|
|
@@ -530,7 +487,7 @@ class Api extends CatchController
|
|
|
// }
|
|
|
|
|
|
|
|
|
- //消息处理
|
|
|
+ //消息处理--重点区域
|
|
|
public function handleMessage($text, $mac, $time, $ues_redis){
|
|
|
while(strlen($text)>=24){
|
|
|
|
|
@@ -679,6 +636,230 @@ class Api extends CatchController
|
|
|
}
|
|
|
return $text ?$text : "";
|
|
|
}
|
|
|
+ //消息处理--室内
|
|
|
+ public function handleMessageIndoor($text, $mac, $time, $ues_redis){
|
|
|
+ while(strlen($text)>=24){
|
|
|
+
|
|
|
+ $da=substr($text,0,24);
|
|
|
+ $t1 = substr($da,8,2)=='00'||substr($da,8,2)=='10'||substr($da,8,2)=='01' ? true:false;
|
|
|
+ $t2 =substr($da,10,6)=="FFFFFF"||substr($da,10,6)=="000000" ?true:false;
|
|
|
+
|
|
|
+ if($t1&&$t2){
|
|
|
+ // var_dump($text);
|
|
|
+ $rfid= substr($da,0,8);
|
|
|
+ $rssi1= hexdec(substr($da,16,2));
|
|
|
+ $rssi2= hexdec(substr($da,18,2));
|
|
|
+ $rssi3= hexdec(substr($da,20,2));
|
|
|
+ $rssi4= hexdec(substr($da,22,2));
|
|
|
+
|
|
|
+ $DA=[
|
|
|
+ 'mac' => $mac,
|
|
|
+ 'label' =>$rfid,
|
|
|
+ 'rssi1' => $rssi1,
|
|
|
+ 'rssi2' => $rssi2,
|
|
|
+ 'rssi3' => $rssi3,
|
|
|
+ 'rssi4' => $rssi4,
|
|
|
+ 'report_time'=>$time
|
|
|
+ ];
|
|
|
+
|
|
|
+ $field = $mac."_".$rfid;
|
|
|
+ $info = $ues_redis->hget("indoor_rfidinfos",$field);
|
|
|
+ debug_log("indoor_InAndOUT","数据:".json_encode($DA,true));
|
|
|
+
|
|
|
+ if($rssi1 ==255 && $rssi2 == 255 && $rssi3 == 255 && $rssi4 == 255){
|
|
|
+ debug_log("indoor_InAndOUT","无效数据:".json_encode($DA,true));
|
|
|
+ }else{
|
|
|
+ if(!$info){
|
|
|
+ $info = [
|
|
|
+ "mac" => $mac,
|
|
|
+ "id" => $rfid,
|
|
|
+ "firs_time" => $time,
|
|
|
+ "time" => $time,
|
|
|
+ "status" => 2,//2出状态,1进状态
|
|
|
+ "rssi" => [
|
|
|
+ [
|
|
|
+ "front" => $rssi1,
|
|
|
+ "behind" => $rssi2,
|
|
|
+ "left" => $rssi3,
|
|
|
+ "right" => $rssi4,
|
|
|
+ "time" => $time
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $ues_redis->hset("indoor_rfidinfos",$field, json_encode($info,true));
|
|
|
+ debug_log("indoor_rfidinfos_redis_set_record","redis更新记录".json_encode($info,true));
|
|
|
+ }else{
|
|
|
+ $info = json_decode($info,true);
|
|
|
+
|
|
|
+ $config = $ues_redis->hget("anbang_four_wire", $info["mac"]);
|
|
|
+
|
|
|
+ if (!$config) {
|
|
|
+ # code...
|
|
|
+ $config = [
|
|
|
+ "front_in" => 80,
|
|
|
+ "behind_in" => 80,
|
|
|
+ "left_in" => 80,
|
|
|
+ "right_in" => 80,
|
|
|
+ "front_out" => 255,
|
|
|
+ "behind_out" => 255,
|
|
|
+ "left_out" => 255,
|
|
|
+ "right_out" => 255,
|
|
|
+ "expInt" => 12,
|
|
|
+ "effSigNum" => 6
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $config = json_decode($config,true);
|
|
|
+ }
|
|
|
+ // var_dump("+++++++++++++++++",$config);
|
|
|
+
|
|
|
+ $info["time"] = $time;
|
|
|
+ $newRssi = [
|
|
|
+ "front" => $rssi1,
|
|
|
+ "behind" => $rssi2,
|
|
|
+ "left" => $rssi3,
|
|
|
+ "right" => $rssi4,
|
|
|
+ "time" => $time
|
|
|
+ ];
|
|
|
+ $rssisArr = $info["rssi"];
|
|
|
+
|
|
|
+ // var_dump("+++++++++++++++++", $time, $newRssi["time"]);
|
|
|
+
|
|
|
+ foreach ($rssisArr as $k => $v) {
|
|
|
+ # code...
|
|
|
+ if( ($time - $v["time"] ) > $config['expInt'] ){
|
|
|
+ unset($rssisArr[$k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // var_dump("+++++++++++++++++",$rssisArr);
|
|
|
+ if(count($rssisArr) == $config['effSigNum']){
|
|
|
+ array_shift($rssisArr);
|
|
|
+ array_push($rssisArr, $newRssi);
|
|
|
+ }else{
|
|
|
+ array_push($rssisArr, $newRssi);
|
|
|
+ }
|
|
|
+
|
|
|
+ $rssisArr =array_values($rssisArr);
|
|
|
+ // var_dump("+++++++++++++++++",$rssisArr);
|
|
|
+ $info["rssi"] = $rssisArr;
|
|
|
+
|
|
|
+ // var_dump("------------",$info["rssi"]);
|
|
|
+
|
|
|
+ $cacCount = count($rssisArr);
|
|
|
+ // if($cacCount > $EFF_SIG_NUM){
|
|
|
+ $sum1 = 0;
|
|
|
+ $sum2 = 0;
|
|
|
+ $sum3 = 0;
|
|
|
+ $sum4 = 0;
|
|
|
+ foreach ($rssisArr as $k => $v) {
|
|
|
+ # code...
|
|
|
+ $sum1 += ($v["front"] == 255 ? 90 : $v["front"]);
|
|
|
+ $sum2 += ($v["behind"] == 255 ? 90 : $v["behind"]);
|
|
|
+ $sum3 += ($v["left"] == 255 ? 90 : $v["left"]);
|
|
|
+ $sum4 += ($v["right"] == 255 ? 90 : $v["right"]);
|
|
|
+ }
|
|
|
+ $info["avg"] = [
|
|
|
+ "front" => number_format( $sum1/$cacCount, 2 ),
|
|
|
+ "behind" => number_format( $sum2/$cacCount, 2 ),
|
|
|
+ "left" => number_format( $sum3/$cacCount, 2 ),
|
|
|
+ "right" => number_format( $sum4/$cacCount, 2 ),
|
|
|
+ ];
|
|
|
+ // var_dump($cacCount, $EFF_SIG_NUM, "dddddddd");
|
|
|
+ if ($cacCount == $config['effSigNum']) {
|
|
|
+ # code...
|
|
|
+ $info = $this->compAndPushIndoor($info ,$config, $ues_redis);
|
|
|
+ }
|
|
|
+ $ues_redis->hset("indoor_rfidinfos",$field, json_encode($info,true));
|
|
|
+
|
|
|
+ debug_log("indoor_rfidinfos_redis_set_record","redis更新记录".json_encode($info,true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $text=substr($text,24);
|
|
|
+ }else{
|
|
|
+ $text=substr($text,1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $text ?$text : "";
|
|
|
+ }
|
|
|
+ //判断进出和推送--室内考勤
|
|
|
+ public function compAndPushIndoor($info, $config, $ues_redis){
|
|
|
+ //标签多,数据多时候,判断完成后放入redis,异步推送,当前暂时直接推
|
|
|
+
|
|
|
+ // $config = $ues_redis->hget("anbang_four_wire", $info["mac"]);
|
|
|
+
|
|
|
+ //{"front_in":44,"front_out":44,"behind_in":50,"behind_out":50,"left_in":55,"left_out":55,"right_out":44,"right_out":44}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $avg = $info['avg'];
|
|
|
+ $status = $info['status'];
|
|
|
+
|
|
|
+ $flagIn = $avg["front"] < $config["front_in"] || $avg["behind"] < $config["behind_in"] || $avg["left"] < $config["left_in"] || $avg["right"] < $config["right_in"];
|
|
|
+ $flagOut = $avg["front"] > $config["front_out"] && $avg["behind"] > $config["behind_out"] && $avg["left"] > $config["left_out"] && $avg["right"] > $config["right_out"];
|
|
|
+
|
|
|
+ $url="http://localhost:8115/api/api/accessClassReport";
|
|
|
+ // $url="http://61.175.203.188:10001/api/accessClassReport";
|
|
|
+ // if($flagIn && $status == 2){
|
|
|
+ if($flagIn){
|
|
|
+ if ($info["pushTime"] && (time()-$info['pushTime']) < 3 ) {
|
|
|
+ # code...
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+ //推送进
|
|
|
+ $info['status'] = 1;
|
|
|
+
|
|
|
+ $url_data = [
|
|
|
+ "mac" => $info["mac"],
|
|
|
+ "data" => [
|
|
|
+ [
|
|
|
+ "label" => $info["id"],
|
|
|
+ "time" => $info["time"],
|
|
|
+ "dirt" => 1,
|
|
|
+ "rssi" => $info["rssi"],//数组 [{"front":72,"behind":255,"left":255,"right":255,"time":1685067709},{"front":76,"behind":255,"left":255,"right":255,"time":1685067710}]
|
|
|
+ "avg" => $info["avg"] //{"front":"77.17","behind":"90.00","left":"90.00","right":"90.00"}
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $ues_redis->lpush("indoor_inoutres_push", json_encode($url_data));
|
|
|
+
|
|
|
+ $info['pushTime'] = time();
|
|
|
+ // debug_log("push_indoor_res","进推送依赖:".json_encode($info));
|
|
|
+ // $url_res= curl_http_post(json_encode($url_data),$url,false);
|
|
|
+ // debug_log("push_indoor_res","远程返回结果".$url_res);
|
|
|
+ }
|
|
|
+ // if($info['id'] == "E2B15AD5"){
|
|
|
+ // var_dump($flagIn, $flagOut, $status, $avg["front"],$avg["behind"],$avg["left"], $avg["right"]);
|
|
|
+ // }
|
|
|
+ if($flagOut && $status == 1){
|
|
|
+ if ($info["pushTime"] && (time()-$info['pushTime']) < 5 ) {
|
|
|
+ # code...
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+ //推送出
|
|
|
+ $info['status'] = 2;
|
|
|
+ $url_data = [
|
|
|
+ "mac" => $info["mac"],
|
|
|
+ "data" => [
|
|
|
+ [
|
|
|
+ "label" => $info["id"],
|
|
|
+ "time" => $info["time"],
|
|
|
+ "dirt" => 2,
|
|
|
+ "rssi" => $info["rssi"],//数组 [{"front":72,"behind":255,"left":255,"right":255,"time":1685067709},{"front":76,"behind":255,"left":255,"right":255,"time":1685067710}]
|
|
|
+ "avg" => $info["avg"] //{"front":"77.17","behind":"90.00","left":"90.00","right":"90.00"}
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ $ues_redis->lpush("indoor_inoutres_push", json_encode($url_data));
|
|
|
+ // debug_log("push_indoor_res","出推送依赖:".json_encode($info));
|
|
|
+ // $url_res= curl_http_post(json_encode($url_data),$url,false);
|
|
|
+ $info['pushTime'] = time();
|
|
|
+
|
|
|
+ // debug_log("push_indoor_res","远程返回结果".$url_res);
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
//判断进出和推送
|
|
|
public function compAndPush($info, $config ){
|
|
|
//标签多,数据多时候,判断完成后放入redis,异步推送,当前暂时直接推
|
|
@@ -698,7 +879,7 @@ class Api extends CatchController
|
|
|
|
|
|
$url="http://localhost:8115/api/areaReport";
|
|
|
if($flagIn && $status == 2){
|
|
|
- if ($info["pushTime"] && (time()-$info['pushTime']) < 5 ) {
|
|
|
+ if ($info["pushTime"] && (time()-$info['pushTime']) < 5 ) {
|
|
|
# code...
|
|
|
return $info;
|
|
|
}
|
|
@@ -771,27 +952,6 @@ class Api extends CatchController
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 删除前1天的数据
|
|
|
*
|