cqp 6 months ago
parent
commit
aedd10adb4

+ 2 - 1
app/Http/Controllers/Api/ReportFormsController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Api;
 
 use App\Model\SystemL;
+use App\Service\EquipmentService;
 use App\Service\ReportFormsService;
 use Illuminate\Http\Request;
 
@@ -93,7 +94,7 @@ class ReportFormsController extends BaseController
     }
 
     public function deviceList(Request $request){
-        $device = SystemL::$device;
+        $device = (new EquipmentService())->getDeviceList();
         $data = [];
         foreach ($device as $k => $v){
             $data[] = [

+ 13 - 10
app/Http/Controllers/Api/ScreenController.php

@@ -18,6 +18,7 @@ use App\Model\SalesFrom;
 use App\Model\ScrappCount;
 use App\Model\SystemL;
 use App\Model\Team;
+use App\Service\EquipmentService;
 use App\Service\FyySqlServerService;
 use App\Service\ReportFormsService;
 use Carbon\Carbon;
@@ -440,7 +441,8 @@ class ScreenController extends BaseController
     public function product_num(Request $request){
         //数据模型
         $models = [];
-        foreach (SystemL::$device as $k => $v){
+        $device = (new EquipmentService())->getDeviceList();
+        foreach ($device as $k => $v){
             $models[$k] = [
                 "machine_day_num"=> 0,
                 "machine_month_num"=> 0,
@@ -467,7 +469,7 @@ class ScreenController extends BaseController
             ->whereIn('data_point_name',[SystemL::run,SystemL::work,SystemL::stop,SystemL::standBy])
             ->get()->toArray();
         //组织当日数据
-        $this->fillData($today,1,$models);
+        $this->fillData($today,1,$models,$device);
 
         //上周时间
         $previousWeekStartDate = Carbon::now()->subWeek()->startOfWeek();
@@ -487,12 +489,12 @@ class ScreenController extends BaseController
                 ->whereIn('data_point_name',[SystemL::run,SystemL::work,SystemL::stop,SystemL::standBy])
                 ->get()->toArray();
             //组织上周数据
-            $this->fillData($list_week,2,$models);
+            $this->fillData($list_week,2,$models,$device);
             //缓存
 //            Cache::put($last_week_key,json_encode($list_week),86400);
         }else{
             //有缓存 填充数据 组织上周数据
-            $this->fillData($return_last_week,2,$models);
+            $this->fillData($return_last_week,2,$models,$device);
         }
 
         //上月时间
@@ -513,12 +515,12 @@ class ScreenController extends BaseController
                 ->whereIn('data_point_name',[SystemL::run,SystemL::work,SystemL::stop,SystemL::standBy])
                 ->get()->toArray();
             //组织上月数据
-            $this->fillData($list_month,3,$models);
+            $this->fillData($list_month,3,$models,$device);
             //缓存
 //            Cache::put($last_month_key,json_encode($list_month),86400);
         }else{
             //有缓存 填充数据 组织上周数据
-            $this->fillData($return_last_month,3,$models);
+            $this->fillData($return_last_month,3,$models,$device);
         }
 
         $return = [];
@@ -603,7 +605,7 @@ class ScreenController extends BaseController
      * @param $type
      * @param $models
      */
-    public function fillData($list,$type,&$models){
+    public function fillData($list,$type,&$models,$device){
         if(empty($list)) return;
 
         $run_time = $process_time = $fault = $start_time = [];
@@ -637,7 +639,7 @@ class ScreenController extends BaseController
                 }
             }
         }
-        foreach (SystemL::$device as $key => $value){
+        foreach ($device as $key => $value){
             //运行次数
             $run_num = $run_time[$key] ?? 0;
             //工作次数
@@ -781,8 +783,9 @@ class ScreenController extends BaseController
         //数据模型
         $models = [];
         $is_all_close = 1;
-        $e_map = Equipment::where('del_time',0)->pluck('id','code');
-        foreach (SystemL::$device as $k => $v){
+        $e_map = Equipment::where('del_time',0)->pluck('id','code')->toArray();
+        $device = (new EquipmentService())->getDeviceList();
+        foreach ($device as $k => $v){
             $is_close = 1;
             if(isset($map[$v])){
                 $max_time = intval($map[$v]['max_time']) ?? 0;

+ 8 - 0
app/Service/EquipmentService.php

@@ -221,4 +221,12 @@ class EquipmentService extends Service
 
         return [true, $data];
     }
+
+    public function getDeviceList($index = "title", $value = "code"){
+        $deviceList = Equipment::where('del_time',0)
+            ->select('id','title','code')
+            ->get()->toArray();
+
+        return array_column($deviceList,$value,$index);
+    }
 }

+ 7 - 4
app/Service/ReportFormsService.php

@@ -865,9 +865,11 @@ class ReportFormsService extends Service
 
         $process_time = [];
 
+        $device = (new EquipmentService())->getDeviceList();
         $result = SystemL::where('time','>=',$data['time'][0])
             ->where('time','<',$data['time'][1])
             ->where('data_point_name',SystemL::standBy)
+            ->whereIn('device_name',array_keys($device))
             ->select('device_name','time','value')
             ->get()->toArray();
 
@@ -886,7 +888,7 @@ class ReportFormsService extends Service
         sort($time_all);
 
         //数据结构模型
-        foreach (SystemL::$device as $k => $v){
+        foreach ($device as $k => $v){
             if(isset($process_time[$k])){
                 foreach ($time_all as $t){
                     if(! isset($process_time[$k][$t])){
@@ -927,15 +929,16 @@ class ReportFormsService extends Service
         $day = $this->returnDays($data['time'], false);
         if($day > 31) return [false, '查询时间仅支持范围区间在31天内'];
 
+        $device = (new EquipmentService())->getDeviceList();
+        $device_name = array_keys($device);
         //获取数据
         $result = SystemL::where('time','>=',$data['time'][0])
             ->where('time','<',$data['time'][1])
+            ->whereIn('device_name', $device_name)
             ->select('device_name','time','value','data_point_name')
             ->get()->toArray();
 
         if(empty($result)) return [true,[]];
-        $device_name = array_values(array_unique(array_column($result,'device_name')));
-
 
         $run_time = $process_time = $fault = $time_all = [];
         foreach ($result as $value){
@@ -971,7 +974,7 @@ class ReportFormsService extends Service
 
         //组织模型  返回大致的数据结构
         $models = [];
-        foreach (SystemL::$device as $k => $v){
+        foreach ($device as $k => $v){
             foreach ($time_all as $t){
                 $models[$k][$t] = 0;
             }