@pisell/pisellos 0.0.115 → 0.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,6 +37,7 @@ import { getResourcesMap } from "../../modules/Resource/utils";
37
37
  import { cloneDeep } from 'lodash-es';
38
38
  import { calcCalendarDataByScheduleResult, calcMinTimeMaxTimeBySchedules, getAllSortedDateRanges } from "../../modules/Schedule/utils";
39
39
  import { disableAllDates, disableDatesBeforeOneDay, generateMonthDates, handleAvailableDateByResource } from "../../modules/Date/utils";
40
+ import { calculateResourceAvailableTime, findFastestAvailableResource } from "./utils/timeslots";
40
41
  export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
41
42
  _inherits(BookingByStepImpl, _BaseModule);
42
43
  var _super = _createSuper(BookingByStepImpl);
@@ -1817,6 +1818,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1817
1818
  // .format("HH:mm");
1818
1819
  // 根据 start_time 和 end_time 去匹配资源
1819
1820
  var targetResource = null;
1821
+ var targetResourceTime = 0;
1820
1822
  var _iterator3 = _createForOfIteratorHelper(resources),
1821
1823
  _step3;
1822
1824
  try {
@@ -1859,8 +1861,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1859
1861
  }
1860
1862
  return res.usable;
1861
1863
  });
1862
- if (canUseTime && !n.onlyComputed) {
1864
+ var currentResourceIdleTime = calculateResourceAvailableTime({
1865
+ resource: n,
1866
+ timeSlots: timeSlots,
1867
+ currentCapacity: totalCapacity + (capacity || 0)
1868
+ });
1869
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1863
1870
  targetResource = n;
1871
+ targetResourceTime = currentResourceIdleTime;
1864
1872
  return 1; // break
1865
1873
  }
1866
1874
  },
@@ -2058,7 +2066,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2058
2066
  })) {
2059
2067
  return;
2060
2068
  }
2061
- var targetResource = targetRenderList[0];
2069
+ var fastestResource = findFastestAvailableResource({
2070
+ resources: targetRenderList,
2071
+ currentCapacity: currentCapacity,
2072
+ countMap: selectResourcesMap
2073
+ });
2074
+ var targetResource = fastestResource || targetRenderList[0];
2062
2075
  targetResource.capacity = currentCapacity;
2063
2076
  // 在这里处理 children 的数据
2064
2077
  checkSubResourcesCapacity(targetResource);
@@ -0,0 +1,25 @@
1
+ import { ResourceItem, TimeSliceItem } from "./resources";
2
+ /**
3
+ * 计算资源在指定时间段内的总可用时间(以分钟为单位)
4
+ * @param resource 需要计算可用时间的资源
5
+ * @param timeSlots 要检查可用性的时间段
6
+ * @param currentCapacity 当前预约所需的容量
7
+ * @returns 总可用时间(分钟)
8
+ */
9
+ export declare function calculateResourceAvailableTime({ resource, timeSlots, currentCapacity, }: {
10
+ resource: ResourceItem;
11
+ timeSlots: TimeSliceItem;
12
+ currentCapacity?: number;
13
+ }): number;
14
+ /**
15
+ * 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
16
+ * @param resources 资源列表
17
+ * @param currentCapacity 当前预约所需的容量
18
+ * @param countMap 已预约数量映射
19
+ * @returns 最快可用的资源
20
+ */
21
+ export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
22
+ resources: ResourceItem[];
23
+ currentCapacity?: number;
24
+ countMap?: Record<number, number>;
25
+ }): ResourceItem | null;
@@ -0,0 +1,209 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ 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); }
3
+ 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; }
4
+ import dayjs from "dayjs";
5
+ /**
6
+ * 计算资源在指定时间段内的总可用时间(以分钟为单位)
7
+ * @param resource 需要计算可用时间的资源
8
+ * @param timeSlots 要检查可用性的时间段
9
+ * @param currentCapacity 当前预约所需的容量
10
+ * @returns 总可用时间(分钟)
11
+ */
12
+ export function calculateResourceAvailableTime(_ref) {
13
+ var resource = _ref.resource,
14
+ timeSlots = _ref.timeSlots,
15
+ _ref$currentCapacity = _ref.currentCapacity,
16
+ currentCapacity = _ref$currentCapacity === void 0 ? 1 : _ref$currentCapacity;
17
+ // 过滤出与给定日期相同的资源时间
18
+ var matchingTimes = resource.times.filter(function (time) {
19
+ return dayjs(time.start_at).isSame(dayjs(timeSlots.start_at), 'day');
20
+ });
21
+ if (matchingTimes.length === 0) return 0;
22
+
23
+ // 计算所有时间段与目标时间槽的重叠部分
24
+ var overlaps = [];
25
+ var _iterator = _createForOfIteratorHelper(matchingTimes),
26
+ _step;
27
+ try {
28
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
29
+ var time = _step.value;
30
+ // 计算实际重叠的时间段
31
+ var overlapStart = dayjs(time.start_at).isAfter(dayjs(timeSlots.start_at)) ? dayjs(time.start_at) : dayjs(timeSlots.start_at);
32
+ var overlapEnd = dayjs(time.end_at).isBefore(dayjs(timeSlots.end_at)) ? dayjs(time.end_at) : dayjs(timeSlots.end_at);
33
+
34
+ // 只有当重叠时间段有效时才添加
35
+ if (overlapStart.isBefore(overlapEnd)) {
36
+ overlaps.push({
37
+ start: overlapStart,
38
+ end: overlapEnd
39
+ });
40
+ }
41
+ }
42
+
43
+ // 合并重叠的时间段,计算并集
44
+ } catch (err) {
45
+ _iterator.e(err);
46
+ } finally {
47
+ _iterator.f();
48
+ }
49
+ if (overlaps.length === 0) return 0;
50
+
51
+ // 按开始时间排序
52
+ overlaps.sort(function (a, b) {
53
+ return a.start.diff(b.start);
54
+ });
55
+
56
+ // 合并重叠的时间段
57
+ var merged = [];
58
+ var current = overlaps[0];
59
+ for (var i = 1; i < overlaps.length; i++) {
60
+ var next = overlaps[i];
61
+
62
+ // 如果当前时间段与下一个时间段重叠或相邻,则合并
63
+ if (current.end.isSameOrAfter(next.start)) {
64
+ current.end = current.end.isAfter(next.end) ? current.end : next.end;
65
+ } else {
66
+ // 不重叠,添加当前时间段到结果中,开始处理下一个
67
+ merged.push(current);
68
+ current = next;
69
+ }
70
+ }
71
+ merged.push(current);
72
+
73
+ // 计算所有合并后时间段的总时长
74
+ var totalAvailableMinutes = 0;
75
+ for (var _i = 0, _merged = merged; _i < _merged.length; _i++) {
76
+ var segment = _merged[_i];
77
+ totalAvailableMinutes += segment.end.diff(segment.start, 'minute');
78
+ }
79
+ return totalAvailableMinutes;
80
+ }
81
+
82
+ /**
83
+ * 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
84
+ * @param resources 资源列表
85
+ * @param currentCapacity 当前预约所需的容量
86
+ * @param countMap 已预约数量映射
87
+ * @returns 最快可用的资源
88
+ */
89
+ export function findFastestAvailableResource(_ref2) {
90
+ var resources = _ref2.resources,
91
+ _ref2$currentCapacity = _ref2.currentCapacity,
92
+ currentCapacity = _ref2$currentCapacity === void 0 ? 1 : _ref2$currentCapacity,
93
+ _ref2$countMap = _ref2.countMap,
94
+ countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap;
95
+ var currentTime = dayjs();
96
+ var fastestTime = null;
97
+ var fastestResources = [];
98
+
99
+ // 遍历所有资源,找到最快可用的时间点
100
+ var _iterator2 = _createForOfIteratorHelper(resources),
101
+ _step2;
102
+ try {
103
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
104
+ var _resource = _step2.value;
105
+ // 获取资源当天的时间段
106
+ var todayTimes = _resource.times.filter(function (time) {
107
+ return dayjs(time.start_at).isSame(currentTime, 'day');
108
+ });
109
+ if (todayTimes.length === 0) continue;
110
+
111
+ // 按开始时间排序
112
+ todayTimes.sort(function (a, b) {
113
+ return dayjs(a.start_at).diff(dayjs(b.start_at));
114
+ });
115
+
116
+ // 找到第一个可用的时间段
117
+ var _iterator3 = _createForOfIteratorHelper(todayTimes),
118
+ _step3;
119
+ try {
120
+ var _loop = function _loop() {
121
+ var time = _step3.value;
122
+ var startTime = dayjs(time.start_at);
123
+
124
+ // 如果开始时间在当前时间之前,跳过
125
+ if (startTime.isBefore(currentTime)) return 0; // continue
126
+
127
+ // 检查这个时间段是否可用
128
+ if (_resource.resourceType === 'single') {
129
+ var _time$event_list;
130
+ // 单个预约类型:检查是否有预约
131
+ var hasBooking = (_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.some(function (event) {
132
+ return dayjs(event.start_at).isSame(startTime);
133
+ });
134
+ if (!hasBooking) {
135
+ if (!fastestTime || startTime.isSame(fastestTime)) {
136
+ fastestTime = startTime;
137
+ fastestResources.push(_resource);
138
+ } else if (startTime.isBefore(fastestTime)) {
139
+ fastestTime = startTime;
140
+ fastestResources = [_resource];
141
+ }
142
+ return 1; // break
143
+ }
144
+ } else {
145
+ var _time$event_list2;
146
+ // 多个预约类型:检查容量
147
+ var totalCapacity = _resource.capacity || 0;
148
+ var usedCapacity = ((_time$event_list2 = time.event_list) === null || _time$event_list2 === void 0 ? void 0 : _time$event_list2.reduce(function (sum, event) {
149
+ return dayjs(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
150
+ }, 0)) || 0;
151
+ var remainingCapacity = totalCapacity - usedCapacity;
152
+ if (remainingCapacity >= (countMap[_resource.id] || 0) + currentCapacity) {
153
+ if (!fastestTime || startTime.isSame(fastestTime)) {
154
+ fastestTime = startTime;
155
+ fastestResources.push(_resource);
156
+ } else if (startTime.isBefore(fastestTime)) {
157
+ fastestTime = startTime;
158
+ fastestResources = [_resource];
159
+ }
160
+ return 1; // break
161
+ }
162
+ }
163
+ },
164
+ _ret;
165
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
166
+ _ret = _loop();
167
+ if (_ret === 0) continue;
168
+ if (_ret === 1) break;
169
+ }
170
+ } catch (err) {
171
+ _iterator3.e(err);
172
+ } finally {
173
+ _iterator3.f();
174
+ }
175
+ }
176
+
177
+ // 如果没有找到可用资源,返回null
178
+ } catch (err) {
179
+ _iterator2.e(err);
180
+ } finally {
181
+ _iterator2.f();
182
+ }
183
+ if (!fastestTime || fastestResources.length === 0) return null;
184
+
185
+ // 如果只有一个最快可用的资源,直接返回
186
+ if (fastestResources.length === 1) return fastestResources[0];
187
+
188
+ // 如果有多个最快可用的资源,比较它们的空闲时间
189
+ var maxIdleTime = 0;
190
+ var selectedResource = null;
191
+ for (var _i2 = 0, _fastestResources = fastestResources; _i2 < _fastestResources.length; _i2++) {
192
+ var resource = _fastestResources[_i2];
193
+ var idleTime = calculateResourceAvailableTime({
194
+ resource: resource,
195
+ timeSlots: {
196
+ start_time: fastestTime.format('HH:mm'),
197
+ end_time: fastestTime.format('HH:mm'),
198
+ start_at: fastestTime,
199
+ end_at: fastestTime
200
+ },
201
+ currentCapacity: (countMap[resource.id] || 0) + currentCapacity
202
+ });
203
+ if (idleTime > maxIdleTime) {
204
+ maxIdleTime = idleTime;
205
+ selectedResource = resource;
206
+ }
207
+ }
208
+ return selectedResource;
209
+ }
@@ -43,6 +43,7 @@ var import_utils = require("../../modules/Resource/utils");
43
43
  var import_lodash_es = require("lodash-es");
44
44
  var import_utils2 = require("../../modules/Schedule/utils");
45
45
  var import_utils3 = require("../../modules/Date/utils");
46
+ var import_timeslots = require("./utils/timeslots");
46
47
  import_dayjs.default.extend(import_isSameOrBefore.default);
47
48
  import_dayjs.default.extend(import_isSameOrAfter.default);
48
49
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
@@ -1172,6 +1173,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1172
1173
  }, {});
1173
1174
  if (timeSlots) {
1174
1175
  let targetResource = null;
1176
+ let targetResourceTime = 0;
1175
1177
  for (const n of resources) {
1176
1178
  const mTimes = n.times.filter((n2) => {
1177
1179
  return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
@@ -1201,8 +1203,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1201
1203
  }
1202
1204
  return res.usable;
1203
1205
  });
1204
- if (canUseTime && !n.onlyComputed) {
1206
+ const currentResourceIdleTime = (0, import_timeslots.calculateResourceAvailableTime)({
1207
+ resource: n,
1208
+ timeSlots,
1209
+ currentCapacity: totalCapacity + (capacity || 0)
1210
+ });
1211
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1205
1212
  targetResource = n;
1213
+ targetResourceTime = currentResourceIdleTime;
1206
1214
  break;
1207
1215
  }
1208
1216
  }
@@ -1384,7 +1392,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1384
1392
  )) {
1385
1393
  return;
1386
1394
  }
1387
- const targetResource = targetRenderList[0];
1395
+ const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
1396
+ resources: targetRenderList,
1397
+ currentCapacity,
1398
+ countMap: selectResourcesMap
1399
+ });
1400
+ const targetResource = fastestResource || targetRenderList[0];
1388
1401
  targetResource.capacity = currentCapacity;
1389
1402
  (0, import_resources.checkSubResourcesCapacity)(targetResource);
1390
1403
  if (!selectResourcesMap[targetResource.id]) {
@@ -0,0 +1,25 @@
1
+ import { ResourceItem, TimeSliceItem } from "./resources";
2
+ /**
3
+ * 计算资源在指定时间段内的总可用时间(以分钟为单位)
4
+ * @param resource 需要计算可用时间的资源
5
+ * @param timeSlots 要检查可用性的时间段
6
+ * @param currentCapacity 当前预约所需的容量
7
+ * @returns 总可用时间(分钟)
8
+ */
9
+ export declare function calculateResourceAvailableTime({ resource, timeSlots, currentCapacity, }: {
10
+ resource: ResourceItem;
11
+ timeSlots: TimeSliceItem;
12
+ currentCapacity?: number;
13
+ }): number;
14
+ /**
15
+ * 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
16
+ * @param resources 资源列表
17
+ * @param currentCapacity 当前预约所需的容量
18
+ * @param countMap 已预约数量映射
19
+ * @returns 最快可用的资源
20
+ */
21
+ export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
22
+ resources: ResourceItem[];
23
+ currentCapacity?: number;
24
+ countMap?: Record<number, number>;
25
+ }): ResourceItem | null;
@@ -0,0 +1,159 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BookingByStep/utils/timeslots.ts
30
+ var timeslots_exports = {};
31
+ __export(timeslots_exports, {
32
+ calculateResourceAvailableTime: () => calculateResourceAvailableTime,
33
+ findFastestAvailableResource: () => findFastestAvailableResource
34
+ });
35
+ module.exports = __toCommonJS(timeslots_exports);
36
+ var import_dayjs = __toESM(require("dayjs"));
37
+ function calculateResourceAvailableTime({
38
+ resource,
39
+ timeSlots,
40
+ currentCapacity = 1
41
+ }) {
42
+ const matchingTimes = resource.times.filter((time) => {
43
+ return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
44
+ });
45
+ if (matchingTimes.length === 0)
46
+ return 0;
47
+ const overlaps = [];
48
+ for (const time of matchingTimes) {
49
+ const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
50
+ const overlapEnd = (0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at)) ? (0, import_dayjs.default)(time.end_at) : (0, import_dayjs.default)(timeSlots.end_at);
51
+ if (overlapStart.isBefore(overlapEnd)) {
52
+ overlaps.push({ start: overlapStart, end: overlapEnd });
53
+ }
54
+ }
55
+ if (overlaps.length === 0)
56
+ return 0;
57
+ overlaps.sort((a, b) => a.start.diff(b.start));
58
+ const merged = [];
59
+ let current = overlaps[0];
60
+ for (let i = 1; i < overlaps.length; i++) {
61
+ const next = overlaps[i];
62
+ if (current.end.isSameOrAfter(next.start)) {
63
+ current.end = current.end.isAfter(next.end) ? current.end : next.end;
64
+ } else {
65
+ merged.push(current);
66
+ current = next;
67
+ }
68
+ }
69
+ merged.push(current);
70
+ let totalAvailableMinutes = 0;
71
+ for (const segment of merged) {
72
+ totalAvailableMinutes += segment.end.diff(segment.start, "minute");
73
+ }
74
+ return totalAvailableMinutes;
75
+ }
76
+ function findFastestAvailableResource({
77
+ resources,
78
+ currentCapacity = 1,
79
+ countMap = {}
80
+ }) {
81
+ var _a, _b;
82
+ const currentTime = (0, import_dayjs.default)();
83
+ let fastestTime = null;
84
+ let fastestResources = [];
85
+ for (const resource of resources) {
86
+ const todayTimes = resource.times.filter((time) => {
87
+ return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
88
+ });
89
+ if (todayTimes.length === 0)
90
+ continue;
91
+ todayTimes.sort((a, b) => {
92
+ return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
93
+ });
94
+ for (const time of todayTimes) {
95
+ const startTime = (0, import_dayjs.default)(time.start_at);
96
+ if (startTime.isBefore(currentTime))
97
+ continue;
98
+ if (resource.resourceType === "single") {
99
+ const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
100
+ return (0, import_dayjs.default)(event.start_at).isSame(startTime);
101
+ });
102
+ if (!hasBooking) {
103
+ if (!fastestTime || startTime.isSame(fastestTime)) {
104
+ fastestTime = startTime;
105
+ fastestResources.push(resource);
106
+ } else if (startTime.isBefore(fastestTime)) {
107
+ fastestTime = startTime;
108
+ fastestResources = [resource];
109
+ }
110
+ break;
111
+ }
112
+ } else {
113
+ const totalCapacity = resource.capacity || 0;
114
+ const usedCapacity = ((_b = time.event_list) == null ? void 0 : _b.reduce((sum, event) => {
115
+ return (0, import_dayjs.default)(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
116
+ }, 0)) || 0;
117
+ const remainingCapacity = totalCapacity - usedCapacity;
118
+ if (remainingCapacity >= (countMap[resource.id] || 0) + currentCapacity) {
119
+ if (!fastestTime || startTime.isSame(fastestTime)) {
120
+ fastestTime = startTime;
121
+ fastestResources.push(resource);
122
+ } else if (startTime.isBefore(fastestTime)) {
123
+ fastestTime = startTime;
124
+ fastestResources = [resource];
125
+ }
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ }
131
+ if (!fastestTime || fastestResources.length === 0)
132
+ return null;
133
+ if (fastestResources.length === 1)
134
+ return fastestResources[0];
135
+ let maxIdleTime = 0;
136
+ let selectedResource = null;
137
+ for (const resource of fastestResources) {
138
+ const idleTime = calculateResourceAvailableTime({
139
+ resource,
140
+ timeSlots: {
141
+ start_time: fastestTime.format("HH:mm"),
142
+ end_time: fastestTime.format("HH:mm"),
143
+ start_at: fastestTime,
144
+ end_at: fastestTime
145
+ },
146
+ currentCapacity: (countMap[resource.id] || 0) + currentCapacity
147
+ });
148
+ if (idleTime > maxIdleTime) {
149
+ maxIdleTime = idleTime;
150
+ selectedResource = resource;
151
+ }
152
+ }
153
+ return selectedResource;
154
+ }
155
+ // Annotate the CommonJS export names for ESM import in node:
156
+ 0 && (module.exports = {
157
+ calculateResourceAvailableTime,
158
+ findFastestAvailableResource
159
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.115",
4
+ "version": "0.0.116",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",