import { baseHttpUtils } from "@/utils/http/baseHttpUtils";
import {
  datacenter_pre,
  dict_pre,
  equipcomponent_pre,
  equipquery_pre,
  floor_pre,
  graphhic_pre,
  object_pre,
  rwd_pre,
  zone
} from "./preTypes";
import { middlewareHttpUtils } from "@/utils/http/middlewareHttpUtils";
class ScanController {
  static http = new baseHttpUtils();
  static middlewareHttp = new middlewareHttpUtils();
  /**
   * 查询不在当前系统下的设备
   */
  static async getEquipNotInSys(params, fn) {
    const res = await this.http.postRequest(
      equipquery_pre + `/equip-sys?sysId=${params.sysId}`,
      params
    );
    return fn ? fn(res) : res;
  }
  /**
    *@description: 获取设定参数和动态参数

    *@param {*} params

    *@return {*}
  */
  static async BeatchQueryParam(params, fn) {
    let data = params.data;
    const res = await ScanController.http.postRequest(
      `/rwd/iot/data/current?projectId=${params.projectId}&groupCode=${params.groupCode}&appId=${params.appId}`,
      data
    );
    return fn ? fn(res) : res;
  }
  /** 

  *@description: 根据条件查询项目下设备部件数量

  *@param {*} params

  *@return {*}
  */
  static async countPartsDie(params) {
    const res = await ScanController.http.postRequest(
      equipquery_pre + "/count",
      params
    );
  }
  /**

  *@description: 根据设备或部件批量创建资产

  *@param {*}

  *@return {*}
  */
  static async createPropertys(params) {
    return await ScanController.http.postRequest(
      equipquery_pre + "/creat-propertys",
      params
    );
  }
  /**

  *@description: 根据id删除资产信息

  *@param {*}

  *@return {*}
  */
  static async deleteProperty(params) {
    return await ScanController.http.postRequest(
      object_pre + "/property/delete",
      params
    );
  }
  /**

  *@description: 查询资产 同时关联设备信息

  *@param {*}

  *@return {*}
  */
  static async propertyLinkEq(params) {
    return await ScanController.http.postRequest(
      datacenter_pre + "/property/property-query",
      params
    );
  }
  /** 
  @description: 修改资产的附件功能
  @param {*}
  @return {*}
  */
  static async propertyUpdate(params) {
    return await ScanController.http.postRequest(
      datacenter_pre + "/property/update",
      params
    );
  }
  /**
   *@description: 查询资产
   *@param {*}
   *@return {*}
   */
  static async queryProperty(params) {
    return await ScanController.http.postRequest(
      object_pre + "/property/query",
      params
    );
  }
  /**
   *@description: 更新资产信息
   *@param {*}
   *@return {*}
   */
  static async updateProperty(params) {
    return await ScanController.http.postRequest(
      object_pre + "/property/update",
      params
    );
  }
  /**
   *@description: 删除系统信息
   *@param {*}
   *@return {*}
   */
  static async deleteGeneralSys(params) {
    return await ScanController.http.postRequest(
      object_pre + "/general-system/delete",
      params
    );
  }
  /**

  *@description: 更新系统信息
  *@param {*}
  *@return {*}
  */
  static async updateGeneralSys(params) {
    return await ScanController.http.postRequest(
      object_pre + "/general-system/update",
      params
    );
  }
  /**
  @description: 创建资产所需(Family族id3位编码)-根据设备类型(4位编码)或部件类型(6位编码)查询,!!设备与设备族的关系
  @param {*}
  @return {*}
  */
  static async getEquipBelongs(params) {
    return await ScanController.http.postRequest(
      dict_pre + "/family/query",
      params
    );
  }

  /**
  @description: 查询建筑信息
  @param {*}
  @return {*}
  */
  static async buildingQuery(params) {
    var result = await ScanController.http.postRequest(object_pre + "/building/query", params);
    result.content = result.content || result.data;
    return result;
  }
  /**
  @description: 关系-竖井所在建筑
  @param {*}
  @return {*}
  */
  static async shaftLinkBuild(params) {
    return await ScanController.http.postRequest(
      datacenter_pre + "/rel/sh-in-bd/link-bd",
      params
    );
  }
  /**
   *@description: 查询系统信息 - 建筑楼层 - 系统一对多
   *@param {*} params
   *@return {*}
   */
  static async querySysLinkBuild(params, fn) {
    let url = object_pre + "/general-system/query-new";
    if (params.buildingId) {
      url += `?buildingId=${params.buildingId}`;
    }
    if (params.floorId) {
      url += `&floorId=${params.floorId}`;
    }
    const res = await ScanController.http.postRequest(url, params);
    return fn ? fn(res) : res;
  }
  static async countGeneralSys(params: any, fn: any) {
    const res = await ScanController.http.postRequest(
      object_pre + "/general-system/count",
      params
    );
    return fn ? fn(res) : res;
  }
  /**
   *@description: 获取楼层信息
   *@param {*}
   *@return {*}
   */
  static async getFloorMsgByFloorID(params?: any) {
    return await ScanController.http.postRequest(
      object_pre + "/floor/query",
      params
    );
  }
  /**
   *@description: //设备清单 - 查询系统关联专业 - 查询系统信息 - 查询系统所属专业类型
   *@param {*}
   *@return {*}
   */
  static async queryLinkSys(params) {
    return await ScanController.http.postRequest(
      object_pre + "/general-system/query",
      params
    );
  }
  static async getAllProject(params, fn) {
    const res = await this.middlewareHttp.postRequest(
      "/object/project/query/obj",
      params
    );
    return fn ? fn(res) : res;
  }

  /**
   * @description: 创建系统所在建筑关系,系统一对多,覆盖
   * @param {*} params
   * @param {*} fn
   * @return {*}
   */
  static async sysRelateBuild(params, fn) {
    const res = await ScanController.http.postRequest(
      datacenter_pre + "/rel/sy-in-bd/link-bd",
      params
    );
    return fn ? fn(res) : res;
  }
  /**
   * @description: 创建系统所在建筑关系,系统一对多,覆盖
   * @param {*} params
   * @param {*} fn
   * @return {*}
   */
  static async sysRelateFloor(params, fn) {
    const res = await ScanController.http.postRequest(
      datacenter_pre + "/rel/sy-in-fl/link-fl",
      params
    );
    return fn ? fn(res) : res;
  }
  static async getEquipInSys(params, fn) {
    const res = await ScanController.http.postRequest(
      `${equipquery_pre}/sys-equip`,
      params
    );
    return fn ? fn(res) : res;
  }
  static async sysLinkEquip(params, fn) {
    const res = await ScanController.http.postRequest(
      `${datacenter_pre}/rel/sy-in-eq/link-sy-eq`,
      params
    );
    return fn ? fn(res) : res;
  }
  /**
   * 设备清单 - 更新设备
   * @param params
   */
  static async updateEquip(params) {
    return await this.http.postRequest(object_pre + "/equip/update", params);
  }
  /**
   * 设备清单 - 根据对象删除系统和设备的关系
   * @param params
   */
  static async sysUnlinkEquip(params, fn) {
    const res = await this.http.postRequest(
      datacenter_pre + "/sy-in-eq/unlinks-sy-eq",
      params
    );
    return fn ? fn(res) : res;
  }
  static async TypePartsDie() { }
  /**
   * 下载报告-查询key值
   * @param params
   * @returns
   */
  static async queryDownloadsKey(params) {
    return await this.http.postRequest(
      graphhic_pre + "/downloads/point/key",
      params
    );
  }
  /**
   * 下载模板-设备静态信息维护模板
   * @param params
   * @returns
   */
  static async equipTemplate(params) {
    window.location.href =
      (window as any).__systemConf.baseServiceUrl +
      graphhic_pre +
      "/downloads/equip/template";
    // return await this.http.getRequest(
    //   graphhic_pre + "/downloads/equip/template",
    //   params
    // );
  }
  /**
   * 修改设备的附件功能
   * @param params
   * @returns
   */
  static async queryUpdate(params) {
    return await this.http.postRequest(equipquery_pre + "/update", params);
  }
  static async equipLinkSys() { }
  /**
   * 查询建筑信息+count
   */
  static async buildingQueryAndCount(params) {
    return await this.http.postRequest(
      equipcomponent_pre + "/building/query",
      params
    );
  }
  /**
   * 查询楼层信息+sign
   */
  static async floorQueryAndSign(params) {
    return await this.http.postRequest(
      equipcomponent_pre + "/floor/query",
      params
    );
  }
  /**
   * 建筑楼层管理-删除楼层(该接口有删除失败的原因)
   */
  static async deleteFloorInfo(params) {
    return await this.http.postRequest(floor_pre + "/single/delete", params);
  }
  /**
   * 根据id删除建筑信息(该接口有删除失败的原因)
   */
  static async deleteBuildInfo(params) {
    return await this.http.postRequest(
      object_pre + "/building/single/delete",
      params
    );
  }
  /**
   * 创建建筑信息
   */
  static async objectCreateBuild(params) {
    return await this.http.postRequest(object_pre + "/building/create", params);
  }
  /**
   * 查询建筑信息
   */
  static async objectQueryBuild(params) {
    return await this.http.postRequest(object_pre + "/building/query", params);
  }
  /**
   * 查询建筑信息
   */
  static async objectUpdateBuild(params) {
    return await this.http.postRequest(object_pre + "/building/update", params);
  }
  /**
   * 建筑楼层管理-创建楼层关联关系
   */
  static async createRelationInFloor(params) {
    return await this.http.postRequest(
      datacenter_pre + "/rel/fl-through-fl/link-or",
      params
    );
  }
  /**
   * 建筑楼层管理-修改楼层
   */
  static async manageUpdateFloor(params) {
    return await this.http.postRequest(floor_pre + "/update", params);
  }
  /**
   * 楼层接口-----更新楼层轮廓
   */
  static async floorUpdateOutline(params) {
    return await this.http.postRequest(floor_pre + "/update-outline", params);
  }
  /**
   * 楼层接口-----查询楼层轮廓
   */
  static async floorQueryOutline(params) {
    return await this.http.postRequest(floor_pre + "/query-outline", params);
  }
  /**
   * 设备清单 - 创建设备-关联资产-关联系统
   */
  static async createEquipAndProperty(params) {
    return await this.http.postRequest(
      object_pre + "/equip/creat-equip-pro",
      params
    );
  }
  /**
   * @description: 创建系统---处理建筑楼层(一对多)
   * @param {*}
   * @return {*}
   */
  static async createSystemBuildFloor(params, fn) {
    const res = await this.http.postRequest(
      object_pre + "/general-system/create-bd-fl",
      params
    );
    return fn ? fn(res) : res;
  }
  /**
   * 更新项目信息
   */
  static async updateProjectInfo(params) {
    return await this.http.postRequest(object_pre + "/project/update", params);
  }

  //修改业务空间对象和建筑楼层的关系
  static async handleZoneUpdateBd(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/update-fl-bd', param);
    success(result);
  }

  //创建空间分区对象
  static async zoneCreate(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/create', param);
    success(result);
  }

  //跟据id删除分区对象
  static async zoneDelete(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/delete', param);
    success(result);
  }

  //查询分区对象信息
  static async zoneQuery(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/query', param);
    result.content = result.content || result.data;
    success(result);
  }

  //更新分区对象信息
  static async zoneUpdate(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/update', param);
    success(result);
  }

  //创建空间分类型
  static async zoneCreateType(param, success) {
    let result = await this.middlewareHttp.postRequest('/object/zone/create-type', param);
    success(result);
  }

  //查询分区信息
  static async queryZone(param, success) {
    let data = param.data
    let url = `/object/${zone[param.zone]}/query`;
    var result = await this.middlewareHttp.postRequest(url, data);
    result.content = result.content || result.data;
    success(result);
  }

  //查询分区对象轮廓线
  static async zoneQueryOutline(param, success) {
    let url = `/object/zone/query-outline`
    let result = await this.middlewareHttp.postRequest(url, param);
    result.content = result.content || result.data;
    success(result);
  }

  //更新分区对象轮廓线
  static async zoneUpdateOutline(param, success) {
    let url = `/object//zone/update-outline`
    let result = await this.middlewareHttp.postRequest(url, param);
    success(result);
  }

}

export default ScanController;
