import request from '@/utils/request'
const api = '/bi-api'

export const reportCategoryList = (params) => request.get(api + '/visual/self/report/list', { params })
export const reportCategorySave = (data) => request.post(api + '/visual/self/report/submit', data)
export const reportCategoryDel = (params) => request.post(api + '/visual/self/report/remove', {}, { params })
export const reportDetail = (params) => request.get(api + '/visual/selfReport/detail', { params })
export const reportList = (params) => request.get(api + '/visual/selfReport/list', { params })
export const reportSaveSimple = (data) => request.post(api + '/visual/selfReport/update', data)
export const reportSave = (data) => request.post(api + '/visual/selfReport/submit', data, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
export const reportDel = (id) => request.post(api + '/visual/selfReport/delete?ids=' + id)
export const reportCopy = (data) => request.post(api + '/visual/selfReport/copy', data)
export const reportSort = (ids) => request.post(api + '/visual/selfReport/adjustOrder?ids=' + ids)
export const reportAuthList = (id) => request.get(api + '/visual/report/permission/dataPermList/' + id)
export const reportAuthSave = (data) => request.post(api + '/visual/report/permission/perform', data)
export const reportCollectCategoryList = (params) => request.get(api + '/visual/category/favourite/report/list', { params })
export const reportCollectCategorySave = (data) => request.get(api + '/visual/category/favourite/report/submit', data)
export const reportCollectCategoryDel = (params) => request.get(api + '/visual/category/favourite/report/remove', {}, { params })
export const reportAuthListByAuth = (params) => request.get(api + '/visual/report/permission/selfReportIdList', { params })
export const reportAuthSaveByAuth = (data) => request.post(api + '/visual/report/permission/submit', data)

export const getDatasourceDetail = (params) => {
  return request({
    url: api + '/report/reportdatasource/detail',
    method: 'get',
    params
  })
}
export const getList = (current, size, params) => {
  return request({
    url: api + '/blade-report/report/rest/list',
    method: 'get',
    params: {
      ...params,
      current,
      size
    }
  })
}
export const remove = (ids) => {
  return request({
    url: api + '/blade-report/report/rest/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
//数据源管理
export const reportdatasourceList = () => {
  return request({
    url: api + '/report/reportdatasource/list',
    method: 'get'
  })
}
//根据租户ID查询数据源
export const cubeDatasourceTenantid = (tenantId) => {
  return request({
    url: api + '/cube/data/datasource/tenantid',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: 'get',
    params: {
      tenantId
    }
  })
}
//根据租户ID查询数据集
export const cubeDataCubeTenantid = (params) => {
  return request.get(api + '/cube/data/cube/tenantid', { params })
}
export const reportdatasourcePage = (params) => {
  return request.get(api + '/report/reportdatasource/page', { params })
}
export const reportdatasourceSave = (params) => {
  return request({
    url: api + '/report/reportdatasource/save',
    method: 'post',
    data: params
  })
}
export const reportdatasourceUpdate = (params) => {
  return request({
    url: api + '/report/reportdatasource/update',
    method: 'post',
    data: params
  })
}
export const reportdatasourceDetail = () => {
  return request({
    url: api + '/report/reportdatasource/list',
    method: 'get'
  })
}
export const reportdatasourceRemove = (ids) => {
  return request({
    url: api + '/report/reportdatasource/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
export const baseInfoListViews = (id) => {
  return request({
    url: api + '/report/baseInfo/listViews',
    method: 'get',
    params: {
      dataSourceId: id
    }
  })
}
export const listViewsByDataSource = (params) => {
  return request({
    url: api + '/report/baseInfo/listViewsByDataSource',
    method: 'get',
    params
  })
}
export const reportBaseInfoListColumns = (params) => {
  return request({
    url: api + '/report/baseInfo/listColumns',
    method: 'get',
    params: params
  })
}
export const listColumnsByDatasource = (params) => {
  return request({
    url: api + '/report/baseInfo/listColumnsByDatasource',
    method: 'get',
    params: params
  })
}
export const baseInforemoveBaseInfoCache = (params) => {
  return request({
    url: api + '/report/baseInfo/removeBaseInfoCache',
    method: 'get',
    params: params
  })
}
// 报表指标分类接口
export const indexcategorySubmit = (params) => {
  return request({
    url: api + '/indexcategory/submit',
    method: 'post',
    data: params
  })
}
export const indexcategoryList = (params) => {
  return request({
    url: api + '/indexcategory/list',
    method: 'get',
    params: params
  })
}
// 报表指标信息接口
export const indexinfoSubmit = (params) => {
  return request({
    url: api + '/indexinfo/submit',
    method: 'post',
    data: params
  })
}
export const indexinfoList = (params) => {
  return request({
    url: api + '/indexinfo/list',
    method: 'get',
    params: params
  })
}
export const indexinfoDetail = (params) => {
  return request({
    url: api + '/indexinfo/detail',
    method: 'get',
    params: params
  })
}
export const reportdatasourceTestDs = (params) => {
  return request({
    url: api + '/report/reportdatasource/testDs',
    method: 'post',
    data: params
  })
}
//报表管理接口

export const dataapicategorySubmit = (params) => {
  return request({
    url: api + '/dataapicategory/submit',
    method: 'post',
    data: params
  })
}
export const dataapicategoryRemove = (ids) => {
  return request({
    url: api + '/dataapicategory/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
//接口管理
export const dataapiList = (params) => {
  return request({
    url: api + '/report/dataapi/list',
    method: 'get',
    params: params
  })
}
export const dataapiPage = (params) => {
  return request({
    url: api + '/report/dataapi/page',
    method: 'get',
    params: params
  })
}
export const dataapiSubmit = (data) => {
  return request({
    url: api + '/report/dataapi/submit',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}
export const dataapiExecute = (params) => {
  return request({
    url: api + '/report/dataapi/execute',
    method: 'post',
    data: params
  })
}
export const dataapiDetail = (id) => {
  return request({
    url: api + '/report/dataapi/detail',
    method: 'get',
    params: {
      id: id
    }
  })
}
export const dataapiRemove = (ids) => {
  return request({
    url: api + '/report/dataapi/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
export const dataapiDetailKey = (key) => {
  return request({
    url: api + '/report/dataapi/detail',
    method: 'get',
    params: {
      apiKey: key
    }
  })
}
export const dataapicheck = (apiKey) => {
  return request({
    url: api + '/report/dataapi/check?apiKey=' + apiKey,
    method: 'post'
  })
}
export const openurl = (key, params = '', method = 'get') =>
  request({
    url: api + '/report/dataapi/' + key,
    method: method,
    params: params
  })
export const openapi = (url, params = {}, method = 'get', headers) =>
  request({
    url: url,
    method: method,
    params: params,
    headers: headers
  })
export const reportApi = (apiKey, params = {}, method = 'post') =>
  request({
    url: api + '/report/reportApi/' + apiKey,
    method: method,
    data: params
  })
export const getReportData = (params) => {
  return request({
    url: api + '/report/reportApi/getReportData',
    method: 'post',
    data: params
  })
}
export const dataQuerydoing = (params) => {
  return request({
    url: api + '/report/dataQuery/doing',
    method: 'post',
    data: params
  })
}
//报表维度管理接口 批量提交 batCreate
export const dimensionList = (params) => {
  return request({
    url: api + '/report/dimension/list',
    method: 'get',
    params: params
  })
}
export const dimensionsubmit = (params) => {
  return request({
    url: api + '/report/dimension/submit',
    method: 'post',
    data: params
  })
}
export const dimensionremove = (params) => {
  return request({
    url: api + '/report/dimension/remove',
    method: 'post',
    params: params
  })
}
export const dimensionbatCreate = (param) => {
  return request({
    url: api + '/report/dimension/batCreate',
    method: 'post',
    data: param
  })
}
export const batSaveDimension = (param) => {
  return request({
    url: api + '/report/dimension/batSaveDimension',
    method: 'post',
    data: param
  })
}
export const getDetailList = (param) => {
  return request({
    url: api + '/bigdata/visual/detailList',
    method: 'get',
    params: param
  })
}
export const saveHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/save',
    method: 'post',
    data: param
  })
}
export const updateHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/update',
    method: 'post',
    data: param
  })
}
export const deleteHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/remove',
    method: 'post',
    params: {
      ids: param
    }
  })
}
export const getHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/list',
    method: 'get',
    params: param
  })
}
export const saveHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/save',
    method: 'post',
    data: param
  })
}
export const updateHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/update',
    method: 'post',
    data: param
  })
}
export const removeHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/remove',
    method: 'post',
    params: {
      ids: param
    }
  })
}
export const getHistoryreportList = (param) => {
  return request({
    url: api + '/historyreportinfo/list',
    method: 'get',
    params: param
  })
}
export const getHistoryreportDetail = (param) => {
  return request({
    url: api + '/historyreportinfo/detail',
    method: 'get',
    params: {
      id: param
    }
  })
}
export const invorkComApi = (url, method, params) => {
  const vueRequest = new Vue().$request
  if (method == 'get') {
    let paramUrl = ''
    if (params) {
      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          const value = params[key]
          paramUrl += `&${key}=${value}`
        }
      }
      if (paramUrl) {
        //替换第一个字符为?
        paramUrl = paramUrl.replace('&', '?')
        url += paramUrl
      }
    }
    return vueRequest.get(url)
  } else {
    return request({
      url: url,
      method: 'post',
      params: params
    })
  }
}
export const getMapGeoJson = (url) => {
  return request({
    url: url,
    method: 'get'
  })
}
export const permSave = (params) => {
  return request({
    url: api + '/report/perm/save',
    method: 'post',
    data: params
  })
}
export const permUpdate = (params) => {
  return request({
    url: api + '/report/perm/update',
    method: 'post',
    data: params
  })
}
export const permDetail = (datasourceId) => {
  return request({
    url: api + '/report/perm/detail',
    method: 'get',
    params: {
      datasourceId
    }
  })
}
export const batchuploadAppend = (params) => {
  return request({
    url: api + '/cube/file/uploadAppend',
    method: 'post',
    data: params
  })
}
export const tableBlood = (params) => request.get(api + '/visual/bloodRelation/treeByTable', { params })
export const dsAuthList = (params) => request.get(api + '/report/permission/dataPerms', { params })
export const dsAuthSave = (data) => request.post(api + '/report/permission/submit', data)

export const tableDataPreview = (params) => request.get(api + '/cube/sqlview/data-browser', { params })

const prefix = 'http://121.204.249.37:8080/etl-api'
export const dataapiRelease = (params) => request.post(prefix + '/report/dataapi/release', params)

// 上传静态数据创建数据集和物理表
export const uploadStaticData = (params) => request.post(api + '/cube/static-data/submit', params)
// 获取静态数据列表
export const staticDataList = (params) => request.get(api + '/cube/static-data/list', { params })
