Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

q 1 tahun lalu
induk
melakukan
976dcd64a7

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

@@ -151,6 +151,84 @@ class CameraApiController extends BaseController
         return self::successResponse($data);
     }
 
+    //宁煤摄像头统计字符串
+    public function getTotalString(){
+        $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;
+            }
+        }
+
+        //宁煤在离线数量
+        $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($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{
+                array_push($data,[
+                    'title'=>$v->title,
+                    'mine_code'=>$v->slug."_jituan",
+                    'total'=>$total,
+                    'total_online'=>$total_online,
+                    'total_offline'=>$total - $total_online,
+                    'rate'=>$rate
+                ]);
+            }
+        }
+
+        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);
+    }
+
     //宁煤不在线摄像头列表
     public function offlineList(){
         $mine_code = Input::get('mine_code', '');

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

@@ -46,6 +46,7 @@ Route::namespace('Api')->group(function () {
     Route::post('camera/get_risk_ningmei', 'CameraApiController@getRiskNingmei');//宁煤高风险摄像头
     Route::post('camera/get_total_ningmei', 'CameraApiController@getTotalNingmei');//宁煤摄像头统计
     Route::post('camera/offline_list', 'CameraApiController@offlineList');//宁煤不在线摄像头列表
+    Route::post('camera/get_total_string', 'CameraApiController@getTotalString');//宁煤摄像头统计字符串
     Route::get('test', 'CameraApiController@test');
     Route::post('oss_url','CameraApiController@ossUrl');//文章图片上传至阿里云
     Route::post('article_list','CameraApiController@articleList');//文章列表