import request from '@/utils/request'
export const api = 'etl-api';
export const getDatasourceDetail = params => {
  return request({
    url: "/report/reportdatasource/detail",
    method: "get",
    params
  });
};
export const getList = (current, size, params) => {
  return request({
    url: "/blade-report/report/rest/list",
    method: "get",
    params: {
      ...params,
      current,
      size
    }
  });
};
export const remove = ids => {
  return request({
    url: "/blade-report/report/rest/remove",
    method: "post",
    params: {
      ids
    }
  });
};
//数据源管理
export const reportdatasourceList = () => {
  return request({
    url: "/report/reportdatasource/list",
    method: "get"
  });
};
//根据租户ID查询数据源
export const cubeDatasourceTenantid = tenantId => {
  return request({
    url:  "/cube/data/datasource/tenantid",
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: "get",
    params: {
      tenantId
    }
  });
};
//根据租户ID查询数据集
export const cubeDataCubeTenantid = tenantId => {
  return request({
    url:  "/cube/data/cube/tenantid",
    method: "get",
    params: {
      tenantId
    }
  });
}
export const reportdatasourcePage = params => {
  return request.get("/report/reportdatasource/page", {params});
};
export const reportdatasourceSave = params => {
  return request({
    url: "/report/reportdatasource/save",
    method: "post",
    data: params
  });
};
export const reportdatasourceUpdate = params => {
  return request({
    url: "/report/reportdatasource/update",
    method: "post",
    data: params
  });
};
export const reportdatasourceDetail = () => {
  return request({
    url: "/report/reportdatasource/list",
    method: "get"
  });
};
export const reportdatasourceRemove = ids => {
  return request({
    url: "/report/reportdatasource/remove",
    method: "post",
    params: {
      ids
    }
  });
};
export const baseInfoListViews = id => {
  return request({
    url: "/report/baseInfo/listViews",
    method: "get",
    params: {
      dataSourceId: id
    }
  });
};
export const listViewsByDataSource = params => {
  return request({
    url: "/report/baseInfo/listViewsByDataSource",
    method: "get",
    params
  });
};
export const reportBaseInfoListColumns = params => {
  return request({
    url: "/report/baseInfo/listColumns",
    method: "get",
    params: params
  });
};
export const listColumnsByDatasource = params => {
  return request({
    url: "/report/baseInfo/listColumnsByDatasource",
    method: "get",
    params: params
  });
};
export const baseInforemoveBaseInfoCache = params => {
  return request({
    url: "/report/baseInfo/removeBaseInfoCache",
    method: "get",
    params: params
  });
};
// 报表指标分类接口
export const indexcategorySubmit = params => {
  return request({
    url: "/indexcategory/submit",
    method: "post",
    data: params
  });
};
export const indexcategoryList = params => {
  return request({
    url: "/indexcategory/list",
    method: "get",
    params: params
  });
};
// 报表指标信息接口
export const indexinfoSubmit = params => {
  return request({
    url: "/indexinfo/submit",
    method: "post",
    data: params
  });
};
export const indexinfoList = params => {
  return request({
    url: "/indexinfo/list",
    method: "get",
    params: params
  });
};
export const indexinfoDetail = params => {
  return request({
    url: "/indexinfo/detail",
    method: "get",
    params: params
  });
};
export const reportdatasourceTestDs = params => {
  return request({
    url: "/report/reportdatasource/testDs",
    method: "post",
    data: params
  });
};
//报表管理接口
export const reportList = params => {
  return request({
    url: "/report/report/list",
    method: "get",
    params: params
  });
};
//接口分类
export function dataapicategoryList (params) {
  return request({
    url: "/dataapicategory/list",
    method: "get",
    params: params
  });
}
export const dataapicategorySubmit = params => {
  return request({
    url: "/dataapicategory/submit",
    method: "post",
    data: params
  });
};
export const dataapicategoryRemove = ids => {
  return request({
    url: "/dataapicategory/remove",
    method: "post",
    params: {
      ids
    }
  });
};
//接口管理
export const dataapiList = params => {
  return request({
    url: "/report/dataapi/list",
    method: "get",
    params: params
  });
};
export const dataapiPage = params => {
  return request({
    url: "/report/dataapi/page",
    method: "get",
    params: params
  });
};
export const dataapiSubmit = data => {
  return request({
    url: "/report/dataapi/submit",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json;charset=UTF-8"
    }
  });
};
export const dataapiExecute = params => {
  return request({
    url: "/report/dataapi/execute",
    method: "post",
    data: params
  });
};
export const dataapiDetail = id => {
  return request({
    url: "/report/dataapi/detail",
    method: "get",
    params: {
      id: id
    }
  });
};
export const dataapiRemove = ids => {
  return request({
    url: "/report/dataapi/remove",
    method: "post",
    params: {
      ids
    }
  });
};
export const dataapiDetailKey = key => {
  return request({
    url: "/report/dataapi/detail",
    method: "get",
    params: {
      apiKey: key
    }
  });
};
export const dataapicheck = apiKey => {
  return request({
    url: "/report/dataapi/check?apiKey=" + apiKey,
    method: "post"
  });
};
export const openurl = (key, params = "", method = "get") =>
  request({
    url: "/open/" + 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: "/report/reportApi/" + apiKey,
    method: method,
    data: params
  });
export const getReportData = params => {
  return request({
    url: "/report/reportApi/getReportData",
    method: "post",
    data: params
  });
};
export const dataQuerydoing = params => {
  return request({
    url: "/report/dataQuery/doing",
    method: "post",
    data: params
  });
};
//报表维度管理接口 批量提交 batCreate
export const dimensionList = params => {
  return request({
    url: "/report/dimension/list",
    method: "get",
    params: params
  });
};
export const dimensionsubmit = params => {
  return request({
    url: "/report/dimension/submit",
    method: "post",
    data: params
  });
};
export const dimensionremove = params => {
  return request({
    url: "/report/dimension/remove",
    method: "post",
    params: params
  });
};
export const dimensionbatCreate = param => {
  return request({
    url: "/report/dimension/batCreate",
    method: "post",
    data: param
  });
};
export const batSaveDimension = (param) => {
  return request({
    url: '/report/dimension/batSaveDimension',
    method: 'post',
    data: param
  });
};
export const getDetailList = (param) => {
  return request({
    url: '/bigdata/visual/detailList',
    method: 'get',
    params: param
  });
};
export const saveHistoryReport = (param) => {
  return request({
    url: '/historyreportinfo/save',
    method: 'post',
    data: param
  });
};
export const updateHistoryReport = (param) => {
  return request({
    url: '/historyreportinfo/update',
    method: 'post',
    data: param
  });
};
export const deleteHistoryReport = (param) => {
  return request({
    url: '/historyreportinfo/remove',
    method: 'post',
    params: {
      ids: param
    }
  });
};
export const getHistoryreportFolder = (param) => {
  return request({
    url: '/historyreportfolder/list',
    method: 'get',
    params: param
  });
};
export const saveHistoryreportFolder = (param) => {
  return request({
    url: '/historyreportfolder/save',
    method: 'post',
    data: param
  });
};
export const updateHistoryreportFolder = (param) => {
  return request({
    url: '/historyreportfolder/update',
    method: 'post',
    data: param
  });
};
export const removeHistoryreportFolder = (param) => {
  return request({
    url: '/historyreportfolder/remove',
    method: 'post',
    params: {
      ids: param
    }
  });
};
export const getHistoryreportList = (param) => {
  return request({
    url: '/historyreportinfo/list',
    method: 'get',
    params: param
  });
};
export const getHistoryreportDetail = (param) => {
  return request({
    url: '/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: "/report/perm/save",
    method: "post",
    data: params
  });
};
export const permUpdate = params => {
  return request({
    url: "/report/perm/update",
    method: "post",
    data: params
  });
};
export const permDetail = datasourceId => {
  return request({
    url: "/report/perm/detail",
    method: "get",
    params: {
      datasourceId
    }
  });
};
export const batchuploadAppend = params => {
  return request({
    url: "/cube/file/uploadAppend",
    method: "post",
    data: params
  });
};
export const getDeptTree = (tenantId) => {
  return request({
    url: '/blade-system/dept/tree',
    method: 'get',
    params: {
      tenantId,
    }
  })
}
export const getUserList = (current, size, params, deptId) => {
  return request({
    url: '/blade-user/page',
    method: 'get',
    params: {
      ...params,
      current,
      size,
      deptId,
    }
  });
};
export const tableBlood = params => request.get('/visual/bloodRelation/treeByTable', {params});
export const dsAuthList = params => request.get('/report/permission/dataPerms', {params});
export const dsAuthSave = data => request.post('/report/permission/submit', data);

export const tableDataPreview = params => request.get('/report/baseInfo/data-browser', {params})

export const dataapiRelease = params => request.post('/report/dataapi/release', params)
export const optionList = params => request.get('/visual/dynamicData/enumValueList', {params});
export const enumCheck = params => request.get( '/visual/dynamicData/checkTableUseEnum', {params});
