cqpCow 1 anno fa
parent
commit
61f17719a3
2 ha cambiato i file con 48 aggiunte e 0 eliminazioni
  1. 16 0
      app/Service/GatewayService.php
  2. 32 0
      app/Service/SystemlService.php

+ 16 - 0
app/Service/GatewayService.php

@@ -65,8 +65,10 @@ class GatewayService extends Service
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
         if(! empty($data['ip'])) $model->where('ip', 'LIKE', '%'.$data['ip'].'%');
+        if(isset($data['is_online'])) $model->where('is_online', $data['is_online']);
 
         $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list);
 
         return [true,$list];
     }
@@ -92,4 +94,18 @@ class GatewayService extends Service
 
         return [true,''];
     }
+
+    public function fillData($data){
+        if(empty($data['data'])) return $data;
+
+        //获取仓是否在线离线状态
+        $online = SystemlService::getIsOnlineStatusGateWay(array_column($data['data'],'id'));
+
+        foreach ($data['data'] as $key => $value){
+            $tmp_online = $online[$value['id']] ?? 0;
+            $data['data'][$key]['is_online'] = $tmp_online;
+        }
+
+        return $data;
+    }
 }

+ 32 - 0
app/Service/SystemlService.php

@@ -183,4 +183,36 @@ class SystemlService extends Service
 
         return $result;
     }
+
+    public static function getIsOnlineStatusGateWay($gateway){
+        if(empty($gateway)) return [];
+
+        //网关是否在线
+        $result = [];
+        foreach ($gateway as $value){
+            $result[$value] = 0;
+        }
+
+        $device = Device::where('del_time',0)
+            ->whereIn('gateway_id',$gateway)
+            ->select('code','gateway_id')
+            ->get()->toArray();
+        $gateway_connect_device = [];
+        foreach ($device as $value){
+            $gateway_connect_device[$value['gateway_id']][] = $value['code'];
+        }
+
+        //获取最新设备的数据
+        $data = self::getLastData(array_column($device,'code'));
+        foreach ($gateway_connect_device as $gateway => $value){
+            if(! empty($result[$gateway])) continue;
+            foreach ($value as $code){
+                if(isset($data[$code])){
+                    $result[$gateway] = 1;
+                }
+            }
+        }
+
+        return $result;
+    }
 }