"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Service = void 0;
var _utils = require("@vtx/utils");
var _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var colorObj = {
  0: {
    0: 'rgba(115,160,250,1)',
    1: 'rgba(115,222,179,1)',
    2: 'rgba(41,166,52,1)',
    3: 'rgba(156,191,48,1)',
    4: 'rgba(243,184,37,1)',
    5: 'rgba(235,83,46,1)',
    6: 'rgba(219,44,111,1)',
    7: 'rgba(145,121,242,1)'
  },
  1: {
    0: 'rgba(115,160,250,0.5)',
    1: 'rgba(115,222,179,0.5)',
    2: 'rgba(41,166,52,0.5)',
    3: 'rgba(156,191,48,0.5)',
    4: 'rgba(243,184,37,0.5)',
    5: 'rgba(235,83,46,0.5)',
    6: 'rgba(219,44,111,0.5)',
    7: 'rgba(145,121,242,0.5)'
  }
};
var handleData = function handleData(_ref) {
  var xdate = _ref.xdate,
    data = _ref.data,
    chartData = _ref.chartData,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 0 : _ref$type;
  var newXdate = [];
  if (chartData === null || chartData === void 0 ? void 0 : chartData.length) {
    chartData.map(function (item) {
      var _a;
      if ((_a = item.dataList) === null || _a === void 0 ? void 0 : _a.length) {
        item.dataList.map(function (v) {
          if (!xdate.includes(v === null || v === void 0 ? void 0 : v.timeDesc)) {
            xdate.push(v.timeDesc);
          }
        });
      }
    });
    // 时间做排序
    newXdate = xdate.sort(function (a, b) {
      return (0, _moment["default"])(a).valueOf() - (0, _moment["default"])(b).valueOf();
    });
    // 并集时间点上因子无数据存null
    chartData.map(function (item) {
      var _a;
      if ((_a = item.dataList) === null || _a === void 0 ? void 0 : _a.length) {
        var factorList = [];
        xdate.map(function (v) {
          var factorItem = item.dataList.find(function (value) {
            return value.timeDesc === v;
          });
          if (factorItem) {
            factorList.push(factorItem.value);
          } else {
            factorList.push(null);
          }
        });
        item.factorList = factorList;
      }
    });
    chartData.map(function (item, i) {
      data.push({
        factorCode: item.factorCode,
        opcCode: item.opcCode,
        name: item.factorName,
        data: item.factorList,
        xAxisIndex: type,
        color: colorObj[type][i] || ''
      });
    });
  }
  return {
    newXdate: newXdate
  };
};
var Service = exports.Service = {
  getMonitorData: function getMonitorData(_ref2) {
    var id = _ref2.id,
      publicUrlJCSS = _ref2.publicUrlJCSS,
      startTime = _ref2.startTime,
      endTime = _ref2.endTime,
      compareFacilityId = _ref2.compareFacilityId,
      factorCode = _ref2.factorCode,
      compareFactorCode = _ref2.compareFactorCode,
      filterParams = _ref2.filterParams,
      isRelateDevice = _ref2.isRelateDevice,
      deviceId = _ref2.deviceId,
      isDevice = _ref2.isDevice;
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/hisDataByFacilities"), {
      data: Object.assign(Object.assign(Object.assign(Object.assign({}, isDevice ? {
        deviceId: id
      } : {
        facilityId: id
      }), {
        compareFacilityId: compareFacilityId,
        startTime: startTime,
        endTime: endTime,
        factorCode: factorCode,
        compareFactorCode: compareFactorCode
      }), isRelateDevice ? {
        deviceId: deviceId
      } : {}), filterParams || {})
    }).then(function (res) {
      var xdate = [];
      var compareXdate = [];
      var data = [];
      var compareData = [];
      var monitorData = [];
      // 参照数据
      var referData = [];
      // 对比数据
      var compareData1 = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res.data) {
        monitorData = res === null || res === void 0 ? void 0 : res.data;
        if (monitorData === null || monitorData === void 0 ? void 0 : monitorData.length) {
          referData = monitorData.find(function (v) {
            return v.isCompare === '0';
          });
          compareData1 = monitorData.find(function (v) {
            return v.isCompare === '1';
          });
        }
        // 获取所有因子时间轴并集
        // 对比
        var _handleData = handleData({
            xdate: compareXdate,
            data: compareData,
            chartData: compareData1 === null || compareData1 === void 0 ? void 0 : compareData1.groupDTOList,
            type: 0
          }),
          newXdate = _handleData.newXdate;
        compareXdate = newXdate;
        // 参照
        var _handleData2 = handleData({
            xdate: xdate,
            data: data,
            chartData: referData === null || referData === void 0 ? void 0 : referData.groupDTOList,
            type: 1
          }),
          referDate = _handleData2.newXdate;
        xdate = referDate;
      }
      return {
        xdate: xdate,
        data: data,
        compareData: compareData,
        compareXdate: compareXdate
      };
    });
  },
  UseMonitorType: function UseMonitorType() {
    // 监测类型
    var _useRequest = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/device/monitor/type/list");
      }, {
        refreshDeps: []
      }),
      data = _useRequest.data;
    var monitorTypeData = ((data === null || data === void 0 ? void 0 : data.data) || []).map(function (v) {
      return Object.assign(Object.assign({}, v), {
        value: v.id
      });
    });
    return {
      monitorTypeData: monitorTypeData
    };
  },
  getCompareObject: function getCompareObject(_ref3) {
    var publicUrlJCSS = _ref3.publicUrlJCSS,
      monitorTypeIds = _ref3.monitorTypeIds,
      filterParams = _ref3.filterParams,
      isRelateDevice = _ref3.isRelateDevice,
      isDevice = _ref3.isDevice;
    // 根据监测类型查询基础设施列表
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/listFilterByMonitorTypeCodes"), {
      data: Object.assign({
        monitorTypeIds: monitorTypeIds
      }, filterParams || {})
    }).then(function (res) {
      var _a;
      var compareObjectData = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && ((_a = res.data) === null || _a === void 0 ? void 0 : _a.length)) {
        compareObjectData = res.data.map(function (v) {
          return Object.assign(Object.assign({}, v), {
            value: isRelateDevice || isDevice ? v.deviceId : v.objectId,
            label: isRelateDevice || isDevice ? v.deviceCode : v.objectName
          });
        });
      }
      return compareObjectData;
    });
  },
  getCompareFactor: function getCompareFactor(_ref4) {
    var id = _ref4.id,
      publicUrlJCSS = _ref4.publicUrlJCSS,
      filterParams = _ref4.filterParams,
      isRelateDevice = _ref4.isRelateDevice,
      deviceId = _ref4.deviceId,
      isDevice = _ref4.isDevice;
    // 获取设施因子集合
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/getFactors"), {
      data: Object.assign(Object.assign(Object.assign({}, isDevice ? {
        deviceId: id
      } : {
        facilityId: id
      }), isRelateDevice ? {
        deviceId: deviceId
      } : {}), filterParams || {})
    }).then(function (res) {
      var compareFactorList = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && (res === null || res === void 0 ? void 0 : res.data)) {
        Object.keys(res.data).map(function (v) {
          compareFactorList.push({
            label: res.data[v],
            key: v,
            value: v
          });
        });
      }
      return compareFactorList;
    });
  }
};
//# sourceMappingURL=api.js.map
