| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace App\Console\Commands;
- use App\Enum\ApiEnum;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class CameraStatusHistory extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'camera:statushistory';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '摄像头统计历史数据';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->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;$i<count($xczyd);$i++){
- $mine_all->where('degree','not like',$xczyd[$i].'%');
- }
- }
- if(count($ydjk) > 0){
- for($i=0;$i<count($ydjk);$i++){
- $mine_all->where('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']
- ]);
- }
- }
- }
|