You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.4 KiB
89 lines
3.4 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\AepSdk\Apis\Aep_device_management;
|
|
use think\Db;
|
|
use think\Exception;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
use think\exception\DbException;
|
|
use think\exception\PDOException;
|
|
|
|
class Device extends Base
|
|
{
|
|
|
|
/**
|
|
* 获取设备信息列表
|
|
* @return false|string
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws Exception
|
|
* @throws ModelNotFoundException
|
|
* @throws PDOException
|
|
*/
|
|
public function queryDeviceList()
|
|
{
|
|
$app_key = config('iot.app_key');
|
|
$app_secret = config('iot.app_secret');
|
|
$tableName = 'bs_product_device';
|
|
|
|
$productList = Db::table('bs_product')->where('status', 1)->field('productId,apiKey')->select();
|
|
|
|
$updateStatus = ['status' => 0];
|
|
foreach ($productList as $productListRow) {
|
|
|
|
$apiKey = $productListRow['apiKey'];
|
|
$productId = $productListRow['productId'];
|
|
$idArr = [];
|
|
|
|
$result = Aep_device_management::QueryDeviceList($app_key, $app_secret, $apiKey, $productId);
|
|
|
|
$jsonDataDe = json_decode($result, true);
|
|
|
|
|
|
if ($jsonDataDe['code'] !== 0) continue;
|
|
|
|
$list = $jsonDataDe['result']['list'];
|
|
|
|
if (!$list) {
|
|
Db::table($tableName)->where('productId', $productId)->update($updateStatus);
|
|
continue;
|
|
}
|
|
|
|
foreach ($list as $item) {
|
|
|
|
|
|
$deviceId = $item['deviceId'];
|
|
|
|
$queryRes = Db::table($tableName)->where('deviceId', $deviceId)->find();
|
|
|
|
$data = [
|
|
'deviceId' => $deviceId, // 设备id
|
|
'deviceName' => $item['deviceName'], // 终端名称
|
|
'tenantId' => $item['tenantId'], // 租户id
|
|
'productId' => $item['productId'], // 产品id
|
|
'firmwareVersion' => $item['firmwareVersion'], // String,固件版本
|
|
'deviceStatus' => $item['deviceStatus'], //Integer 设备状态 0:已注册,1:已激活,2:已注销
|
|
'createTime' => $item['createTime'], // 创建时间
|
|
'updateTime' => $item['updateTime'], // 修改时间
|
|
'netStatus' => $item['netStatus'], // 设备在线状态
|
|
'onlineAt' => $item['onlineAt'], // 设备最后上线时间
|
|
'offlineAt' => $item['offlineAt'], // 设备最后下线时间
|
|
];
|
|
if (isset($item['imei'])) $data['imei'] = $item['imei'];// String,IMEI号,全局唯一,根据产品的Endpoint必填,创建时可相同,则删除原产品新建产品
|
|
if (isset($item['imsi'])) $data['imsi'] = $item['imsi'];// String,IMSI号,根据产品的Endpoint选填
|
|
if (isset($item['autoObserver'])) $data['autoObserver'] = $item['autoObserver'];// 是否订阅,0.订阅1.不订阅
|
|
if (isset($item['createBy'])) $data['createBy'] = $item['createBy'];// 创建者
|
|
if (isset($item['updateBy'])) $data['updateBy'] = $item['updateBy'];// 修改者
|
|
|
|
$idArr = $this->queryUpdate($tableName, $queryRes, $data, $idArr);
|
|
}
|
|
|
|
$this->updateStatus($tableName, $idArr);
|
|
}
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
}
|