Browse Source

摄像头接口

任敬轩 4 months ago
parent
commit
46aeac2f18

+ 59 - 76
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -202,100 +202,83 @@ class CameraApiController extends BaseController
     }
 
     //宁煤摄像头统计
-    public function getTotalNingmeibak(){
+    public function getTotalNingmeiWeek(){
         $result['status'] = true;
         $result['msg']    = ApiEnum::RETURN_SUCCESS;
 
-        //宁煤集团
-        $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
-
-        $ydjk = DB::table('mine_list')->where('title','移动监控')->where('deleted_at',null)->get();
-        $ydjk_list = [];
-        if(count($ydjk) > 0){
-            for($i=0;$i<count($ydjk);$i++){
-                array_push($ydjk_list,$ydjk[$i]->id);
+        $type = Input::get('type', '');
 
-            }
-        }
-        $ydjk_son = DB::table('mine_list')->whereIn('parent_id',$ydjk_list)->where('deleted_at',null)->get();
-        if(count($ydjk_son) > 0){
-            for($i=0;$i<count($ydjk_son);$i++){
-                array_push($ydjk_list,$ydjk_son[$i]->id);
+        $data = [];
 
+        if($type == 'nmjt' || $type == ''){
+            $list = DB::table('camera_status_history')->where('title','宁煤公司')->where('date', '<=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+            $total = 0;
+            $total_online = 0;
+            $totle_offline = 0;
+            $rate = 0;
+            if(count($list) > 0){
+                for($i=0;$i<count($list);$i++){
+                    $total = $total + $list[$i]->total;
+                    $total_online = $total_online + $list[$i]->total_online;
+                    $totle_offline = $totle_offline + $list[$i]->totle_offline;
+                    $rate = $rate + $list[$i]->rate;
+                }
             }
+            array_push($data,[
+                'title'=>           $list[0]->title,
+                'mine_code'=>       $list[0]->mine_code,
+                'total'=>           $total/count($list),
+                'total_online'=>    $total_online/count($list),
+                'total_offline'=>   $totle_offline/count($list),
+                'rate'=>            $rate/count($list)
+            ]);
         }
 
-        $mine_all = DB::table('mine_list')->where('deleted_at',null)->whereNotIn('id',$ydjk_list)->get();//所有区域
-
-        $mine_ningmei = [];//宁煤集团所有区域
-        foreach($mine_all as $k=>$v){
-            if(explode('|',$v->degree)[0] == $ningmei[0]->id){
-                $mine_ningmei[] = $v->id;
-            }
+        if($type == 'nmjt'){
+            return self::successResponse($data);
         }
 
-        //宁煤在离线数量
-        $data[0]['title'] = '宁煤公司';
-        $data[0]['mine_code'] = $ningmei[0]->slug;
-        $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
-        $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
-        $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
-        $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
-
         //宁煤下各矿在离线数量
-        $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
-        foreach($mine_list as $k => $v){
-            $mine_use = [];//宁煤下每个矿所有区域
-            foreach($mine_all as $key=>$value){
-                if(count(explode('|',$value->degree)) > 1){
-                    if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
-                        $mine_use[] = $value->id;
-                    }
-                }
-            }
-
-            $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
-            $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
-
-            if($total == 0){
-                $rate = "0%";
-            }else{
-                $rate = round($total_online / $total * 100,2)."%";
-            }
+        if($type == 'mtdw'){
+            $id_list = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157'];
 
-            if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
-                $res['title'] = $v->title;
-                $res['mine_code'] = $v->slug."_jituan";
-                $res['total'] = $total;
-                $res['total_online'] = $total_online;
-                $res['total_offline'] = $total - $total_online;
-                $res['rate'] = $rate;
-            }else{
-                if($v->slug == 'ShuiDianFenGongSi'){
-                    $v->title = '供电分公司';
+        }elseif($type == 'hgdw'){
+            $id_list = ['2447', '2525', '2557', '2576', '3868', '2597', '3452'];
+        }elseif($type == 'ndtl'){
+            $id_list = ['6001'];
+        }elseif($type == 'qtdw'){
+            $id_list = ['2628', '2599', '2600', '2611', '3167'];
+        }elseif($type == 'gfx'){
+            $id_list = ['4272'];
+        }
+
+        $unit_list = DB::table('mine_list')->whereIn('id',$id_list)->pluck('title');
+        if(count($unit_list) > 0){
+            for($i=0;$i<count($unit_list);$i++){
+                $list = DB::table('camera_status_history')->where('title',$unit_list[$i])->where('date', '<=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
+                $total = 0;
+                $total_online = 0;
+                $totle_offline = 0;
+                $rate = 0;
+                if(count($list) > 0){
+                    for($j=0;$j<count($list);$j++){
+                        $total = $total + $list[$j]->total;
+                        $total_online = $total_online + $list[$j]->total_online;
+                        $totle_offline = $totle_offline + $list[$j]->totle_offline;
+                        $rate = $rate + $list[$j]->rate;
+                    }
                 }
                 array_push($data,[
-                    'title'=>$v->title,
-                    'mine_code'=>$v->slug."_jituan",
-                    'total'=>$total,
-                    'total_online'=>$total_online,
-                    'total_offline'=>$total - $total_online,
-                    'rate'=>$rate
+                    'title'=>           $unit_list[$i],
+                    'mine_code'=>       $list[0]->mine_code,
+                    'total'=>           $total/count($list),
+                    'total_online'=>    $total_online/count($list),
+                    'total_offline'=>   $totle_offline/count($list),
+                    'rate'=>            $rate/count($list)
                 ]);
             }
         }
 
-        if(isset($res)){
-            array_push($data,[
-                'title'=>$res['title'],
-                'mine_code'=>$res['mine_code'],
-                'total'=>$res['total'],
-                'total_online'=>$res['total_online'],
-                'total_offline'=>$res['total_offline'],
-                'rate'=>$res['rate']
-            ]);
-        }
-
         return self::successResponse($data);
     }
 

+ 1 - 0
Modules/Camera/Routes/api.php

@@ -48,6 +48,7 @@ Route::namespace('Api')->group(function () {
     Route::post('camera/picture_base64', 'CameraApiController@pictureBase64');//宁煤存base64图片
     Route::post('camera/get_risk_ningmei', 'CameraApiController@getRiskNingmei');//宁煤高风险摄像头
     Route::post('camera/get_total_ningmei', 'CameraApiController@getTotalNingmei');//宁煤摄像头统计
+    Route::post('camera/get_total_ningmei_week', 'CameraApiController@getTotalNingmeiWeek');//宁煤摄像头周统计
     Route::post('camera/offline_list', 'CameraApiController@offlineList');//宁煤不在线摄像头列表
     Route::get('camera/get_total_string', 'CameraApiController@getTotalString');//宁煤摄像头统计字符串
     Route::get('test', 'CameraApiController@test');