@pisell/pisellos 0.0.567 → 0.0.568
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.
- package/dist/core/index.js +6 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -3
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +1 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +14 -41
- package/dist/modules/Payment/index.js +142 -270
- package/dist/modules/Payment/walletpass.js +4 -5
- package/dist/modules/Rules/index.js +0 -7
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +88 -121
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/products/index.js +29 -49
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +32 -40
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +5 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -246
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.d.ts +5 -0
- package/dist/solution/VenueBooking/index.js +364 -327
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +130 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +92 -53
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
- package/lib/model/strategy/adapter/promotion/evaluator.js +381 -231
- package/lib/model/strategy/adapter/promotion/examples.js +139 -159
- package/lib/model/strategy/adapter/promotion/index.js +1 -49
- package/lib/model/strategy/adapter/promotion/type.js +199 -35
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +652 -402
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +22 -45
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +306 -241
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +72 -78
- package/lib/modules/Cart/utils/changePrice.js +26 -62
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +216 -153
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +117 -113
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +63 -74
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +332 -320
- package/lib/modules/Order/types.js +24 -33
- package/lib/modules/Order/utils.js +350 -284
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +566 -432
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +216 -107
- package/lib/modules/Payment/utils.js +50 -47
- package/lib/modules/Payment/walletpass.js +221 -203
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +111 -110
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +60 -82
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/Rules/index.js +1172 -872
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +59 -68
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +176 -193
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -167
- package/lib/modules/Schedule/index.js +97 -107
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -70
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +782 -429
- package/lib/modules/index.js +212 -57
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +882 -623
- package/lib/server/modules/index.js +85 -59
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +195 -231
- package/lib/server/modules/order/types.js +107 -32
- package/lib/server/modules/order/utils/filterBookings.js +174 -140
- package/lib/server/modules/order/utils/filterOrders.js +89 -60
- package/lib/server/modules/products/index.js +430 -335
- package/lib/server/modules/products/types.js +41 -34
- package/lib/server/modules/quotation/index.js +76 -77
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +216 -187
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +134 -119
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1530 -1343
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +147 -122
- package/lib/solution/BookingTicket/types.js +38 -64
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +64 -80
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +82 -80
- package/lib/solution/BookingTicket/utils/scan/index.js +90 -94
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +227 -158
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +218 -200
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +803 -840
- package/lib/solution/ScanOrder/types.js +34 -34
- package/lib/solution/ScanOrder/utils.js +372 -331
- package/lib/solution/ShopDiscount/index.js +230 -236
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +309 -172
- package/lib/solution/VenueBooking/index.d.ts +5 -0
- package/lib/solution/VenueBooking/index.js +886 -929
- package/lib/solution/VenueBooking/types.js +20 -40
- package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +88 -106
- package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +102 -37
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,51 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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/modules/Schedule/getDateIsInSchedule.ts
|
|
30
|
-
var getDateIsInSchedule_exports = {};
|
|
31
|
-
__export(getDateIsInSchedule_exports, {
|
|
32
|
-
getDateIsInSchedule: () => getDateIsInSchedule,
|
|
33
|
-
getScheduleStartEndTimePoints: () => getScheduleStartEndTimePoints
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
34
5
|
});
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
exports.getScheduleStartEndTimePoints = exports.getDateIsInSchedule = void 0;
|
|
7
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
8
|
+
var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
|
|
9
|
+
var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
_dayjs.default.extend(_isSameOrAfter.default);
|
|
12
|
+
_dayjs.default.extend(_isSameOrBefore.default);
|
|
13
|
+
|
|
14
|
+
// 获取时间是否在日程范围内
|
|
15
|
+
const getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
42
16
|
if (!dateTime || !scheduleList || scheduleList.length === 0) {
|
|
43
17
|
return false;
|
|
44
18
|
}
|
|
45
|
-
const targetDate = (0,
|
|
19
|
+
const targetDate = (0, _dayjs.default)(dateTime);
|
|
46
20
|
if (!targetDate.isValid()) {
|
|
47
21
|
return false;
|
|
48
22
|
}
|
|
23
|
+
|
|
24
|
+
// 遍历所有日程项
|
|
49
25
|
for (const schedule of scheduleList) {
|
|
50
26
|
if (isTimeInScheduleItem(dateTime, schedule)) {
|
|
51
27
|
return true;
|
|
@@ -53,173 +29,263 @@ var getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
|
53
29
|
}
|
|
54
30
|
return false;
|
|
55
31
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
|
|
33
|
+
// 判断时间是否在单个日程项范围内
|
|
34
|
+
exports.getDateIsInSchedule = getDateIsInSchedule;
|
|
35
|
+
const isTimeInScheduleItem = (dateTime, schedule) => {
|
|
36
|
+
const targetDate = (0, _dayjs.default)(dateTime);
|
|
37
|
+
const targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
|
|
38
|
+
const targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
|
|
39
|
+
|
|
60
40
|
switch (schedule.type) {
|
|
61
|
-
case
|
|
41
|
+
case 'standard':
|
|
62
42
|
return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
63
|
-
case
|
|
43
|
+
case 'time-slots':
|
|
64
44
|
return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
65
|
-
case
|
|
45
|
+
case 'designation':
|
|
66
46
|
return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
67
47
|
default:
|
|
68
48
|
return false;
|
|
69
49
|
}
|
|
70
50
|
};
|
|
71
|
-
|
|
51
|
+
|
|
52
|
+
// 处理标准类型日程
|
|
53
|
+
const isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
72
54
|
if (!schedule.start_time || !schedule.end_time) {
|
|
73
55
|
return false;
|
|
74
56
|
}
|
|
75
|
-
const startDate = (0,
|
|
76
|
-
const endDate = (0,
|
|
57
|
+
const startDate = (0, _dayjs.default)(schedule.start_time);
|
|
58
|
+
const endDate = (0, _dayjs.default)(schedule.end_time);
|
|
59
|
+
|
|
60
|
+
// 先检查是否在基础时间范围内(不考虑重复),end 为开区间
|
|
77
61
|
const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isBefore(endDate);
|
|
78
|
-
if (schedule.repeat_type ===
|
|
62
|
+
if (schedule.repeat_type === 'none') {
|
|
79
63
|
return isInBasicRange;
|
|
80
64
|
}
|
|
65
|
+
|
|
66
|
+
// 处理重复日程
|
|
81
67
|
return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
|
|
82
68
|
};
|
|
83
|
-
|
|
69
|
+
|
|
70
|
+
// 处理时间段类型日程
|
|
71
|
+
const isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
84
72
|
if (!schedule.start_time) {
|
|
85
73
|
return false;
|
|
86
74
|
}
|
|
87
|
-
const scheduleStartDate = (0,
|
|
75
|
+
const scheduleStartDate = (0, _dayjs.default)(schedule.start_time.split(' ')[0]);
|
|
88
76
|
if (!isDateInTimeSlotsSchedule(targetDate, schedule, scheduleStartDate)) {
|
|
89
77
|
return false;
|
|
90
78
|
}
|
|
91
79
|
for (const timeSlot of schedule.time_slot) {
|
|
92
|
-
const slotStart = (0,
|
|
93
|
-
const slotEnd = (0,
|
|
80
|
+
const slotStart = (0, _dayjs.default)(`${targetDateString} ${timeSlot.start_time}:00`);
|
|
81
|
+
const slotEnd = (0, _dayjs.default)(`${targetDateString} ${timeSlot.end_time}:00`);
|
|
94
82
|
if (targetDate.isSameOrAfter(slotStart) && targetDate.isBefore(slotEnd)) {
|
|
95
83
|
return true;
|
|
96
84
|
}
|
|
97
85
|
}
|
|
98
86
|
return false;
|
|
99
87
|
};
|
|
100
|
-
|
|
88
|
+
|
|
89
|
+
// 处理指定类型日程
|
|
90
|
+
const isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
101
91
|
if (!schedule.designation) {
|
|
102
92
|
return false;
|
|
103
93
|
}
|
|
94
|
+
|
|
95
|
+
// @ts-ignore
|
|
104
96
|
for (const designation of schedule.designation) {
|
|
105
97
|
const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
|
|
106
98
|
const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
|
|
107
|
-
const startDate = (0,
|
|
108
|
-
const endDate = (0,
|
|
99
|
+
const startDate = (0, _dayjs.default)(startDateTime);
|
|
100
|
+
const endDate = (0, _dayjs.default)(endDateTime);
|
|
109
101
|
if (targetDate.isSameOrAfter(startDate) && targetDate.isBefore(endDate)) {
|
|
110
102
|
return true;
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
105
|
return false;
|
|
114
106
|
};
|
|
115
|
-
|
|
107
|
+
|
|
108
|
+
// 处理重复日程逻辑
|
|
109
|
+
const isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
|
|
116
110
|
if (!schedule.repeat_rule) {
|
|
117
111
|
return false;
|
|
118
112
|
}
|
|
119
|
-
const {
|
|
120
|
-
|
|
113
|
+
const {
|
|
114
|
+
repeat_rule,
|
|
115
|
+
repeat_type
|
|
116
|
+
} = schedule;
|
|
117
|
+
const targetDateOnly = (0, _dayjs.default)(targetDateString); // 只取日期部分
|
|
118
|
+
|
|
119
|
+
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
121
120
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
122
121
|
for (const includedDate of repeat_rule.included_date) {
|
|
123
|
-
const includeStartDate = (0,
|
|
124
|
-
const includeEndDate = (0,
|
|
125
|
-
if (targetDateOnly.isSameOrAfter(includeStartDate,
|
|
122
|
+
const includeStartDate = (0, _dayjs.default)(includedDate.start);
|
|
123
|
+
const includeEndDate = (0, _dayjs.default)(includedDate.end);
|
|
124
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
125
|
+
// 在包含日期中,直接返回true,无需检查其他条件
|
|
126
126
|
return true;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
// 检查是否在排除日期中
|
|
130
132
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
131
|
-
const excludeStartDate = (0,
|
|
132
|
-
const excludeEndDate = (0,
|
|
133
|
-
|
|
133
|
+
const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
|
|
134
|
+
const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
|
|
135
|
+
// 检查目标日期是否在排除范围内(包含边界)
|
|
136
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
134
137
|
return false;
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
|
|
141
|
+
// 检查重复规则的结束条件
|
|
142
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
143
|
+
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
139
144
|
if (targetDate.isAfter(ruleEndDate)) {
|
|
140
145
|
return false;
|
|
141
146
|
}
|
|
142
147
|
}
|
|
148
|
+
|
|
149
|
+
// 根据重复类型检查
|
|
143
150
|
switch (repeat_type) {
|
|
144
|
-
case
|
|
151
|
+
case 'daily':
|
|
145
152
|
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
146
|
-
case
|
|
153
|
+
case 'weekly':
|
|
147
154
|
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
148
155
|
default:
|
|
149
156
|
return false;
|
|
157
|
+
// 不支持月和年重复
|
|
150
158
|
}
|
|
151
159
|
};
|
|
152
|
-
|
|
153
|
-
|
|
160
|
+
|
|
161
|
+
// 每日重复逻辑
|
|
162
|
+
const isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
163
|
+
const daysDiff = targetDate.diff(startDate, 'day');
|
|
154
164
|
if (daysDiff < 0) {
|
|
155
165
|
return false;
|
|
156
166
|
}
|
|
167
|
+
|
|
168
|
+
// 检查频率
|
|
157
169
|
if (daysDiff % repeatRule.frequency !== 0) {
|
|
158
170
|
return false;
|
|
159
171
|
}
|
|
172
|
+
|
|
173
|
+
// 检查时间是否在日程的时间范围内
|
|
160
174
|
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
161
175
|
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
162
176
|
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
177
|
+
|
|
178
|
+
// 每日重复:每天都在相同的时间段内有效 [start, end)
|
|
163
179
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay < endTimeOfDay;
|
|
164
180
|
};
|
|
165
|
-
|
|
166
|
-
|
|
181
|
+
|
|
182
|
+
// 每周重复逻辑
|
|
183
|
+
const isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
184
|
+
const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
185
|
+
|
|
186
|
+
// 检查是否在指定的星期几内
|
|
167
187
|
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
168
188
|
return false;
|
|
169
189
|
}
|
|
170
|
-
|
|
190
|
+
|
|
191
|
+
// 计算周差
|
|
192
|
+
const weeksDiff = targetDate.diff(startDate, 'week');
|
|
171
193
|
if (weeksDiff < 0) {
|
|
172
194
|
return false;
|
|
173
195
|
}
|
|
196
|
+
|
|
197
|
+
// 检查频率
|
|
174
198
|
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
175
199
|
return false;
|
|
176
200
|
}
|
|
201
|
+
|
|
202
|
+
// 检查时间是否在日程的时间范围内
|
|
177
203
|
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
178
204
|
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
179
205
|
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
180
206
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay < endTimeOfDay;
|
|
181
207
|
};
|
|
182
|
-
|
|
208
|
+
|
|
209
|
+
// 日程时间段类型
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 获取当前日期日程时间点
|
|
213
|
+
* @param date 日期 YYYY-MM-DD
|
|
214
|
+
* @param scheduleList 日程列表
|
|
215
|
+
* @returns 当前日期日程时间点 结构,数组 [{
|
|
216
|
+
*
|
|
217
|
+
* // HH:mm
|
|
218
|
+
* end_time: string,
|
|
219
|
+
* // HH:mm
|
|
220
|
+
* start_time: string,
|
|
221
|
+
* // 日期时间
|
|
222
|
+
* // YYYY-MM-DD HH:mm:ss
|
|
223
|
+
* end_at: Dayjs,
|
|
224
|
+
* // YYYY-MM-DD HH:mm:ss
|
|
225
|
+
* start_at: Dayjs,
|
|
226
|
+
*
|
|
227
|
+
* }]
|
|
228
|
+
*/
|
|
229
|
+
const getScheduleStartEndTimePoints = (date, scheduleList) => {
|
|
183
230
|
if (!date || !scheduleList || scheduleList.length === 0) {
|
|
184
231
|
return [];
|
|
185
232
|
}
|
|
186
|
-
const targetDate = (0,
|
|
233
|
+
const targetDate = (0, _dayjs.default)(date);
|
|
187
234
|
if (!targetDate.isValid()) {
|
|
188
235
|
return [];
|
|
189
236
|
}
|
|
190
237
|
const timeSlots = [];
|
|
238
|
+
|
|
239
|
+
// 遍历所有日程
|
|
191
240
|
for (const schedule of scheduleList) {
|
|
192
241
|
const slots = extractTimeSlotsFromSchedule(date, schedule);
|
|
193
242
|
timeSlots.push(...slots);
|
|
194
243
|
}
|
|
244
|
+
|
|
245
|
+
// 去重并排序时间段
|
|
195
246
|
return mergeAndSortTimeSlots(timeSlots);
|
|
196
247
|
};
|
|
197
|
-
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 从单个日程中提取指定日期的时间段
|
|
251
|
+
*/
|
|
252
|
+
exports.getScheduleStartEndTimePoints = getScheduleStartEndTimePoints;
|
|
253
|
+
const extractTimeSlotsFromSchedule = (date, schedule) => {
|
|
198
254
|
switch (schedule.type) {
|
|
199
|
-
case
|
|
255
|
+
case 'standard':
|
|
200
256
|
return extractStandardScheduleTimeSlots(date, schedule);
|
|
201
|
-
case
|
|
257
|
+
case 'time-slots':
|
|
202
258
|
return extractTimeSlotsScheduleTimeSlots(date, schedule);
|
|
203
|
-
case
|
|
259
|
+
case 'designation':
|
|
204
260
|
return extractDesignationScheduleTimeSlots(date, schedule);
|
|
205
261
|
default:
|
|
206
262
|
return [];
|
|
207
263
|
}
|
|
208
264
|
};
|
|
209
|
-
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* 提取标准类型日程的时间段
|
|
268
|
+
*/
|
|
269
|
+
const extractStandardScheduleTimeSlots = (date, schedule) => {
|
|
210
270
|
if (!schedule.start_time || !schedule.end_time) {
|
|
211
271
|
return [];
|
|
212
272
|
}
|
|
213
|
-
const targetDate = (0,
|
|
214
|
-
const startDate = (0,
|
|
215
|
-
const endDate = (0,
|
|
273
|
+
const targetDate = (0, _dayjs.default)(date);
|
|
274
|
+
const startDate = (0, _dayjs.default)(schedule.start_time);
|
|
275
|
+
const endDate = (0, _dayjs.default)(schedule.end_time);
|
|
276
|
+
|
|
277
|
+
// 检查日期是否在日程范围内
|
|
216
278
|
if (!isDateInStandardSchedule(targetDate, schedule, startDate, endDate)) {
|
|
217
279
|
return [];
|
|
218
280
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
const
|
|
281
|
+
|
|
282
|
+
// 提取时间部分
|
|
283
|
+
const startTime = startDate.format('HH:mm');
|
|
284
|
+
const endTime = endDate.format('HH:mm');
|
|
285
|
+
|
|
286
|
+
// 构造完整的日期时间
|
|
287
|
+
const startAt = (0, _dayjs.default)(`${date} ${startTime}:00`);
|
|
288
|
+
const endAt = (0, _dayjs.default)(`${date} ${endTime}:00`);
|
|
223
289
|
return [{
|
|
224
290
|
start_time: startTime,
|
|
225
291
|
end_time: endTime,
|
|
@@ -227,22 +293,30 @@ var extractStandardScheduleTimeSlots = (date, schedule) => {
|
|
|
227
293
|
end_at: endAt
|
|
228
294
|
}];
|
|
229
295
|
};
|
|
230
|
-
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 提取时间段类型日程的时间段
|
|
299
|
+
*/
|
|
300
|
+
const extractTimeSlotsScheduleTimeSlots = (date, schedule) => {
|
|
231
301
|
if (!schedule.start_time || !schedule.time_slot || schedule.time_slot.length === 0) {
|
|
232
302
|
return [];
|
|
233
303
|
}
|
|
234
|
-
const targetDate = (0,
|
|
235
|
-
const scheduleStartDate = (0,
|
|
304
|
+
const targetDate = (0, _dayjs.default)(date);
|
|
305
|
+
const scheduleStartDate = (0, _dayjs.default)(schedule.start_time.split(' ')[0]);
|
|
306
|
+
|
|
307
|
+
// 检查日期是否在日程的有效范围内(考虑重复规则)
|
|
236
308
|
if (!isDateInTimeSlotsSchedule(targetDate, schedule, scheduleStartDate)) {
|
|
237
309
|
return [];
|
|
238
310
|
}
|
|
239
311
|
const slots = [];
|
|
312
|
+
|
|
313
|
+
// 提取所有时间段
|
|
240
314
|
for (const timeSlot of schedule.time_slot) {
|
|
241
315
|
if (!timeSlot.start_time || !timeSlot.end_time) {
|
|
242
316
|
continue;
|
|
243
317
|
}
|
|
244
|
-
const startAt = (0,
|
|
245
|
-
const endAt = (0,
|
|
318
|
+
const startAt = (0, _dayjs.default)(`${date} ${timeSlot.start_time}:00`);
|
|
319
|
+
const endAt = (0, _dayjs.default)(`${date} ${timeSlot.end_time}:00`);
|
|
246
320
|
slots.push({
|
|
247
321
|
start_time: timeSlot.start_time,
|
|
248
322
|
end_time: timeSlot.end_time,
|
|
@@ -252,63 +326,90 @@ var extractTimeSlotsScheduleTimeSlots = (date, schedule) => {
|
|
|
252
326
|
}
|
|
253
327
|
return slots;
|
|
254
328
|
};
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 检查日期是否在时间段类型日程范围内
|
|
332
|
+
*/
|
|
333
|
+
const isDateInTimeSlotsSchedule = (targetDate, schedule, scheduleStartDate) => {
|
|
334
|
+
// 不重复的日程
|
|
335
|
+
if (schedule.repeat_type === 'none') {
|
|
336
|
+
// 只在 start_time 的日期有效
|
|
337
|
+
return targetDate.isSame(scheduleStartDate, 'day');
|
|
258
338
|
}
|
|
339
|
+
|
|
340
|
+
// 重复的日程,需要检查重复规则
|
|
259
341
|
if (!schedule.repeat_rule) {
|
|
260
342
|
return false;
|
|
261
343
|
}
|
|
262
|
-
const {
|
|
344
|
+
const {
|
|
345
|
+
repeat_rule,
|
|
346
|
+
repeat_type
|
|
347
|
+
} = schedule;
|
|
348
|
+
|
|
349
|
+
// 检查是否在包含日期中(优先级最高)
|
|
263
350
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
264
351
|
for (const includedDate of repeat_rule.included_date) {
|
|
265
|
-
const includeStartDate = (0,
|
|
266
|
-
const includeEndDate = (0,
|
|
267
|
-
if (targetDate.isSameOrAfter(includeStartDate,
|
|
352
|
+
const includeStartDate = (0, _dayjs.default)(includedDate.start);
|
|
353
|
+
const includeEndDate = (0, _dayjs.default)(includedDate.end);
|
|
354
|
+
if (targetDate.isSameOrAfter(includeStartDate, 'day') && targetDate.isSameOrBefore(includeEndDate, 'day')) {
|
|
268
355
|
return true;
|
|
269
356
|
}
|
|
270
357
|
}
|
|
271
358
|
}
|
|
359
|
+
|
|
360
|
+
// 检查是否在排除日期中
|
|
272
361
|
if (repeat_rule.excluded_date && repeat_rule.excluded_date.length > 0) {
|
|
273
362
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
274
|
-
const excludeStartDate = (0,
|
|
275
|
-
const excludeEndDate = (0,
|
|
276
|
-
if (targetDate.isSameOrAfter(excludeStartDate,
|
|
363
|
+
const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
|
|
364
|
+
const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
|
|
365
|
+
if (targetDate.isSameOrAfter(excludeStartDate, 'day') && targetDate.isSameOrBefore(excludeEndDate, 'day')) {
|
|
277
366
|
return false;
|
|
278
367
|
}
|
|
279
368
|
}
|
|
280
369
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
370
|
+
|
|
371
|
+
// 检查重复规则的结束条件
|
|
372
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
373
|
+
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
374
|
+
if (targetDate.isAfter(ruleEndDate, 'day')) {
|
|
284
375
|
return false;
|
|
285
376
|
}
|
|
286
377
|
}
|
|
287
|
-
|
|
378
|
+
|
|
379
|
+
// 检查是否在开始日期之前
|
|
380
|
+
if (targetDate.isBefore(scheduleStartDate, 'day')) {
|
|
288
381
|
return false;
|
|
289
382
|
}
|
|
383
|
+
|
|
384
|
+
// 根据重复类型检查
|
|
290
385
|
switch (repeat_type) {
|
|
291
|
-
case
|
|
386
|
+
case 'daily':
|
|
292
387
|
return isDateInDailyRepeat(targetDate, scheduleStartDate, repeat_rule);
|
|
293
|
-
case
|
|
388
|
+
case 'weekly':
|
|
294
389
|
return isDateInWeeklyRepeat(targetDate, scheduleStartDate, repeat_rule);
|
|
295
390
|
default:
|
|
296
391
|
return false;
|
|
297
392
|
}
|
|
298
393
|
};
|
|
299
|
-
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* 提取指定日期类型日程的时间段
|
|
397
|
+
*/
|
|
398
|
+
const extractDesignationScheduleTimeSlots = (date, schedule) => {
|
|
300
399
|
if (!schedule.designation) {
|
|
301
400
|
return [];
|
|
302
401
|
}
|
|
303
|
-
const targetDate = (0,
|
|
402
|
+
const targetDate = (0, _dayjs.default)(date);
|
|
304
403
|
const designations = Array.isArray(schedule.designation) ? schedule.designation : [schedule.designation];
|
|
305
404
|
const slots = [];
|
|
306
405
|
for (const designation of designations) {
|
|
307
|
-
const startDate = (0,
|
|
308
|
-
const endDate = (0,
|
|
406
|
+
const startDate = (0, _dayjs.default)(designation.start_date);
|
|
407
|
+
const endDate = (0, _dayjs.default)(designation.end_date);
|
|
408
|
+
|
|
409
|
+
// 检查日期是否在指定范围内(考虑重复规则)
|
|
309
410
|
if (isDateInDesignationSchedule(targetDate, schedule, designation, startDate, endDate)) {
|
|
310
|
-
const startAt = (0,
|
|
311
|
-
const endAt = (0,
|
|
411
|
+
const startAt = (0, _dayjs.default)(`${date} ${designation.start_time}:00`);
|
|
412
|
+
const endAt = (0, _dayjs.default)(`${date} ${designation.end_time}:00`);
|
|
312
413
|
slots.push({
|
|
313
414
|
start_time: designation.start_time,
|
|
314
415
|
end_time: designation.end_time,
|
|
@@ -319,125 +420,196 @@ var extractDesignationScheduleTimeSlots = (date, schedule) => {
|
|
|
319
420
|
}
|
|
320
421
|
return slots;
|
|
321
422
|
};
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* 检查日期是否在指定日期类型日程范围内
|
|
426
|
+
*/
|
|
427
|
+
const isDateInDesignationSchedule = (targetDate, schedule, designation, startDate, endDate) => {
|
|
428
|
+
// 不重复的日程
|
|
429
|
+
if (schedule.repeat_type === 'none') {
|
|
430
|
+
// 检查日期是否在指定的日期范围内
|
|
431
|
+
return targetDate.isSameOrAfter(startDate, 'day') && targetDate.isSameOrBefore(endDate, 'day');
|
|
325
432
|
}
|
|
433
|
+
|
|
434
|
+
// 重复的日程,需要检查重复规则
|
|
326
435
|
if (!schedule.repeat_rule) {
|
|
327
436
|
return false;
|
|
328
437
|
}
|
|
329
|
-
const {
|
|
438
|
+
const {
|
|
439
|
+
repeat_rule,
|
|
440
|
+
repeat_type
|
|
441
|
+
} = schedule;
|
|
442
|
+
|
|
443
|
+
// 检查是否在包含日期中(优先级最高)
|
|
330
444
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
331
445
|
for (const includedDate of repeat_rule.included_date) {
|
|
332
|
-
const includeStartDate = (0,
|
|
333
|
-
const includeEndDate = (0,
|
|
334
|
-
if (targetDate.isSameOrAfter(includeStartDate,
|
|
446
|
+
const includeStartDate = (0, _dayjs.default)(includedDate.start);
|
|
447
|
+
const includeEndDate = (0, _dayjs.default)(includedDate.end);
|
|
448
|
+
if (targetDate.isSameOrAfter(includeStartDate, 'day') && targetDate.isSameOrBefore(includeEndDate, 'day')) {
|
|
335
449
|
return true;
|
|
336
450
|
}
|
|
337
451
|
}
|
|
338
452
|
}
|
|
453
|
+
|
|
454
|
+
// 检查是否在排除日期中
|
|
339
455
|
if (repeat_rule.excluded_date && repeat_rule.excluded_date.length > 0) {
|
|
340
456
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
341
|
-
const excludeStartDate = (0,
|
|
342
|
-
const excludeEndDate = (0,
|
|
343
|
-
if (targetDate.isSameOrAfter(excludeStartDate,
|
|
457
|
+
const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
|
|
458
|
+
const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
|
|
459
|
+
if (targetDate.isSameOrAfter(excludeStartDate, 'day') && targetDate.isSameOrBefore(excludeEndDate, 'day')) {
|
|
344
460
|
return false;
|
|
345
461
|
}
|
|
346
462
|
}
|
|
347
463
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
464
|
+
|
|
465
|
+
// 检查重复规则的结束条件
|
|
466
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
467
|
+
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
468
|
+
if (targetDate.isAfter(ruleEndDate, 'day')) {
|
|
351
469
|
return false;
|
|
352
470
|
}
|
|
353
471
|
}
|
|
354
|
-
|
|
355
|
-
|
|
472
|
+
|
|
473
|
+
// 检查是否在基本日期范围内
|
|
474
|
+
if (!targetDate.isSameOrAfter(startDate, 'day') || !targetDate.isSameOrBefore(endDate, 'day')) {
|
|
475
|
+
// 对于重复日程,如果不在基本范围内,还需要检查是否符合重复规则
|
|
476
|
+
// 只要在 startDate 之后,并且符合重复规则即可
|
|
477
|
+
if (targetDate.isBefore(startDate, 'day')) {
|
|
356
478
|
return false;
|
|
357
479
|
}
|
|
358
480
|
}
|
|
481
|
+
|
|
482
|
+
// 根据重复类型检查
|
|
359
483
|
switch (repeat_type) {
|
|
360
|
-
case
|
|
484
|
+
case 'daily':
|
|
361
485
|
return isDateInDailyRepeat(targetDate, startDate, repeat_rule);
|
|
362
|
-
case
|
|
486
|
+
case 'weekly':
|
|
363
487
|
return isDateInWeeklyRepeat(targetDate, startDate, repeat_rule);
|
|
364
488
|
default:
|
|
365
489
|
return false;
|
|
366
490
|
}
|
|
367
491
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* 检查日期是否在标准日程范围内
|
|
495
|
+
*/
|
|
496
|
+
const isDateInStandardSchedule = (targetDate, schedule, startDate, endDate) => {
|
|
497
|
+
const targetDateString = targetDate.format('YYYY-MM-DD');
|
|
498
|
+
|
|
499
|
+
// 不重复的日程
|
|
500
|
+
if (schedule.repeat_type === 'none') {
|
|
501
|
+
// 检查日期是否在范围内
|
|
502
|
+
const scheduleStartDate = startDate.format('YYYY-MM-DD');
|
|
503
|
+
const scheduleEndDate = endDate.format('YYYY-MM-DD');
|
|
504
|
+
return targetDate.isSameOrAfter(scheduleStartDate, 'day') && targetDate.isSameOrBefore(scheduleEndDate, 'day');
|
|
374
505
|
}
|
|
506
|
+
|
|
507
|
+
// 重复的日程,需要检查重复规则
|
|
375
508
|
if (!schedule.repeat_rule) {
|
|
376
509
|
return false;
|
|
377
510
|
}
|
|
378
|
-
const {
|
|
511
|
+
const {
|
|
512
|
+
repeat_rule,
|
|
513
|
+
repeat_type
|
|
514
|
+
} = schedule;
|
|
515
|
+
|
|
516
|
+
// 检查是否在包含日期中
|
|
379
517
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
380
518
|
for (const includedDate of repeat_rule.included_date) {
|
|
381
|
-
const includeStartDate = (0,
|
|
382
|
-
const includeEndDate = (0,
|
|
383
|
-
if (targetDate.isSameOrAfter(includeStartDate,
|
|
519
|
+
const includeStartDate = (0, _dayjs.default)(includedDate.start);
|
|
520
|
+
const includeEndDate = (0, _dayjs.default)(includedDate.end);
|
|
521
|
+
if (targetDate.isSameOrAfter(includeStartDate, 'day') && targetDate.isSameOrBefore(includeEndDate, 'day')) {
|
|
384
522
|
return true;
|
|
385
523
|
}
|
|
386
524
|
}
|
|
387
525
|
}
|
|
526
|
+
|
|
527
|
+
// 检查是否在排除日期中
|
|
388
528
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
389
|
-
const excludeStartDate = (0,
|
|
390
|
-
const excludeEndDate = (0,
|
|
391
|
-
if (targetDate.isSameOrAfter(excludeStartDate,
|
|
529
|
+
const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
|
|
530
|
+
const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
|
|
531
|
+
if (targetDate.isSameOrAfter(excludeStartDate, 'day') && targetDate.isSameOrBefore(excludeEndDate, 'day')) {
|
|
392
532
|
return false;
|
|
393
533
|
}
|
|
394
534
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
535
|
+
|
|
536
|
+
// 检查重复规则的结束条件
|
|
537
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
538
|
+
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
539
|
+
if (targetDate.isAfter(ruleEndDate, 'day')) {
|
|
398
540
|
return false;
|
|
399
541
|
}
|
|
400
542
|
}
|
|
401
|
-
|
|
543
|
+
|
|
544
|
+
// 检查是否在开始日期之前
|
|
545
|
+
if (targetDate.isBefore(startDate, 'day')) {
|
|
402
546
|
return false;
|
|
403
547
|
}
|
|
548
|
+
|
|
549
|
+
// 根据重复类型检查
|
|
404
550
|
switch (repeat_type) {
|
|
405
|
-
case
|
|
551
|
+
case 'daily':
|
|
406
552
|
return isDateInDailyRepeat(targetDate, startDate, repeat_rule);
|
|
407
|
-
case
|
|
553
|
+
case 'weekly':
|
|
408
554
|
return isDateInWeeklyRepeat(targetDate, startDate, repeat_rule);
|
|
409
555
|
default:
|
|
410
556
|
return false;
|
|
411
557
|
}
|
|
412
558
|
};
|
|
413
|
-
|
|
414
|
-
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* 检查日期是否符合每日重复规则
|
|
562
|
+
*/
|
|
563
|
+
const isDateInDailyRepeat = (targetDate, startDate, repeatRule) => {
|
|
564
|
+
const daysDiff = targetDate.diff(startDate, 'day');
|
|
415
565
|
if (daysDiff < 0) {
|
|
416
566
|
return false;
|
|
417
567
|
}
|
|
568
|
+
|
|
569
|
+
// 检查频率
|
|
418
570
|
return daysDiff % repeatRule.frequency === 0;
|
|
419
571
|
};
|
|
420
|
-
|
|
421
|
-
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* 检查日期是否符合每周重复规则
|
|
575
|
+
*/
|
|
576
|
+
const isDateInWeeklyRepeat = (targetDate, startDate, repeatRule) => {
|
|
577
|
+
const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
578
|
+
|
|
579
|
+
// 检查是否在指定的星期几内
|
|
422
580
|
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
423
581
|
return false;
|
|
424
582
|
}
|
|
425
|
-
|
|
583
|
+
|
|
584
|
+
// 计算周差
|
|
585
|
+
const weeksDiff = targetDate.diff(startDate, 'week');
|
|
426
586
|
if (weeksDiff < 0) {
|
|
427
587
|
return false;
|
|
428
588
|
}
|
|
589
|
+
|
|
590
|
+
// 检查频率
|
|
429
591
|
return weeksDiff % repeatRule.frequency === 0;
|
|
430
592
|
};
|
|
431
|
-
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* 对时间段去重并排序
|
|
596
|
+
* 只移除开始时间和结束时间完全相同的重复时间段
|
|
597
|
+
*/
|
|
598
|
+
const mergeAndSortTimeSlots = slots => {
|
|
432
599
|
if (slots.length === 0) {
|
|
433
600
|
return [];
|
|
434
601
|
}
|
|
602
|
+
|
|
603
|
+
// 按开始时间排序
|
|
435
604
|
const sorted = [...slots].sort((a, b) => {
|
|
436
605
|
return a.start_at.valueOf() - b.start_at.valueOf();
|
|
437
606
|
});
|
|
607
|
+
|
|
608
|
+
// 去重:移除开始和结束时间完全相同的时间段
|
|
438
609
|
const unique = [];
|
|
439
|
-
const seenKeys =
|
|
610
|
+
const seenKeys = new Set();
|
|
440
611
|
for (const slot of sorted) {
|
|
612
|
+
// 使用开始时间和结束时间作为唯一键
|
|
441
613
|
const key = `${slot.start_time}-${slot.end_time}`;
|
|
442
614
|
if (!seenKeys.has(key)) {
|
|
443
615
|
seenKeys.add(key);
|
|
@@ -445,9 +617,4 @@ var mergeAndSortTimeSlots = (slots) => {
|
|
|
445
617
|
}
|
|
446
618
|
}
|
|
447
619
|
return unique;
|
|
448
|
-
};
|
|
449
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
450
|
-
0 && (module.exports = {
|
|
451
|
-
getDateIsInSchedule,
|
|
452
|
-
getScheduleStartEndTimePoints
|
|
453
|
-
});
|
|
620
|
+
};
|