/*
 * @Author: Badguy
 * @Date: 2022-04-13 14:35:17
 * @LastEditTime: 2022-05-13 09:26:03
 * @LastEditors: your name
 * @Description: 数据整合接口
 * have a nice day!
 */

import request from '@/utils/request'
import { getToken } from '@/utils/auth'
import { Message } from 'element-ui'

export function GeneralDataReception (params) {
  return request({
    url: '/openApi/generalDataReception',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

export function Query (params) {
  return request({
    url: '/openApi/query',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

//服务管理-启动
export function Start (params) {
  return request({
    url: '/openApi/start',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

//服务管理-停止
export function Stop (params) {
  return request({
    url: '/openApi/stop',
    method: 'post',
    headers: {
      'content-type': 'application/json'
    },
    data: params
  })
}

export async function myQuery (obj) {
  const params = {
    event: '0',
    token: getToken()
  }
  try {
    const result = await Query(Object.assign(params, obj))
    if (Number(result.code) === 0) {
      return result.returnData
    } else {
      Message.error(result.message ?? '失败')
      return Promise.reject(result.message)
    }
  } catch (error) {
    return Promise.reject(error)
  }
}
