"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Service = void 0;
var _utils = require("@vtx/utils");
var _moment = _interopRequireDefault(require("moment"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var nameObj = {
  0: '对比',
  1: '参照'
};
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,
    checkboxOptions = _ref.checkboxOptions,
    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 (checkboxOptions) {
        checkboxOptions.push({
          label: item.factorName,
          value: item.factorCode,
          title: item.factorName,
          key: item.factorCode
        });
      }
      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,
        name: "".concat(nameObj[type] || '').concat(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,
      compareStartTime = _ref2.compareStartTime,
      compareEndTime = _ref2.compareEndTime,
      filterParams = _ref2.filterParams,
      isRelateDevice = _ref2.isRelateDevice,
      deviceId = _ref2.deviceId,
      isDevice = _ref2.isDevice;
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/hisDataByTimes"), {
      data: Object.assign(Object.assign(Object.assign(Object.assign({}, isDevice ? {
        deviceId: id
      } : {
        facilityId: id
      }), {
        startTime: startTime,
        endTime: endTime,
        compareStartTime: compareStartTime,
        compareEndTime: compareEndTime
      }), isRelateDevice ? {
        deviceId: deviceId
      } : {}), filterParams || {})
    }).then(function (res) {
      var xdate = [];
      var compareXdate = [];
      var data = []; // 参照
      var compareData = []; // 对比
      var monitorData = [];
      var checkboxOptions = [];
      // 参照数据
      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,
            checkboxOptions: checkboxOptions,
            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 {
        monitorData: referData,
        xdate: xdate,
        data: data,
        compareData: compareData,
        compareXdate: compareXdate,
        checkboxOptions: checkboxOptions
      };
    });
  }
};
//# sourceMappingURL=api.js.map
