index.ts 1.32 KB
import { DeviceAttributeItemType, HistoryData } from './model';
import { defHttp } from '/@/utils/http/axios';
import { OrderByEnum } from '/@/views/device/localtion/cpns/TimePeriodForm/config';

// 获取历史数据
export const getDeviceHistoryInfo = (params: Recordable, orderBy = OrderByEnum.DESC) => {
  return defHttp.get<HistoryData>(
    {
      url: `/plugins/telemetry/DEVICE/${params.entityId}/values/timeseries`,
      params: { ...params, entityId: null, orderBy },
    },
    {
      joinPrefix: false,
      withShareToken: true,
    }
  );
};

// 获取设备数据的keys
export const getDeviceDataKeys = (id: string) => {
  return defHttp.get<string[]>(
    {
      url: `/plugins/telemetry/DEVICE/${id}/keys/timeseries`,
    },
    {
      joinPrefix: false,
    }
  );
};
// 获取设备状态,在线 or 离线时间
export const getDeviceActiveTime = (entityId: string) => {
  return defHttp.get<DeviceAttributeItemType[]>(
    {
      url: `/plugins/telemetry/DEVICE/${entityId}/values/attributes?keys=active`,
    },
    {
      joinPrefix: false,
      withShareToken: true,
    }
  );
};

// 获取设备属性
export const getDeviceAttribute = (entityId: string) => {
  return defHttp.get(
    {
      url: `/plugins/telemetry/DEVICE/${entityId}/values/attributes?keys`,
    },
    {
      joinPrefix: false,
    }
  );
};