import request from "./axios.js";
// export const baseURL = "http://10.81.3.154:6015/";
export const baseURL = "http://192.168.1.105:6015/";
import JSONBIG from "json-bigint";

// 获取场站数据
export function fetchStationListAll() {
  return request({
    baseURL: baseURL,
    url: `alertrule/querywpllist`,
    method: "get",
  });
}

//获取部件及预警类型列表
export function fetchRelatePartAndAlarmType() {
  return request({
    baseURL: baseURL,
    url: "alertrule/queryalarmtypellist",
    method: "get",
  });
}
//获取型号列表
export const fetchModel = () => {
  return request({
    baseURL: baseURL,
    url: "alertrule/querywpbyymodellist",
    method: "get",
  });
};
//获取升压站列表
export const fetchBooststation = () => {
  return request({
    baseURL: baseURL,
    url: "alertrule/querysubllist",
    method: "get",
  });
};
//查询自定义预警列表
export function custombj_fetchTableData(params) {
  return request({
    baseURL: baseURL,
    url: "alertrule/page",
    method: "get",
    params,
  });
}

//根据场站编号，风机型号获取AI/DI测点
export const fetchPointList = (wpId = "", modelId = "") => {
  return request({
    baseURL: baseURL,
    url: `alertrule/querywtpointlist?wpId=${wpId}&modelId=${modelId}`,
    method: "get",
  });
};
//根据升压站编号获取AI/DI测点
export const fetchPointListByBootst = (subId = "") => {
  return request({
    baseURL: baseURL,
    url: `alertrule/querysubpointllist?subId=${subId}`,
    method: "get",
  });
};
//新增/修改自定义预警
export const custombj_postSave = (form) => {
  return request({
    baseURL: baseURL,
    url: "alertrule/save",
    method: "post",
    data: form,
  });
};
//自定义预警模板下载
export const custombj_importTemplate = () => {
  return request({
    baseURL: baseURL,
    url: "alertrule/get-import-template",
    method: "get",
    responseType: "blob",
  });
};

//根据风场id获取所有风机
export const fetchWindturbineList = (wpId = "") => {
  return request({
    baseURL: baseURL,
    url: `alertrule/querywtlist?wpId=${wpId}`,
    method: "get",
  });
};

//根据structcode获取AI.DI测点
export const fetchAIDIPointList = (
  deviceId,
  structcode,
  stationId,
  windturbineId,
  pageNum,
  pageSize
) => {
  return request({
    baseURL: baseURL,
    url: "info/point",
    method: "get",
    params: {
      deviceId,
      structcode,
      stationId,
      windturbineId,
      pageNum,
      pageSize,
    },
  });
};

// ---------------------------------------- 基础数据- 字典------------------------------------------------

//
export const get_datadictionary = (pageNum, pageSize, name, category) => {
  return request({
    baseURL: baseURL,
    method: "get",
    url: `datadictionary/page?pageNum=${pageNum}&pageSize=${pageSize}&name=${name}&category=${category}`,
  });
};
// 新增 修改
export const post_saveorupdate = (data) => {
  return request({
    baseURL: baseURL,method: "post",
    url: `datadictionary/save`,
    data,
  });
};
// ----------------------------------------end 基础数据- 风机管理------------------------------------------------

//获取服务端公钥
export const getPublickey = (query) => {
  return request({
    url: "info/publickey",
  });
};
// login
export const loginRequest = (params) => {
  return request.post("user/login", params);
};
//register
export const registerRequest = (params) => {
  return request.post("user/registers", params);
};
// 报警配置缓存清理
export const getRestart = () => {
  return request({
    url: `custom/restart`,
    baseURL: "/custom/",
  });
};
export const getRestart2 = () => {
  return request({
    url: `windturbine/restart`,
    baseURL: "/windturbine/",
  });
};
export const getRestart3 = () => {
  return request({
    url: `scadas/restart`,
    baseURL: "/scadas/",
  });
};

//----------------------------------------homePAge------------------------------------------------
//根据风场id获取所有风机
export const getintellList = (query) => {
  return request({
    url: "home/early/latest",
    method: "get",
    params: {
      stationId: query,
    },
    showLoading: {
      statu: false,
    },
  });
};
export const getReportList = (params) => {
  return request({
    url: "earlyreport/list",
    method: "get",
    params: params,
    showLoading: {
      statu: false,
    },
  });
};
export const getreportReviewList = (query) => {
  return request({
    url: "inspectorder/port/list",
    method: "get",
    params: {
      stationId: query,
    },
  });
};
export const getHomeOrdercount = (query) => {
  return request({
    url: "home/ordercount",
    method: "get",
    showLoading: {
      statu: false,
    },
  });
};
//首页获取机型接口
export const getHomeAlertrule = (params) => {
  return request({
    url: "home/alertrule",
    method: "get",
    params: params,
    showLoading: {
      statu: false,
    },
  });
};
export const getHomeDangerHidden = (params) => {
  return request({
    url: "home/hidden/danger",
    method: "get",
    showLoading: {
      statu: false,
    },
  });
};
export const getHomeDurationTotal = (params) => {
  return request({
    url: "home/total/duration",
    method: "get",
    showLoading: {
      statu: false,
    },
  });
};
// 巡检计划
export const getCheckList = (params) => {
  return request({
    url: "inspectorder/order/page",
    method: "get",
    params: params,
  });
};

// 风机原始数据统计
// 列表接口
export const getAlarmCountList = (params) => {
  return request.get(
    `windturbineAlarmCount/query/list?stationid=${params.stationid}&starttime=${params.starttime}&endtime=${params.endtime}`
  );
};

// 弹窗数据接口
export const getDialogData = (params) => {
  return request.get(
    `windturbineAlarmCount/query/detail?stationid=${params.stationid}&starttime=${params.starttime}&endtime=${params.endtime}&windturbineid=${params.windturbineid}&parts=${params.parts}`
  );
};

// 设备隐患评审报告
export const postSubmitReport = (params) => {
  return request.post("inspectorder/update", params);
};

// ----------------------------------------user------------------------------------------------
export const getUserList = () => {
  return request.get(`user/getall`);
};
export const editRequest = (params) => {
  return request.post("user/edituser", params);
};
export const deleteUser = (data) => {
  return request.delete(`user/${data}`);
};
// ----------------------------------------user------------------------------------------------
// ----------------------------------------system------------------------------------------------

// 获取故障弹窗
export const getjumpwindow = () => {
  return request.get(`userset/jumpwindow`);
};
//  获取语音播报
export const getfaultread = () => {
  return request.get(`userset/faultread`);
};
// 保存是否故障弹窗
export const postjumpwindow = (params) => {
  return request.post(`userset/jumpwindow?isjump=${params}`);
};
// 保存是否语音播报
export const postfaultread = (params) => {
  return request.post(`userset/faultread?isread=${params}`);
};
// ----------------------------------------system------------------------------------------------

//获取所有风场
export const fetchStationList = () => {
  return request({
    url: "info/station",
    method: "get",
  });
};
// //获取所有风场光伏
// export const fetchStationListAll = () => {
//   return request({
//     url: "info/station/all",
//     method: "get",
//   });
// };

// ----------------------------------------安全生产- 报警记录------------------------------------------------
//查询历史报警记录
export const alarm_history = (params) => {
  return request({
    url: `alarm/history/page2`,
    params: params,
  });
};
//导出历史报警记录
export const new_alarm_history = (params) => {
  // return request.get(`alarm/history/export?stationid=${params.stationid}&starttime=${params.starttime}&endtime=${params.endtime}&windturbineid=&category1=&category2=&rank=&modelid=&snapid=&messagetype=&keyword=`)

  return request({
    method: "get",
    url: `alarm/history/export?stationid=${params.stationid}&starttime=${params.starttime}&endtime=${params.endtime}&windturbineid=&category1=&category2=&rank=&modelid=&snapid=&messagetype=&keyword=`,
    headers: {
      "Content-Type": "application/json",
    },
    responseType: "blob",
    showLoading: {
      text: "拼命下载中...",
    },
    timeout: 99999999,
  });
};

//查报警
export const alarm_snap = (params) => {
  return request({
    url: `alarm/snap`,
    params: params,
  });
};
// ----------------------------------------安全生产- 实时报警------------------------------------------------

//实时故障 最高级
export const alarm_fault_recent = (params) => {
  return request({
    url: `fault/recent`,
    params: params,
    showLoading: {
      statu: false,
    },
    transformResponse: [
      function (data) {
        const json = JSONBIG({
          storeAsString: true,
        });
        const res = json.parse(data);
        return res;
      },
    ],
  });
};
//实时故障 第一次请求
export const alarm_fault_top = (params) => {
  return request({
    url: `fault/snap/top`,
    params: params,
  });
};
//底下的实时报警
export const alarm_snap_top = (params) => {
  return request({
    url: `alarm/snap/top`,
    params: params,
    showLoading: {
      statu: false,
    },
    timeout: 1000,
  });
};
//报警确认
export const get_fault_confirm = (params) => {
  return request({
    url: `fault/confirm`,
    params: params,
  });
};

// ----------------------------------------安全生产- 实时数据查询------------------------------------------------

// get 实时data
export const getAdapterLatest = (stationId, AIlist) => {
  return request({
    url: `ts/latest?uniformCodes=${AIlist}&thingId=${stationId}&thingType=windturbine`,
    baseURL: "http://10.81.3.152:8098/",
    showLoading: {
      statu: false,
    },
    timeout: 1000,
    transformResponse: [
      function (data) {
        const json = JSONBIG({
          storeAsString: true,
        });
        const res = json.parse(data);
        return res;
      },
    ],
  });
};
// get 历史数据
export const getAdapterHistory = (stationId, AIpoint, startTs, endTs) => {
  return request({
    url: `ts/history/raw?uniformCode=${AIpoint}&thingId=${stationId}&thingType=windturbine&startTs=${startTs}&endTs=${endTs}`,
    baseURL: "http://10.81.3.152:8098/",
  });
};
// get 历史数据
export const getAdapterHistorysnap = (
  stationId,
  AIpoint,
  startTs,
  endTs,
  interval
) => {
  return request({
    url: `ts/history/snap?uniformCode=${AIpoint}&thingId=${stationId}&thingType=windturbine&startTs=${startTs}&endTs=${endTs}&interval=${interval}`,
    baseURL: "/adapter/",
  });
};
// 批量导出
export const AdapterHistoryExport = (activeAI, activeWT, startTs, endTs) => {
  return request({
    url: `ts/history/raw?uniformCode=${activeAI}&thingId=${activeWT}&thingType=windturbine&startTs=${startTs}&endTs=${endTs}`,
    baseURL: "/adapter/",
  });
};
// ----------------------------------------基础数据- 设备管理------------------------------------------------
//查询全部设备型号接口
export const device_list = () => {
  return request.get(`device/model/list`);
};
//获取结构tree
export function tree(params) {
  return request({
    url: "device/structure/tree/windturbine",
    method: "get",
    transformResponse: [
      function (data) {
        const json = JSONBIG({
          storeAsString: true,
        });
        const res = json.parse(data);
        return res;
      },
    ],
  });
}
//根据结构获取测点
export function point(
  code,
  pagenum,
  pagesize,
  categorydata,
  keyword,
  deviceId,
  model
) {
  return request.get(
    `device/metrics/page?pagenum=${pagenum}&pagesize=${pagesize}&deviceId=${deviceId}&categorydata=${categorydata}&keyword=${keyword}&model=${model}&structureCode=${code}`
  );
}
//测点新增
export function metrics(params) {
  return request.post(`device/metrics/single`, params);
}
//测点删除
export function delmetrics(params) {
  return request.delete(`device/metrics/single/delete/${params}`);
}
//测点导入

//tree新增 添加一个设备结构节点
export function treeAdd(params) {
  return request.post(`device/structure`, params);
}
//tree删除 tree删除一个设备结构节点
export function treeDel(params) {
  return request.delete(`device/structure/delete/${params}`);
}

// 故障模式
// get All
export const faultmode_windturbine = () => {
  return request.get(`device/faultmode/windturbine`);
};
// 根据 structurecode get
export const faultmode_structurecode = (params) => {
  return request.get(`device/faultmode/windturbine/${params}`);
};
// 根据 id delete
export const faultmode_delete = (params) => {
  return request.delete(`device/faultmode/delete/${params}`);
};

// 新增 修改
export const faultmode_add_edit = (data) => {
  return request.post(`device/faultmode`, data);
};

// ---------------------------------------- 报警配置- 自定义预警------------------------------------------------

// 获取机型
export function getStationinfo(params) {
  return request({
    url: `info/stationinfo?stationId=${params}`,
    method: "get",
    showLoading: {
      statu: false,
    },
  });
}

// 获取规则
export function alertrule2_list() {
  return request.get(`alertrule2/list/`);
}

//根据场站编号，风机型号获取DI测点new
export const getDIPointList = (minModel) => {
  return request({
    url: "testingpointDI/point",
    method: "get",
    params: {
      minModel,
    },
  });
};
//根据场站编号，获取电气DI测点
export const fetchElectricDIPointList = (stationId) => {
  return request({
    url: "info/electrical_point_di",
    method: "get",
    params: {
      stationId: stationId,
    },
  });
};
//根据电气测点，获取测点信息
export const fetchElectricDIPointByPointId = (pointId) => {
  return request({
    url: "info/electrical_point_di/byId",
    method: "get",
    params: {
      pointId: pointId,
    },
  });
};

//根据风场编号获取电气AI测点
export const fetch_electrical_point_ai = (stationId) => {
  return request({
    url: "info/electrical_point_ai",
    method: "get",
    params: {
      stationId: stationId,
    },
  });
};
//根据风场编号获取电气DI测点
export const fetch_electrical_point_di = (stationId) => {
  return request({
    url: "info/electrical_point_di",
    method: "get",
    params: {
      stationId: stationId,
    },
  });
};
//获取报警类型
export const fetchWarningType = () => {
  return request({
    url: "info/warning_type",
    method: "get",
  });
};

//获取报警种类
export const fetchWarningClassify = () => {
  return request({
    url: "info/warning_classify",
    method: "get",
  });
};
export const custombj_batchImport = (list) => {
  return request.post("alertrule2/save-batch", list);
};

//******************************end****************************************//

//******************************升压站报警API************************************//

export const scadabj_fetchTableData = (query) => {
  return request({
    url: "scadabj/page",
    method: "get",
    params: query,
    timeout: 20000,
    transformResponse: [
      // 处理17位数字精度问题
      function (data) {
        const json = JSONBIG({
          storeAsString: true,
        });
        const res = json.parse(data);
        return res;
      },
    ],
  });
};
export const scadabj_postSave = (objData) => {
  return request.post("scadabj/save", objData);
};
export const scadabj_batchImport = (list) => {
  return request.post("scadabj/save-batch", list);
};
//********************************************end********************************//\

//********************************************报警记录日志********************************//\
export const fetchruleventLogs = (pagenum, pagesize, ruleName, ruleType) => {
  return request({
    url: "rulevent/page",
    method: "get",
    params: {
      pagenum,
      pagesize,
      ruleName,
      ruleType,
    },
  });
};

//********************************************end********************************//\

//******************************风机报警API************************************//
export const windturbinebj_fetchTableData = (query) => {
  return request({
    url: "warning2/page",
    method: "get",
    params: query,
    timeout: 20000,
  });
};
export const windturbinebj_postSave = (form) => {
  return request.post("warning2/save", form);
};
export const windturbinebj_batchImport = (list) => {
  return request.post("warning2/save-batch", list);
};

export const fetchLeaf = () => {
  return request({
    url: "warning2/page",
    method: "get",
    params: {
      pagenum: 1,
      pagesize: 10000,
      isLeaf: 0,
    },
  });
};

//根据风机型号获取DI测点统一编码相关数据 testingpointdi2
export const getDIPointByModelId = (query) => {
  return request({
    url: "info/testing_point_di",
    method: "get",
    params: query,
  });
};

//******************************end*******************************************//
//******************************预警统计*******************************************//
export const statistics_querymap = (params) => {
  return request.get(`alarm/count/querymap2`, { params: params });
};
export const statistics_querybyname = (params) => {
  return request.get("alarm/count/querybyname2", { params: params });
};
export const statistics_lineandproject = (params) => {
  return request.get("alarm/count/lineandproject2", { params: params });
};
//******************************end*******************************************//

//******************************预警分析*******************************************//
export const warning_query_new = (params) => {
  return request.get(`alarm/count/query/new2`, { params: params });
};
export const warning_detail = (params) => {
  return request({
    url: `analysis/detail`,
    params: params,
    timeout: 60000,
  });
};
// export const statistics_lineandproject = params => {
//     return request.get('alarm/count/lineandproject', { params: params })
// };

//******************************end*******************************************//

//*****************************旧诊断报告*******************************************//
export const earlywarnscore_list = (params) => {
  return request.get(`earlywarnscore/list`, { params: params });
};
export const warning_query_new3 = (params) => {
  return request.get(`alarm/count/query/new3`, { params: params });
};
//******************************end*******************************************//

//*****************************新诊断报告*******************************************//
export const getList = (params) => {
  return request.get(
    `earlyreport/list?pagenum=${params.pagenum}&pagesize=${params.pagesize}&stationId=${params.stationId}&keyword=&starttime=&endtime=`
  );
};

export const getReportDetail = (id) => {
  return request({
    url: `earlyreport/info?id=${id}`,
    method: "get",
    showLoading: {
      statu: false,
    },
  });
};

//******************************end*******************************************//
