"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.processService = exports.MoniotrService = exports.BaseService = exports.AppraiseService = exports.AlarmService = void 0;
var _utils = require("@vtx/utils");
var _ahooks = require("ahooks");
var BaseService = exports.BaseService = {
  useBaseDetail: function useBaseDetail(id) {
    var _a, _b, _c, _d, _e, _f;
    var _useRequest = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/jcss-reborn/facility/get', {
          data: {
            id: id,
            coordType: 'bd09'
          }
        });
      }, {
        refreshDeps: [id]
      }),
      baseInfoRes = _useRequest.data;
    var info = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var _useRequest2 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/jcss-reborn/facility/type/config/getByCode', {
          data: {
            code: baseInfoRes.data.typeCode
          }
        });
      }, {
        ready: !!((_a = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data) === null || _a === void 0 ? void 0 : _a.typeCode),
        refreshDeps: [(_b = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data) === null || _b === void 0 ? void 0 : _b.typeCode]
      }),
      tabConfig = _useRequest2.data;
    var photos = (info === null || info === void 0 ? void 0 : info.photoIds) ? JSON.parse(info.photoIds) : (info === null || info === void 0 ? void 0 : info.typePhotoIds) ? JSON.parse(info.typePhotoIds) : [];
    return {
      photos: photos,
      info: info,
      tabIsFilter: !!((_d = (_c = tabConfig === null || tabConfig === void 0 ? void 0 : tabConfig.data) === null || _c === void 0 ? void 0 : _c.popupConfigJson) === null || _d === void 0 ? void 0 : _d.length),
      tabConfig: ((_f = (_e = tabConfig === null || tabConfig === void 0 ? void 0 : tabConfig.data) === null || _e === void 0 ? void 0 : _e.popupConfigJson) === null || _f === void 0 ? void 0 : _f.filter(function (ele) {
        return ele.display;
      }).map(function (ele) {
        return {
          key: ele.code,
          title: ele.name
        };
      })) || [],
      visited: !!tabConfig
    };
  },
  //基础设施详情展示字段
  getFields: function getFields(code) {
    var _a, _b, _c;
    var _useRequest3 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/jcss-reborn/facility/type/view/detail', {
          data: {
            code: code
          }
        });
      }, {
        refreshDeps: [code],
        ready: !!code
      }),
      data = _useRequest3.data;
    return {
      fields: (data === null || data === void 0 ? void 0 : data.data) ? ((_a = data.data.baseFields) === null || _a === void 0 ? void 0 : _a.filter(function (ele) {
        return ele.key !== 'photoIds' && ele.key !== 'geometryInfo';
      }).concat(data.data.customFields)) || [] : [],
      beenSmart: ((_c = (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.customFields) === null || _c === void 0 ? void 0 : _c.findIndex(function (ele) {
        return ele.key === 'beenSmart' && ele.enabled;
      })) > -1
    };
  },
  useBaseInfo: function useBaseInfo(id, startDate, endDate) {
    // 实时运行情况
    var _useRequest4 = (0, _ahooks.useRequest)(function () {
        return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
          data: JSON.stringify({
            code: 'ZHGC_DIFF_DATATYPE_SUM_MONITOR_VALUE_BY_TYPE',
            parameters: {
              gcId: id,
              startDate: startDate,
              endDate: endDate
            }
          })
        });
      }, {
        refreshDeps: [id, startDate, endDate]
      }),
      situationRes = _useRequest4.data;
    return {
      situationRes: (situationRes === null || situationRes === void 0 ? void 0 : situationRes.data) || []
    };
  },
  useBaseAlarmInfo: function useBaseAlarmInfo(id, startTime, endTime) {
    //本月报警类型分析
    var _useRequest5 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/statisticsByStandardCode', {
          data: {
            baseInfoId: id,
            startDateStr: startTime,
            endDateStr: endTime
          }
        });
      }, {
        refreshDeps: [id, startTime, endTime]
      }),
      alarmTypeRes = _useRequest5.data;
    return {
      alarmTypeRes: (alarmTypeRes === null || alarmTypeRes === void 0 ? void 0 : alarmTypeRes.data) || []
    };
  },
  useBaseAlarmTypes: function useBaseAlarmTypes(id, startTime, endTime) {
    //报警明细类型
    var _useRequest6 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/statisticsByStandardCode', {
          data: {
            baseInfoId: id,
            startDateStr: startTime,
            endDateStr: endTime
          }
        });
      }, {
        refreshDeps: [id, startTime, endTime]
      }),
      alarmTypeRes = _useRequest6.data;
    return {
      alarmTypeRes: (alarmTypeRes === null || alarmTypeRes === void 0 ? void 0 : alarmTypeRes.data) || []
    };
  },
  useAlarmDetails: function useAlarmDetails(id, standardCode, start, end, page, sort, order) {
    var _a, _b;
    var _useRequest7 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/queryList.smvc', {
          data: {
            baseInfoId: id,
            standardCode: standardCode,
            startDateStr: start,
            endDateStr: end,
            page: page,
            rows: 10,
            sort: sort,
            order: order
          }
        });
      }, {
        refreshDeps: [id, standardCode, start, end, page, sort, order]
      }),
      res = _useRequest7.data;
    var dataSource = ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.rows) || [];
    var total = (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.total;
    return {
      detail: {
        dataSource: dataSource,
        total: total
      }
    };
  }
};
var MoniotrService = exports.MoniotrService = {
  useRealtime: function useRealtime(id, date) {
    var _a;
    var _useRequest8 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/imageTextBoard/queryMonitorData.smvc', {
          data: {
            baseInfoId: id,
            date: date
          }
        });
      }, {
        refreshDeps: [id, date]
      }),
      realtimeRes = _useRequest8.data;
    return {
      realtimeList: ((_a = realtimeRes === null || realtimeRes === void 0 ? void 0 : realtimeRes.data) === null || _a === void 0 ? void 0 : _a.standardList) || []
    };
  },
  useMonitorType: function useMonitorType(id) {
    var _useRequest9 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/imageTextBoard/loadStandardType.smvc', {
          data: {
            baseInfoId: id
          }
        });
      }, {
        refreshDeps: [id]
      }),
      monitorTypeRes = _useRequest9.data;
    var names = ['PersonNum', 'OdorValue', 'SeatNum'];
    var monitorType = (monitorTypeRes === null || monitorTypeRes === void 0 ? void 0 : monitorTypeRes.data) ? monitorTypeRes.data.filter(function (ele) {
      return names.includes(ele.standardCode);
    }).map(function (ele) {
      return {
        label: ele.standardCodeName,
        key: ele.standardCode,
        standardUnit: ele.standardUnit
      };
    }) : [];
    return {
      monitorType: monitorType
    };
  },
  useMonitorChart: function useMonitorChart(id, startDate, endDate, filterKey) {
    var _a;
    var url = getUrl(filterKey);
    var param = {};
    if (filterKey === 'SeatNum') {
      param = {
        startTime: startDate,
        endTime: endDate
      };
    } else {
      param = {
        startDate: startDate,
        endDate: endDate
      };
    }
    var _useRequest0 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get(url, {
          data: Object.assign(Object.assign({
            baseInfoId: id
          }, param), {
            statisticalPeriod: 'day'
          })
        });
      }, {
        ready: !!filterKey,
        refreshDeps: [id, startDate, endDate, filterKey]
      }),
      monitorChartRes = _useRequest0.data;
    var series = [];
    if (Array.isArray((_a = monitorChartRes === null || monitorChartRes === void 0 ? void 0 : monitorChartRes.data) === null || _a === void 0 ? void 0 : _a.series)) {
      series = monitorChartRes.data.series.map(function (ele) {
        return {
          data: ele.data,
          name: ele.name,
          type: 'line'
        };
      });
    }
    var monitorChart = Object.assign(Object.assign({}, monitorChartRes === null || monitorChartRes === void 0 ? void 0 : monitorChartRes.data), {
      series: series
    });
    return {
      monitorChart: monitorChart
    };
  }
};
// 监测信息，根据监测类型获取不同的url
var getUrl = function getUrl(key) {
  var url = '';
  switch (key) {
    case 'PersonNum':
      url = 'personNum/getEcharts.smvc';
      break;
    case 'OdorValue':
      url = 'odor/getEcharts.smvc';
      break;
    case 'temperature':
      url = 'temperature/getEcharts.smvc';
      break;
    case 'humidity':
      url = 'humidity/getEcharts.smvc';
      break;
    case 'WaterUse':
      url = 'waterBySensor/getEcharts.smvc';
      break;
    case 'ElecUse':
      url = 'electricityPowerBySensor/getEcharts.smvc';
      break;
    case 'SeatNum':
      url = 'seat/getEcharts.smvc';
      break;
    default:
      break;
  }
  return "/cloud/zhgc/api/np/v1/".concat(url);
};
var AlarmService = exports.AlarmService = {
  //信息汇总
  useAlarmSummary: function useAlarmSummary(id, dateValue) {
    var _useRequest1 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/statisticsByYearOnYear', {
          data: {
            baseInfoId: id,
            dateValue: dateValue
          }
        });
      }, {
        refreshDeps: [id, dateValue]
      }),
      alarmSummaryRes = _useRequest1.data;
    var alarmSummary = (alarmSummaryRes === null || alarmSummaryRes === void 0 ? void 0 : alarmSummaryRes.data) || [];
    return {
      alarmSummary: alarmSummary
    };
  },
  // 报警记录
  useAlarmRecord: function useAlarmRecord(id, standardCode, start, end, page, sort, order) {
    var _a, _b;
    var _useRequest10 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/queryList.smvc', {
          data: {
            baseInfoId: id,
            standardCode: standardCode,
            startDateStr: start,
            endDateStr: end,
            page: page,
            rows: 10,
            sort: sort,
            order: order
          }
        });
      }, {
        refreshDeps: [id, standardCode, start, end, page, sort, order]
      }),
      alarmRecordRes = _useRequest10.data;
    var dataSource = ((_a = alarmRecordRes === null || alarmRecordRes === void 0 ? void 0 : alarmRecordRes.data) === null || _a === void 0 ? void 0 : _a.rows) || [];
    var total = (_b = alarmRecordRes === null || alarmRecordRes === void 0 ? void 0 : alarmRecordRes.data) === null || _b === void 0 ? void 0 : _b.total;
    return {
      detail: {
        dataSource: dataSource,
        total: total
      }
    };
  },
  // 类型分析
  useAlarmTrend: function useAlarmTrend(id, startDateStr, endDateStr) {
    var _useRequest11 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/standardDataAlarm/statisticsByMonth', {
          data: {
            baseInfoId: id,
            startDateStr: startDateStr,
            endDateStr: endDateStr
          }
        });
      }, {
        refreshDeps: [id]
      }),
      alarmTrendRes = _useRequest11.data;
    var alarmTrend = (alarmTrendRes === null || alarmTrendRes === void 0 ? void 0 : alarmTrendRes.data) || [];
    return {
      alarmTrend: alarmTrend
    };
  }
};
var AppraiseService = exports.AppraiseService = {
  //信息汇总
  useAppraisSummary: function useAppraisSummary(id, startDate, endDate) {
    var _useRequest12 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/baseInfoAssess/baseInfoAssessStatistics', {
          data: {
            baseInfoId: id,
            startDateStr: startDate,
            endDateStr: endDate
          }
        });
      }, {
        refreshDeps: [id, startDate, endDate]
      }),
      appraiseSummaryRes = _useRequest12.data;
    var appraiseSummary = (appraiseSummaryRes === null || appraiseSummaryRes === void 0 ? void 0 : appraiseSummaryRes.data) || [];
    return {
      appraiseSummary: appraiseSummary
    };
  },
  // 报警记录
  useAppraiseRecord: function useAppraiseRecord(id, startDate, endDate, page, sorter, order) {
    var _a, _b;
    var _useRequest13 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zhgc/api/np/v1/baseInfoAssess/queryList.smvc', {
          data: {
            baseInfoId: id,
            startDate: startDate,
            endDate: endDate,
            page: page,
            rows: 10,
            sorter: sorter,
            order: order
          }
        });
      }, {
        ready: !!startDate,
        refreshDeps: [id, startDate, endDate, page, sorter, order]
      }),
      appraiseRecordRes = _useRequest13.data;
    var dataSource = ((_a = appraiseRecordRes === null || appraiseRecordRes === void 0 ? void 0 : appraiseRecordRes.data) === null || _a === void 0 ? void 0 : _a.rows) || [];
    var total = (_b = appraiseRecordRes === null || appraiseRecordRes === void 0 ? void 0 : appraiseRecordRes.data) === null || _b === void 0 ? void 0 : _b.total;
    return {
      records: {
        dataSource: dataSource,
        total: total
      }
    };
  }
};
// 组态图
var processService = exports.processService = {
  hasProcess: function hasProcess(id) {
    var _useRequest14 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/device/process/process/get', {
          data: {
            facilityId: id
          }
        });
      }, {
        refreshDeps: [id]
      }),
      data = _useRequest14.data;
    return !!(data === null || data === void 0 ? void 0 : data.data);
  }
};
//# sourceMappingURL=api.js.map
