"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.WarningData = exports.BaseData = void 0;

var _utils = require("@vtx/utils");

var _moment = _interopRequireDefault(require("moment"));

var _ahooks = require("ahooks");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var baseInfoField = [{
  label: '所属单位',
  key: 'belongUnitName'
}, {
  label: '使用单位',
  key: 'useUnitName'
}, {
  label: '所属标段',
  key: 'bidSectionName'
}, {
  label: '行政区划',
  key: 'divisionName'
}, {
  label: '责任人',
  key: 'manageStaffName'
}, {
  label: '联系人',
  key: 'contact'
}, {
  label: '联系方式',
  key: 'contactWay'
}];
var jxhInfoField = [{
  label: '车辆品牌',
  key: 'carBrand'
}, {
  label: '车辆型号',
  key: 'carType'
}, {
  label: '购置时间',
  key: 'procurementDate'
}, {
  label: '购置金额',
  key: 'procurementAmt'
}, {
  label: '发票编号',
  key: 'invoiceCode'
}, {
  label: '证书编号',
  key: 'certificateCode'
}, {
  label: '证书保管人',
  key: 'certificateKeeper'
}, {
  label: '车辆识别代号',
  key: 'identifyCode'
}, {
  label: '发动机号',
  key: 'engineCode'
}, {
  label: '车辆厂牌',
  key: 'carLabel'
}, {
  label: '出厂日期',
  key: 'productionDate'
}, {
  label: '出厂地',
  key: 'productionPlace'
}, {
  label: '自有重量',
  key: 'ownWeight'
}, {
  label: '整备质量',
  key: 'curbWeight'
}, {
  label: '核定载质量',
  key: 'regulationWeight'
}, {
  label: '车辆用途',
  key: 'carUseWay'
}, {
  label: '车辆性质',
  key: 'carProperty'
}, {
  label: '车辆属性',
  key: 'carAttrOne'
}, {
  label: '核定载员',
  key: 'regulationPerson'
}, {
  label: '作业宽度',
  key: 'carWorkingWidth'
}, {
  label: '行驶证照片',
  type: 'img',
  key: 'driveLicensePhotoIds'
}];
var BaseData = {
  useBaseInfo: function useBaseInfo(id, start, end) {
    var _useRequest = (0, _ahooks.useRequest)(function () {
      return _utils.request.get('/cloud/gps-reborn/sdk/car/getCarInfoByProductType', {
        data: {
          carId: id,
          coordType: 'bd09'
        }
      });
    }, {
      refreshDeps: [id]
    }),
        baseInfoRes = _useRequest.data;

    var baseInfo = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var realTimeInfo = {
      time: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.equipmentTime,
      location: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.address,
      status: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.carStatusStr,
      speed: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.gpsSpeed,
      mile: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.accuMileage,
      percent: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.completePercent
    };

    var _useRequest2 = (0, _ahooks.useRequest)(function () {
      return _utils.request.get('/cloud/gps-reborn/car/np/getCarDetailById', {
        data: {
          id: id,
          coordType: 'bd09'
        }
      });
    }, {
      refreshDeps: [id]
    }),
        carTempInfo = _useRequest2.data;

    var carInfo = carTempInfo === null || carTempInfo === void 0 ? void 0 : carTempInfo.data;
    var jxhInfo = jxhInfoField.map(function (item) {
      var value = carInfo === null || carInfo === void 0 ? void 0 : carInfo[item.key];

      if (item.type === 'img') {
        value = JSON.parse(value || '[]');
      }

      return _objectSpread(_objectSpread({}, item), {}, {
        value: value
      });
    });
    var info = baseInfoField.map(function (item) {
      return _objectSpread(_objectSpread({}, item), {}, {
        value: carInfo === null || carInfo === void 0 ? void 0 : carInfo[item.key]
      });
    });

    var _useRequest3 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'JSSJZLJ_CAR_ROAD_PERMIT',
          parameters: {
            carId: id
          }
        })
      });
    }, {
      refreshDeps: [id]
    }),
        permissionRes = _useRequest3.data;
    /** 基础信息 */


    var permissionData = (permissionRes === null || permissionRes === void 0 ? void 0 : permissionRes.data) || [];
    var permissionInfo = permissionData.map(function (item) {
      return [{
        label: '通行证编号',
        key: 'code',
        value: item === null || item === void 0 ? void 0 : item.code
      }, {
        label: '有效期',
        key: 'effect',
        value: item === null || item === void 0 ? void 0 : item.effect
      }, {
        label: '运输路线',
        key: 'roadNames',
        value: item === null || item === void 0 ? void 0 : item.roadNames
      }, {
        label: '垃圾类型',
        key: 'rubbishType',
        value: item === null || item === void 0 ? void 0 : item.rubbishType
      }];
    });

    var _useRequest4 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_CAR_WORK_SUMMARY',
          parameters: {
            carId: id,
            startDate: (0, _moment["default"])(start).format('YYYY-MM-DD'),
            endDate: (0, _moment["default"])(end).format('YYYY-MM-DD')
          }
        })
      });
    }, {
      refreshDeps: [id, start, end]
    }),
        workSummaryRes = _useRequest4.data;

    var workSummary = (workSummaryRes === null || workSummaryRes === void 0 ? void 0 : workSummaryRes.data) || {};

    if (workSummary.work_duration) {
      var seconds = workSummary.work_duration / 1000;
      workSummary.duration = {
        hour: Math.floor(seconds / 3600),
        minute: Math.floor(seconds % 3600 / 60),
        second: Math.floor(seconds % 60)
      };
    } // 作业分析


    var _useRequest5 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_CAR_WORK_STATISTICS',
          parameters: {
            carId: id,
            startDate: (0, _moment["default"])(start).format('YYYY-MM-DD'),
            endDate: (0, _moment["default"])(end).format('YYYY-MM-DD')
          }
        })
      });
    }, {
      refreshDeps: [id, start, end]
    }),
        workChartRes = _useRequest5.data;

    var workChart = (workChartRes === null || workChartRes === void 0 ? void 0 : workChartRes.data) || [];
    var days = (0, _moment["default"])(end).diff((0, _moment["default"])(start), 'd') + 1;
    workChart = _toConsumableArray(new Array(days)).map(function (_, index) {
      var date = (0, _moment["default"])(start).add(index, 'd').format('YYYY-MM-DD');
      var data = workChart.find(function (e) {
        return e.work_date === date;
      });

      if (data) {
        return data;
      } else {
        return {
          work_date: date
        };
      }
    });
    return {
      info: info,
      jxhInfo: jxhInfo,
      permissionInfo: permissionInfo,
      realTimeInfo: realTimeInfo,
      workSummary: workSummary,
      workChart: workChart
    };
  },
  useAlarmStat: function useAlarmStat(id, start, end) {
    var _useRequest6 = (0, _ahooks.useRequest)(function () {
      return _utils.request.get('/cloud/gps-reborn/car/detail/alarmSumWithDetail', {
        data: {
          carId: id,
          beginTime: (0, _moment["default"])(start).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
          endTime: (0, _moment["default"])(end).endOf('day').format('YYYY-MM-DD HH:mm:ss')
        }
      });
    }, {
      refreshDeps: [id, start, end]
    }),
        res = _useRequest6.data;

    var data = res === null || res === void 0 ? void 0 : res.data;
    var totalSeconds = (data === null || data === void 0 ? void 0 : data.alarmSum.totalSeconds) || 0;
    var statInfo = {
      times: data === null || data === void 0 ? void 0 : data.alarmSum.total,
      days: data === null || data === void 0 ? void 0 : data.alarmSum.totalDays,
      hour: Math.floor(totalSeconds / 3600),
      minute: Math.floor(totalSeconds % 3600 / 60),
      second: Math.floor(totalSeconds % 60)
    };
    var statChartInfo = (data === null || data === void 0 ? void 0 : data.alarmGroupByType.items) || [];
    var statLineInfo = (data === null || data === void 0 ? void 0 : data.alarmGroupByDayType.items) || [];
    return {
      statInfo: statInfo,
      statChartInfo: statChartInfo,
      statLineInfo: statLineInfo
    };
  },
  getTodayWorkMile: function getTodayWorkMile(id) {
    var _useRequest7 = (0, _ahooks.useRequest)(function () {
      return _utils.request.get('/cloud/zyqs-reborn/api/noshift/realtime/getWorkMileage', {
        data: {
          carId: id,
          startTime: (0, _moment["default"])().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
          endTime: (0, _moment["default"])().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
          onlyOnShift: true
        }
      });
    }, {
      refreshDeps: [id]
    }),
        data = _useRequest7.data;

    return (data === null || data === void 0 ? void 0 : data.data) || 0;
  }
};
exports.BaseData = BaseData;
var WarningData = {
  useStatList: function useStatList(id, start, end, carType) {
    if (carType === 'jxh') {
      return [{
        key: 'all',
        count: 0,
        label: '全部'
      }, {
        key: 'CarOverSpeed',
        count: 0,
        label: '超速'
      }];
    }

    var _useRequest8 = (0, _ahooks.useRequest)(function () {
      return _utils.request.get('/cloud/gps-reborn/alarm/record/statisticsPage', {
        data: {
          carIds: id,
          startTime: (0, _moment["default"])(start).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
          endTime: (0, _moment["default"])(end).endOf('day').format('YYYY-MM-DD HH:mm:ss')
        }
      });
    }, {
      refreshDeps: [id, start, end]
    }),
        res = _useRequest8.data;

    var data = [{
      key: 'all',
      count: 0,
      label: '全部'
    }];

    if (res && res.data) {
      data[0] = {
        key: 'all',
        count: res.data.totalCount,
        label: '全部'
      };
      var ext = res.data.summary.map(function (i) {
        return {
          key: i.alarmType,
          count: i.totalCount,
          label: i.alarmTypeName
        };
      });
      data.push.apply(data, _toConsumableArray(ext));
    }

    return data;
  },
  getWarningList: function getWarningList(page, size, id, start, end, tab) {
    return _utils.request.get('/cloud/gps-reborn/alarm/record/pageList', {
      data: {
        page: page,
        rows: size,
        carIds: id,
        startTime: (0, _moment["default"])(start).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        endTime: (0, _moment["default"])(end).endOf('day').format('YYYY-MM-DD HH:mm:ss'),
        alarmStrategyName: tab
      }
    }).then(function (res) {
      if (res.result === 0) {
        res.data.list = res.data.rows;
      }

      return res.data;
    });
  },
  getJxhWarningList: function getJxhWarningList(page, size, id, start, end, tab) {
    return _utils.request.get('/cloud/zyqs-reborn/api/noshift/event/page', {
      data: {
        pageNo: page - 1,
        pageSize: size,
        carIds: id,
        startDate: (0, _moment["default"])(start).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        endDate: (0, _moment["default"])(end).endOf('day').format('YYYY-MM-DD HH:mm:ss'),
        subCategoryCode: tab,
        categoryCode: 'Alarm'
      }
    }).then(function (res) {
      if (res.result === 0) {
        res.data.list = res.data.rows;
      }

      return res.data;
    });
  },
  exportData: function exportData(params) {
    return (0, _utils.downloadFile)('/cloud/gps-reborn/alarm/record/export', {
      data: _objectSpread(_objectSpread({}, params), {}, {
        startTime: (0, _moment["default"])(params.startTime).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        endTime: (0, _moment["default"])(params.endTime).endOf('day').format('YYYY-MM-DD HH:mm:ss')
      })
    }, 'blob');
  },
  exportJxhData: function exportJxhData(params) {
    return (0, _utils.downloadFile)('/cloud/zyqs-reborn/api/noshift/event/excel', {
      data: _objectSpread(_objectSpread({}, params), {}, {
        startDate: (0, _moment["default"])(params.startDate).startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        endDate: (0, _moment["default"])(params.endDate).endOf('day').format('YYYY-MM-DD HH:mm:ss')
      })
    }, 'blob');
  }
};
exports.WarningData = WarningData;
//# sourceMappingURL=api.js.map
