| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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;
- //宁煤集团
- $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;
- }
- }
- //宁煤在离线数量
- $ningmei['title'] = '宁煤公司';
- $ningmei['mine_code'] = $ningmei[0]->slug;
- $ningmei['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
- $ningmei['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
- $ningmei['total_offline'] = $ningmei['total'] - $ningmei['total_online'];
- $ningmei['rate'] = round($ningmei['total_online'] / $ningmei['total'] * 100,2);
- $ningmei['type'] = 0;
- $ningmei['created_at'] = date('Y-m-d H:i:s');
- $ningmei['updated_at'] = date('Y-m-d H:i:s');
- DB::table('camera_status_history')->insert($ningmei);
- $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
- ]);
- }
- }
- 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']
- ]);
- if(strpos($res['title'], '煤矿') !== false || strpos($res['title'], '洗选') !== false){
- $res['type'] = 1;
- }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
- $res['type'] = 2;
- }else{
- $res['type'] = 3;
- }
- $res['created_at'] = date('Y-m-d H:i:s');
- $res['updated_at'] = date('Y-m-d H:i:s');
- DB::table('camera_status_history')->insert($res);
- }
- }
- }
|