任敬轩 преди 4 седмици
родител
ревизия
b1517937e3
променени са 3 файла, в които са добавени 88 реда и са изтрити 0 реда
  1. 10 0
      Modules/Admin/Http/Controllers/Api/ApiController.php
  2. 2 0
      Modules/Admin/Routes/api.php
  3. 76 0
      Modules/Admin/Services/ApiService.php

+ 10 - 0
Modules/Admin/Http/Controllers/Api/ApiController.php

@@ -278,6 +278,16 @@ class ApiController extends BaseController
         return self::successResponse($result);
     }
 
+    //全流程巡检记录排名
+    public function getRecordSort()
+    {
+        $depart = Input::get('depart', 'all');
+        $start_date = Input::get('start_date', '');
+        $end_date = Input::get('end_date', '');
+        $result = ApiService::getRecordSort($depart, $start_date,$end_date);
+        return self::successResponse($result);
+    }
+
     //网格化巡检记录列表
     public function getResultList()
     {

+ 2 - 0
Modules/Admin/Routes/api.php

@@ -42,6 +42,8 @@ Route::namespace('Api')->group(function () {
     Route::post('fanwei/get_result_conition', 'ApiController@getResultConition');//7
     //网格化巡检记录查询
     Route::post('fanwei/get_result_record', 'ApiController@getResultRecord');//9
+    //全流程巡检记录排名
+    Route::post('fanwei/get_record_sort', 'ApiController@getRecordSort');//9
     //网格化巡检记录列表
     Route::post('fanwei/get_result_list', 'ApiController@getResultList');
     //网格化巡检记录列表明细

+ 76 - 0
Modules/Admin/Services/ApiService.php

@@ -366,6 +366,82 @@ class ApiService{
         return $result;
     }
 
+    //全流程巡检记录排名
+    public static function getRecordSort($depart,$start_date,$end_date)
+    {
+        $result['status'] = true;
+        $result['msg']    = ApiEnum::RETURN_SUCCESS;
+        $result['data']   = [];
+
+        $query = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl');
+        if ($depart != 'all') {
+            $query = $query->where('xjdw', $depart);
+        }
+        $query = $query->whereBetween($start_date,$end_date);
+        $query = $query->get();
+
+        $people_list = [];
+        if(count($query) > 0){
+            for($i=0;$i<count($query);$i++){
+                if(!in_array($query[$i]->lrr,$people_list)){
+                    $people_list[] = $query[$i]->lrr;
+                }
+            }
+        }
+
+        $list = [];
+        $pie = [];
+        if(count($people_list) > 0){
+            for($i=0;$i<count($people_list);$i++){
+                $area_list = [];
+                for($j=0;$j<count($query);$j++){
+                    if($people_list[$i] == $query[$j]->lrr){
+                        $list[$i]['department'] = str_replace("洗选中心", "", $query[$j]->xjdw);
+                        $area_list[] = $query[$j]->xjqy;
+                    }
+                }
+                $unit_zd = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcqyzd')->where('szxmc',$list[$i]['department'])->where('IS_DELETE',0)->pluck('qymc');
+
+                $minCount = PHP_INT_MAX;
+
+                foreach ($unit_zd as $itemB) {
+                    // 如果数组A中不包含数组B中的某个项,则直接退出
+                    if (!in_array($itemB, $area_list)) {
+                        $minCount = 0;
+                    }
+
+                    // 计算该项在数组A中出现的次数
+                    $count = 0;
+                    foreach ($area_list as $itemA) {
+                        if ($itemA == $itemB) {
+                            $count++;
+                        }
+                    }
+
+                    // 更新最少的数量
+                    $minCount = min($minCount, $count);
+                }
+
+                $lrr = explode('|',$people_list[$i]);
+                $list[$i]['lastname'] = $lrr[0];
+                $list[$i]['person_id'] = $lrr[1];
+                $list[$i]['count'] = $minCount;
+
+                $pie[$i]['name'] = $lrr[0];
+                $pie[$i]['value'] = $minCount;
+            }
+        }
+
+        usort($list, function($a, $b) {
+            return $b['count'] <=> $a['count']; // 降序
+        });
+
+        $result['data']['list'] = $list;
+        $result['data']['pie'] = $pie;
+
+        return $result;
+    }
+
     //网格化巡检记录列表
     public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
     {