|
@@ -70,6 +70,141 @@ class CameraApiController extends BaseController
|
|
|
return self::successResponse($result);
|
|
|
}
|
|
|
|
|
|
+ //宁煤摄像头统计
|
|
|
+ public function getTotalNingmei(){
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //宁煤在离线数量
|
|
|
+ $data[$ningmei[0]->title]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
|
|
|
+ $data[$ningmei[0]->title]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
|
|
|
+ $data[$ningmei[0]->title]['total_offline'] = $data[$ningmei[0]->title]['total'] - $data[$ningmei[0]->title]['total_online'];
|
|
|
+
|
|
|
+ //宁煤下各矿在离线数量
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data[$v->title]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('deleted_at',null)->count();
|
|
|
+ $data[$v->title]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('camera_status',1)->where('deleted_at',null)->count();
|
|
|
+ $data[$v->title]['total_offline'] = $data[$v->title]['total'] - $data[$v->title]['total_online'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::successResponse($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //宁煤高风险摄像头
|
|
|
+ public function getRiskNingmei(){
|
|
|
+ $mine_code = Input::get('mine_code', '');
|
|
|
+ if (!$mine_code) {
|
|
|
+ return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['status'] = true;
|
|
|
+ $result['msg'] = ApiEnum::RETURN_SUCCESS;
|
|
|
+
|
|
|
+ //宁煤集团
|
|
|
+ $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
|
|
|
+
|
|
|
+ //宁煤集团下级单位
|
|
|
+ $mine = DB::table('mine_list')
|
|
|
+ ->where('parent_id',$ningmei[0]->id)
|
|
|
+ ->where('slug','like','%'.$mine_code.'%')
|
|
|
+ ->where('deleted_at',null)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ //子区域树形列表
|
|
|
+ $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
|
|
|
+ $risk_id = null;
|
|
|
+ if(count($child_list)>0){
|
|
|
+ $risk_id = $this->mineTree($child_list);
|
|
|
+ }
|
|
|
+
|
|
|
+ $mine_list = [];
|
|
|
+
|
|
|
+ if($risk_id != null){
|
|
|
+ $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
|
|
|
+ if(count($risk) > 0){
|
|
|
+ //有子区域
|
|
|
+ $mine_list = $this->riskTree($risk,[]);
|
|
|
+ }else{
|
|
|
+ //没有子区域
|
|
|
+ $mine_list[] = $risk_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $camera_list = DB::table('camera_list')
|
|
|
+ ->select('camera_list.*','mine_list.title')
|
|
|
+ ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
|
|
|
+ ->where('camera_list.deleted_at',null)
|
|
|
+ ->whereIn('camera_list.mine_id',$mine_list)
|
|
|
+ ->orderBy('sort', 'desc')->get();
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ foreach($camera_list as $k=>$v){
|
|
|
+ $result[$k]['parent_id'] = $ningmei[0]->id;
|
|
|
+ $result[$k]['camera_id'] = $v->id;
|
|
|
+ $result[$k]['mine_name'] = $v->title;
|
|
|
+ $result[$k]['camera_name'] = $v->camera_name;
|
|
|
+ $result[$k]['cover_picture'] = $v->cover_picture;
|
|
|
+ $result[$k]['camera_status'] = $v->camera_status;
|
|
|
+ $result[$k]['base64'] = $v->base64;
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::successResponse($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function mineTree($regions)
|
|
|
+ {
|
|
|
+ $arr = null;
|
|
|
+ foreach ($regions as $key => $value) {
|
|
|
+ $risk = explode('高风险作业',$value->title);
|
|
|
+ if (count($risk)>1){
|
|
|
+ return $value->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
|
|
|
+ if (count($mine_child) > 0) {
|
|
|
+ $arr = self::mineTree($mine_child, $value->id);
|
|
|
+ if($arr != null){
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function riskTree($regions,$risk_list)
|
|
|
+ {
|
|
|
+ foreach ($regions as $key => $value) {
|
|
|
+ $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
|
|
|
+ if (count($risk_child) > 0) {
|
|
|
+ $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
|
|
|
+ }else{
|
|
|
+ $risk_list[] = $value->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $risk_list;
|
|
|
+ }
|
|
|
+
|
|
|
//高风险区域摄像头
|
|
|
public function getCameraByMinecode(){
|
|
|
$mine_code = Input::get('mine_code', '');
|