| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Modules\Camera\Entities\CameraList;
- use Modules\Camera\Enum\CameraEnum;
- use Modules\Camera\Services\CameraServices;
- use Modules\Mine\Entities\MineList;
- use Modules\Mine\Entities\MineListExt;
- use Modules\Mine\Services\MineServices;
- class UpdateHkList extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'hklist:update';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '同步海康区域及摄像头列表';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->updateAreaList();
- $this->updateCameraList();
- }
- //同步区域列表
- public function updateAreaList()
- {
- //查询使用海康服务器的矿区id
- $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
- foreach ($mine_id_list as $key => $val) {
- MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL);
- }
- }
- public function updateCameraList()
- {
- //查询存在index_code列表
- $index_code_list = MineList::where('index_code', '!=', null)->get();
- foreach ($index_code_list as $key => $val) {
- $degree = explode('|', $val->degree);
- $trans_result = CameraServices::getHaiKangTransList($degree[0]);
- $result = CameraServices::getHaiKangCamera($degree[0], $val->index_code, CameraEnum::CAMERA_TYPE_ALL);
- if ($result['status'] && $trans_result['status']) {
- $trans_arr = [];
- foreach ($trans_result['data'] as $tk => $tv) {
- $trans_arr[$tv['indexCode']]['ip'] = $tv['ip'];
- }
- foreach ($result['data'] as $k => $v) {
- $camera_ip = $trans_arr[$v['trans_code']]['ip'];
- $params = [
- 'mine_id' => $val->id,
- 'camera_name' => $v['camera_name'],
- 'index_code' => $v['camera_id'],
- 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
- 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
- 'ip' => $camera_ip,
- 'port' => CameraEnum::HAK_DEFAULT_PORT,
- 'com_number' => $v['com_number'],
- ];
- CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
- }
- }
- }
- }
- }
|