import request from '@/utils/request'

// 查询设备管理列表
export function listEquipment(query) {
  return request({
    url: '/dcs/equipment/list',
    method: 'get',
    params: query
  })
}

// 查询设备管理详细
export function getEquipment(equipmentId) {
  return request({
    url: '/dcs/equipment/' + equipmentId,
    method: 'get'
  })
}

// 新增设备管理
export function addEquipment(data) {
  return request({
    url: '/dcs/equipment',
    method: 'post',
    data: data
  })
}

// 修改设备管理
export function updateEquipment(data) {
  return request({
    url: '/dcs/equipment',
    method: 'put',
    data: data
  })
}

// 删除设备管理
export function delEquipment(equipmentId) {
  return request({
    url: '/dcs/equipment/' + equipmentId,
    method: 'delete'
  })
}

//根据设备类型获取设备树状结构列表
export function getEquipmentTreeByDataType(dataType) {
  return request({
    url: '/hnyz/equipment/getEquipmentTreeByDataType?dataType=' + dataType,
    method: 'post',
  })
}

//获取传感器相关的设备类型列表
export function getEquipmentSensorTree() {
  return request({
    url: '/hnyz/equipment/getEquipmentSensorTree',
    method: 'get',
  })
}

//influxDB数据查询
export function queryWithFlux({ measurement, fields, timeRangeStart, timeRangeStop, windowPeriod, aggregateFunction }) {
  return request({
    url: '/influxdb/queryWithFlux',
    method: 'post',
    headers: {
      repeatSubmit: false,//允许重复提交
    },
    data: {
      "bucket": "shanghai_dcs_bucket",//桶名
      "measurement": measurement,//表名-数据类型
      "fields": fields,//查询字段数组
      "timeRangeStart": timeRangeStart,
      "timeRangeStop": timeRangeStop,
      "windowPeriod": windowPeriod,//时间间隔
      "aggregateFunction": aggregateFunction,//聚合函数
    }
  })
}
