|
@@ -10,7 +10,17 @@ use App\Model\SystemL;
|
|
|
class SystemlService extends Service
|
|
class SystemlService extends Service
|
|
|
{
|
|
{
|
|
|
public static function getLastData($code = [], $min = -1){
|
|
public static function getLastData($code = [], $min = -1){
|
|
|
- if(empty($code)) return [];
|
|
|
|
|
|
|
+ if(empty($code)) {
|
|
|
|
|
+ $codes = Device::where('del_time',0)->select('code','device_type_id')->get()->toArray();
|
|
|
|
|
+ if(empty($codes)) return [];
|
|
|
|
|
+ $code = array_column($codes,'code');
|
|
|
|
|
+ $code_type_map = array_column($codes,'device_type_id','code');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $return = [];
|
|
|
|
|
+ foreach ($code as $value){
|
|
|
|
|
+ $return[$value] = [];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$time = strtotime($min.' min',time());
|
|
$time = strtotime($min.' min',time());
|
|
|
$time = $time * 1000;
|
|
$time = $time * 1000;
|
|
@@ -21,15 +31,15 @@ class SystemlService extends Service
|
|
|
->orderBy('id','desc')
|
|
->orderBy('id','desc')
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
|
|
|
|
- $return = [];
|
|
|
|
|
if(! empty($result)){
|
|
if(! empty($result)){
|
|
|
foreach ($result as $value){
|
|
foreach ($result as $value){
|
|
|
- if(isset($return[$value['device_no']])) continue;
|
|
|
|
|
|
|
+ if(! empty($return[$value['device_no']])) continue;
|
|
|
//只取每个设备最新的一条数据
|
|
//只取每个设备最新的一条数据
|
|
|
$return[$value['device_no']] = [
|
|
$return[$value['device_no']] = [
|
|
|
'data_point_name' => $value['data_point_name'],
|
|
'data_point_name' => $value['data_point_name'],
|
|
|
'value' => $value['value']
|
|
'value' => $value['value']
|
|
|
];
|
|
];
|
|
|
|
|
+ if(! empty($code_type_map[$value['device_no']])) $return[$value['device_no']]['device_type_id'] = $code_type_map[$value['device_no']];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -100,7 +110,7 @@ class SystemlService extends Service
|
|
|
//获取最新设备的数据
|
|
//获取最新设备的数据
|
|
|
$data = self::getLastData(array_column($screen,'code'));
|
|
$data = self::getLastData(array_column($screen,'code'));
|
|
|
foreach ($data as $key => $value){
|
|
foreach ($data as $key => $value){
|
|
|
- if(isset($screen_map[$key])){
|
|
|
|
|
|
|
+ if(isset($screen_map[$key]) && ! empty($value)){
|
|
|
$tmp = $screen_map[$key];
|
|
$tmp = $screen_map[$key];
|
|
|
$tmp_coordinate = $tmp['coordinate'];
|
|
$tmp_coordinate = $tmp['coordinate'];
|
|
|
if(isset($result[$tmp['screen_id']]) && $tmp_coordinate){
|
|
if(isset($result[$tmp['screen_id']]) && $tmp_coordinate){
|
|
@@ -167,7 +177,7 @@ class SystemlService extends Service
|
|
|
//获取最新设备的数据
|
|
//获取最新设备的数据
|
|
|
$data = self::getLastData(array_column($screen,'code'));
|
|
$data = self::getLastData(array_column($screen,'code'));
|
|
|
foreach ($data as $key => $value){
|
|
foreach ($data as $key => $value){
|
|
|
- if(isset($screen_map[$key])){
|
|
|
|
|
|
|
+ if(isset($screen_map[$key]) && ! empty($value)){
|
|
|
$tmp = $screen_map[$key];
|
|
$tmp = $screen_map[$key];
|
|
|
if(isset($result[$tmp['screen_id']]) && $value['value'] == 1){
|
|
if(isset($result[$tmp['screen_id']]) && $value['value'] == 1){
|
|
|
$result[$tmp['screen_id']] = 1;
|
|
$result[$tmp['screen_id']] = 1;
|
|
@@ -201,7 +211,7 @@ class SystemlService extends Service
|
|
|
foreach ($gateway_connect_device as $gateway => $value){
|
|
foreach ($gateway_connect_device as $gateway => $value){
|
|
|
if(! empty($result[$gateway])) continue;
|
|
if(! empty($result[$gateway])) continue;
|
|
|
foreach ($value as $code){
|
|
foreach ($value as $code){
|
|
|
- if(isset($data[$code])){
|
|
|
|
|
|
|
+ if(! empty($data[$code])){
|
|
|
$result[$gateway] = 1;
|
|
$result[$gateway] = 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|