فهرست منبع

添加网格化接口

qiuzijian 1 سال پیش
والد
کامیت
871484732c

+ 15 - 0
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Input;
 use Illuminate\Support\Facades\Log;
 use Modules\Camera\Entities\CameraList;
 use Modules\Camera\Enum\CameraEnum;
+use Modules\Camera\Http\Controllers\Api\TdwyController;
 use Modules\Camera\Services\CameraServices;
 use Modules\Mine\Entities\MineList;
 use Modules\Mine\Entities\MineListExt;
@@ -639,6 +640,12 @@ class CameraApiController extends BaseController
                 $result = CameraServices::getHkHls($camera_id,$parent_id);
 
             }
+            //大华摄像头
+            elseif($is_hak == 2){
+                //同步大华视频服务器摄像头
+                $tdwy = new TdwyController();
+                $result = $tdwy->dahuaRtsp($camera_id,$parent_id);
+            }
             //信息技术中心测试ws协议
 //            elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
 //                $result = CameraServices::getHkWs($camera_id,$parent_id);
@@ -1728,6 +1735,13 @@ class CameraApiController extends BaseController
         if(count($risk) > 0){
             $camera_info = explode('|',$risk[0]->camera_id);
 
+            $is_hak = MineListExt::where('mine_id', $camera_info[1])->value('is_hak');
+            if($is_hak == 2){
+                $type = 'rtsp';
+            }else{
+                $type = 'm3u8';
+            }
+
             if($risk[0]->risk_type != '' && $risk[0]->risk_type !=null){
                 $risk_type_value = $risk_type[$risk[0]->risk_type];
             }else{
@@ -1773,6 +1787,7 @@ class CameraApiController extends BaseController
 
             $result['camera']['camera_id'] = $camera_id[0];
             $result['camera']['parent_id'] = $camera_id[1];
+            $result['camera']['camera_type'] = $type;
         }
 
         return self::successResponse($result);

+ 189 - 0
Modules/Camera/Http/Controllers/Api/TdwyController.php

@@ -8,11 +8,15 @@
 
 namespace Modules\Camera\Http\Controllers\Api;
 
+use Illuminate\Http\Request;
 use App\Http\Controllers\Api\BaseController;
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Input;
+use Modules\Camera\Entities\CameraList;
 use Modules\Camera\Enum\CameraEnum;
 use Modules\Mine\Entities\MineList;
+use Modules\Mine\Enum\MineEnum;
 use Modules\Mine\Services\MineServices;
 
 
@@ -226,4 +230,189 @@ class TdwyController extends BaseController
         curl_close($ch);
         return $data;
     }
+
+    //同步大华视频服务器摄像头
+    public function dahuaCamera(){
+        //大华需要同步的区域
+        $dahua_ext = DB::table('mine_list_ext')
+            ->where('is_hak',MineEnum::IS_HAK_DH)
+            ->where('deleted_at',null)->get();
+        if(count($dahua_ext) > 0){
+            for($i=0;$i<count($dahua_ext);$i++){
+                $ip = $dahua_ext[$i]->ip.':'.$dahua_ext[$i]->port;
+
+                //获取public_key
+                $url = '/evo-apigw/evo-oauth/1.0.0/oauth/public-key';
+                $result = $this->httpRequest($ip.$url);
+                if($result['data']['publicKey']){
+                    $public_key = $result['data']['publicKey'];
+                }else{
+                    return;
+                }
+
+                //获取access_token
+                $url2 = '/evo-apigw/evo-oauth/1.0.0/oauth/extend/token';
+                $username_password = explode('|',$dahua_ext[$i]->sOrgId);
+                if(count($username_password) != 2){
+                    return;
+                }
+                $password = $this->rsaEncode($username_password[1],$public_key);
+                $params = [
+                    'grant_type'=>'password',
+                    'username'=>$username_password[0],
+                    'password'=>$password,
+                    'client_id'=>$dahua_ext[$i]->key,
+                    'client_secret'=>$dahua_ext[$i]->secret,
+                    'public_key'=>$public_key
+                ];
+                $result2 = $this->httpRequest($ip.$url2,'post',$params);
+                if($result2['data']['access_token']){
+                    $access_token = $result2['data']['access_token'];
+                }else{
+                    return;
+                }
+
+                //获取摄像头列表
+                $url3 = '/evo-apigw/evo-brm/1.2.0/device/channel/subsystem/page';
+                $params2 = [
+                    'pageNum'=>1,
+                    'pageSize'=>1000,
+                    'sortType'=>'ASC',
+                    'sort'=>'channelSn',
+                ];
+                $result3 = $this->httpRequest($ip.$url3,'post',$params2,$access_token);
+
+//                DB::table('camera_list')->where('mine_id',$dahua_ext[$i]->mine_id)->delete();
+                if($result3['data']['pageData']){
+                    $camera_list = $result3['data']['pageData'];
+                    if(count($camera_list) > 0){
+                        for($j=0;$j<count($camera_list);$j++){
+                            $param['mine_id'] = $dahua_ext[$i]->mine_id;
+                            $param['revert_id'] = 'NullId';
+                            $param['sort'] = 1;
+                            $param['camera_name'] = $camera_list[$j]['channelName'];
+                            $param['camera_source'] = 2;
+                            $param['index_code'] = $camera_list[$j]['channelCode'];
+                            $param['video_recorder'] = 2;
+//                            $param['created_at'] = date('Y-m-d H:i:s');
+//                            $param['updated_at'] = date('Y-m-d H:i:s');
+//                            DB::table('camera_list')->insert($param);
+                            CameraList::updateOrCreate(['index_code' => $camera_list[$j]['channelCode']], $param);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    //大华rtsp
+    public function dahuaRtsp($camera_id,$parent_id){
+        $dahua_ext = DB::table('mine_list_ext')
+            ->where('mine_id',$parent_id)
+            ->where('deleted_at',null)->get();
+        if(count($dahua_ext) > 0){
+            $ip = $dahua_ext[0]->ip.':'.$dahua_ext[0]->port;
+
+            //获取public_key
+            $url = '/evo-apigw/evo-oauth/1.0.0/oauth/public-key';
+            $result1 = $this->httpRequest($ip.$url);
+            if($result1['data']['publicKey']){
+                $public_key = $result1['data']['publicKey'];
+            }else{
+                return;
+            }
+
+            //获取access_token
+            $url2 = '/evo-apigw/evo-oauth/1.0.0/oauth/extend/token';
+            $username_password = explode('|',$dahua_ext[0]->sOrgId);
+            if(count($username_password) != 2){
+                return;
+            }
+            $password = $this->rsaEncode($username_password[1],$public_key);
+            $params = [
+                'grant_type'=>'password',
+                'username'=>$username_password[0],
+                'password'=>$password,
+                'client_id'=>$dahua_ext[0]->key,
+                'client_secret'=>$dahua_ext[0]->secret,
+                'public_key'=>$public_key
+            ];
+            $result2 = $this->httpRequest($ip.$url2,'post',$params);
+            if($result2['data']['access_token']){
+                $access_token = $result2['data']['access_token'];
+            }else{
+                return;
+            }
+
+            $camera = DB::table('camera_list')->where('id',$camera_id)->get();
+
+            $url4 = '/evo-apigw/admin/API/MTS/Video/StartVideo';
+            $params3['data'] = [
+                'channelId'=>$camera[0]->index_code,
+                'dataType'=>'1',
+                'streamType'=>'1'
+            ];
+            $result4 = $this->httpRequest($ip.$url4,'post',$params3,$access_token);
+            if($result4['data']['url'] && $result4['data']['token']){
+                $rtsp = explode('|',$result4['data']['url']);
+                if($rtsp[1]){
+                    $result['data'] = [
+                        'camera_id' => $camera_id,
+                        'url' => $rtsp[1].'?token='.$result4['data']['token']
+                    ];
+                    return $result;
+                }
+            }
+        }
+    }
+
+    //接口第三方调用
+    public function httpRequest($url, $format = 'get', $data = null, $token = null){
+        //设置头信息
+        $headerArray =array("Content-type:application/json;","Accept:application/json");
+
+        if ($token) {
+            $headerArray[] = "Authorization:bearer " . $token;
+        }
+
+        $curl=curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
+        if ($format == 'post') {
+            //post传值设置post传参
+            curl_setopt($curl, CURLOPT_POST, 1);
+            if ($data) {
+                $data = json_encode($data);
+                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+            }
+        }
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
+        $data=json_decode(curl_exec($curl), true);
+        curl_close($curl);
+        //返回接口返回数据
+        return $data;
+    }
+
+    public function rsaEncode($password,$rsa_public_key)
+    {
+        // 要执行的代码
+        $rsa_public = "-----BEGIN PUBLIC KEY-----\n";
+        $rsa_public = $rsa_public.$rsa_public_key;
+        $rsa_public = $rsa_public."\n-----END PUBLIC KEY-----";
+        $key = openssl_pkey_get_public($rsa_public);
+        if (!$key) {
+            echo "公钥不可用\n";
+            echo $rsa_public;
+        }
+        //openssl_public_encrypt 第一个参数只能是string
+        //openssl_public_encrypt 第二个参数是处理后的数据
+        //openssl_public_encrypt 第三个参数是openssl_pkey_get_public返回的资源类型
+        $return_en = openssl_public_encrypt($password, $crypted, $key);
+        if (!$return_en) {
+            echo "加密失败,请检查RSA秘钥";
+        }
+        return base64_encode($crypted);
+    }
 }

+ 4 - 1
Modules/Camera/Routes/api.php

@@ -38,6 +38,8 @@ Route::middleware('auth:api')->namespace('Api')->group(function () {
     Route::post('testadd', 'CameraApiController@testadd');
     Route::post('testupdate', 'CameraApiController@testupdate');
     Route::get('testdel', 'CameraApiController@testdel');
+
+
 });
 
 Route::namespace('Api')->group(function () {
@@ -73,5 +75,6 @@ Route::namespace('Api')->group(function () {
     Route::post('task_xixuan/work_search', 'CameraApiController@workSearch');//首頁作业查询
     Route::post('task_xixuan/area_work_search', 'CameraApiController@areaWorkSearch');//首頁片区作业查询
 
-    Route::post('task_xixuan/get_dahua_list', 'CameraApiController@getDahuaList');//获取大华视频服务器播放列表
+    //大华视频接口
+    Route::post('task_xixuan/dahua_camera','TdwyController@dahuaCamera');//大华手动同步
 });

+ 38 - 0
Modules/Camera/Services/CameraServices.php

@@ -1830,6 +1830,44 @@ class CameraServices
         return $result;
     }
 
+    //大华切片逻辑
+    public static function dahuafiles($parent_id, $camera_id){
+        $result['status'] = true;
+        $result['msg']    = ApiEnum::RETURN_SUCCESS;
+
+        $camera = CameraList::find($camera_id);
+
+        $degree = MineList::where('id', $camera->mine_id)->value('degree');
+        $degree = explode('|', $degree);
+
+        $path = '';
+        foreach ($degree as $key => $val) {
+            $path .= MineList::where('id', $val)->value('title') . '/';
+        }
+        $path .= $camera->camera_name . '/' . date('Ymd');
+
+        //标记摄像头为在线状态
+        CameraList::where('id', $camera_id)->update(['camera_status' => CameraEnum::CAMERA_STATUS_ONLINE]);
+
+        //如果m3u8文件已拉取,直接返回播放链接
+        if ($camera->revert_id == CameraEnum::CAMERA_FILE_EXIST) {
+            $result['data'] = [
+                'camera_id' => $camera_id,
+                'url' => env('VIDEO_SYSTEM_URL') . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . '?' . time(),
+            ];
+            return $result;
+        }
+
+        $tdwy = new TdwyController();
+        $tdwy->dahuaRtsp($camera_id,$parent_id);
+        $rtsp = $tdwy->dahuaRtsp($camera_id,$parent_id);
+
+        $res = self::getVideoStream($rtsp, $path, $camera_id);
+        $result['data'] = $res['data'];
+        return $result;
+    }
+
+
     //通过rtmp同步m3u8文件并返回url
     public static function downloadCameraFiles($parent_id, $camera_id)
     {

+ 4 - 0
app/Console/Commands/UpdateHkList.php

@@ -366,6 +366,10 @@ class UpdateHkList extends Command
         //天地摄像头同步结束时间
 //        $syn['td_camera_end_time'] = date('Y-m-d H:i:s');
 //        DB::table('syn')->where('id',$syn_id)->update($syn);
+
+        //同步大华视频服务器摄像头
+        $tdwy = new TdwyController();
+        $tdwy->dahuaCamera();
     }
 
     //转义摄像头名称中的特殊字符

+ 218 - 0
public/inspection_record.html

@@ -0,0 +1,218 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
+    <script src="https://unpkg.com/element-ui@2.15.14/lib/index.js"></script>
+	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
+	<style>
+		@import url("https://unpkg.com/element-ui@2.15.14/lib/theme-chalk/index.css");
+		*{
+			margin:0;
+			padding:0;
+		}
+		.el-calendar__header{
+			border:none;
+		}
+		.el-calendar__body{
+			margin-top:-24px;
+		}
+		td{
+			text-align:center;
+		}
+		.el-calendar-table .el-calendar-day{
+			height:auto;
+		}
+		.el-calendar-table td{
+			border:none;
+		}
+		.el-calendar-table tr td:first-child{
+			border:none;
+		}
+		.el-calendar-table .el-calendar-day{
+			padding:6px;
+		}
+		.el-calendar-table tr:first-child td{
+			border:none;
+		}
+		.el-calendar-day span{
+			font-size:14px;
+		}
+		.form{
+			display:flex;
+			justify-content: space-between;
+			padding:0 20px;
+			margin-top:-20px;
+			margin-bottom:-20px;
+		}
+		.form input{
+			background:#F6F6F6;
+			border:none;
+			border-radius: 10px;
+			width:120px;
+			padding:5px 10px;
+		}
+		.form button{
+			border:none;
+			color:white;
+			background:#3B70FE;
+			border-radius: 10px;
+			width:60px;
+			height:40px;
+		}
+		.list{
+			padding:20px;
+		}
+		.list .item{
+			display:flex;
+			justify-content: space-between;
+			align-items: center;
+			margin-bottom:20px;
+		}
+		.list .item .left{
+			display:flex;
+			align-items: center;
+			position:relative;
+		}
+		.list .item .left .shu{
+			border-left:1px solid #DADADA;
+			width:1px;
+			height:30px;
+			position:absolute;
+			left:5px;
+			top:16px;
+		}
+		.list .item span{
+			color:#DADADA;
+		}
+		.list .item .left .yuan{
+			width:10px;
+			height:10px;
+			border-radius: 50%;
+			border:1px solid #DBDBDB;
+			margin-right:10px;
+		}
+		.list .item .left .through{
+			background:#3F6EFE;
+		}
+	</style>
+</head>
+
+<body>
+    <div id="app">
+        <el-calendar v-model="val">
+        </el-calendar>
+		<div class="form">
+			<!-- <input type="text" v-model="section" placeholder="单位名称"> -->
+			<!-- <input type="text" v-model="name" placeholder="姓名"> -->
+			<el-form :inline="true" class="demo-form-inline">
+			  <el-form-item>
+			    <el-select v-model="section" placeholder="单位名称" @change="handleSectionChange">
+			      <el-option v-for="(item,index) in select_list" :key="index" :label="item.name" :value="item.name"></el-option>
+			    </el-select>
+			  </el-form-item>
+			  <el-form-item>
+			    <el-select v-model="name" placeholder="姓名">
+			      <el-option v-for="(item,index) in name_select" :key="index" :label="item.person_name" :value="item.person_id"></el-option>
+			    </el-select>
+			  </el-form-item>
+			</el-form>
+			<button @click="search">搜索</button>
+		</div>
+		<div class="list">
+			<div class="item" v-for="(item,index) in record_list" :key="index" @click="page_dump(item.url)">
+				<div class="left">
+					<div class="yuan" :class="{ 'through': item.date }"></div>
+					<div class="shu"></div>
+					<p>{{item.area}}</p>
+				</div>
+				<span>{{item.date}}</span>
+			</div>
+		</div>
+    </div>
+
+    <script>
+        var Main = {
+            data() {
+              return {
+                val: new Date(),
+				section:'',
+				name:'',
+				ind:0,
+				select_list:[],
+				name_select:[],
+				record_list:[]
+              }
+            },
+			created(){
+				this.get_select()
+			},
+			watch: {
+			    val(newValue, oldValue) {
+			      this.get_select()
+			      // 在这里可以处理选中日期改变的逻辑
+			      // 例如:
+			      // this.fetchEvents(newValue); // 拉取新选中日期的事件
+			    },
+			  },
+			methods:{
+				search(){
+					this.get_select()
+					const date = new Date(this.val);
+					const year = date.getFullYear();
+					const month = ('0' + (date.getMonth() + 1)).slice(-2);  // 月份从0开始,需要加1并补零
+					const day = ('0' + date.getDate()).slice(-2);           // 获取日并补零
+					const formattedDate = `${year}-${month}-${day}`;
+					const loading = this.$loading({
+					  lock: true,
+					  text: '数据加载中',
+					  spinner: 'el-icon-loading',
+					  background: 'rgba(0, 0, 0, 0.7)'
+					});
+					axios.post('http://anvideo.nxmy.com:8011/api/fanwei/get_person_travel',{'person_id':this.name,'date':formattedDate,'depart':this.section})
+						.then( (response)=> {
+							this.record_list = response.data.content.data
+							loading.close()
+						})
+						.catch(function (error) {
+							console.log(error);
+							loading.close()
+						});
+				},
+				get_select() {
+					const date = new Date(this.val);
+					const year = date.getFullYear();
+					const month = ('0' + (date.getMonth() + 1)).slice(-2);  // 月份从0开始,需要加1并补零
+					const day = ('0' + date.getDate()).slice(-2);           // 获取日并补零
+					const formattedDate = `${year}-${month}-${day}`;
+					
+					axios.post('http://anvideo.nxmy.com:8011/api/fanwei/get_query_conition',{'date':formattedDate})
+						.then( (response)=> {
+							this.select_list = response.data.content.data
+						})
+						.catch(function (error) {
+							console.log(error);
+						});
+				},
+				handleSectionChange() {
+					this.name = ''
+					this.ind = this.select_list.findIndex(item => item.name === this.section)
+					this.name_select = this.select_list[this.ind].person_list
+				},
+				page_dump(url){
+					if(url != ''){
+						window.location.href = 'http://10.186.132.147'+url
+					}
+				}
+			}
+          }
+        var Ctor = Vue.extend(Main)
+        new Ctor().$mount('#app')
+    </script>
+</body>
+
+</html>