"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StaticService = exports.ConfigService = exports.BaseService = void 0;
var _utils = require("@vtx/utils");
var _ahooks = require("ahooks");
var _util = _interopRequireDefault(require("../util"));
var _lodash = _interopRequireDefault(require("lodash"));
var _numberPrecision = _interopRequireDefault(require("number-precision"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var workTypeColors = ['#0082FF', '#00A56A', '#FF9A28'];
var ConfigService = exports.ConfigService = {
  useConfig: function useConfig() {
    var _useRequest = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/zyqs-zqb/api/v101/systemConfig/load');
      }, {
        onError: function onError(error) {
          if (error.status === 404) {
            //
          }
        }
      }),
      data = _useRequest.data,
      loading = _useRequest.loading;
    return {
      data: data === null || data === void 0 ? void 0 : data.data,
      loading: loading
    };
  }
};
var BaseService = exports.BaseService = {
  useBaseInfo: function useBaseInfo(id, service, loading, hasRule) {
    var _a, _b, _c, _d;
    var _useRequest2 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/v1.5/road/").concat(id));
      }, {
        refreshDeps: [id, loading, hasRule],
        ready: !loading && hasRule
      }),
      baseInfoRes = _useRequest2.data;
    var _useRequest3 = (0, _ahooks.useRequest)(function () {
        return _util["default"].getForTenantId('/cloud/jcss-reborn/facility/type/getByCode', {
          body: {
            code: 'tr',
            tenantId: ''
          }
        });
      }, {
        refreshDeps: [id]
      }),
      showConfig = _useRequest3.data;
    var info = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var showbidSection = ((_a = showConfig === null || showConfig === void 0 ? void 0 : showConfig.data) === null || _a === void 0 ? void 0 : _a.code) == 'tr' ? (_c = (_b = showConfig === null || showConfig === void 0 ? void 0 : showConfig.data) === null || _b === void 0 ? void 0 : _b.fieldJson) === null || _c === void 0 ? void 0 : _c.find(function (item) {
      return item.key == 'tenderId' && item.enabled == true;
    }) : true;
    var baseInfo = (_d = [{
      label: '管理单位',
      key: 'manageUnitName',
      value: info === null || info === void 0 ? void 0 : info.manageUnitName
    }, {
      label: '路段长度',
      key: 'roadSpace',
      value: "".concat((info === null || info === void 0 ? void 0 : info.roadSpace) || '0', "m")
    }, {
      label: '行政区划',
      key: 'divisionName',
      value: info === null || info === void 0 ? void 0 : info.divisionName
    }, {
      label: '路段宽度(m)',
      key: 'roadWidth',
      value: "".concat((info === null || info === void 0 ? void 0 : info.roadWidth) || '0', "m")
    }, showbidSection && {
      label: '所属标段',
      key: 'bidSectionName',
      value: info === null || info === void 0 ? void 0 : info.bidSectionName
    }, {
      label: '作业单位',
      key: 'companyName',
      value: info === null || info === void 0 ? void 0 : info.companyName
    }]) === null || _d === void 0 ? void 0 : _d.filter(Boolean);
    var rules = (info === null || info === void 0 ? void 0 : info.rules) || [];
    var workTypeColorMap = {};
    _lodash["default"].uniqBy(rules, 'workTypeName').forEach(function (item, index) {
      workTypeColorMap[item.workTypeName] = workTypeColors[index % workTypeColors.length];
    });
    return {
      baseInfo: baseInfo,
      rules: rules,
      info: info,
      workTypeColorMap: workTypeColorMap
    };
  },
  useJcss: function useJcss(id, coordType) {
    var _a, _b, _c, _d, _e, _f;
    var _useRequest4 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/jcss-reborn/facility/get', {
          data: {
            id: id,
            coordType: coordType || 'bd09'
          }
        });
      }, {
        refreshDeps: [id]
      }),
      jcssBaseInfoRes = _useRequest4.data;
    var jcssInfo = jcssBaseInfoRes === null || jcssBaseInfoRes === void 0 ? void 0 : jcssBaseInfoRes.data;
    var hasRule = ((_b = (_a = jcssInfo === null || jcssInfo === void 0 ? void 0 : jcssInfo.dataJson) === null || _a === void 0 ? void 0 : _a.roadWorkTypeId) === null || _b === void 0 ? void 0 : _b.indexOf('jxhbj')) > -1;
    var _useRequest5 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get('/cloud/jcss-reborn/facility/type/config/getByCode', {
          data: {
            code: 'tr'
          }
        });
      }, {
        refreshDeps: [id]
      }),
      tabConfig = _useRequest5.data;
    return {
      jcssInfo: jcssInfo,
      hasRule: hasRule,
      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
    };
  },
  useRecordService: function useRecordService(id, date, service) {
    // 车辆作业信息
    var _useRequest6 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/kanban/getCarWorkInfoByRoadId"), {
          data: {
            roadId: id,
            date: date
          }
        });
      }, {
        refreshDeps: [id, date, service]
      }),
      carWorkRecordRes = _useRequest6.data;
    var carWorkRecord = [];
    var groupByCarCode = _lodash["default"].groupBy((carWorkRecordRes === null || carWorkRecordRes === void 0 ? void 0 : carWorkRecordRes.data) || [], 'carCode');
    Object.keys(groupByCarCode).forEach(function (carCode) {
      var list = groupByCarCode[carCode];
      list[0].rowSpan = list.length;
      carWorkRecord.push.apply(carWorkRecord, _toConsumableArray(list));
    });
    return {
      carWorkRecord: carWorkRecord
    };
  },
  useWorkOverview: function useWorkOverview(id, date, service) {
    var _useRequest7 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/kanban/workOverview"), {
          data: {
            roadId: id,
            date: date
          }
        });
      }, {
        refreshDeps: [id, date, service]
      }),
      workInfoRes = _useRequest7.data;
    return {
      workInfo: (workInfoRes === null || workInfoRes === void 0 ? void 0 : workInfoRes.data) || []
    };
  },
  useRoadReport: function useRoadReport(roadId, startDate, endDate) {
    var _useRequest8 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/zyqs-zqb/api/np/noshift/report/roadWorkDailyReport", {
          data: {
            roadId: roadId,
            startDate: startDate,
            endDate: endDate
          }
        });
      }, {
        refreshDeps: [roadId, startDate, endDate]
      }),
      roadReport = _useRequest8.data;
    var groupByDate = _lodash["default"].groupBy((roadReport === null || roadReport === void 0 ? void 0 : roadReport.data) || [], 'workDate');
    var obj = {};
    Object.keys(groupByDate).forEach(function (date) {
      var workMileage = groupByDate[date].reduce(function (acc, cur) {
        return _numberPrecision["default"].plus(acc, cur.workMileage);
      }, 0);
      var planMileage = groupByDate[date].reduce(function (acc, cur) {
        return _numberPrecision["default"].plus(acc, cur.planMileage);
      }, 0);
      var completePercent = planMileage ? (workMileage / planMileage * 100).toFixed(2) : 0;
      obj[date] = {
        workMileage: workMileage,
        planMileage: planMileage,
        completePercent: completePercent
      };
    });
    return {
      roadWorkInfo: obj
    };
  }
};
var StaticService = exports.StaticService = {
  useSummaryInfo: function useSummaryInfo(id, startDate, endDate, service) {
    var _useRequest9 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/kanban/summaryStatistics"), {
          data: {
            roadId: id,
            startDate: startDate,
            endDate: endDate
          }
        });
      }, {
        refreshDeps: [id, startDate, endDate, service]
      }),
      summaryInfoRes = _useRequest9.data;
    var summaryInfo = summaryInfoRes === null || summaryInfoRes === void 0 ? void 0 : summaryInfoRes.data;
    //完成率统计
    var _useRequest0 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/kanban/completionRateStatistics"), {
          data: {
            roadId: id,
            startDate: startDate,
            endDate: endDate
          }
        });
      }, {
        refreshDeps: [id, startDate, endDate, service]
      }),
      completionRateRes = _useRequest0.data;
    var completionRate = completionRateRes === null || completionRateRes === void 0 ? void 0 : completionRateRes.data;
    // 作业里程分析
    var _useRequest1 = (0, _ahooks.useRequest)(function () {
        return _utils.request.get("/cloud/".concat(service ? service : 'zyqs-reborn', "/api/kanban/workMileageAnalysis"), {
          data: {
            roadId: id,
            startDate: startDate,
            endDate: endDate
          }
        });
      }, {
        refreshDeps: [id, startDate, endDate, service]
      }),
      mileAnalysisRes = _useRequest1.data;
    var mileAnalysis = (mileAnalysisRes === null || mileAnalysisRes === void 0 ? void 0 : mileAnalysisRes.data) || [];
    return {
      summaryInfo: summaryInfo,
      completionRate: completionRate,
      mileAnalysis: mileAnalysis
    };
  }
};
//# sourceMappingURL=api.js.map
