import request from '@/utils/request'

// 获取设备出厂列表
export const getDeviceLeavesFactoryList = data => {
    for (let key in data) {
        if (data[key] === '') {
            delete data[key]
        }
    }
    data.orderBy = 'desc'
    return request({
        url: '/cs-device-boot/EquipmentDelivery/list',
        method: 'POST',
        data: data
    })
}

// 新增出厂设备
export const addEquipmentDelivery = data => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/addEquipmentDelivery',
        method: 'POST',
        data: data
    })
}

// 删除出厂设备
export const deleteEquipmentDelivery = id => {
    let form = new FormData()
    form.append('id', id)
    return request({
        url: '/cs-device-boot/EquipmentDelivery/AuditEquipmentDelivery',
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 恢复出厂设置
export const resetEquipmentDelivery = id => {
    let form = new FormData()
    form.append('nDid', id)
    return request({
        url: '/access-boot/device/resetFactory',
        method: 'POST',
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 编辑出厂设备

export const editEquipmentDelivery = data => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/updateEquipmentDelivery',
        method: 'POST',
        data: data
    })
}

// 设备树

export const getDeviceTree = () => {
    return request({
        url: '/cs-device-boot/csLedger/deviceTree',
        method: 'POST'
    })
}
// 四层设备树(监测点层)
export const lineTree = () => {
    return request({
        url: '/cs-device-boot/csLedger/lineTree',
        method: 'POST'
    })
}

//装置基础数据和模板数据
export const getDeviceData = (deviceId, type, lineId = '') => {
    let form = new FormData()
    form.append('deviceId', deviceId)
    form.append('lineId', lineId)
    form.append('type', type)
    return request({
        url: '/cs-device-boot/EquipmentDelivery/deviceData',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

//根据数据集获取详细数据
export const getArrayBySet = dataSet => {
    let form = new FormData()
    form.append('dataSet', dataSet)
    return request({
        url: '/cs-device-boot/csDataArray/getArrayBySet',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 根据数据集获取指标数据
export const getTargetById = id => {
    let form = new FormData()
    form.append('id', id)
    return request({
        url: '/cs-device-boot/csDataArray/getTargetById',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 查询分组
export const getGroup = dataSet => {
    let form = new FormData()
    form.append('dataSet', dataSet)
    return request({
        url: '/cs-device-boot/csGroup/getGroup',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 删除分组
export const deleteGroup = groupId => {
    let form = new FormData()
    form.append('groupId', groupId)
    return request({
        url: '/cs-device-boot/csGroup/deleteGroup',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 更新组和指标关系

export const updateGroArr = data => {
    return request({
        url: '/cs-device-boot/csGroArr/updateGroArr',
        method: 'POST',
        data: data
    })
}

// 装置分组实时数据
export const deviceRtData = data => {
    let form = new FormData()
    form.append('id', data.id)
    form.append('lineId', data.lineId)
    form.append('pageNum', data.pageNum)
    form.append('pageSize', data.pageSize)
    form.append('searchValue', data.searchValue)

    return request({
        url: '/cs-device-boot/csGroup/deviceRtData',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}

// 装置分组历史数据
export const deviceHisData = data => {
    return request({
        url: '/cs-device-boot/csGroup/deviceHistoryData',
        method: 'POST',
        data: Object.assign(
            {
                endTime: '',
                id: '',
                lineId: '',
                pageNum: 1,
                pageSize: 20,
                startTime: ''
            },
            data
        )
    })
}

// 查询设备数据趋势

export const getDeviceDataTrend = data => {
    return request({
        url: '/cs-harmonic-boot/datatrend/querydatatrend',
        method: 'POST',
        data: data
    })
}

// 查询游客配置
export const getVisitorConfig = () => {
    return request({
        url: '/cs-device-boot/csTouristData/queryAll',
        method: 'POST'
    })
}

// 更新游客配置
export const updateVisitorConfig = data => {
    return request({
        url: '/cs-device-boot/csTouristData/add',
        method: 'POST',
        data: data
    })
}

// 移除游客配置

export const deleteVisitorConfig = data => {
    return request({
        url: '/cs-device-boot/csTouristData/remove',
        method: 'POST',
        data: data
    })
}

// 上传拓扑图
export const uploadTopo = file => {
    let form = new FormData()
    form.append('file', file)
    return request({
        url: '/cs-device-boot/topologyTemplate/uploadImage',
        method: 'POST',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data: form
    })
}

// 上传拓扑图模板监测点位置
export const uploadTopoPoint = data => {
    return request({
        url: '/cs-device-boot/lineTemplate/addLineTemplate',
        method: 'POST',
        data: data
    })
}

// 查询拓扑图模板
export const getTopoTemplate = () => {
    return request({
        url: '/cs-device-boot/topologyTemplate/queryImage',
        method: 'POST'
    })
}

//删除拓扑图模板
export const deleteTopoTemplate = id => {
    let form = new FormData()
    form.append('id', id)
    return request({
        url: '/cs-device-boot/topologyTemplate/deleteImage',
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: form
    })
}
//删除拓扑图模板
export const userLogquery = data => {
    return request({
        url: '/cs-device-boot/cslog/queryLog',
        method: 'POST',
        data: data
    })
}
export const queryPushLog = data => {
    return request({
        url: '/cs-device-boot/csEventSendMsg/queryLog',
        method: 'POST',
        data: data
    })
}
export const queryDebugLog = data => {
    return request({
        url: '/cs-device-boot/process/queryPage',
        method: 'POST',
        data: data
    })
}

// 批量导入设备
export const batchImportDevice = file => {
    let form = new FormData()
    form.append('file', file)
    return request({
        url: '/cs-device-boot/EquipmentDelivery/importEquipment',
        method: 'POST',
        responseType: 'blob',
        data: form
    })
}
