Ver código fonte

Merge remote-tracking branch 'origin/master'

q 1 ano atrás
pai
commit
ac5f6a2db8

+ 163 - 9
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -168,12 +168,14 @@ class CameraApiController extends BaseController
         }
 
         //宁煤在离线数量
-        $data[0]['title'] = '宁煤公司';
-        $data[0]['mine_code'] = $ningmei[0]->slug;
-        $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
-        $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
-        $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
-        $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
+        $nm['title'] = '宁煤公司';
+        $nm['mine_code'] = $ningmei[0]->slug;
+        $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
+        $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
+        $nm['total_offline'] = $nm['total'] - $nm['total_online'];
+        $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
+
+        $data = [];
 
         //宁煤下各矿在离线数量
         $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
@@ -191,9 +193,9 @@ class CameraApiController extends BaseController
             $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
 
             if($total == 0){
-                $rate = "0%";
+                $rate = "0";
             }else{
-                $rate = round($total_online / $total * 100,2)."%";
+                $rate = round($total_online / $total * 100,2);
             }
 
             if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
@@ -226,7 +228,116 @@ class CameraApiController extends BaseController
             ]);
         }
 
-        return self::successResponse($data);
+        $timestamp = strtotime(date('Y-m-d H:i:s'));
+        $hour = date('G', $timestamp);
+        $minute = date('i', $timestamp);
+        $month = date('n', $timestamp);
+        $day = date('j', $timestamp);
+        if($minute == '00'){
+            $minute = '';
+        }
+        if ($hour < 12) {
+            $time = $month."月".$day."号上午".$hour."时".$minute;
+        } elseif ($hour >= 12 && $hour < 18) {
+            $time = $month."月".$day."号下午".$hour."时".$minute;
+        } else {
+            $time = $month."月".$day."号晚上".$hour."时".$minute;
+        }
+
+        $unit_max_name = '';
+        $unit_max_rate = 0;
+        $unit_min_name = '';
+        $unit_min_rate = 100;
+
+        $mzy_max_name = '';
+        $mzy_max_rate = 0;
+        $mzy_min_name = '';
+        $mzy_min_rate = 100;
+
+        $other_max_name = '';
+        $other_max_rate = 0;
+        $other_min_name = '';
+        $other_min_rate = 100;
+
+        if(count($data)>0){
+            for($i=0;$i<count($data);$i++){
+                if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
+
+                    if($data[$i]['rate'] > $unit_max_rate){
+                        $unit_max_rate = $data[$i]['rate'];
+                    }
+                    if($data[$i]['rate'] < $unit_min_rate){
+                        $unit_min_rate = $data[$i]['rate'];
+                    }
+
+                }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
+
+                    if($data[$i]['rate'] > $mzy_max_rate){
+                        $mzy_max_rate = $data[$i]['rate'];
+                    }
+                    if($data[$i]['rate'] < $mzy_min_rate){
+                        $mzy_min_rate = $data[$i]['rate'];
+                    }
+
+                }else{
+
+                    if($data[$i]['rate'] > $other_max_rate){
+                        $other_max_rate = $data[$i]['rate'];
+                    }
+                    if($data[$i]['rate'] < $other_min_rate){
+                        $other_min_rate = $data[$i]['rate'];
+                    }
+
+                }
+            }
+
+            for($i=0;$i<count($data);$i++){
+                if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
+
+                    if($data[$i]['rate'] == $unit_max_rate){
+                        $unit_max_name = $unit_max_name.'、'.$data[$i]['title'];
+                    }
+                    if($data[$i]['rate'] == $unit_min_rate){
+                        $unit_min_name = $unit_max_name.'、'.$data[$i]['title'];
+                    }
+
+                }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
+
+                    if($data[$i]['rate'] == $mzy_max_rate){
+                        $mzy_max_name = $mzy_max_name.'、'.$data[$i]['title'];
+                    }
+                    if($data[$i]['rate'] == $mzy_min_rate){
+                        $mzy_min_name = $mzy_max_name.'、'.$data[$i]['title'];
+                    }
+
+                }else{
+
+                    if($data[$i]['rate'] == $other_max_rate){
+                        $other_max_name = $other_max_name.'、'.$data[$i]['title'];
+                    }
+                    if($data[$i]['rate'] == $other_min_rate){
+                        $other_min_name = $other_max_name.'、'.$data[$i]['title'];
+                    }
+
+                }
+            }
+        }
+
+        $unit_max_name = mb_substr($unit_max_name, 1);
+        $unit_min_name = mb_substr($unit_min_name, 1);
+        $mzy_max_name = mb_substr($mzy_max_name, 1);
+        $mzy_min_name = mb_substr($mzy_min_name, 1);
+        $other_max_name = mb_substr($other_max_name, 1);
+        $other_min_name = mb_substr($other_min_name, 1);
+
+        $result['data'] = '本周公司视频摄像头在线数'.$nm['total_online'].'个,'.'在线率为'.$nm['rate'].'%('.$time
+            .'统计)。其中:①煤炭生产建设单位在线率排名第一的单位是'.$unit_max_name.',在线率达到'.$unit_max_rate
+            .'%;排名末位的单位是'.$unit_min_name.',在线率达到'.$unit_min_rate
+            .'%。②煤制油化工单位在线率排名第一的单位是'.$mzy_max_name.',在线率达到'.$mzy_max_rate.'%;排名末位的单位是'
+            .$mzy_min_name.',在线率达到'.$mzy_min_rate.'%。③其他单位在线率排名第一的单位是'.$other_max_name
+            .',在线率达到'.$other_max_rate.'%;排名末位的单位是'.$other_min_name.',在线率达到'.$other_min_rate.'%。';
+
+        return self::successResponse($result);
     }
 
     //宁煤不在线摄像头列表
@@ -1126,4 +1237,47 @@ class CameraApiController extends BaseController
             return false;
         }
     }
+
+    //摄像头访问记录入库
+    public function cameraRecordInsert(Request $request){
+        $params = $request->all();
+
+        if(isset($params['staff_num']) && isset($params['name']) && isset($params['department']) && isset($params['post']) && isset($params['camera_id']) && isset($params['start_time'])){
+            $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
+            $mine = DB::table('mine_list')->where('id',$camera[0]->mine_id)->get();
+            $degree = explode('|',$mine[0]->degree);
+            $unit = DB::table('mine_list')->where('id',$degree[0])->get();
+
+            $data['staff_num'] = $params['staff_num'];
+            $data['name'] = $params['name'];
+            $data['department'] = $params['department'];
+            $data['post'] = $params['post'];
+            $data['mine_id'] = $camera[0]->mine_id;
+            $data['camera_id'] = $params['camera_id'];
+            $data['camera_name'] = $camera[0]->camera_name;
+            $data['unit_name'] = $unit[0]->title;
+            if(isset($params['base64']) && $params['base64'] != null && $params['base64'] != ''){
+                $data['base64'] = $params['base64'];
+            }
+            $data['start_time'] = date('Y-m-d').' '.$params['start_time'];
+            // $data['start_time'] = date('Y-m-d').' '.$params['end_time'];
+            $data['created_at'] = date('Y-m-d H:i:s');
+            $data['updated_at'] = date('Y-m-d H:i:s');
+
+            DB::table('camera_record')->insert($data);
+        }
+    }
+
+    //摄像头访问记录列表
+    public function cameraRecordList(Request $request){
+        $params = $request->all();
+
+        if (!isset($params['camera_id'])) {
+            return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
+        }
+
+        $camera_record = DB::table('camera_record')->where('camera_id',$params['camera_id'])->where('deleted_at',null)->orderBy('created_at','desc')->limit(20)->get();
+
+        return self::successResponse($camera_record);
+    }
 }

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

@@ -46,10 +46,12 @@ Route::namespace('Api')->group(function () {
     Route::post('camera/get_risk_ningmei', 'CameraApiController@getRiskNingmei');//宁煤高风险摄像头
     Route::post('camera/get_total_ningmei', 'CameraApiController@getTotalNingmei');//宁煤摄像头统计
     Route::post('camera/offline_list', 'CameraApiController@offlineList');//宁煤不在线摄像头列表
-    Route::post('camera/get_total_string', 'CameraApiController@getTotalString');//宁煤摄像头统计字符串
+    Route::get('camera/get_total_string', 'CameraApiController@getTotalString');//宁煤摄像头统计字符串
     Route::get('test', 'CameraApiController@test');
     Route::post('oss_url','CameraApiController@ossUrl');//文章图片上传至阿里云
     Route::post('article_list','CameraApiController@articleList');//文章列表
     Route::post('duty_information','CameraApiController@dutyInformation');//值班信息
     Route::post('type_list','CameraApiController@typeList');//分类列表
+    Route::post('camera_record_insert','CameraApiController@cameraRecordInsert');//摄像托访问记录入库
+    Route::post('camera_record_list','CameraApiController@cameraRecordList');//摄像托访问记录列表
 });

+ 2 - 2
Modules/Camera/Services/CameraServices.php

@@ -2091,9 +2091,9 @@ class CameraServices
 //        }
 
         //取流进程
-//        $exec = 'nohup /usr/bin/ffmpeg -i "' . $video_url . '" -vcodec copy -acodec copy -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';
+//      $exec = 'nohup /usr/bin/ffmpeg -i "' . $video_url . '" -vcodec copy -acodec copy -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';
 
-//        $exec = 'nohup /usr/bin/ffmpeg -rtsp_transport tcp -i "' . $video_url . '" -b:v 200k -c:v libx264 -c:a copy -s 384*288 -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 -threads 4 /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';
+//      $exec = 'nohup /usr/bin/ffmpeg -rtsp_transport tcp -i "' . $video_url . '" -b:v 200k -c:v libx264 -c:a copy -s 384*288 -vbsf h264_mp4toannexb -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 2 -threads 4 /www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path . '/' . CameraEnum::M3U8_FILE_NAME . ' >/dev/null &';
         shell_exec($exec);
 
         //sleep10秒生成文件

+ 142 - 0
app/Console/Commands/CameraStatusHistory.php

@@ -0,0 +1,142 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Enum\ApiEnum;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class CameraStatusHistory extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'camera:statushistory';
+
+    /**
+     * 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->cameraStatusHistory();
+    }
+
+    //摄像头统计历史数据
+    public function cameraStatusHistory()
+    {
+        $result['status'] = true;
+        $result['msg']    = ApiEnum::RETURN_SUCCESS;
+
+        //宁煤集团
+        $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
+
+        $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
+        $mine_ningmei = [];//宁煤集团所有区域
+        foreach($mine_all as $k=>$v){
+            if(explode('|',$v->degree)[0] == $ningmei[0]->id){
+                $mine_ningmei[] = $v->id;
+            }
+        }
+
+        //宁煤在离线数量
+        $nm['title'] = '宁煤公司';
+        $nm['mine_code'] = $ningmei[0]->slug;
+        $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
+        $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
+        $nm['total_offline'] = $nm['total'] - $nm['total_online'];
+        $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
+        $nm['type'] = 0;
+        $nm['date'] = date('Y-m-d');
+        DB::table('camera_status_history')->insert($nm);
+
+        $data = [];
+
+        //宁煤下各矿在离线数量
+        $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
+        foreach($mine_list as $k => $v){
+            $mine_use = [];//宁煤下每个矿所有区域
+            foreach($mine_all as $key=>$value){
+                if(count(explode('|',$value->degree)) > 1){
+                    if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
+                        $mine_use[] = $value->id;
+                    }
+                }
+            }
+
+            $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
+            $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
+
+            if($total == 0){
+                $rate = "0";
+            }else{
+                $rate = round($total_online / $total * 100,2);
+            }
+
+            if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
+                $res['title'] = $v->title;
+                $res['mine_code'] = $v->slug."_jituan";
+                $res['total'] = $total;
+                $res['total_online'] = $total_online;
+                $res['total_offline'] = $total - $total_online;
+                $res['rate'] = $rate;
+            }else{
+                array_push($data,[
+                    'title'=>$v->title,
+                    'mine_code'=>$v->slug."_jituan",
+                    'total'=>$total,
+                    'total_online'=>$total_online,
+                    'total_offline'=>$total - $total_online,
+                    'rate'=>$rate
+                ]);
+            }
+
+            $ins['title'] = $v->title;
+            $ins['mine_code'] = $v->slug;
+            $ins['total'] = $total;
+            $ins['total_online'] = $total_online;
+            $ins['total_offline'] = $total - $total_online;
+            $ins['rate'] = $rate;
+            if(strpos($v->title, '煤矿') !== false || strpos($v->title, '洗选') !== false){
+                $ins['type'] = 1;
+            }elseif(strpos($v->title, '煤制油') !== false || strpos($v->title, '烯烃') !== false || strpos($v->title, '甲醇') !== false || strpos($v->title, '精蜡') !== false){
+                $ins['type'] = 2;
+            }else{
+                $ins['type'] = 3;
+            }
+            $ins['date'] = date('Y-m-d');
+            DB::table('camera_status_history')->insert($ins);
+        }
+
+        if(isset($res)){
+            array_push($data,[
+                'title'=>$res['title'],
+                'mine_code'=>$res['mine_code'],
+                'total'=>$res['total'],
+                'total_online'=>$res['total_online'],
+                'total_offline'=>$res['total_offline'],
+                'rate'=>$res['rate']
+            ]);
+        }
+    }
+}