Browse Source

记录同步时间

任敬轩 2 years ago
parent
commit
3e80269881

+ 43 - 0
Modules/Camera/Database/Migrations/2023_04_19_102509_create_syn_table.php

@@ -0,0 +1,43 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateSynTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('syn', function (Blueprint $table) {
+            $table->bigIncrements('id')->comment('ID');
+            $table->string('hk_area_start_time')->nullable()->comment('海康区域同步开始时间');
+            $table->string('hk_area_end_time')->nullable()->comment('海康区域同步结束时间');
+            $table->string('hk_camera_start_time')->nullable()->comment('海康摄像头同步开始时间');
+            $table->string('hk_camera_end_time')->nullable()->comment('海康摄像头同步结束时间');
+            $table->string('td_area_start_time')->nullable()->comment('天地区域同步开始时间');
+            $table->string('td_area_end_time')->nullable()->comment('天地区域同步结束时间');
+            $table->string('td_camera_start_time')->nullable()->comment('天地摄像头同步开始时间');
+            $table->string('td_camera_end_time')->nullable()->comment('天地摄像头同步结束时间');
+            $table->string('nm_area_start_time')->nullable()->comment('宁煤区域同步开始时间');
+            $table->string('nm_area_end_time')->nullable()->comment('宁煤区域同步结束时间');
+            $table->string('nm_camera_time')->nullable()->comment('宁煤摄像头同步时间');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('syn');
+    }
+}

+ 52 - 9
app/Console/Commands/UpdateHkList.php

@@ -58,13 +58,28 @@ class UpdateHkList extends Command
         //查询使用海康服务器的矿区id
         $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
 
-        Log::info('海康区域同步开始---');
+        //海康区域同步开始时间
+        $syn['hk_area_start_time'] = date('Y-m-d H:i:s');
+
         foreach ($mine_id_list as $key => $val) {
-            MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL);
+            if($val == 968){
+                //宁煤区域同步开始时间
+                $syn['nm_area_start_time'] = date('Y-m-d H:i:s');
+
+                MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL);
+
+                //宁煤区域同步结束时间
+                $syn['nm_area_end_time'] = date('Y-m-d H:i:s');
+            }else{
+                MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL);
+            }
         }
-        Log::info('海康区域同步结束---');
 
-        Log::info('天地区域同步开始---');
+        //海康区域同步结束时间
+        $syn['hk_area_end_time'] = date('Y-m-d H:i:s');
+        //天地区域同步开始时间
+        $syn['td_area_start_time'] = date('Y-m-d H:i:s');
+
         //同步天地伟业矿区区域
         $mine_list_ext = DB::table('mine_list_ext')
             ->select('mine_list_ext.*','mine_list.parent_id')
@@ -97,7 +112,10 @@ class UpdateHkList extends Command
                 //dd($result['data']['list']);
             }
         }
-        Log::info('天地区域同步开始---');
+
+        //天地区域同步结束时间
+        $syn['td_area_end_time'] = date('Y-m-d H:i:s');
+        DB::table('syn')->insert($syn);
     }
 
     public function updateCameraList()
@@ -139,8 +157,17 @@ class UpdateHkList extends Command
             }
         }
 
-        Log::info('海康摄像头同步开始---');
+        //海康摄像头同步开始时间
+        $syn['hk_camera_start_time'] = date('Y-m-d H:i:s');
+
+        $nm_camera_time = 0;
         foreach ($index_code_list as $key => $val) {
+
+            if($val->parent_id == 968){
+                //宁煤同步摄像头开始时间
+                $nm_start_time = time();
+            }
+
             $degree       = explode('|', $val->degree);
 //            $trans_result = CameraServices::getHaiKangTransList($degree[0]);
             $result       = CameraServices::getHaiKangCamera($degree[0], $val->index_code, CameraEnum::CAMERA_TYPE_ALL);
@@ -184,8 +211,18 @@ class UpdateHkList extends Command
                 //删除不存在的摄像头
                 CameraList::where('mine_id', $val->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
             }
+
+            if(isset($nm_start_time)){
+                //宁煤同步摄像头时间
+                $nm_camera_time += time() - $nm_start_time;
+            }
+
         }
-        Log::info('海康摄像头同步结束---');
+
+        $syn['nm_camera_time'] = $nm_camera_time/60;//宁煤单个区域同步时间
+
+        //海康摄像头同步结束时间
+        $syn['hk_camera_end_time'] = date('Y-m-d H:i:s');
 
         //天地伟业需要同步的矿区
         $mine_list_ext = DB::table('mine_list_ext')
@@ -199,7 +236,9 @@ class UpdateHkList extends Command
             ->where('mine_list_ext.secret','!=','')
             ->where('mine_list_ext.deleted_at',null)->get();
 
-        Log::info('天地摄像头同步开始---');
+        //天地摄像头同步开始时间
+        $syn['td_camera_start_time'] = date('Y-m-d H:i:s');
+
         if(sizeof($mine_list_ext)>0){
             for($i=0;$i<sizeof($mine_list_ext);$i++){//循环同步所有天地伟业矿区
                 //矿区下所有区域
@@ -269,7 +308,11 @@ class UpdateHkList extends Command
                 }
             }
         }
-        Log::info('天地摄像头同步结束---');
+
+        //天地摄像头同步结束时间
+        $syn['td_camera_end_time'] = date('Y-m-d H:i:s');
+        $syn_id = DB::table('syn')->orderBy('id','desc')->pluck('id')->first();
+        DB::table('syn')->update($syn)->where('id',$syn_id);
     }
 
     //转义摄像头名称中的特殊字符