From 0466e710a71f92813fcc37d6e5c50ac44f3b5fe8 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Tue, 9 Jan 2024 10:34:19 +0800 Subject: [PATCH] fixed --- app/adminapi/logic/device/DeviceLogic.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/adminapi/logic/device/DeviceLogic.php b/app/adminapi/logic/device/DeviceLogic.php index 35ab007e..7a75d473 100644 --- a/app/adminapi/logic/device/DeviceLogic.php +++ b/app/adminapi/logic/device/DeviceLogic.php @@ -201,16 +201,20 @@ class DeviceLogic extends BaseLogic ->findOrEmpty(); $monitorItemArray = []; + if (!empty($detail['monitor_item'])) { + $monitorItemArray = explode(',', $detail['monitor_item']); + } + $dictTypeId = Db::name('dict_type')->where('type', 'monitor_item')->value('id'); $monitorItemArray = Db::name('dict_data')->where('type_id', $dictTypeId)->whereIn('value', $monitorItemArray)->field(['name', 'value'])->select()->toArray(); foreach($monitorItemArray as $k=>$v) { $monitorItemArray[$k]['device_id'] = $params['id']; $monitorItemArray[$k]['monitor_value'] = '-'; $monitorItemArray[$k]['last_time'] = '-'; - $monitorData = Db::name('land_collection')->where('device_id', $params['id'])->where('monitor_item', $v['value'])->order(['id' => 'desc'])->find(); + $monitorData = Db::name('land_collection')->where('device_id', $params['id'])->order(['id' => 'desc'])->find(); if (!empty($monitorData)) { - $monitorItemArray[$k]['monitor_value'] = $monitorData['monitor_value']; - $monitorItemArray[$k]['last_time'] = date('Y-m-d H:i:s', $monitorData['create_time']); + $monitorItemArray[$k]['monitor_value'] = $monitorData[$v['value']]; + $monitorItemArray[$k]['last_time'] =$monitorData['create_time']; } } $detail['monitor_item'] = $monitorItemArray; @@ -227,14 +231,14 @@ class DeviceLogic extends BaseLogic $limitOffset = ($pageNo - 1) * $pageSize; $limitLength = $pageSize; $where['device_id'] = $params['id']; - $where['monitor_item'] = $params['monitor_type']; - $lists = Db::name('device_monitor_data') + $lists = Db::name('land_collection') ->where($where) + ->field(["{$params['monitor_type']} as monitor_value", 'id', 'create_time']) ->limit($limitOffset, $limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); - $count = Db::name('device_monitor_data')->where($where)->count(); + $count = Db::name('land_collection')->where($where)->count(); return compact('lists', 'count', 'page_no', 'page_size'); } } \ No newline at end of file