UpdateHkList.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Modules\Camera\Entities\CameraList;
  5. use Modules\Camera\Enum\CameraEnum;
  6. use Modules\Camera\Services\CameraServices;
  7. use Modules\Mine\Entities\MineList;
  8. use Modules\Mine\Entities\MineListExt;
  9. use Modules\Mine\Services\MineServices;
  10. class UpdateHkList extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'hklist:update';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '同步海康区域及摄像头列表';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $this->updateAreaList();
  41. $this->updateCameraList();
  42. }
  43. //同步区域列表
  44. public function updateAreaList()
  45. {
  46. //查询使用海康服务器的矿区id
  47. $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
  48. foreach ($mine_id_list as $key => $val) {
  49. MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL);
  50. }
  51. }
  52. public function updateCameraList()
  53. {
  54. //查询存在index_code列表
  55. $index_code_list = MineList::where('index_code', '!=', null)->get();
  56. foreach ($index_code_list as $key => $val) {
  57. $degree = explode('|', $val->degree);
  58. $result = CameraServices::getHaiKangCamera($degree[0], $val->index_code, CameraEnum::CAMERA_TYPE_ALL);
  59. if ($result['status']) {
  60. foreach ($result['data'] as $k => $v) {
  61. $params = [
  62. 'mine_id' => $val->id,
  63. 'camera_name' => $v['camera_name'],
  64. 'index_code' => $v['camera_id'],
  65. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  66. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  67. ];
  68. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  69. }
  70. }
  71. }
  72. }
  73. }