cameraStatusHistory(); } //摄像头统计历史数据 public function cameraStatusHistory() { $result['status'] = true; $result['msg'] = ApiEnum::RETURN_SUCCESS; DB::table('camera_status_history')->where('date', '<=', date('Y-m-d H:i:s', strtotime('-30 days')))->delete(); //宁煤集团 $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get(); $mine_all = DB::table('mine_list')->where('deleted_at',null); $xczyd = DB::table('mine_list')->where('deleted_at',null)->where('title','现场作业点')->pluck('degree'); $ydjk = DB::table('mine_list')->where('deleted_at',null)->where('title','移动监控')->pluck('degree'); if(count($xczyd) > 0){ for($i=0;$iwhere('degree','not like',$xczyd[$i].'%'); } } if(count($ydjk) > 0){ for($i=0;$iwhere('degree','not like',$ydjk[$i].'%'); } } $mine_all = $mine_all->get(); $mine_ningmei = [];//宁煤集团所有区域 foreach($mine_all as $k=>$v){ if(explode('|',$v->degree)[0] == $ningmei[0]->id){ $mine_ningmei[] = $v->id; } } //宁煤在离线数量 $nm['title'] = '宁煤公司'; $nm['mine_code'] = $ningmei[0]->slug; $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count(); $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count(); $nm['total_offline'] = $nm['total'] - $nm['total_online']; $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2); $nm['type'] = 0; $nm['date'] = date('Y-m-d'); DB::table('camera_status_history')->insert($nm); $data = []; //宁煤下各矿在离线数量 $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 ]); } $ins['title'] = $v->title; $ins['mine_code'] = $v->slug; $ins['total'] = $total; $ins['total_online'] = $total_online; $ins['total_offline'] = $total - $total_online; $ins['rate'] = $rate; if(strpos($v->title, '煤矿') !== false || strpos($v->title, '洗选') !== false){ $ins['type'] = 1; }elseif(strpos($v->title, '煤制油') !== false || strpos($v->title, '烯烃') !== false || strpos($v->title, '甲醇') !== false || strpos($v->title, '精蜡') !== false){ $ins['type'] = 2; }else{ $ins['type'] = 3; } $ins['date'] = date('Y-m-d'); DB::table('camera_status_history')->insert($ins); } 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'] ]); } } }