Explorar el Código

Merge branch 'master' of http://git.jieweizhineng.com/ushio/video_system into master

任敬轩 hace 2 días
padre
commit
cac2b19acc

+ 458 - 19
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -3088,8 +3088,6 @@ class CameraApiController extends BaseController
             ->whereDate('t.create_time', $date)
             ->where('t.is_delete',0)
             ->where('t.delete_type',0)
-            ->where('t.wwdw',null)
-            ->where('t.sgdd',null)
             ->where('t.current_step','结束节点')
             ->whereNotNull('t.flow_id');
 
@@ -3438,8 +3436,6 @@ class CameraApiController extends BaseController
             ->leftJoin('uf_xx_area as area','area.id','=','coal.area_id')
             ->where('risk.is_delete',0)
             ->where('risk.delete_type',0)
-            ->where('risk.wwdw',null)
-            ->where('risk.sgdd',null)
             ->whereDate('risk.create_time', $date)
             // ->whereIn('risk.risk_level',[0,1])
             ->where('risk.current_step','结束节点')
@@ -3677,8 +3673,6 @@ class CameraApiController extends BaseController
             ->where('t.is_delete', 0)
             ->where('t.current_step','结束节点')
             ->where('t.delete_type',0)
-            ->where('t.wwdw',null)
-            ->where('t.sgdd',null)
             ->whereNotNull('flow_id')
             ->where('move_camera','!=',null)
             ->orderBy('create_time')->get();
@@ -3766,8 +3760,6 @@ class CameraApiController extends BaseController
             ->where('t.wcqk',0)
             ->where('t.is_delete',0)
             ->where('t.delete_type',0)
-            ->where('t.wwdw',null)
-            ->where('t.sgdd',null)
             ->where('t.current_step','结束节点')
             ->whereNotNull('t.flow_id')
             ->get();
@@ -3895,8 +3887,6 @@ class CameraApiController extends BaseController
                     ->where('wcqk',0)
                     ->where('t.is_delete',0)
                     ->where('t.delete_type',0)
-                    ->where('t.wwdw',null)
-                    ->where('t.sgdd',null)
                     ->where('t.current_step','结束节点')
                     ->whereNotNull('t.flow_id')
                     ->orderBy('create_time')->get();
@@ -3992,8 +3982,6 @@ class CameraApiController extends BaseController
                     ->where('wcqk',0)
                     ->where('t.is_delete',0)
                     ->where('t.delete_type',0)
-                    ->where('t.wwdw',null)
-                    ->where('t.sgdd',null)
                     ->where('t.current_step','结束节点')
                     ->whereNotNull('t.flow_id')
                     ->orderBy('create_time')->get();
@@ -4081,8 +4069,6 @@ class CameraApiController extends BaseController
             ->whereBetween('t.create_time', [$start_time, $end_time])
             ->where('t.is_delete',0)
             ->where('t.delete_type',0)
-            ->where('t.wwdw',null)
-            ->where('t.sgdd',null)
             ->where('t.current_step','结束节点')
             ->whereNotNull('t.flow_id')
             ->orderBy('t1.sort')
@@ -4215,8 +4201,6 @@ class CameraApiController extends BaseController
         $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
             ->whereBetween('create_time', [$start_time, $end_time])
             ->where('is_delete',0)
-            ->where('wwdw',null)
-            ->where('sgdd',null)
             ->where('current_step','结束节点')
             ->where('delete_type',0)
             ->whereNotNull('flow_id')
@@ -4529,7 +4513,8 @@ class CameraApiController extends BaseController
                     $line['index'] = ++$risk_index;
                     $line['wwdw_num'] = $wwdw_num;
                     $line['coal_washery'] = $value->title;
-                    $line['work_place_num'] = $v->sgdsl;
+//                    $line['work_place_num'] = $v->sgdsl;
+                    $line['work_place_num'] = "Discard";
                     $line['wwdw'] = $v->wwdw;
                     $line['place'] = $coal_washery_dict[$v->sgdd]->title;
                     $line['level'] = $level_total;
@@ -4651,6 +4636,462 @@ class CameraApiController extends BaseController
     }
 
 
+
+    public function export62(Request $request){
+
+        $date = $request->query('date', date('Y-m-d'));
+        $coal_washery_id = $request->query('coal_washery_id');
+        $area_id = $request->query('area_id');
+
+        $classes = ['早班','中班','夜班','早班、中夜、夜班','早班、夜班','早班、中夜'];
+        $risk_desc = ['高风险','中风险','低风险'];
+        $risk_describe_dict = [0=>"设备日常检修、维护", 1=>"停产检修", 2=>"大中修", 3=>"计划性检修", 4=>"委外施工"];
+        // 风险类型
+        $risk_type = DB::connection('mysql_fwe10')
+            ->table('field_option as t')
+            ->where('t.field_id', '1055270106096394246')
+            ->where('t.is_delete',0)
+            ->where('t.delete_type',0)
+            ->get();
+        // 如果上边查到的风险类型还有问题的话,就用下边的维护的,不要去查数据库
+        $risk_type_dict = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
+        foreach ($risk_type as $key=>$value) {
+            $risk_type_key = $value->value_key;
+            $risk_type_name = $value->NAME;
+            $risk_type_dict[$risk_type_key] = $risk_type_name;
+        }
+
+        $risk_list = DB::connection('mysql_fwe10')
+            ->table('uf_xx_risk_assignment as t')
+            ->whereDate('t.create_time', $date)
+            ->where('t.is_delete',0)
+            ->where('t.delete_type',0)
+            ->whereNotNull('t.wwdw')
+            ->whereNotNull('t.sgdd')
+            ->where('t.current_step','结束节点')
+            ->whereNotNull('t.flow_id');
+
+
+        $previousDayTimestamp = strtotime($date . ' -1 day');
+        $previousDay = date('Y-m-d', $previousDayTimestamp);
+
+        $risk_list_previousDay = DB::connection('mysql_fwe10')
+            ->table('uf_xx_risk_assignment as t')
+            ->whereDate('t.create_time', $previousDay)
+            ->where('t.is_delete',0)
+            ->where('t.delete_type',0)
+            ->whereNotNull('t.wwdw')
+            ->whereNotNull('t.sgdd')
+            ->where('t.current_step','结束节点')
+            ->whereNotNull('t.flow_id');
+
+        if (!empty($coal_washery_id)) $risk_list->where('t.coal_washery_id', $coal_washery_id); // 筛选洗煤厂
+        if (!empty($area_id)) {
+            $risk_list->join('uf_xx_coal_washery as t1','t.coal_washery_id','=','t1.id')
+                ->where('t1.is_delete',0)
+                ->where('t1.delete_type',0)
+                ->join('uf_xx_area as t2','t1.area_id','=','t2.id')
+                ->where('t2.is_delete',0)
+                ->where('t2.delete_type',0)
+                ->where('t2.id', $area_id)
+                ->select([
+                    't.*'
+            ]);
+            $risk_list_previousDay->join('uf_xx_coal_washery as t1','t.coal_washery_id','=','t1.id')
+                ->where('t1.is_delete',0)
+                ->where('t1.delete_type',0)
+                ->join('uf_xx_area as t2','t1.area_id','=','t2.id')
+                ->where('t2.is_delete',0)
+                ->where('t2.delete_type',0)
+                ->where('t2.id', $area_id)
+                ->select([
+                    't.*'
+            ]);
+        }
+
+        $risk_list = $risk_list->orderBy('risk_level')->get();
+
+        $risk_list_previousDay = $risk_list_previousDay->orderBy('risk_level')->get();
+
+
+        // 洗煤厂数据
+        $coal_washery_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery as t')->where('t.is_delete',0);
+
+        $coal_washery_list = $coal_washery_list->select('t.*')->orderBy('t.sort')->get();
+
+
+        // 存放每个洗煤厂的信息
+        $coal_washery_dict = [];
+        foreach ($coal_washery_list as $key=>$value) {
+            $coal_washery_dict[$value->ID] = $value;
+        }
+
+        $res = [
+            "num"       => 0,
+            "gao"       => 0,
+            "zhong"     => 0,
+            "di"        => 0,
+            "risk_info" => "",
+            "risk_list"   => [],
+        ];
+
+        // 以下两行统计高风险中的不同风险类型各有几项(中风险同理)
+        $risk_zhong_con = [];
+        $risk_gao_con = [];
+        $coal_washery_risk_list = [];
+
+        // 统计委外单位的数量
+        $outsourcedUnit_total = [];
+        // 统计作业总人数
+        $people_total = 0;
+
+        // 组织字典
+        foreach ($risk_list as $key=>$value) {
+            // 获取洗煤厂ID
+            $coal_washery_id = $value->coal_washery_id;
+
+            if (!in_array($value->wwdw,$outsourcedUnit_total)){
+                $outsourcedUnit_total[] = $value->wwdw;
+            }
+
+            $people_total += $value->work_num;
+
+            // 风险数量统计
+            $risk_level = $value->risk_level;  // 风险类型
+            // 当 $risk_type_dict[$value->risk_type] 存在时取对应的值,不存在时取值 未知风险
+            $risk_type = $risk_type_dict[$value->risk_type] ?? "未知风险";
+
+            if($risk_level == 0) {
+                $res['gao']++;
+                if (!isset($risk_gao_con[$risk_type])) {
+                    $risk_gao_con[$risk_type] = 1;
+                } else {
+                    $risk_gao_con[$risk_type] ++;
+                };
+            } else if($risk_level == 1) {
+                $res['zhong']++;
+                if (!isset($risk_zhong_con[$risk_type])) {
+                    $risk_zhong_con[$risk_type] = 1;
+                } else {
+                    $risk_zhong_con[$risk_type] ++;
+                };
+            } else {
+                $res['di']++;
+            }
+
+            // 煤矿风险列表
+            $coal_washery_risk_list[$coal_washery_id][] = $value;
+        }
+
+        $wwdwNum = count($outsourcedUnit_total);
+        $res['num'] = count($risk_list);
+
+
+        if ($res['gao'] > 0) {
+            $risk_gao_info = '(其中:';
+            foreach ($risk_gao_con as $key => $value) {
+                $risk_gao_info .= $key.$value.'项,';
+            }
+            $risk_gao_info = substr($risk_gao_info, 0, -3);
+            $risk_gao_info .= ');';
+        } else {
+            $risk_gao_info = ";";
+        }
+
+        if ($res['zhong'] > 0) {
+            $risk_zhong_info = '(其中:';
+            foreach ($risk_zhong_con as $key => $value) {
+                $risk_zhong_info .= $key.$value.'项,';
+            }
+            $risk_zhong_info = substr($risk_zhong_info, 0, -3);
+            $risk_zhong_info .= ');';
+        } else {
+            $risk_zhong_info = ";";
+        }
+
+
+
+        // 统计前一天的相关数据
+        $preHigh = 0;
+        $preMid = 0;
+        $preLow = 0;
+        $prePeople = 0;
+        $preRiskNum = count($risk_list_previousDay);
+        $preWwdw = [];
+        foreach ($risk_list_previousDay as $key=>$value) {
+            // 获取洗煤厂ID
+            $coal_washery_id = $value->coal_washery_id;
+
+            if (!in_array($value->wwdw,$preWwdw)){
+                $preWwdw[] = $value->wwdw;
+            }
+
+            $prePeople += $value->work_num;
+
+            // 风险数量统计
+            $risk_level = $value->risk_level;  // 风险类型
+            // 当 $risk_type_dict[$value->risk_type] 存在时取对应的值,不存在时取值 未知风险
+            $risk_type = $risk_type_dict[$value->risk_type] ?? "未知风险";
+
+            if($risk_level == 0) {
+                $preHigh++;
+            } else if($risk_level == 1) {
+                $preMid++;
+            } else {
+                $preLow++;
+            }
+
+            // 煤矿风险列表
+            $pre_day_coal_washery_risk_list[$coal_washery_id][] = $value;
+        }
+
+        $preWwdwNum = count($preWwdw);
+
+        // 委外单位相差
+        $preVar1 = sprintf("%+d", $wwdwNum - $preWwdwNum);
+        // 总作业想相差
+        $preVar2 = sprintf("%+d", $res['num'] - $preRiskNum);
+        // 高
+        $preVar3 = sprintf("%+d",$res['gao'] - $preHigh);
+        // 中
+        $preVar4 = sprintf("%+d",$res['zhong'] - $preMid);
+        // 低
+        $preVar5 = sprintf("%+d",$res['di'] - $preLow);
+        // 总人数相差
+        $preVar6 = sprintf("%+d",$people_total - $prePeople);
+
+
+
+        $res['risk_info'] = "1.委外施工单位共".$wwdwNum."个(".$preVar1."),总作业项:".$res['num']."项(".$preVar2.");高风险:".$res['gao']."项(".$preVar3.")".$risk_gao_info."中风险:".$res['zhong']."项(".$preVar4.")".$risk_zhong_info."低风险:".$res['di']."项(".$preVar5.");总作业人数:".$people_total."人(".$preVar6.")。";
+
+
+
+
+
+        $total2 = '';
+        $index_1 = 0;
+        foreach ($coal_washery_dict as $key => $value) {
+            $id = $value->ID;
+            if (isset($coal_washery_risk_list[$id])) {
+
+                // 拿出当前id煤矿的所有风险
+                $coal_washery_risk_info_arr = $coal_washery_risk_list[$id];
+                $wwdw = [];
+                $sgdd = [];
+                $zyrs =  0;
+
+                $gao = 0;
+                $zhong = 0;
+                $di = 0;
+
+                foreach ($coal_washery_risk_info_arr as $k => $v) {
+                    if(!in_array($v->wwdw,$wwdw)){
+                        $wwdw[] = $v->wwdw;
+                    }
+                    if (!in_array($v->sgdd,$sgdd)){
+                        $sgdd[] = $v->sgdd;
+                    }
+                    $zyrs += $v->work_num;
+                    if ($v->risk_level == 0){
+                        $gao++;
+                    } else if ($v->risk_level == 1){
+                        $zhong++;
+                    }else{
+                        $di++;
+                    }
+
+                }
+                $level_total = '';
+                if ($gao   > 0) $level_total .= '高风险'.$gao."项\n";
+                if ($zhong > 0) $level_total .= '中风险'.$zhong."项\n";
+                if ($di    > 0) $level_total .= '低风险'.$di."项\n";
+                $level_total = mb_substr($level_total, 0, mb_strlen($level_total) - 1);
+
+                $wwdw_num = count($wwdw);
+                $sgdd_num = count($sgdd);
+
+                /**
+                 * 以下代码是对前一天的对应洗煤厂的统计
+                 *
+                 */
+                // 如果当前洗煤厂前一天有数据则拿出来统计没有相关的数据为零
+                $pre_wwdw = [];
+                $pre_sgdd = [];
+                $pre_zyrs =  0;
+
+                if (isset($pre_day_coal_washery_risk_list[$id])) {
+
+                    // 拿出当前id煤矿的所有风险
+                    $pre_coal_washery_risk_info_arr = $pre_day_coal_washery_risk_list[$id];
+
+
+                    foreach ($pre_coal_washery_risk_info_arr as $k => $v) {
+                        if(!in_array($v->wwdw,$pre_wwdw)){
+                            $pre_wwdw[] = $v->wwdw;
+                        }
+                        if (!in_array($v->sgdd,$pre_sgdd)){
+                            $pre_sgdd[] = $v->sgdd;
+                        }
+                        $pre_zyrs += $v->work_num;
+                    }
+
+                }
+                $pre_wwdw_num = count($pre_wwdw);
+                $pre_sgdd_num = count($pre_sgdd);
+
+                // 委外单位差值
+                $preVar7 = sprintf("%+d",$wwdw_num - $pre_wwdw_num);
+                // 作业单位差值
+                $preVar8 = sprintf("%+d",$sgdd_num - $pre_sgdd_num);
+                // 作业人数差值
+                $preVar9 = sprintf("%+d",$zyrs - $pre_zyrs);
+
+                $total2 .= ++$index_1.'.'.$value->title.'引进委外单位'.$wwdw_num.'个('.$preVar7.'),作业单位'.$sgdd_num.'个('.$preVar8.'),作业人数:'.$zyrs."人(".$preVar9.")。\n";
+
+
+                $line = [
+                    'index' => '',
+                    'fxdj' => '',
+                    'fxlx' => '',
+                    'coal_washery' => '',
+                    'wwdw'=>'',
+                    'wwdw_num'=>'',
+                    'work_place_num' => '',
+                    'level' => "",
+                    'content' => '',
+                    'place' => '',
+                    'dkr' => '',
+                    'zrs' => $zyrs,
+                    'rs' => 0,
+                ];
+
+                $risk_index = 0;
+                foreach ($coal_washery_risk_info_arr as $k => $v) {
+
+
+                    $line['index'] = ++$risk_index;
+                    $line['wwdw_num'] = $wwdw_num;
+                    $line['coal_washery'] = $value->title;
+//                    $line['work_place_num'] = $v->sgdsl;
+                    $line['work_place_num'] = "Discard";
+                    $line['wwdw'] = $v->wwdw;
+                    $line['place'] = $coal_washery_dict[$v->sgdd]->title;
+                    $line['level'] = $level_total;
+                    $line['content'] = $v->risk_name;
+                    $line['dkr'] = $v->work_people;
+                    $line['rs'] = $v->work_num;
+
+                    if ($v->risk_level == 0) {
+                        $line['fxdj'] = '高风险';
+                    } elseif ($v->risk_level == 1) {
+                        $line['fxdj'] = '中风险';
+                    } else {
+                        $line['fxdj'] = '低风险';
+                    }
+                    if($v->risk_type != null) {
+                        $line['fxlx'] = $risk_type_dict[$v->risk_type];
+                    }else{
+                        $line['fxlx'] = '未知';
+                    }
+
+                    $res['risk_list'][] = $line;
+
+
+
+                }
+
+            }
+        }
+
+        $res['risk_info2'] = $total2;
+
+        /**
+         *
+         * 以下代码以施工地点为中新统计相关数据
+         */
+        $work_place_list=[];
+        foreach ($risk_list as $key1=>$v1) {
+            // 获取施工地点id
+            $work_place = $v1->sgdd;
+            // 施工地点列表
+            $work_place_list[$work_place][] = $v1;
+
+        }
+
+        $pre_work_place_list=[];
+        foreach ($risk_list_previousDay as $key1=>$v1) {
+            // 获取施工地点id
+            $pre_work_place = $v1->sgdd;
+            // 施工地点列表
+            $pre_work_place_list[$pre_work_place][] = $v1;
+
+        }
+
+        $uniqueKeys = array_keys($work_place_list);
+        $count1 = count($uniqueKeys);
+        $var3 = (int) ($count1 / 2);
+
+
+        $total3 = '';
+        $total4 = '';
+        $index_2 = 0;
+        foreach ($coal_washery_dict as $key=>$value) {
+
+            $id = $value->ID;
+
+            if (isset($work_place_list[$id])) {
+
+                $workNumber = 0;
+                $riskWorkNum = 0;
+
+                // 拿出当前施工地点的所有风险
+                $work_place_list_arr = $work_place_list[$id];
+                foreach ($work_place_list_arr as $k => $v) {
+                    $workNumber += $v->work_num;
+                }
+                $riskWorkNum = count($work_place_list_arr);
+
+
+                $preWorkNumber = 0;
+                $preRiskWorkNum = 0;
+                if (isset($pre_work_place_list[$id])) {
+
+                    // 拿出当前施工地点的所有风险
+                    $pre_work_place_list_arr = $pre_work_place_list[$id];
+                    foreach ($pre_work_place_list_arr as $k => $v) {
+                        $preWorkNumber += $v->work_num;
+                    }
+                    $preRiskWorkNum = count($pre_work_place_list_arr);
+                }
+
+                // 委外作业项差值
+                $preVar10 = sprintf("%+d",$riskWorkNum - $preRiskWorkNum);
+                // 作业人数差值
+                $preVar11 = sprintf("%+d",$workNumber - $preWorkNumber);
+
+                if (++$index_2<=$var3){
+                    $total3 .= $index_2.'.'.$value->title.'委外作业'.$riskWorkNum.'项('.$preVar10.'),作业人数:'.$workNumber."人(".$preVar11.");\n";
+                } else{
+                    $total4 .= $index_2.'.'.$value->title.'委外作业'.$riskWorkNum.'项('.$preVar10.'),作业人数:'.$workNumber."人(".$preVar11.");\n";
+                }
+
+
+
+            }
+        }
+
+
+
+        $res['risk_info3'] = $total3;
+        $res['risk_info4'] = $total4;
+
+
+
+
+        return $res;
+    }
+
+
     public function export7(Request $request){
 
         $date = $request->query('date', date('Y-m-d'));
@@ -4680,8 +5121,6 @@ class CameraApiController extends BaseController
             ->whereDate('t.create_time', $date)
             ->where('t.is_delete',0)
             ->where('t.delete_type',0)
-            ->where('t.wwdw',null)
-            ->where('t.sgdd',null)
             ->where('t.current_step','结束节点')
             ->whereNotNull('t.flow_id');
 

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

@@ -101,6 +101,7 @@ Route::namespace('Api')->group(function () {
     Route::post('task_xixuan/export4', 'CameraApiController@export4');//导出盯控次数统计
     Route::post('task_xixuan/export5', 'CameraApiController@export5');//导出人均盯控次数统计
     Route::post('task_xixuan/export6', 'CameraApiController@export6');//导出委外作业清单
+    Route::post('task_xixuan/export62', 'CameraApiController@export62');//导出委外作业清单
 
 
     //大华视频接口