import request from '@/utils/request'

// 查询设备分组
export function listDeviceGroup(userId) {
    return request({
        url: '/iot/group/list?pageSize=30&pageNum=1&userId='+userId,
        method: 'get'
    })
}


// 查询设备
export function listDevice(pageNum,deviceName,deptId) {
    let url = '/iot/device/shortList?pageNum='+pageNum+'&pageSize=12';
    if(deviceName){
        url  = url +"&deviceName="+encodeURIComponent(deviceName)
    }
    if(deptId){
        url  = url +"&deptId="+deptId
    }
    return request({
        url: url,
        method: 'get'
    })
}
//获取设备详情
export function getDetail(id){
    return request({
        url: '/iot/device/'+id,
        method: 'get'
    })
}
//获取设备状态
export function getDeviceStatus(id,childId){
    let url = '/iot/device/runningStatus/'+id;
    if(childId){
        url = url+"?childId="+childId;
    }
    return request({
        url: url,
        method: 'get'
    })
}
//物模型缓存
export function cacheJsonThingsModel(id){
    let url = '/iot/model/cache/'+id;
    return request({
        url: url,
        method: 'get'
    })
}

//获取设备消息列表
export function getDeviceMsg(){
    let url = '/iot/configqrcode/list?pageSize=10';
    return request({
        url: url,
        method: 'get'
    })
}
//绑定设备码
export function bindDeviceQrcode(qrcode,deviceNo){
    let url = '/iot/device/bind?deviceNo='+deviceNo+"&qrcode="+qrcode;
    return request({
        url: url,
        method: 'get',
    })
}
//获取警报列表
export function getAlertList(pageNum,pageSize){
    let url = '/iot/alertLog/list?pageNum='+pageNum+'&pageSize='+pageSize;
    return request({
        url: url,
        method: 'get',
    })
}
//处理报警
export function handleAlert(alertLog){
    return request({
        url: '/iot/alertLog',
        data:alertLog,
        method: 'put',
    })
}
//查询详情
export function getAlertLog(id){
    return request({
        url: '/iot/alertLog/'+id,
        method: 'get',
    })
}
//根据二维码找到设备详情
export function getDevcieByQrcode(id){
    return request({
        url: '/iot/device/getDeviceByQrcode?qrcode='+id,
        method: 'get',
    })
}

//根据二维码找到设备详情
export function bingDeviceDept(device){
    return request({
        url: '/iot/device',
        data:device,
        method: 'put',
    })
}
//主动上报错误
export function reportError(err){
    return request({
        url: '/iot/desc',
        data:err,
        method: 'post',
    })
}

/**
 * 主动上报列表
 * @param pageNum
 * @param pageSize
 * @returns {*}
 */
export function errorList(pageNum,pageSize){
    let url = '/iot/desc/list?pageNum='+pageNum+'&pageSize='+pageSize;
    return request({
        url: url,
        method: 'get',
    })
}
//设备注销记录
export function resetList(pageNum,pageSize,deviceName){
    let url = '/iot/reset/list?pageNum='+pageNum+'&pageSize='+pageSize;
    if(deviceName){
        url  = url +"&deviceName="+encodeURIComponent(deviceName)
    }
    return request({
        url: url,
        method: 'get',
    })
}
//获取设备运行时间统计
export function getDeviceRunTime(deviceid){
    let url = '/iot/device/getDeviceRunTime/'+deviceid
    return request({
        url: url,
        method: 'get',
    })
}
//获取所有runtime事件排序
export function getAllDeviceRunTime(){
    let url = '/iot/device/rankRunTime'
    return request({
        url: url,
        method: 'get',
    })
}

