@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,120 +1,98 @@
|
|
|
1
|
-
|
|
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);
|
|
1
|
+
"use strict";
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__export(order_exports, {
|
|
32
|
-
OrderModule: () => OrderModule
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
33
5
|
});
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
exports.OrderModule = void 0;
|
|
7
|
+
var _lodashEs = require("lodash-es");
|
|
8
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
+
var _BaseModule = require("../../../modules/BaseModule");
|
|
10
|
+
var _types = require("./types");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
/**
|
|
13
|
+
* SQLite 存储名称
|
|
14
|
+
*/
|
|
15
|
+
const INDEXDB_STORE_NAME = 'orders';
|
|
16
|
+
const ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Order 模块 - 基础框架
|
|
20
|
+
*/
|
|
21
|
+
class OrderModule extends _BaseModule.BaseModule {
|
|
22
|
+
defaultName = 'order';
|
|
23
|
+
defaultVersion = '1.0.0';
|
|
24
|
+
store;
|
|
25
|
+
dbManager;
|
|
26
|
+
orderDataSource;
|
|
27
|
+
pendingSyncMessages = [];
|
|
28
|
+
syncTimer;
|
|
29
|
+
ORDER_SYNC_DEBOUNCE_MS = 5_000;
|
|
30
|
+
// Map<resource_id, OrderId[]> 资源到订单的倒排索引
|
|
31
|
+
resourceIdIndex = new Map();
|
|
32
|
+
logger; // LoggerManager 实例
|
|
33
|
+
storage;
|
|
42
34
|
constructor(name, version) {
|
|
43
35
|
super(name, version);
|
|
44
|
-
this.defaultName = "order";
|
|
45
|
-
this.defaultVersion = "1.0.0";
|
|
46
|
-
this.pendingSyncMessages = [];
|
|
47
|
-
this.ORDER_SYNC_DEBOUNCE_MS = 5e3;
|
|
48
|
-
// Map<resource_id, OrderId[]> 资源到订单的倒排索引
|
|
49
|
-
this.resourceIdIndex = /* @__PURE__ */ new Map();
|
|
50
36
|
}
|
|
51
37
|
async initialize(core, options) {
|
|
52
|
-
var _a, _b;
|
|
53
38
|
this.core = core;
|
|
54
|
-
this.store = options
|
|
55
|
-
if (!this.store.map)
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const app = appPlugin == null ? void 0 : appPlugin.getApp();
|
|
39
|
+
this.store = options?.store;
|
|
40
|
+
if (!this.store.map) this.store.map = new Map();
|
|
41
|
+
const appPlugin = core.getPlugin('app');
|
|
42
|
+
const app = appPlugin?.getApp();
|
|
59
43
|
if (app) {
|
|
60
44
|
this.dbManager = app.sqlite;
|
|
61
45
|
this.logger = app.logger;
|
|
62
46
|
this.storage = app.storage;
|
|
63
|
-
const coreData = app.data.store.getStore().getDataByModel(
|
|
64
|
-
if (!
|
|
65
|
-
const today = (0,
|
|
66
|
-
if (coreData
|
|
47
|
+
const coreData = app.data.store.getStore().getDataByModel('core');
|
|
48
|
+
if (!this.store.createdAtQuery?.sales_time_between && coreData?.core) {
|
|
49
|
+
const today = (0, _dayjs.default)();
|
|
50
|
+
if (coreData?.core.operating_day_boundary) {
|
|
67
51
|
const operatingDayBoundary = coreData.core.operating_day_boundary;
|
|
68
|
-
if (operatingDayBoundary.type ===
|
|
69
|
-
const boundaryTime = String(operatingDayBoundary.time ||
|
|
70
|
-
const boundaryStart = (0,
|
|
71
|
-
const boundaryEnd = boundaryStart.add(1,
|
|
52
|
+
if (operatingDayBoundary.type === 'start_time') {
|
|
53
|
+
const boundaryTime = String(operatingDayBoundary.time || '').trim();
|
|
54
|
+
const boundaryStart = (0, _dayjs.default)(`${today.format('YYYY-MM-DD')} ${boundaryTime}`);
|
|
55
|
+
const boundaryEnd = boundaryStart.add(1, 'day');
|
|
72
56
|
if (boundaryStart.isValid()) {
|
|
73
57
|
this.store.createdAtQuery = {
|
|
74
|
-
sales_time_between: [
|
|
75
|
-
boundaryStart.format("YYYY-MM-DD HH:mm:ss"),
|
|
76
|
-
boundaryEnd.format("YYYY-MM-DD HH:mm:ss")
|
|
77
|
-
]
|
|
58
|
+
sales_time_between: [boundaryStart.format('YYYY-MM-DD HH:mm:ss'), boundaryEnd.format('YYYY-MM-DD HH:mm:ss')]
|
|
78
59
|
};
|
|
79
60
|
} else {
|
|
61
|
+
// 边界时间异常时回退到自然日,避免 createdAtQuery 为空导致后续查询异常
|
|
80
62
|
this.store.createdAtQuery = {
|
|
81
|
-
sales_time_between: [
|
|
82
|
-
today.startOf("day").format("YYYY-MM-DD HH:mm:ss"),
|
|
83
|
-
today.endOf("day").format("YYYY-MM-DD HH:mm:ss")
|
|
84
|
-
]
|
|
63
|
+
sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
|
|
85
64
|
};
|
|
86
65
|
}
|
|
87
66
|
} else {
|
|
88
67
|
this.store.createdAtQuery = {
|
|
89
|
-
sales_time_between: [
|
|
90
|
-
today.startOf("day").format("YYYY-MM-DD HH:mm:ss"),
|
|
91
|
-
today.endOf("day").format("YYYY-MM-DD HH:mm:ss")
|
|
92
|
-
]
|
|
68
|
+
sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
|
|
93
69
|
};
|
|
94
70
|
}
|
|
95
71
|
} else {
|
|
72
|
+
// TODO: 这里后续可能需要使用店铺营业时间查询
|
|
96
73
|
this.store.createdAtQuery = {
|
|
97
|
-
sales_time_between: [today.startOf(
|
|
74
|
+
sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
|
|
98
75
|
};
|
|
99
76
|
}
|
|
100
77
|
}
|
|
101
78
|
}
|
|
102
|
-
if (Array.isArray(
|
|
79
|
+
if (Array.isArray(options?.initialState?.list)) {
|
|
103
80
|
this.store.list = options.initialState.list;
|
|
104
81
|
this.syncOrdersMap();
|
|
105
|
-
this.core.effects.emit(
|
|
82
|
+
this.core.effects.emit(_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
106
83
|
} else {
|
|
107
84
|
this.store.list = [];
|
|
108
|
-
this.store.map =
|
|
85
|
+
this.store.map = new Map();
|
|
109
86
|
}
|
|
110
87
|
this.initOrderDataSource();
|
|
111
88
|
this.setupOrderSync();
|
|
112
|
-
this.logInfo(
|
|
89
|
+
this.logInfo('OrderServer模块初始化完成', {
|
|
113
90
|
hasDbManager: !!this.dbManager,
|
|
114
91
|
hasLogger: !!this.logger,
|
|
115
92
|
initialOrderCount: this.store.list.length
|
|
116
93
|
});
|
|
117
94
|
}
|
|
95
|
+
|
|
118
96
|
/**
|
|
119
97
|
* 记录信息日志
|
|
120
98
|
* @param title 日志标题
|
|
@@ -124,14 +102,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
124
102
|
try {
|
|
125
103
|
if (this.logger) {
|
|
126
104
|
this.logger.addLog({
|
|
127
|
-
type:
|
|
105
|
+
type: 'info',
|
|
128
106
|
title: `[OrderServerModule] ${title}`,
|
|
129
107
|
metadata: metadata || {}
|
|
130
108
|
});
|
|
131
109
|
}
|
|
132
110
|
} catch {
|
|
111
|
+
// 日志记录失败不影响主流程
|
|
133
112
|
}
|
|
134
113
|
}
|
|
114
|
+
|
|
135
115
|
/**
|
|
136
116
|
* 记录错误日志
|
|
137
117
|
* @param title 日志标题
|
|
@@ -141,21 +121,38 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
141
121
|
try {
|
|
142
122
|
if (this.logger) {
|
|
143
123
|
this.logger.addLog({
|
|
144
|
-
type:
|
|
124
|
+
type: 'error',
|
|
145
125
|
title: `[OrderServerModule] ${title}`,
|
|
146
126
|
metadata: metadata || {}
|
|
147
127
|
});
|
|
148
128
|
}
|
|
149
129
|
} catch {
|
|
130
|
+
// 日志记录失败不影响主流程
|
|
150
131
|
}
|
|
151
132
|
}
|
|
152
133
|
async preload() {
|
|
134
|
+
// const cachedOrders = await this.loadOrdersFromSQLite()
|
|
135
|
+
// const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
|
|
136
|
+
// // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
|
|
137
|
+
// if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
|
|
138
|
+
// this.store.list = cloneDeep(cachedOrders)
|
|
139
|
+
// this.syncOrdersMap()
|
|
140
|
+
// this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
|
|
141
|
+
// return
|
|
142
|
+
// }
|
|
143
|
+
|
|
144
|
+
// if (hasPulledInCurrentWindow) {
|
|
145
|
+
// this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
|
|
146
|
+
// lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
|
|
147
|
+
// })
|
|
148
|
+
// return
|
|
149
|
+
// }
|
|
150
|
+
|
|
153
151
|
const orders = await this.loadOrdersByServer();
|
|
154
|
-
if (orders.length === 0)
|
|
155
|
-
|
|
156
|
-
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
152
|
+
if (orders.length === 0) return;
|
|
153
|
+
this.store.list = (0, _lodashEs.cloneDeep)(orders);
|
|
157
154
|
this.syncOrdersMap();
|
|
158
|
-
this.core.effects.emit(
|
|
155
|
+
this.core.effects.emit(_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
159
156
|
}
|
|
160
157
|
getOrders() {
|
|
161
158
|
return this.store.list;
|
|
@@ -163,6 +160,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
163
160
|
getOrderById(id) {
|
|
164
161
|
return this.store.map.get(this.getIdKey(id));
|
|
165
162
|
}
|
|
163
|
+
|
|
166
164
|
/** 按 order_id 查询(推荐) */
|
|
167
165
|
getOrderByOrderId(orderId) {
|
|
168
166
|
return this.store.map.get(this.getIdKey(orderId));
|
|
@@ -183,25 +181,23 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
183
181
|
}
|
|
184
182
|
}
|
|
185
183
|
await this.saveOrdersToSQLite(orderList);
|
|
186
|
-
await this.core.effects.emit(
|
|
184
|
+
await this.core.effects.emit(_types.OrderHooks.onOrdersLoaded, orderList);
|
|
187
185
|
return orderList;
|
|
188
186
|
}
|
|
189
187
|
getOrdersByResourceId(resourceId) {
|
|
190
188
|
const ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
191
|
-
return ids.map(
|
|
189
|
+
return ids.map(id => this.store.map.get(id)).filter(order => !!order);
|
|
192
190
|
}
|
|
193
191
|
getRoutes() {
|
|
194
192
|
return [];
|
|
195
193
|
}
|
|
196
194
|
destroy() {
|
|
197
|
-
var _a;
|
|
198
195
|
if (this.syncTimer) {
|
|
199
196
|
clearTimeout(this.syncTimer);
|
|
200
|
-
this.syncTimer =
|
|
197
|
+
this.syncTimer = undefined;
|
|
201
198
|
}
|
|
202
199
|
this.pendingSyncMessages = [];
|
|
203
|
-
if (
|
|
204
|
-
this.orderDataSource.destroy();
|
|
200
|
+
if (this.orderDataSource?.destroy) this.orderDataSource.destroy();
|
|
205
201
|
super.destroy();
|
|
206
202
|
}
|
|
207
203
|
syncOrdersMap() {
|
|
@@ -209,83 +205,66 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
209
205
|
this.resourceIdIndex.clear();
|
|
210
206
|
for (const order of this.store.list) {
|
|
211
207
|
const id = order.order_id;
|
|
212
|
-
if (id ===
|
|
213
|
-
continue;
|
|
208
|
+
if (id === undefined || id === null) continue;
|
|
214
209
|
this.store.map.set(this.getIdKey(id), order);
|
|
215
210
|
const resourceIds = this.extractResourceIds(order);
|
|
216
211
|
for (const resourceId of resourceIds) {
|
|
217
212
|
const key = String(resourceId);
|
|
218
213
|
const existing = this.resourceIdIndex.get(key) || [];
|
|
219
|
-
if (existing.some(
|
|
220
|
-
continue;
|
|
214
|
+
if (existing.some(eid => this.getIdKey(eid) === this.getIdKey(id))) continue;
|
|
221
215
|
existing.push(id);
|
|
222
216
|
this.resourceIdIndex.set(key, existing);
|
|
223
217
|
}
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
extractResourceIds(order) {
|
|
227
|
-
const ids =
|
|
228
|
-
const visitResources =
|
|
229
|
-
if (!Array.isArray(resources))
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
ids.add(String(rid));
|
|
235
|
-
if (Array.isArray(resource == null ? void 0 : resource.children))
|
|
236
|
-
visitResources(resource.children);
|
|
221
|
+
const ids = new Set();
|
|
222
|
+
const visitResources = resources => {
|
|
223
|
+
if (!Array.isArray(resources)) return;
|
|
224
|
+
resources.forEach(resource => {
|
|
225
|
+
const rid = resource?.relation_id;
|
|
226
|
+
if (rid !== undefined && rid !== null && rid !== '') ids.add(String(rid));
|
|
227
|
+
if (Array.isArray(resource?.children)) visitResources(resource.children);
|
|
237
228
|
});
|
|
238
229
|
};
|
|
239
|
-
if (Array.isArray(order
|
|
240
|
-
order.bookings.forEach(
|
|
230
|
+
if (Array.isArray(order?.bookings)) {
|
|
231
|
+
order.bookings.forEach(booking => visitResources(booking?.resources || []));
|
|
241
232
|
}
|
|
242
233
|
return [...ids];
|
|
243
234
|
}
|
|
244
235
|
getOrderDateKey(order) {
|
|
245
|
-
|
|
246
|
-
const candidates = [
|
|
247
|
-
order == null ? void 0 : order.schedule_date,
|
|
248
|
-
order == null ? void 0 : order.create_date,
|
|
249
|
-
order == null ? void 0 : order.created_at,
|
|
250
|
-
(_b = (_a = order == null ? void 0 : order.bookings) == null ? void 0 : _a[0]) == null ? void 0 : _b.start_date,
|
|
251
|
-
(_d = (_c = order == null ? void 0 : order.bookings) == null ? void 0 : _c[0]) == null ? void 0 : _d.select_date
|
|
252
|
-
];
|
|
236
|
+
const candidates = [order?.schedule_date, order?.create_date, order?.created_at, order?.bookings?.[0]?.start_date, order?.bookings?.[0]?.select_date];
|
|
253
237
|
for (const v of candidates) {
|
|
254
|
-
if (!v)
|
|
255
|
-
continue;
|
|
238
|
+
if (!v) continue;
|
|
256
239
|
const text = String(v);
|
|
257
|
-
if (!text)
|
|
258
|
-
|
|
259
|
-
return text.split("T")[0].split(" ")[0];
|
|
240
|
+
if (!text) continue;
|
|
241
|
+
return text.split('T')[0].split(' ')[0];
|
|
260
242
|
}
|
|
261
|
-
return
|
|
243
|
+
return undefined;
|
|
262
244
|
}
|
|
245
|
+
|
|
263
246
|
/**
|
|
264
247
|
* 初始化 OrderDataSource 实例
|
|
265
248
|
*/
|
|
266
249
|
initOrderDataSource() {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (!OrderDataSourceClass)
|
|
270
|
-
return;
|
|
250
|
+
const OrderDataSourceClass = this.core.serverOptions?.All_DATA_SOURCES?.OrderDataSource;
|
|
251
|
+
if (!OrderDataSourceClass) return;
|
|
271
252
|
this.orderDataSource = new OrderDataSourceClass();
|
|
272
253
|
}
|
|
254
|
+
|
|
273
255
|
/**
|
|
274
256
|
* 初始化 pubsub 订阅,监听订单变更
|
|
275
257
|
*/
|
|
276
258
|
setupOrderSync() {
|
|
277
|
-
if (!this.orderDataSource)
|
|
278
|
-
return;
|
|
259
|
+
if (!this.orderDataSource) return;
|
|
279
260
|
const shouldSkipHttpPull = this.hasPulledOrdersToday();
|
|
280
261
|
const syncPayload = {
|
|
281
262
|
pubsub: {
|
|
282
|
-
callback:
|
|
263
|
+
callback: res => {
|
|
283
264
|
const message = this.normalizeOrderSyncMessage(res);
|
|
284
|
-
if (!message)
|
|
285
|
-
return;
|
|
265
|
+
if (!message) return;
|
|
286
266
|
this.pendingSyncMessages.push(message);
|
|
287
|
-
if (this.syncTimer)
|
|
288
|
-
clearTimeout(this.syncTimer);
|
|
267
|
+
if (this.syncTimer) clearTimeout(this.syncTimer);
|
|
289
268
|
this.syncTimer = setTimeout(() => {
|
|
290
269
|
this.processOrderSyncMessages();
|
|
291
270
|
}, this.ORDER_SYNC_DEBOUNCE_MS);
|
|
@@ -297,11 +276,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
297
276
|
skipHttp: shouldSkipHttpPull
|
|
298
277
|
};
|
|
299
278
|
this.orderDataSource.run(syncPayload).then(() => {
|
|
300
|
-
if (!shouldSkipHttpPull)
|
|
301
|
-
this.markOrderPulledAtNow();
|
|
279
|
+
if (!shouldSkipHttpPull) this.markOrderPulledAtNow();
|
|
302
280
|
}).catch(() => {
|
|
281
|
+
// 忽略同步初始化异常,避免影响主流程
|
|
303
282
|
});
|
|
304
283
|
}
|
|
284
|
+
|
|
305
285
|
/**
|
|
306
286
|
* 处理防抖后的同步消息批次
|
|
307
287
|
*
|
|
@@ -310,57 +290,49 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
310
290
|
* - 批量(ids):通过 HTTP 按 ids 增量拉取,再 merge 到本地
|
|
311
291
|
*/
|
|
312
292
|
async processOrderSyncMessages() {
|
|
313
|
-
var _a;
|
|
314
293
|
const messages = [...this.pendingSyncMessages];
|
|
315
294
|
this.pendingSyncMessages = [];
|
|
316
|
-
if (messages.length === 0)
|
|
317
|
-
|
|
318
|
-
const upsertOrders = /* @__PURE__ */ new Map();
|
|
295
|
+
if (messages.length === 0) return;
|
|
296
|
+
const upsertOrders = new Map();
|
|
319
297
|
const refreshIds = [];
|
|
320
298
|
for (const msg of messages) {
|
|
321
299
|
const hasBatchIds = Array.isArray(msg.ids) && msg.ids.length > 0;
|
|
322
300
|
const singleId = msg.id ?? msg.order_id;
|
|
323
|
-
const hasSingleId = !hasBatchIds && singleId !==
|
|
301
|
+
const hasSingleId = !hasBatchIds && singleId !== undefined && singleId !== null;
|
|
324
302
|
const rawBody = msg.body || msg.data;
|
|
325
303
|
const normalizedBody = this.normalizeOrderSyncPayload(rawBody);
|
|
326
304
|
if (hasSingleId && normalizedBody) {
|
|
327
305
|
upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
328
306
|
continue;
|
|
329
307
|
}
|
|
330
|
-
if (hasBatchIds)
|
|
331
|
-
refreshIds.push(...msg.ids);
|
|
332
|
-
else if (hasSingleId)
|
|
333
|
-
refreshIds.push(singleId);
|
|
334
|
-
else if ((_a = msg.relation_order_ids) == null ? void 0 : _a.length)
|
|
335
|
-
refreshIds.push(...msg.relation_order_ids);
|
|
308
|
+
if (hasBatchIds) refreshIds.push(...msg.ids);else if (hasSingleId) refreshIds.push(singleId);else if (msg.relation_order_ids?.length) refreshIds.push(...msg.relation_order_ids);
|
|
336
309
|
}
|
|
337
310
|
const uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
|
|
338
311
|
const upsertList = [...upsertOrders.values()];
|
|
339
|
-
if (upsertList.length > 0)
|
|
340
|
-
await this.mergeOrdersToStore(upsertList);
|
|
312
|
+
if (upsertList.length > 0) await this.mergeOrdersToStore(upsertList);
|
|
341
313
|
if (uniqueRefreshIds.length > 0) {
|
|
342
314
|
const freshOrders = await this.fetchOrdersByHttp(uniqueRefreshIds);
|
|
343
|
-
if (freshOrders.length > 0)
|
|
344
|
-
await this.mergeOrdersToStore(freshOrders);
|
|
315
|
+
if (freshOrders.length > 0) await this.mergeOrdersToStore(freshOrders);
|
|
345
316
|
}
|
|
346
|
-
if (upsertList.length === 0 && uniqueRefreshIds.length === 0)
|
|
347
|
-
|
|
348
|
-
await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
317
|
+
if (upsertList.length === 0 && uniqueRefreshIds.length === 0) return;
|
|
318
|
+
await this.core.effects.emit(_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
349
319
|
}
|
|
320
|
+
|
|
350
321
|
/**
|
|
351
322
|
* 通过 HTTP 按 ids 增量拉取订单
|
|
352
323
|
*/
|
|
353
324
|
async fetchOrdersByHttp(ids) {
|
|
354
|
-
if (!this.orderDataSource || ids.length === 0)
|
|
355
|
-
return [];
|
|
325
|
+
if (!this.orderDataSource || ids.length === 0) return [];
|
|
356
326
|
try {
|
|
357
|
-
if (typeof this.orderDataSource.fetchOrdersByIds ===
|
|
358
|
-
const
|
|
359
|
-
return
|
|
327
|
+
if (typeof this.orderDataSource.fetchOrdersByIds === 'function') {
|
|
328
|
+
const orderList = await this.orderDataSource.fetchOrdersByIds(ids);
|
|
329
|
+
return orderList || [];
|
|
360
330
|
}
|
|
361
331
|
const orderList = await this.orderDataSource.run({
|
|
362
332
|
http: {
|
|
363
|
-
query: {
|
|
333
|
+
query: {
|
|
334
|
+
ids
|
|
335
|
+
}
|
|
364
336
|
}
|
|
365
337
|
});
|
|
366
338
|
return orderList || [];
|
|
@@ -368,24 +340,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
368
340
|
return [];
|
|
369
341
|
}
|
|
370
342
|
}
|
|
343
|
+
|
|
371
344
|
/**
|
|
372
345
|
* 将增量订单合并到 store
|
|
373
346
|
*/
|
|
374
347
|
async mergeOrdersToStore(freshOrders) {
|
|
375
|
-
const freshMap =
|
|
348
|
+
const freshMap = new Map();
|
|
376
349
|
for (const order of freshOrders) {
|
|
377
|
-
const id = order
|
|
378
|
-
if (id ===
|
|
379
|
-
continue;
|
|
350
|
+
const id = order?.order_id;
|
|
351
|
+
if (id === undefined || id === null) continue;
|
|
380
352
|
freshMap.set(this.getIdKey(id), order);
|
|
381
353
|
}
|
|
382
|
-
const updatedList = this.store.list.map(
|
|
354
|
+
const updatedList = this.store.list.map(order => {
|
|
383
355
|
const id = order.order_id;
|
|
384
|
-
if (id ===
|
|
385
|
-
return order;
|
|
356
|
+
if (id === undefined || id === null) return order;
|
|
386
357
|
const key = this.getIdKey(id);
|
|
387
|
-
if (!freshMap.has(key))
|
|
388
|
-
return order;
|
|
358
|
+
if (!freshMap.has(key)) return order;
|
|
389
359
|
const fresh = freshMap.get(key);
|
|
390
360
|
freshMap.delete(key);
|
|
391
361
|
return fresh;
|
|
@@ -396,43 +366,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
396
366
|
this.store.list = updatedList;
|
|
397
367
|
this.syncOrdersMap();
|
|
398
368
|
await this.saveOrdersToSQLite(this.store.list);
|
|
399
|
-
this.core.effects.emit(
|
|
369
|
+
this.core.effects.emit(_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
400
370
|
}
|
|
401
371
|
normalizeOrderSyncMessage(res) {
|
|
402
|
-
const data =
|
|
403
|
-
if (!data)
|
|
404
|
-
|
|
405
|
-
const payload = (data == null ? void 0 : data.data) && typeof data.data === "object" ? data.data : void 0;
|
|
372
|
+
const data = res?.data || res;
|
|
373
|
+
if (!data) return null;
|
|
374
|
+
const payload = data?.data && typeof data.data === 'object' ? data.data : undefined;
|
|
406
375
|
const normalized = {
|
|
407
376
|
...data,
|
|
408
|
-
_channelKey: data.module ||
|
|
377
|
+
_channelKey: data.module || 'sales_sync'
|
|
409
378
|
};
|
|
410
|
-
if (!normalized.type && typeof data.event ===
|
|
411
|
-
|
|
412
|
-
if (!normalized.id && data.
|
|
413
|
-
|
|
414
|
-
if (!normalized.
|
|
415
|
-
|
|
416
|
-
if (!normalized.
|
|
417
|
-
normalized.order_id = data.order_id;
|
|
418
|
-
if (!normalized.order_id && (payload == null ? void 0 : payload.order_id) !== void 0)
|
|
419
|
-
normalized.order_id = payload.order_id;
|
|
420
|
-
if (!normalized.body && (payload == null ? void 0 : payload.order_id) !== void 0)
|
|
421
|
-
normalized.body = payload;
|
|
422
|
-
if (!normalized.data && (payload == null ? void 0 : payload.order_id) !== void 0)
|
|
423
|
-
normalized.data = payload;
|
|
379
|
+
if (!normalized.type && typeof data.event === 'string') normalized.type = data.event;
|
|
380
|
+
if (!normalized.id && data.id !== undefined) normalized.id = data.id;
|
|
381
|
+
if (!normalized.id && data.order_id !== undefined) normalized.id = data.order_id;
|
|
382
|
+
if (!normalized.order_id && data.order_id !== undefined) normalized.order_id = data.order_id;
|
|
383
|
+
if (!normalized.order_id && payload?.order_id !== undefined) normalized.order_id = payload.order_id;
|
|
384
|
+
if (!normalized.body && payload?.order_id !== undefined) normalized.body = payload;
|
|
385
|
+
if (!normalized.data && payload?.order_id !== undefined) normalized.data = payload;
|
|
424
386
|
return normalized;
|
|
425
387
|
}
|
|
426
388
|
normalizeOrderSyncPayload(payload) {
|
|
427
|
-
if (!payload)
|
|
428
|
-
return null;
|
|
389
|
+
if (!payload) return null;
|
|
429
390
|
const orderId = payload.order_id;
|
|
430
|
-
if (orderId ===
|
|
431
|
-
|
|
432
|
-
|
|
391
|
+
if (orderId === undefined || orderId === null) return null;
|
|
392
|
+
return {
|
|
393
|
+
...payload,
|
|
394
|
+
order_id: orderId
|
|
395
|
+
};
|
|
433
396
|
}
|
|
434
397
|
uniqueOrderIds(ids) {
|
|
435
|
-
const idMap =
|
|
398
|
+
const idMap = new Map();
|
|
436
399
|
for (const id of ids) {
|
|
437
400
|
idMap.set(this.getIdKey(id), id);
|
|
438
401
|
}
|
|
@@ -441,69 +404,74 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
441
404
|
getIdKey(id) {
|
|
442
405
|
return String(id);
|
|
443
406
|
}
|
|
407
|
+
|
|
444
408
|
/**
|
|
445
409
|
* 当前订单拉取窗口:
|
|
446
410
|
* - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
|
|
447
411
|
* - 无法解析时退化为自然日窗口
|
|
448
412
|
*/
|
|
449
413
|
getCurrentPullWindow() {
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
const range = (_b = (_a = this.store) == null ? void 0 : _a.createdAtQuery) == null ? void 0 : _b.sales_time_between;
|
|
414
|
+
const now = (0, _dayjs.default)();
|
|
415
|
+
const range = this.store?.createdAtQuery?.sales_time_between;
|
|
453
416
|
if (Array.isArray(range) && range.length >= 2) {
|
|
454
|
-
const
|
|
455
|
-
const endExclusiveAt = (0,
|
|
456
|
-
if (
|
|
457
|
-
return {
|
|
417
|
+
const startAt = (0, _dayjs.default)(range[0]);
|
|
418
|
+
const endExclusiveAt = (0, _dayjs.default)(range[1]);
|
|
419
|
+
if (startAt.isValid() && endExclusiveAt.isValid() && endExclusiveAt.isAfter(startAt)) {
|
|
420
|
+
return {
|
|
421
|
+
startAt,
|
|
422
|
+
endExclusiveAt
|
|
423
|
+
};
|
|
458
424
|
}
|
|
459
425
|
}
|
|
460
|
-
const startAt = now.startOf(
|
|
461
|
-
return {
|
|
426
|
+
const startAt = now.startOf('day');
|
|
427
|
+
return {
|
|
428
|
+
startAt,
|
|
429
|
+
endExclusiveAt: startAt.add(1, 'day')
|
|
430
|
+
};
|
|
462
431
|
}
|
|
463
432
|
hasPulledOrdersToday() {
|
|
464
433
|
const lastFullFetchAt = this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY);
|
|
465
|
-
if (!lastFullFetchAt)
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
434
|
+
if (!lastFullFetchAt) return false;
|
|
435
|
+
const parsed = (0, _dayjs.default)(lastFullFetchAt);
|
|
436
|
+
if (!parsed.isValid()) return false;
|
|
437
|
+
|
|
438
|
+
// 按当前拉取窗口判断,而不是自然日判断。
|
|
439
|
+
// 这样在营业日跨日边界(start_time)场景下也能正确判定是否需要重新拉取。
|
|
440
|
+
const {
|
|
441
|
+
startAt,
|
|
442
|
+
endExclusiveAt
|
|
443
|
+
} = this.getCurrentPullWindow();
|
|
471
444
|
return (parsed.isAfter(startAt) || parsed.isSame(startAt)) && parsed.isBefore(endExclusiveAt);
|
|
472
445
|
}
|
|
473
446
|
markOrderPulledAtNow() {
|
|
474
|
-
this.setStorageItem(
|
|
475
|
-
ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY,
|
|
476
|
-
(0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
|
|
477
|
-
);
|
|
447
|
+
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss'));
|
|
478
448
|
}
|
|
479
449
|
getStorageItem(key) {
|
|
480
|
-
var _a;
|
|
481
450
|
try {
|
|
482
|
-
if (
|
|
483
|
-
|
|
484
|
-
if (typeof globalThis !== "undefined" && (globalThis == null ? void 0 : globalThis.localStorage)) {
|
|
451
|
+
if (this.storage?.getStorage) return this.storage.getStorage(key);
|
|
452
|
+
if (typeof globalThis !== 'undefined' && globalThis?.localStorage) {
|
|
485
453
|
return globalThis.localStorage.getItem(key);
|
|
486
454
|
}
|
|
487
455
|
} catch {
|
|
456
|
+
// 忽略存储异常,避免影响主流程
|
|
488
457
|
}
|
|
489
458
|
return null;
|
|
490
459
|
}
|
|
491
460
|
setStorageItem(key, value) {
|
|
492
|
-
var _a;
|
|
493
461
|
try {
|
|
494
|
-
if (
|
|
462
|
+
if (this.storage?.setStorage) {
|
|
495
463
|
this.storage.setStorage(key, value);
|
|
496
464
|
return;
|
|
497
465
|
}
|
|
498
|
-
if (typeof globalThis !==
|
|
466
|
+
if (typeof globalThis !== 'undefined' && globalThis?.localStorage) {
|
|
499
467
|
globalThis.localStorage.setItem(key, value);
|
|
500
468
|
}
|
|
501
469
|
} catch {
|
|
470
|
+
// 忽略存储异常,避免影响主流程
|
|
502
471
|
}
|
|
503
472
|
}
|
|
504
473
|
async loadOrdersFromSQLite() {
|
|
505
|
-
if (!this.dbManager)
|
|
506
|
-
return [];
|
|
474
|
+
if (!this.dbManager) return [];
|
|
507
475
|
try {
|
|
508
476
|
const orders = await this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
509
477
|
return orders || [];
|
|
@@ -512,15 +480,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
512
480
|
}
|
|
513
481
|
}
|
|
514
482
|
async saveOrdersToSQLite(orderList) {
|
|
515
|
-
if (!this.dbManager)
|
|
516
|
-
return;
|
|
483
|
+
if (!this.dbManager) return;
|
|
517
484
|
try {
|
|
518
485
|
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
519
|
-
if (orderList.length === 0)
|
|
520
|
-
return;
|
|
486
|
+
if (orderList.length === 0) return;
|
|
521
487
|
await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
|
|
522
488
|
} catch (error) {
|
|
523
|
-
|
|
489
|
+
// SQLite 异常,避免影响主流程
|
|
490
|
+
this.logError('保存订单到 SQLite 失败', {
|
|
524
491
|
error: error instanceof Error ? error.message : String(error),
|
|
525
492
|
orderList: orderList.length
|
|
526
493
|
});
|
|
@@ -528,16 +495,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
528
495
|
}
|
|
529
496
|
async clear() {
|
|
530
497
|
this.store.list = [];
|
|
531
|
-
this.store.map =
|
|
498
|
+
this.store.map = new Map();
|
|
532
499
|
this.resourceIdIndex.clear();
|
|
533
500
|
if (this.dbManager) {
|
|
534
501
|
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
535
502
|
}
|
|
536
|
-
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY,
|
|
537
|
-
this.core.effects.emit(
|
|
503
|
+
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
504
|
+
this.core.effects.emit(_types.OrderHooks.onOrdersChanged, this.store.list);
|
|
538
505
|
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
0 && (module.exports = {
|
|
542
|
-
OrderModule
|
|
543
|
-
});
|
|
506
|
+
}
|
|
507
|
+
exports.OrderModule = OrderModule;
|