"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 Service = exports.Service = {
  getMonitorData: function getMonitorData(_ref) {
    var id = _ref.id,
      publicUrlJCSS = _ref.publicUrlJCSS,
      startTime = _ref.startTime,
      endTime = _ref.endTime,
      filterParams = _ref.filterParams,
      isRelateDevice = _ref.isRelateDevice,
      deviceId = _ref.deviceId,
      isDevice = _ref.isDevice;
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/hisDataByTime"), {
      data: Object.assign(Object.assign(Object.assign(Object.assign({}, isDevice ? {
        deviceId: id
      } : {
        facilityId: id
      }), {
        startTime: startTime,
        endTime: endTime
      }), isRelateDevice ? {
        deviceId: deviceId
      } : {}), filterParams || {})
    }).then(function (res) {
      var xdate = [];
      var data = [];
      var monitorData = [];
      var checkboxOptions = [];
      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) {
          monitorData.map(function (item) {
            var _a;
            checkboxOptions.push({
              title: item.factorName,
              key: item.factorCode,
              label: item.factorName,
              value: 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);
                }
              });
            }
          });
          // 时间做排序
          xdate = xdate.sort(function (a, b) {
            return (0, _moment["default"])(a).valueOf() - (0, _moment["default"])(b).valueOf();
          });
          // 并集时间点上因子无数据存null
          monitorData.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;
            }
          });
          monitorData.map(function (item) {
            data.push({
              factorCode: item.factorCode,
              name: item.factorName,
              data: item.factorList
            });
          });
        }
      }
      return {
        monitorData: monitorData,
        xdate: xdate,
        data: data,
        checkboxOptions: checkboxOptions
      };
    });
  },
  getTableData: function getTableData(_ref2) {
    var id = _ref2.id,
      publicUrlJCSS = _ref2.publicUrlJCSS,
      startTime = _ref2.startTime,
      endTime = _ref2.endTime,
      current = _ref2.current,
      size = _ref2.size,
      factorCode = _ref2.factorCode,
      filterParams = _ref2.filterParams,
      isRelateDevice = _ref2.isRelateDevice,
      deviceId = _ref2.deviceId,
      isDevice = _ref2.isDevice;
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/pageHisData"), {
      data: Object.assign(Object.assign(Object.assign(Object.assign({}, isDevice ? {
        deviceId: id
      } : {
        facilityId: id
      }), {
        startTime: startTime,
        endTime: endTime,
        size: size,
        current: current,
        factorCode: factorCode
      }), isRelateDevice ? {
        deviceId: deviceId
      } : {}), filterParams || {})
    }).then(function (res) {
      var _a, _b;
      var tableData = [];
      var total = 0;
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && ((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.length)) {
        tableData = res.data.rows;
        total = res.data.total;
      }
      // let xdate = [];
      // let data = [];
      // let monitorData = [];
      // let checkboxOptions = [];
      // if (res?.result === 0 && res.data) {
      //   monitorData = res?.data;
      //   // 获取所有因子时间轴并集
      //   if (monitorData?.length) {
      //     monitorData.map(item => {
      //       checkboxOptions.push({
      //         title: item.factorName,
      //         key: item.factorCode,
      //         label: item.factorName,
      //         value: item.factorCode,
      //       });
      //       if (item.dataList?.length) {
      //         item.dataList.map(v => {
      //           if (!xdate.includes(v?.timeDesc)) {
      //             xdate.push(v.timeDesc);
      //           }
      //         });
      //       }
      //     });
      //     // 时间做排序
      //     xdate = xdate.sort((a, b) => {
      //       return moment(a).valueOf() - moment(b).valueOf();
      //     });
      //     // 并集时间点上因子无数据存null
      //     monitorData.map(item => {
      //       if (item.dataList?.length) {
      //         let factorList = [];
      //         xdate.map(v => {
      //           let factorItem = item.dataList.find(value => {
      //             return value.timeDesc === v;
      //           });
      //           if (factorItem) {
      //             factorList.push(factorItem.value);
      //           } else {
      //             factorList.push(null);
      //           }
      //         });
      //         item.factorList = factorList;
      //       }
      //     });
      //     monitorData.map(item => {
      //       data.push({
      //         factorCode: item.factorCode,
      //         name: item.factorName,
      //         data: item.factorList,
      //       });
      //     });
      //   }
      // }
      return {
        // monitorData,
        // xdate,
        // data,
        // checkboxOptions,
        tableData: tableData,
        total: total
      };
    });
  }
};
//# sourceMappingURL=api.js.map
