UpdateHkList.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $index_code_arr = [];
  66. foreach ($result['data'] as $k => $v) {
  67. $ip = '';
  68. $port = '';
  69. $com_number = '';
  70. if (isset($trans_arr[$v['trans_code']])) {
  71. $ip = $trans_arr[$v['trans_code']]['ip'];
  72. $port = CameraEnum::HAK_DEFAULT_PORT;
  73. $com_number = $v['com_number'];
  74. }
  75. //当前摄像头index_code数组
  76. $index_code_arr[$k] = $v['camera_id'];
  77. $params = [
  78. 'mine_id' => $val->id,
  79. 'camera_name' => $v['camera_name'],
  80. 'index_code' => $v['camera_id'],
  81. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  82. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  83. 'ip' => $ip,
  84. 'port' => $port,
  85. 'com_number' => $com_number,
  86. ];
  87. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  88. }
  89. //删除不存在的摄像头
  90. CameraList::whereNotIn('index_code', $index_code_arr)->delete();
  91. }
  92. }
  93. }
  94. }