likang 2 years ago
parent
commit
14f8b0b7be

+ 75 - 7
catch/api/controller/Api.php

@@ -174,6 +174,10 @@ class Api extends CatchController
 
     }
 
+
+
+
+
     /**
      * 清除数据
      *
@@ -260,10 +264,11 @@ class Api extends CatchController
                                 ];
                                 // debug_log("InAndOUT","得出计算结果:".json_encode($arr));
                                 debug_log("clear_label","发送给远程".json_encode($url_data));
-                                $url="http://47.114.185.186:8115/api/accessReport";
-                                $url_res= curl_http_post(json_encode($url_data),$url,false);
-                               debug_log("clear_label","远程返回结果".$url_res);
-                               debug_log("result","补充计算出的结果计算返回的结果".json_encode($url_data));
+                            //     $url="http://47.114.185.186:8115/api/accessReport";
+                            //     $url_res= curl_http_post(json_encode($url_data),$url,false);
+                            //    debug_log("clear_label","远程返回结果".$url_res);
+                            //    debug_log("result","补充计算出的结果计算返回的结果".json_encode($url_data));
+                               $dispose->getRemoteData($url_data);
                                $this->temporary_label($redis,$item,2);
                              
                             }else{
@@ -287,15 +292,78 @@ class Api extends CatchController
 
             }
 
+   
 
+        }
 
-            
-            
-           
+    }
+
+    /**
+     * 远程推送数据
+     *
+     * @return void
+     */
+    public function remotePush(){
+        while(true){
+            $redis=Cache::store('redis')->handler();
+            $key="push_data";
+           $url="http://47.114.185.186:8115/api/accessReport";
+           //$url="http://127.0.0.1:8000/api/accessReport";
+           sleep(2);
+            while($data=$redis->lPop($key)){
+                if(!empty($data)){
+                    debug_log($key,"远程推送的数据".$data);
+                    $url_res= curl_http_post($data,$url,false);
+                    $num=1;
+                    while($url_res==false){
+                        $num++;
+                        $url_res= curl_http_post($data,$url,false);
+                        if($num>=3){
+                            debug_log($key,"远程推送的地址".$url);
+                            debug_log($key,"连续推送三次失败,远程推送的数据".$data);
+                            break;
+                        }
+                    }
+                    debug_log($key,"远程返回结果".$url_res);
+                }
+
+            }
 
         }
 
+
     }
+
+    // public function test2(){
+    //     while(true){
+    //        // $data='{"mac":"863488051843244","data":[{"label":"E2B81F15","time":1683886407,"dirt":1}]}';
+    //         $data_array=[];
+    //         $data_array[]=[
+    //             "label"=>"E2B81F15",
+    //             'time'=>1683886407,
+    //             'dirt'=>1 //1是进 2是出
+    //         ];
+    //         $url_data=[
+    //             "mac"=>"863488051843244",
+    //             "data"=>$data_array
+    //         ];
+    //         sleep(10);
+    //         $key="push_data";
+    //         $redis=Cache::store('redis')->handler();
+    //         $redis->Rpush($key,json_encode($url_data));
+
+    //     }
+
+    // }
+
+
+
+
+
+
+
+
+
     public function redis_to_mysql_parea(){
 
         $ues_redis=Cache::store('redis')->handler();

+ 6 - 1
catch/api/route.php

@@ -5,7 +5,7 @@
  * @Author: likang
  * @Date: 2022-06-09 10:11:32
  * @LastEditors: likang 1186820806@qq.com
- * @LastEditTime: 2023-05-10 09:08:04
+ * @LastEditTime: 2023-05-19 15:32:33
  */
 // +----------------------------------------------------------------------
 // | CatchAdmin [Just Like ~ ]
@@ -27,8 +27,13 @@ $router->group(function () use ($router) {
 $router->post('api/report', '\catchAdmin\api\controller\Api@report');
 $router->get('api/deleteHistory', '\catchAdmin\api\controller\Api@deleteHistory');
 $router->get('api/test', '\catchAdmin\api\controller\Api@test');
+//推送数据
 $router->get('api/redis', '\catchAdmin\api\controller\Api@redis_to_mysql');
 $router->get('api/clear_redis', '\catchAdmin\api\controller\Api@clear_redis');
+//远程推送数据
+$router->get('api/remote_push', '\catchAdmin\api\controller\Api@remotePush');
+
+
 //打印日志
 $router->get('api/temporary_label_log', '\catchAdmin\api\controller\Api@temporary_label_log');
 $router->get('api/redis_parea', '\catchAdmin\api\controller\Api@redis_to_mysql_parea');

+ 22 - 6
catch/api/service/dispose.php

@@ -250,12 +250,12 @@ class dispose
                                 "mac"=>$data['mac'],
                                 "data"=>$data_array
                             ];
+                            $this->getRemoteData($url_data);
                             // debug_log("InAndOUT","得出计算结果:".json_encode($arr));
-                            debug_log("InAndOUT","发送给远程".json_encode($url_data));
-                            $url="http://47.114.185.186:8115/api/accessReport";
-                            $url_res= curl_http_post(json_encode($url_data),$url,false);
-                           debug_log("InAndOUT","远程返回结果".$url_res);
-                           debug_log("result","正常计算返回的结果".json_encode($url_data));
+                            // debug_log("InAndOUT","发送给远程".json_encode($url_data));
+                            // $url="http://47.114.185.186:8115/api/accessReport";
+                            // $url_res= curl_http_post(json_encode($url_data),$url,false);
+                        
 
                            $this->temporary_label($this->redis,$data['label'],2);
                           $status['dirt']=$res;
@@ -281,6 +281,9 @@ class dispose
        }
 
     }
+
+
+
     //获取所有基站
     public function getStations(){
         $key=$this->stations;
@@ -336,7 +339,20 @@ class dispose
         debug_log("InAndOUT","结算后的结果:".json_encode($res));
         return $res;
     }
-
+/**
+ * 获取远程推送的数据
+ *
+ * @param [type] $url
+ * @param [type] $data
+ * @return void
+ */
+
+public function getRemoteData($data){
+    $key="push_data";
+    $redis=$this->redis;
+    $redis->Rpush($key,json_encode($data));
+    
+}
 
 
 

+ 6 - 1
catch/tag_history/controller/TagHistory.php

@@ -50,6 +50,8 @@ class TagHistory extends CatchController
         $cs_store = Db::name('user_has_roles')->where('uid', $create_id)->where('role_id', 8)->find();
         //公司测试猪耳标
         $companyPigEarTest = Db::name('user_has_roles')->where('uid', $create_id)->where('role_id', 9)->find();
+        //公司测试
+        $companyTest2 = Db::name('user_has_roles')->where('uid', $create_id)->where('role_id', 10)->find();
 
 
 
@@ -147,9 +149,12 @@ class TagHistory extends CatchController
             ,00000098BDA9
             ,00000098BDA7
             "];
+        }elseif($companyTest2){
+            $where[] = ['mac', 'in', '30B5f1013B55'];
+            $where[] = ['lable', 'in', "00000098C145"];
         }
 
-        if(false){
+        if(true){
 
         
         $list = $this->tagHistoryModel->group('mac,lable')->where('addTime','>',strtotime("-10 minutes"))->where($where)