NmCameraStatus.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Modules\Mine\Entities\MineListExt;
  6. use Modules\Camera\Http\Controllers\Api\HaiKangController;
  7. use Illuminate\Support\Facades\Input;
  8. class NmCameraStatus extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'camera:camerastatus';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '宁煤摄像头状态同步';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $start_time = time();
  39. echo '开始时间:'.date('Y-m-d H:i:s');
  40. $this->cameraStatusNm();
  41. echo '时长:'.number_format(((time()-$start_time)/60),2).'分钟';
  42. }
  43. //同步区域列表
  44. public function cameraStatusNm()
  45. {
  46. // ini_set("memory_limit", "-1");
  47. //宁煤集团
  48. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  49. //所有区域
  50. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();
  51. $mine_use = [];//宁煤下每个矿所有区域
  52. foreach($mine_all as $key=>$value){
  53. if(count(explode('|',$value->degree)) > 1){
  54. if(explode('|',$value->degree)[0] == $ningmei[0]->id){
  55. $mine_use[] = $value->id;
  56. }
  57. }
  58. }
  59. $camera = DB::table('camera_list')
  60. ->whereIn('mine_id',$mine_use)
  61. ->where('deleted_at',null)
  62. ->pluck('index_code','id')
  63. ->all();
  64. $query = MineListExt::where('mine_id', $ningmei[0]->id)->first();
  65. Input::replace(
  66. [
  67. 'url' => trim($query->ip, '/') . ':' . $query->port,
  68. 'key' => $query->key,
  69. 'secret' => $query->secret,
  70. ]
  71. );
  72. $haikang = new HaiKangController();
  73. foreach($camera as $k=>$v){
  74. $res['camera_status'] = $haikang->getCameraStatus($v);
  75. DB::table('camera_list')->where('id',$k)->update($res);
  76. }
  77. }
  78. }