CameraStatusHistory.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Enum\ApiEnum;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. class CameraStatusHistory extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'camera:statushistory';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '摄像头统计历史数据';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->cameraStatusHistory();
  37. }
  38. //摄像头统计历史数据
  39. public function cameraStatusHistory()
  40. {
  41. $result['status'] = true;
  42. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  43. //宁煤集团
  44. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  45. $ydjk = DB::table('mine_list')->where('title','移动监控')->where('deleted_at',null)->get();
  46. $ydjk_list = [];
  47. if(count($ydjk) > 0){
  48. for($i=0;$i<count($ydjk);$i++){
  49. array_push($ydjk_list,$ydjk[$i]->id);
  50. }
  51. }
  52. $ydjk_son = DB::table('mine_list')->whereIn('parent_id',$ydjk_list)->where('deleted_at',null)->get();
  53. if(count($ydjk_son) > 0){
  54. for($i=0;$i<count($ydjk_son);$i++){
  55. array_push($ydjk_list,$ydjk_son[$i]->id);
  56. }
  57. }
  58. $mine_all = DB::table('mine_list')->where('deleted_at',null)->whereNotIn('id',$ydjk_list)->get();//所有区域
  59. $mine_ningmei = [];//宁煤集团所有区域
  60. foreach($mine_all as $k=>$v){
  61. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  62. $mine_ningmei[] = $v->id;
  63. }
  64. }
  65. //宁煤在离线数量
  66. $nm['title'] = '宁煤公司';
  67. $nm['mine_code'] = $ningmei[0]->slug;
  68. $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  69. $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  70. $nm['total_offline'] = $nm['total'] - $nm['total_online'];
  71. $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
  72. $nm['type'] = 0;
  73. $nm['date'] = date('Y-m-d');
  74. DB::table('camera_status_history')->insert($nm);
  75. $data = [];
  76. //宁煤下各矿在离线数量
  77. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  78. foreach($mine_list as $k => $v){
  79. $mine_use = [];//宁煤下每个矿所有区域
  80. foreach($mine_all as $key=>$value){
  81. if(count(explode('|',$value->degree)) > 1){
  82. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  83. $mine_use[] = $value->id;
  84. }
  85. }
  86. }
  87. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  88. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  89. if($total == 0){
  90. $rate = "0";
  91. }else{
  92. $rate = round($total_online / $total * 100,2);
  93. }
  94. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  95. $res['title'] = $v->title;
  96. $res['mine_code'] = $v->slug."_jituan";
  97. $res['total'] = $total;
  98. $res['total_online'] = $total_online;
  99. $res['total_offline'] = $total - $total_online;
  100. $res['rate'] = $rate;
  101. }else{
  102. array_push($data,[
  103. 'title'=>$v->title,
  104. 'mine_code'=>$v->slug."_jituan",
  105. 'total'=>$total,
  106. 'total_online'=>$total_online,
  107. 'total_offline'=>$total - $total_online,
  108. 'rate'=>$rate
  109. ]);
  110. }
  111. $ins['title'] = $v->title;
  112. $ins['mine_code'] = $v->slug;
  113. $ins['total'] = $total;
  114. $ins['total_online'] = $total_online;
  115. $ins['total_offline'] = $total - $total_online;
  116. $ins['rate'] = $rate;
  117. if(strpos($v->title, '煤矿') !== false || strpos($v->title, '洗选') !== false){
  118. $ins['type'] = 1;
  119. }elseif(strpos($v->title, '煤制油') !== false || strpos($v->title, '烯烃') !== false || strpos($v->title, '甲醇') !== false || strpos($v->title, '精蜡') !== false){
  120. $ins['type'] = 2;
  121. }else{
  122. $ins['type'] = 3;
  123. }
  124. $ins['date'] = date('Y-m-d');
  125. DB::table('camera_status_history')->insert($ins);
  126. }
  127. if(isset($res)){
  128. array_push($data,[
  129. 'title'=>$res['title'],
  130. 'mine_code'=>$res['mine_code'],
  131. 'total'=>$res['total'],
  132. 'total_online'=>$res['total_online'],
  133. 'total_offline'=>$res['total_offline'],
  134. 'rate'=>$res['rate']
  135. ]);
  136. }
  137. }
  138. }