This commit is contained in:
chenbo 2024-01-09 10:34:19 +08:00
parent 8ad58b7790
commit 0466e710a7
1 changed files with 10 additions and 6 deletions

View File

@ -201,16 +201,20 @@ class DeviceLogic extends BaseLogic
->findOrEmpty(); ->findOrEmpty();
$monitorItemArray = []; $monitorItemArray = [];
if (!empty($detail['monitor_item'])) {
$monitorItemArray = explode(',', $detail['monitor_item']);
}
$dictTypeId = Db::name('dict_type')->where('type', 'monitor_item')->value('id'); $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(); $monitorItemArray = Db::name('dict_data')->where('type_id', $dictTypeId)->whereIn('value', $monitorItemArray)->field(['name', 'value'])->select()->toArray();
foreach($monitorItemArray as $k=>$v) { foreach($monitorItemArray as $k=>$v) {
$monitorItemArray[$k]['device_id'] = $params['id']; $monitorItemArray[$k]['device_id'] = $params['id'];
$monitorItemArray[$k]['monitor_value'] = '-'; $monitorItemArray[$k]['monitor_value'] = '-';
$monitorItemArray[$k]['last_time'] = '-'; $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)) { if (!empty($monitorData)) {
$monitorItemArray[$k]['monitor_value'] = $monitorData['monitor_value']; $monitorItemArray[$k]['monitor_value'] = $monitorData[$v['value']];
$monitorItemArray[$k]['last_time'] = date('Y-m-d H:i:s', $monitorData['create_time']); $monitorItemArray[$k]['last_time'] =$monitorData['create_time'];
} }
} }
$detail['monitor_item'] = $monitorItemArray; $detail['monitor_item'] = $monitorItemArray;
@ -227,14 +231,14 @@ class DeviceLogic extends BaseLogic
$limitOffset = ($pageNo - 1) * $pageSize; $limitOffset = ($pageNo - 1) * $pageSize;
$limitLength = $pageSize; $limitLength = $pageSize;
$where['device_id'] = $params['id']; $where['device_id'] = $params['id'];
$where['monitor_item'] = $params['monitor_type']; $lists = Db::name('land_collection')
$lists = Db::name('device_monitor_data')
->where($where) ->where($where)
->field(["{$params['monitor_type']} as monitor_value", 'id', 'create_time'])
->limit($limitOffset, $limitLength) ->limit($limitOffset, $limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()
->toArray(); ->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'); return compact('lists', 'count', 'page_no', 'page_size');
} }
} }