"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Service = void 0;
var _utils = require("@vtx/utils");
var _ahooks = require("ahooks");
var Service = exports.Service = {
  UseCurrentAlarm: function UseCurrentAlarm(_ref) {
    var id = _ref.id,
      publicUrlJCSS = _ref.publicUrlJCSS,
      filterParams = _ref.filterParams;
    var _a;
    // 当前报警
    var _useRequest = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/nowWarning"), {
          data: Object.assign({
            facilityId: id,
            alarmStatus: 'OCCURRING'
          }, filterParams || {})
        });
      }, {
        refreshDeps: [id]
      }),
      baseInfoRes = _useRequest.data;
    var alarmData = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var dataList = [];
    if ((_a = alarmData === null || alarmData === void 0 ? void 0 : alarmData.dataList) === null || _a === void 0 ? void 0 : _a.length) {
      alarmData.dataList.map(function (v) {
        dataList.push(Object.assign(Object.assign({}, v), {
          label: v.factorName,
          span: 8
        }));
      });
    }
    return {
      alarmData: alarmData,
      dataList: dataList
    };
  },
  UseFactor: function UseFactor(_ref2) {
    var id = _ref2.id,
      publicUrlJCSS = _ref2.publicUrlJCSS,
      filterParams = _ref2.filterParams;
    // 获取设施因子
    var _useRequest2 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/getFactors"), {
          data: Object.assign({
            facilityId: id
          }, filterParams || {})
        });
      }, {
        refreshDeps: [id]
      }),
      baseInfoRes = _useRequest2.data;
    var factor = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var factorList = [];
    if (factor) {
      Object.keys(factor).map(function (v) {
        factorList.push({
          label: factor[v],
          key: v
        });
      });
    }
    return {
      factorList: factorList
    };
  },
  UseAlarmData: function UseAlarmData(_ref3) {
    var id = _ref3.id,
      publicUrlJCSS = _ref3.publicUrlJCSS,
      startTime = _ref3.startTime,
      endTime = _ref3.endTime,
      timeType = _ref3.timeType,
      filterParams = _ref3.filterParams;
    var _a;
    // 报警统计
    var _useRequest3 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/warnInfo"), {
          data: Object.assign({
            facilityId: id,
            startTime: startTime,
            endTime: endTime,
            timeType: timeType,
            alarmType: 1
          }, filterParams || {})
        });
      }, {
        refreshDeps: [id, timeType]
      }),
      baseInfoRes = _useRequest3.data;
    var alarmData = [];
    var total = 0;
    if ((_a = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data) === null || _a === void 0 ? void 0 : _a.length) {
      baseInfoRes.data.map(function (v) {
        if (!v.isTotal) {
          total += v.nowWarnCount || 0;
          alarmData.push({
            name: v.factorName,
            value: v.nowWarnCount,
            factorCode: v.code
          });
        }
      });
    }
    alarmData.map(function (res) {
      res.name = "".concat(res.name || '', '    ').concat(res.value, "\u6B21", '    ').concat(total ? (res.value || 0) / total : 0, "%");
    });
    return {
      alarmData: alarmData
    };
  },
  UseCurrentDetail: function UseCurrentDetail(_ref4) {
    var id = _ref4.id,
      publicUrlJCSS = _ref4.publicUrlJCSS,
      filterParams = _ref4.filterParams;
    // 当前报警穿透
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/warnRecord"), {
      data: Object.assign({
        facilityId: id,
        alarmStatus: 'OCCURRING'
      }, filterParams || {})
    });
  },
  UseAlarmDetail: function UseAlarmDetail(_ref5) {
    var id = _ref5.id,
      publicUrlJCSS = _ref5.publicUrlJCSS,
      startTime = _ref5.startTime,
      endTime = _ref5.endTime,
      factorCode = _ref5.factorCode,
      filterParams = _ref5.filterParams;
    // 报警统计-穿透
    return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/warnRecord"), {
      data: Object.assign({
        facilityId: id,
        startTime: startTime,
        endTime: endTime,
        factorCode: factorCode
      }, filterParams || {})
    });
  },
  UseRecordAlarm: function UseRecordAlarm(_ref6) {
    var id = _ref6.id,
      publicUrlJCSS = _ref6.publicUrlJCSS,
      startTime = _ref6.startTime,
      endTime = _ref6.endTime,
      factorCode = _ref6.factorCode,
      filterParams = _ref6.filterParams;
    //  报警记录
    var _useRequest4 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("".concat(publicUrlJCSS, "/api/facility/warnRecord"), {
          data: Object.assign({
            facilityId: id,
            startTime: startTime,
            endTime: endTime,
            factorCode: factorCode
          }, filterParams || {})
        });
      }, {
        refreshDeps: [id, startTime, endTime, factorCode]
      }),
      baseInfoRes = _useRequest4.data;
    var recordData = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    return {
      recordData: recordData
    };
  }
};
//# sourceMappingURL=api.js.map
