Browse Source

宁煤离线摄像头列表

任敬轩 2 years ago
parent
commit
1582a32a9e

+ 74 - 0
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -148,6 +148,80 @@ class CameraApiController extends BaseController
         return self::successResponse($data);
     }
 
+    //宁煤不在线摄像头列表
+    public function offlineList(){
+        $mine_code = Input::get('mine_code', '');
+        if (!$mine_code) {
+            return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
+        }
+
+        $result['status'] = true;
+        $result['msg']    = ApiEnum::RETURN_SUCCESS;
+
+        //宁煤集团
+        $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
+
+        $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
+        $mine_ningmei = [];//宁煤集团所有区域
+        foreach($mine_all as $k=>$v){
+            if(explode('|',$v->degree)[0] == $ningmei[0]->id){
+                $mine_ningmei[] = $v->id;
+            }
+        }
+
+        $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
+
+        $res = [];
+
+        //如果传参是宁煤显示全部
+        if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
+            //宁煤在离线数量
+            $res['title'] = '宁煤公司';
+            $res['mine_code'] = $ningmei[0]->slug;
+            $res['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
+            $res['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
+            $res['total_offline'] = $res['total'] - $res['total_online'];
+            $res['rate'] = round($res['total_online'] / $res['total'] * 100,2)."%";
+            $res['offline_list'] = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_ningmei)->where('camera_status','!=',1)->where('deleted_at',null)->get();
+
+            return self::successResponse($res);
+        }
+
+        //宁煤下各矿在离线数量
+        $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->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();
+            $total_offline = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status','!=',1)->where('deleted_at',null)->get();
+
+            if($total == 0){
+                $rate = "0%";
+            }else{
+                $rate = round($total_online / $total * 100,2)."%";
+            }
+
+            $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;
+            $res['offline_list'] = $total_offline;
+        }
+
+        return self::successResponse($res);
+    }
+
     //宁煤高风险摄像头
     public function getRiskNingmei(){
         $mine_code = Input::get('mine_code', '');

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

@@ -42,4 +42,5 @@ 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/offline_list', 'CameraApiController@offlineList');//宁煤不在线摄像头列表
 });