Sfoglia il codice sorgente

fix:export5,单位统计排名

Xu·LinPeng 5 mesi fa
parent
commit
914f4ecefc
1 ha cambiato i file con 35 aggiunte e 17 eliminazioni
  1. 35 17
      Modules/Camera/Http/Controllers/Api/CameraApiController.php

+ 35 - 17
Modules/Camera/Http/Controllers/Api/CameraApiController.php

@@ -3935,41 +3935,59 @@ class CameraApiController extends BaseController
             ->where('c.is_delete',0)
             ->orderBy('c.sort')->get();
 
+        $people_data = DB::connection('mysql_fwe10')->table('uf_xx_dkry as t')
+            ->select('t.xm','t.sort')
+            ->where('t.is_delete',0)
+            ->where('t.delete_type',0)
+            ->orderBy('t.sort')
+            ->get();
+
+        $people_arr = [];
+        foreach ($people_data as $key => $value){
+            $people_arr[] = $value->xm;
+        }
+        $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
+            ->whereBetween('create_time', [$start_time, $end_time])
+            ->where('is_delete',0)
+            ->where('current_step','结束节点')
+            ->where('delete_type',0)
+            ->whereNotNull('flow_id')
+//            ->where('coal_washery_id',$coal_list[$i]->ID)
+            ->get();
+        $risk_list_map = [];
+        foreach ($risk_list as $key => $val) {
+            $risk_list_map[$val->coal_washery_id][] = $val;
+        }
         if(count($coal_list) > 0){
             for($i=0;$i<count($coal_list);$i++){
-                $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
-                    ->whereBetween('create_time', [$start_time, $end_time])
-                    ->where('is_delete',0)
-                    ->where('current_step','结束节点')
-                    ->where('delete_type',0)
-                    ->whereNotNull('flow_id')
+                $coal_list_id = $coal_list[$i]->ID;
+                $risk_list = $risk_list_map[$coal_list_id] ?? null;
+                $var_1 = DB::connection('mysql_fwe10')->table('uf_xx_dkry as t')
+                    ->select('t.xm')
+                    ->where('t.is_delete',0)
+                    ->where('t.delete_type',0)
                     ->where('coal_washery_id',$coal_list[$i]->ID)
                     ->get();
+                $var2 = count($var_1);
                 if(count($risk_list) > 0){
                     $control_num = 0;
-                    $people_list = [];
-                    for($j=0;$j<count($risk_list);$j++){
+                    for ($j=0;$j<count($risk_list);$j++){
                         $people = explode('、',$risk_list[$j]->work_people);
-                        $control_num = $control_num + count($people);
-                        for($x=0;$x<count($people);$x++){
-                            array_push($people_list,$people[$x]);
-                        }
+                        $control_num += count(array_intersect($people, $people_arr));
                     }
-                    $people_list = array_unique($people_list);
-
                     $res[$i]['area'] = $coal_list[$i]->area;
                     $res[$i]['unit'] = $coal_list[$i]->title;
                     $res[$i]['work_num'] = count($risk_list);
                     $res[$i]['control_num'] = $control_num;
-                    $res[$i]['people_num'] = count($people_list);
-                    $res[$i]['people_avg_count'] = number_format($control_num/count($people_list), 2);
+                    $res[$i]['people_num'] = $var2;
+                    $res[$i]['people_avg_count'] = $var2 > 0 ? number_format($control_num/$var2, 2) : 0;
                     $res[$i]['sort'] = $coal_list[$i]->sort;
                 }else{
                     $res[$i]['area'] = $coal_list[$i]->area;
                     $res[$i]['unit'] = $coal_list[$i]->title;
                     $res[$i]['work_num'] = 0;
                     $res[$i]['control_num'] = 0;
-                    $res[$i]['people_num'] = 0;
+                    $res[$i]['people_num'] = $var2;
                     $res[$i]['people_avg_count'] = 0;
                     $res[$i]['sort'] = $coal_list[$i]->sort;
                 }