"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toFixd2 = 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; }

var toFixd2 = function toFixd2(num) {
  var newNum = Number(num);
  return newNum ? newNum.toFixed(2) : '';
};

exports.toFixd2 = toFixd2;
var BaseData = {
  useBaseInfo: function useBaseInfo(id, date) {
    var _useRequest = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_GET_ROAD_BY_ID',
          parameters: {
            id: id
          }
        })
      });
    }, {
      refreshDeps: [id]
    }),
        baseInfoRes = _useRequest.data;

    var baseInfo = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var info = [{
      label: '管理单位',
      key: 'deptName',
      value: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.manage_unit_name
    }, {
      label: '作业单位',
      key: 'useUnitName',
      value: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.company_name
    }, {
      label: '行政区划',
      key: 'divisionName',
      value: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.division_name
    }, {
      label: '路段长度(km)',
      key: 'manageStaffName',
      value: toFixd2(baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.road_space)
    }, {
      label: '路段类型',
      key: 'contact',
      value: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.road_type_name
    }, {
      label: '路段宽度(m)',
      key: 'contactWay',
      value: toFixd2(baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.road_width)
    }, {
      label: '所属标段',
      key: 'contactWay',
      value: baseInfo === null || baseInfo === void 0 ? void 0 : baseInfo.bid_section_name
    }];

    var _useRequest2 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_GET_RULE_LIST_BY_ROAD_ID',
          parameters: {
            roadId: id,
            ruleDate: date
          }
        })
      });
    }, {
      refreshDeps: [id, date]
    }),
        workRuleRes = _useRequest2.data;

    var workRule = (workRuleRes === null || workRuleRes === void 0 ? void 0 : workRuleRes.data) || [];

    var _useRequest3 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_GET_ROAD_WORK_SUMMARY',
          parameters: {
            roadId: id,
            runDate: date
          }
        })
      });
    }, {
      refreshDeps: [id, date]
    }),
        roadSummaryRes = _useRequest3.data;

    var roadSummary = ((roadSummaryRes === null || roadSummaryRes === void 0 ? void 0 : roadSummaryRes.data) || []).filter(function (item) {
      return item.work_mileage || item.work_times;
    });

    var _useRequest4 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_GET_ROAD_CAR_WORK_SUMMARY',
          parameters: {
            roadId: id,
            runDate: date
          }
        })
      });
    }, {
      refreshDeps: [id, date]
    }),
        workCarRes = _useRequest4.data;

    var workCar = (workCarRes === null || workCarRes === void 0 ? void 0 : workCarRes.data) || [];
    return {
      info: info,
      workRule: workRule,
      roadSummary: roadSummary,
      workCar: workCar
    };
  },
  useStatistics: function useStatistics(id, start, end, workType) {
    var _useRequest5 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_GET_ROAD_WORK_TOTAL_SUMMARY',
          parameters: {
            roadId: id,
            startDate: start,
            endDate: end,
            workType: workType === '全部' ? '' : workType
          }
        })
      });
    }, {
      refreshDeps: [id, start, end, workType]
    }),
        workTotalRes = _useRequest5.data;

    var workTotal = (workTotalRes === null || workTotalRes === void 0 ? void 0 : workTotalRes.data) || {};

    var _useRequest6 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
        data: JSON.stringify({
          code: 'ZYQS_CAR_WORK_STATISTICS',
          parameters: {
            roadId: id,
            startDate: start,
            endDate: end,
            workType: workType === '全部' ? '' : workType
          }
        })
      });
    }, {
      refreshDeps: [id, start, end, workType]
    }),
        otherRes = _useRequest6.data;

    var other = (otherRes === null || otherRes === void 0 ? void 0 : otherRes.data) || [];
    var days = (0, _moment["default"])(end).diff((0, _moment["default"])(start), 'd') + 1;
    var workMile = {
      xAxis: [],
      planMiles: [],
      workMiles: []
    };
    var workCompleteRate = {
      xAxis: [],
      rates: []
    };
    var workSummary = {
      a: 0,
      b: 0,
      c: 0,
      d: 0
    };

    _toConsumableArray(new Array(days)).forEach(function (_, index) {
      var date = (0, _moment["default"])(start).add(index, 'd').format('YYYY-MM-DD');
      workMile.xAxis.push(date);
      workCompleteRate.xAxis.push(date);
      var data = other.find(function (e) {
        return e.work_date === date;
      });

      if (data) {
        workMile.planMiles.push(toFixd2(data.plan_mileage));
        workMile.workMiles.push(toFixd2(data.work_mileage));
        workCompleteRate.rates.push(data.rate);

        if (data.rate < 50) {
          workSummary.a += 1;
        }

        if (data.rate >= 50 && data.rate < 80) {
          workSummary.b += 1;
        }

        if (data.rate >= 80 && data.rate < 100) {
          workSummary.c += 1;
        }

        if (data.rate === 100) {
          workSummary.d += 1;
        }
      } else {
        workSummary.a += 1;
        workSummary.d += 1;
        workMile.planMiles.push(0);
        workMile.workMiles.push(0);
        workCompleteRate.rates.push(0);
      }
    });

    var _useRequest7 = (0, _ahooks.useRequest)(function () {
      return _utils.request.post('/cloud/management/rest/param/getByParamTypeCode', {
        data: {
          parameters: JSON.stringify({
            paramTypeCode: 'param_zyqs_workingType'
          })
        }
      });
    }, {
      refreshDeps: []
    }),
        workTypeDataRes = _useRequest7.data;

    var workTypeData = [{
      parmCode: '',
      parmName: '全部'
    }].concat(_toConsumableArray((workTypeDataRes === null || workTypeDataRes === void 0 ? void 0 : workTypeDataRes.data) || []));
    return {
      workTotal: workTotal,
      workTypeData: workTypeData,
      workMile: workMile,
      workSummary: workSummary,
      workCompleteRate: workCompleteRate
    };
  }
};
exports.BaseData = BaseData;
//# sourceMappingURL=api.js.map
