UpdateHkList.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $trans_result = CameraServices::getHaiKangTransList($degree[0]);
  59. $result = CameraServices::getHaiKangCamera($degree[0], $val->index_code, CameraEnum::CAMERA_TYPE_ALL);
  60. if ($result['status'] && $trans_result['status']) {
  61. $trans_arr = [];
  62. foreach ($trans_result['data'] as $tk => $tv) {
  63. $trans_arr[$tv['indexCode']]['ip'] = $tv['ip'];
  64. }
  65. foreach ($result['data'] as $k => $v) {
  66. $camera_ip = $trans_arr[$v['trans_code']]['ip'];
  67. $params = [
  68. 'mine_id' => $val->id,
  69. 'camera_name' => $v['camera_name'],
  70. 'index_code' => $v['camera_id'],
  71. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  72. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  73. 'ip' => $camera_ip,
  74. 'port' => CameraEnum::HAK_DEFAULT_PORT,
  75. 'com_number' => $v['com_number'],
  76. ];
  77. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  78. }
  79. }
  80. }
  81. }
  82. }