@pisell/pisellos 0.0.568 → 0.10.1

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.
Files changed (588) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +2 -2
  13. package/dist/modules/BaseModule.js +12 -14
  14. package/dist/modules/BookingContext/index.d.ts +48 -0
  15. package/dist/modules/BookingContext/index.js +566 -0
  16. package/dist/modules/BookingContext/types.d.ts +102 -0
  17. package/dist/modules/BookingContext/types.js +51 -0
  18. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  19. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  20. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  21. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  22. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  23. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  24. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  25. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  26. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  27. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  28. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  29. package/dist/modules/BookingContext/utils/index.js +11 -0
  30. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  31. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  32. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  33. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  34. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  35. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  36. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  37. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  38. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  39. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  40. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  41. package/dist/modules/BookingContext/utils/resources.js +486 -0
  42. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  43. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  44. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  45. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  46. package/dist/modules/Cart/index.js +3 -0
  47. package/dist/modules/Cart/utils/cartProduct.js +27 -5
  48. package/dist/modules/Cart/utils/cartResource.js +0 -2
  49. package/dist/modules/Cart/utils/changePrice.js +11 -11
  50. package/dist/modules/Customer/index.d.ts +20 -0
  51. package/dist/modules/Customer/index.js +172 -83
  52. package/dist/modules/Customer/types.d.ts +2 -0
  53. package/dist/modules/Date/index.js +5 -1
  54. package/dist/modules/Discount/index.d.ts +2 -2
  55. package/dist/modules/Discount/index.js +43 -30
  56. package/dist/modules/Discount/types.d.ts +1 -1
  57. package/dist/modules/OpenData/index.d.ts +8 -0
  58. package/dist/modules/OpenData/index.js +38 -16
  59. package/dist/modules/Order/index.d.ts +449 -24
  60. package/dist/modules/Order/index.js +5460 -574
  61. package/dist/modules/Order/types.d.ts +693 -88
  62. package/dist/modules/Order/types.js +68 -1
  63. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  64. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  65. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  66. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  67. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  68. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  69. package/dist/modules/Order/utils.d.ts +167 -18
  70. package/dist/modules/Order/utils.js +960 -165
  71. package/dist/modules/Payment/index.d.ts +10 -9
  72. package/dist/modules/Payment/index.js +573 -746
  73. package/dist/modules/Payment/types.d.ts +44 -24
  74. package/dist/modules/Payment/utils.d.ts +1 -1
  75. package/dist/modules/Payment/utils.js +4 -3
  76. package/dist/modules/Payment/walletpass.d.ts +0 -2
  77. package/dist/modules/Payment/walletpass.js +49 -33
  78. package/dist/modules/Product/types.d.ts +29 -7
  79. package/dist/modules/ProductList/index.d.ts +17 -13
  80. package/dist/modules/ProductList/index.js +182 -81
  81. package/dist/modules/ProductList/types.d.ts +16 -0
  82. package/dist/modules/Quotation/index.d.ts +22 -2
  83. package/dist/modules/Quotation/index.js +108 -42
  84. package/dist/modules/Quotation/types.d.ts +19 -0
  85. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  86. package/dist/modules/ResourcePlanner/index.js +181 -0
  87. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  88. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  89. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  90. package/dist/modules/ResourcePlanner/types.js +1 -0
  91. package/dist/modules/Rules/index.d.ts +8 -10
  92. package/dist/modules/Rules/index.js +324 -513
  93. package/dist/modules/Rules/types.d.ts +14 -3
  94. package/dist/modules/SalesSummary/index.d.ts +23 -26
  95. package/dist/modules/SalesSummary/index.js +152 -46
  96. package/dist/modules/SalesSummary/types.d.ts +9 -1
  97. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  98. package/dist/modules/SalesSummary/utils.js +804 -165
  99. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
  100. package/dist/modules/Schedule/index.d.ts +18 -5
  101. package/dist/modules/Schedule/index.js +79 -24
  102. package/dist/modules/Schedule/types.d.ts +2 -0
  103. package/dist/modules/Schedule/utils.js +1 -0
  104. package/dist/modules/Step/index.js +1 -0
  105. package/dist/modules/Summary/index.js +4 -3
  106. package/dist/modules/Summary/utils.js +22 -43
  107. package/dist/modules/SurchargeList/index.d.ts +18 -0
  108. package/dist/modules/SurchargeList/index.js +185 -0
  109. package/dist/modules/SurchargeList/types.d.ts +15 -0
  110. package/dist/modules/SurchargeList/types.js +1 -0
  111. package/dist/modules/index.d.ts +3 -0
  112. package/dist/modules/index.js +4 -1
  113. package/dist/plugins/app.d.ts +2 -0
  114. package/dist/plugins/request.d.ts +1 -0
  115. package/dist/plugins/request.js +4 -1
  116. package/dist/plugins/window.js +6 -2
  117. package/dist/server/index.d.ts +462 -8
  118. package/dist/server/index.js +6168 -680
  119. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  120. package/dist/server/modules/floor-plan/index.js +595 -0
  121. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  122. package/dist/server/modules/floor-plan/types.js +13 -0
  123. package/dist/server/modules/index.d.ts +7 -2
  124. package/dist/server/modules/index.js +6 -0
  125. package/dist/server/modules/menu/index.js +41 -32
  126. package/dist/server/modules/order/index.d.ts +207 -14
  127. package/dist/server/modules/order/index.js +2328 -379
  128. package/dist/server/modules/order/types.d.ts +76 -5
  129. package/dist/server/modules/order/types.js +14 -1
  130. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  131. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  132. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  133. package/dist/server/modules/payment/index.d.ts +28 -0
  134. package/dist/server/modules/payment/index.js +305 -0
  135. package/dist/server/modules/payment/types.d.ts +9 -0
  136. package/dist/server/modules/payment/types.js +1 -0
  137. package/dist/server/modules/products/index.d.ts +105 -14
  138. package/dist/server/modules/products/index.js +1416 -521
  139. package/dist/server/modules/products/types.d.ts +34 -1
  140. package/dist/server/modules/products/types.js +4 -0
  141. package/dist/server/modules/quotation/index.d.ts +39 -0
  142. package/dist/server/modules/quotation/index.js +298 -77
  143. package/dist/server/modules/resource/index.d.ts +2 -3
  144. package/dist/server/modules/resource/index.js +109 -86
  145. package/dist/server/modules/schedule/index.d.ts +6 -4
  146. package/dist/server/modules/schedule/index.js +145 -106
  147. package/dist/server/test.json +713 -0
  148. package/dist/server/types.d.ts +2 -0
  149. package/dist/server/utils/product.js +3 -2
  150. package/dist/server/utils/small-ticket.d.ts +71 -0
  151. package/dist/server/utils/small-ticket.js +963 -0
  152. package/dist/solution/BaseSales/index.d.ts +378 -0
  153. package/dist/solution/BaseSales/index.js +4009 -0
  154. package/dist/solution/BaseSales/types.d.ts +394 -0
  155. package/dist/solution/BaseSales/types.js +40 -0
  156. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  157. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  158. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  159. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  160. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  161. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  162. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  163. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  164. package/dist/solution/BaseSales/utils.d.ts +40 -0
  165. package/dist/solution/BaseSales/utils.js +263 -0
  166. package/dist/solution/BookingByStep/index.d.ts +1 -1
  167. package/dist/solution/BookingByStep/index.js +60 -11
  168. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  169. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  170. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  171. package/dist/solution/BookingTicket/index.d.ts +393 -24
  172. package/dist/solution/BookingTicket/index.js +2508 -443
  173. package/dist/solution/BookingTicket/types.d.ts +191 -6
  174. package/dist/solution/BookingTicket/types.js +83 -10
  175. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  176. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  177. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  178. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  179. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  180. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  181. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  182. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  183. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  184. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  185. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  186. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  187. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  189. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  190. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  191. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  192. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
  193. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  194. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  195. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  196. package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
  197. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  198. package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
  199. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  200. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  201. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  202. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  203. package/dist/solution/BuyTickets/index.js +12 -9
  204. package/dist/solution/Checkout/index.d.ts +1 -0
  205. package/dist/solution/Checkout/index.js +275 -209
  206. package/dist/solution/Checkout/utils/index.js +20 -8
  207. package/dist/solution/RegisterAndLogin/config.js +2 -10
  208. package/dist/solution/RegisterAndLogin/index.js +76 -30
  209. package/dist/solution/Sales/index.d.ts +50 -5
  210. package/dist/solution/Sales/index.js +484 -92
  211. package/dist/solution/Sales/types.d.ts +26 -2
  212. package/dist/solution/ScanOrder/index.d.ts +27 -21
  213. package/dist/solution/ScanOrder/index.js +519 -444
  214. package/dist/solution/ScanOrder/types.d.ts +33 -11
  215. package/dist/solution/ScanOrder/types.js +4 -5
  216. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  217. package/dist/solution/ScanOrder/utils.js +109 -34
  218. package/dist/solution/ShopDiscount/index.js +18 -19
  219. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  220. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  221. package/dist/solution/ShopDiscount/utils.js +0 -9
  222. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  223. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  224. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  225. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  226. package/dist/solution/VenueBooking/index.d.ts +32 -51
  227. package/dist/solution/VenueBooking/index.js +741 -808
  228. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  229. package/dist/solution/VenueBooking/types.d.ts +1 -3
  230. package/dist/solution/VenueBooking/types.js +0 -1
  231. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  232. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  233. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  234. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  235. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  236. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  237. package/dist/solution/index.d.ts +2 -0
  238. package/dist/solution/index.js +3 -1
  239. package/dist/types/index.d.ts +12 -2
  240. package/dist/utils/task.js +18 -15
  241. package/dist/utils/watch.js +1 -0
  242. package/lib/apis/picoding.js +0 -2
  243. package/lib/core/index.js +132 -130
  244. package/lib/effects/index.js +57 -46
  245. package/lib/index.d.ts +0 -1
  246. package/lib/index.js +50 -92
  247. package/lib/model/index.js +21 -14
  248. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  249. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  250. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  251. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  252. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  253. package/lib/model/strategy/adapter/index.js +64 -100
  254. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  255. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  256. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  257. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  258. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  259. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  260. package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
  261. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  262. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  263. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  264. package/lib/model/strategy/adapter/type.js +16 -4
  265. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  266. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  267. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  268. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  269. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  270. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  271. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  272. package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
  273. package/lib/model/strategy/engine.js +168 -270
  274. package/lib/model/strategy/index.js +34 -49
  275. package/lib/model/strategy/strategy-example.js +239 -243
  276. package/lib/model/strategy/type.js +40 -100
  277. package/lib/modules/Account/index.js +53 -39
  278. package/lib/modules/Account/types.js +33 -20
  279. package/lib/modules/AccountList/index.js +154 -116
  280. package/lib/modules/AccountList/types.js +31 -30
  281. package/lib/modules/AccountList/utils.js +30 -18
  282. package/lib/modules/BaseModule.d.ts +2 -2
  283. package/lib/modules/BaseModule.js +50 -29
  284. package/lib/modules/BookingContext/index.d.ts +48 -0
  285. package/lib/modules/BookingContext/index.js +368 -0
  286. package/lib/modules/BookingContext/types.d.ts +102 -0
  287. package/lib/modules/BookingContext/types.js +34 -0
  288. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  289. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
  290. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  291. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
  292. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  293. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
  294. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  295. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  296. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  297. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  298. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  299. package/lib/modules/BookingContext/utils/index.js +43 -0
  300. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  301. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  302. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  303. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  304. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  305. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  306. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  307. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  308. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  309. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  310. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  311. package/lib/modules/BookingContext/utils/resources.js +377 -0
  312. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  313. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  314. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  315. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  316. package/lib/modules/Cart/index.js +124 -170
  317. package/lib/modules/Cart/types.js +51 -46
  318. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  319. package/lib/modules/Cart/utils/cartDate.js +61 -56
  320. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  321. package/lib/modules/Cart/utils/cartNote.js +32 -27
  322. package/lib/modules/Cart/utils/cartProduct.js +261 -309
  323. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  324. package/lib/modules/Cart/utils/cartResource.js +78 -72
  325. package/lib/modules/Cart/utils/changePrice.js +59 -31
  326. package/lib/modules/Cart/utils/index.js +48 -106
  327. package/lib/modules/Customer/constants.js +34 -13
  328. package/lib/modules/Customer/index.d.ts +20 -0
  329. package/lib/modules/Customer/index.js +207 -217
  330. package/lib/modules/Customer/types.d.ts +2 -0
  331. package/lib/modules/Customer/types.js +35 -38
  332. package/lib/modules/Date/index.js +115 -116
  333. package/lib/modules/Date/types.js +28 -16
  334. package/lib/modules/Date/utils.js +123 -174
  335. package/lib/modules/Discount/index.d.ts +2 -2
  336. package/lib/modules/Discount/index.js +133 -119
  337. package/lib/modules/Discount/types.d.ts +1 -1
  338. package/lib/modules/Discount/types.js +31 -9
  339. package/lib/modules/Guests/index.js +56 -30
  340. package/lib/modules/Guests/types.js +33 -23
  341. package/lib/modules/Holder/index.js +189 -209
  342. package/lib/modules/Holder/types.js +16 -4
  343. package/lib/modules/Holder/utils.js +49 -20
  344. package/lib/modules/OpenData/index.d.ts +8 -0
  345. package/lib/modules/OpenData/index.js +88 -63
  346. package/lib/modules/OpenData/types.js +16 -4
  347. package/lib/modules/OpenData/utils.js +78 -44
  348. package/lib/modules/Order/index.d.ts +449 -24
  349. package/lib/modules/Order/index.js +4184 -514
  350. package/lib/modules/Order/types.d.ts +693 -88
  351. package/lib/modules/Order/types.js +35 -24
  352. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  353. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  354. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  355. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  356. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  357. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  358. package/lib/modules/Order/utils.d.ts +167 -18
  359. package/lib/modules/Order/utils.js +1085 -414
  360. package/lib/modules/Payment/cash.js +33 -20
  361. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  362. package/lib/modules/Payment/eftpos.js +30 -16
  363. package/lib/modules/Payment/index.d.ts +10 -9
  364. package/lib/modules/Payment/index.js +402 -636
  365. package/lib/modules/Payment/mx51.js +0 -1
  366. package/lib/modules/Payment/types.d.ts +44 -24
  367. package/lib/modules/Payment/types.js +107 -216
  368. package/lib/modules/Payment/utils.d.ts +1 -1
  369. package/lib/modules/Payment/utils.js +50 -52
  370. package/lib/modules/Payment/walletpass.d.ts +0 -2
  371. package/lib/modules/Payment/walletpass.js +216 -221
  372. package/lib/modules/Product/index.js +46 -51
  373. package/lib/modules/Product/types.d.ts +29 -7
  374. package/lib/modules/Product/types.js +16 -4
  375. package/lib/modules/Product/utils.js +33 -32
  376. package/lib/modules/ProductList/index.d.ts +17 -13
  377. package/lib/modules/ProductList/index.js +161 -120
  378. package/lib/modules/ProductList/types.d.ts +16 -0
  379. package/lib/modules/ProductList/types.js +31 -9
  380. package/lib/modules/Quotation/index.d.ts +22 -2
  381. package/lib/modules/Quotation/index.js +154 -64
  382. package/lib/modules/Quotation/types.d.ts +19 -0
  383. package/lib/modules/Quotation/types.js +16 -4
  384. package/lib/modules/Resource/index.js +59 -27
  385. package/lib/modules/Resource/types.js +32 -22
  386. package/lib/modules/Resource/utils.js +38 -30
  387. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  388. package/lib/modules/ResourcePlanner/index.js +148 -0
  389. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  390. package/lib/modules/ResourcePlanner/planner.js +933 -0
  391. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  392. package/lib/modules/ResourcePlanner/types.js +17 -0
  393. package/lib/modules/Rules/index.d.ts +8 -10
  394. package/lib/modules/Rules/index.js +960 -1440
  395. package/lib/modules/Rules/types.d.ts +14 -3
  396. package/lib/modules/Rules/types.js +40 -17
  397. package/lib/modules/SalesSummary/index.d.ts +23 -26
  398. package/lib/modules/SalesSummary/index.js +134 -61
  399. package/lib/modules/SalesSummary/types.d.ts +9 -1
  400. package/lib/modules/SalesSummary/types.js +16 -4
  401. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  402. package/lib/modules/SalesSummary/utils.js +814 -233
  403. package/lib/modules/ScanOrderLogger/index.js +79 -59
  404. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  405. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  406. package/lib/modules/ScanOrderLogger/types.js +16 -4
  407. package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
  408. package/lib/modules/Schedule/index.d.ts +18 -5
  409. package/lib/modules/Schedule/index.js +153 -104
  410. package/lib/modules/Schedule/type.js +16 -4
  411. package/lib/modules/Schedule/types.d.ts +2 -0
  412. package/lib/modules/Schedule/types.js +16 -4
  413. package/lib/modules/Schedule/utils.js +291 -433
  414. package/lib/modules/Step/index.js +52 -40
  415. package/lib/modules/Step/tyeps.js +16 -4
  416. package/lib/modules/Summary/index.js +71 -66
  417. package/lib/modules/Summary/types.js +16 -4
  418. package/lib/modules/Summary/utils.js +418 -791
  419. package/lib/modules/SurchargeList/index.d.ts +18 -0
  420. package/lib/modules/SurchargeList/index.js +109 -0
  421. package/lib/modules/SurchargeList/types.d.ts +15 -0
  422. package/lib/modules/SurchargeList/types.js +17 -0
  423. package/lib/modules/index.d.ts +3 -0
  424. package/lib/modules/index.js +63 -212
  425. package/lib/plugins/app.d.ts +2 -0
  426. package/lib/plugins/app.js +16 -4
  427. package/lib/plugins/index.js +25 -36
  428. package/lib/plugins/request.d.ts +1 -0
  429. package/lib/plugins/request.js +126 -137
  430. package/lib/plugins/shopStore.js +16 -4
  431. package/lib/plugins/user.js +16 -4
  432. package/lib/plugins/window.js +179 -171
  433. package/lib/server/index.d.ts +462 -8
  434. package/lib/server/index.js +4520 -1162
  435. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  436. package/lib/server/modules/floor-plan/index.js +327 -0
  437. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  438. package/lib/server/modules/floor-plan/types.js +34 -0
  439. package/lib/server/modules/index.d.ts +7 -2
  440. package/lib/server/modules/index.js +67 -84
  441. package/lib/server/modules/menu/index.js +122 -146
  442. package/lib/server/modules/menu/types.js +31 -18
  443. package/lib/server/modules/order/index.d.ts +207 -14
  444. package/lib/server/modules/order/index.js +1543 -285
  445. package/lib/server/modules/order/types.d.ts +76 -5
  446. package/lib/server/modules/order/types.js +32 -107
  447. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  448. package/lib/server/modules/order/utils/filterBookings.js +259 -176
  449. package/lib/server/modules/order/utils/filterOrders.js +293 -94
  450. package/lib/server/modules/payment/index.d.ts +28 -0
  451. package/lib/server/modules/payment/index.js +192 -0
  452. package/lib/server/modules/payment/types.d.ts +9 -0
  453. package/lib/server/modules/payment/types.js +17 -0
  454. package/lib/server/modules/products/index.d.ts +105 -14
  455. package/lib/server/modules/products/index.js +850 -475
  456. package/lib/server/modules/products/types.d.ts +34 -1
  457. package/lib/server/modules/products/types.js +34 -41
  458. package/lib/server/modules/quotation/index.d.ts +39 -0
  459. package/lib/server/modules/quotation/index.js +254 -75
  460. package/lib/server/modules/quotation/types.js +31 -21
  461. package/lib/server/modules/resource/index.d.ts +2 -3
  462. package/lib/server/modules/resource/index.js +240 -243
  463. package/lib/server/modules/resource/types.js +33 -42
  464. package/lib/server/modules/schedule/index.d.ts +6 -4
  465. package/lib/server/modules/schedule/index.js +146 -147
  466. package/lib/server/modules/schedule/types.js +21 -14
  467. package/lib/server/modules/schedule/utils.js +163 -334
  468. package/lib/server/test.json +713 -0
  469. package/lib/server/types.d.ts +2 -0
  470. package/lib/server/types.js +16 -4
  471. package/lib/server/utils/index.js +23 -25
  472. package/lib/server/utils/product.js +140 -197
  473. package/lib/server/utils/schedule.js +41 -34
  474. package/lib/server/utils/small-ticket.d.ts +71 -0
  475. package/lib/server/utils/small-ticket.js +904 -0
  476. package/lib/server/utils/time.js +49 -40
  477. package/lib/solution/BaseSales/index.d.ts +378 -0
  478. package/lib/solution/BaseSales/index.js +2533 -0
  479. package/lib/solution/BaseSales/types.d.ts +394 -0
  480. package/lib/solution/BaseSales/types.js +43 -0
  481. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  482. package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
  483. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  484. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  485. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  486. package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
  487. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  488. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
  489. package/lib/solution/BaseSales/utils.d.ts +40 -0
  490. package/lib/solution/BaseSales/utils.js +244 -0
  491. package/lib/solution/BookingByStep/index.d.ts +1 -1
  492. package/lib/solution/BookingByStep/index.js +1340 -1530
  493. package/lib/solution/BookingByStep/types.js +99 -40
  494. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  495. package/lib/solution/BookingByStep/utils/products.js +52 -42
  496. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  497. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  498. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  499. package/lib/solution/BookingTicket/index.d.ts +393 -24
  500. package/lib/solution/BookingTicket/index.js +1374 -184
  501. package/lib/solution/BookingTicket/types.d.ts +191 -6
  502. package/lib/solution/BookingTicket/types.js +79 -40
  503. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  504. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  505. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  506. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  507. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  508. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
  509. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  510. package/lib/solution/BookingTicket/utils/cartView.js +184 -0
  511. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  512. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  513. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  514. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  515. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  516. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  517. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  518. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  519. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  520. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
  521. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  522. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  523. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  524. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
  525. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  526. package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
  527. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  528. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  529. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  530. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  531. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  532. package/lib/solution/BuyTickets/index.js +70 -67
  533. package/lib/solution/BuyTickets/types.js +38 -22
  534. package/lib/solution/Checkout/index.d.ts +1 -0
  535. package/lib/solution/Checkout/index.js +1169 -1463
  536. package/lib/solution/Checkout/types.js +61 -91
  537. package/lib/solution/Checkout/utils/index.js +156 -228
  538. package/lib/solution/PlaceOrder/index.js +0 -55
  539. package/lib/solution/RegisterAndLogin/config.js +462 -503
  540. package/lib/solution/RegisterAndLogin/index.js +630 -633
  541. package/lib/solution/RegisterAndLogin/types.js +76 -189
  542. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  543. package/lib/solution/Sales/index.d.ts +50 -5
  544. package/lib/solution/Sales/index.js +498 -238
  545. package/lib/solution/Sales/types.d.ts +26 -2
  546. package/lib/solution/Sales/types.js +33 -27
  547. package/lib/solution/ScanOrder/index.d.ts +27 -21
  548. package/lib/solution/ScanOrder/index.js +936 -864
  549. package/lib/solution/ScanOrder/types.d.ts +33 -11
  550. package/lib/solution/ScanOrder/types.js +34 -34
  551. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  552. package/lib/solution/ScanOrder/utils.js +422 -385
  553. package/lib/solution/ShopDiscount/index.js +233 -235
  554. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  555. package/lib/solution/ShopDiscount/types.js +37 -15
  556. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  557. package/lib/solution/ShopDiscount/utils.js +172 -309
  558. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  559. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  560. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  561. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  562. package/lib/solution/VenueBooking/index.d.ts +32 -51
  563. package/lib/solution/VenueBooking/index.js +1008 -984
  564. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  565. package/lib/solution/VenueBooking/types.d.ts +1 -3
  566. package/lib/solution/VenueBooking/types.js +39 -20
  567. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  568. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  569. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  570. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  571. package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
  572. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  573. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  574. package/lib/solution/VenueBooking/utils.js +67 -130
  575. package/lib/solution/index.d.ts +2 -0
  576. package/lib/solution/index.js +41 -102
  577. package/lib/store/createStore.js +29 -32
  578. package/lib/types/index.d.ts +12 -2
  579. package/lib/types/index.js +16 -4
  580. package/lib/utils/task.js +36 -36
  581. package/lib/utils/watch.js +47 -81
  582. package/package.json +2 -4
  583. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  584. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  585. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  586. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  587. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  588. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,10 +1,14 @@
1
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
4
6
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
7
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
12
  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; } } }; }
9
13
  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); }
10
14
  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; }
@@ -29,6 +33,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
29
33
  import { cloneDeep } from 'lodash-es';
30
34
  import dayjs from 'dayjs';
31
35
  import { BaseModule } from "../../../modules/BaseModule";
36
+ import { applyOrderCollectionUidRemaps, getOrderCollectionPersistentId, getOrderCollectionReferenceUid, getOrderCollectionUid, isSameOrderCollectionItem, mergeOrderCollectionItems, normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
32
37
  import { OrderHooks } from "./types";
33
38
 
34
39
  /**
@@ -36,6 +41,27 @@ import { OrderHooks } from "./types";
36
41
  */
37
42
  var INDEXDB_STORE_NAME = 'orders';
38
43
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
44
+ var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
45
+ var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
46
+ /** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
47
+ var ORDER_SQLITE_DEDUPE_MS = 15000;
48
+ /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
49
+ var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
50
+ /** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
51
+ var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
52
+
53
+ /**
54
+ * 合并热路径全表去重自检开关:默认关闭。
55
+ * 开启后每次合并会额外对整张 store 做一次 O(n^2) 重复检测并告警,
56
+ * 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
57
+ */
58
+ var ORDER_MERGE_SELF_CHECK = false;
59
+ var ORDER_AUTHORITATIVE_COLLECTION_FIELDS = ['products', 'bookings', 'payments'];
60
+ var ORDER_COLLECTION_KIND_BY_FIELD = {
61
+ products: 'product',
62
+ bookings: 'booking',
63
+ payments: 'payment'
64
+ };
39
65
 
40
66
  /**
41
67
  * Order 模块 - 基础框架
@@ -54,22 +80,69 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
54
80
  _defineProperty(_assertThisInitialized(_this), "orderDataSource", void 0);
55
81
  _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
56
82
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
57
- _defineProperty(_assertThisInitialized(_this), "ORDER_SYNC_DEBOUNCE_MS", 5000);
58
- // Map<resource_id, OrderId[]> 资源到订单的倒排索引
59
- _defineProperty(_assertThisInitialized(_this), "resourceIdIndex", new Map());
83
+ _defineProperty(_assertThisInitialized(_this), "isProcessingSyncBatch", false);
84
+ _defineProperty(_assertThisInitialized(_this), "isIdlePhase", true);
60
85
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
61
86
  // LoggerManager 实例
62
87
  _defineProperty(_assertThisInitialized(_this), "storage", void 0);
88
+ _defineProperty(_assertThisInitialized(_this), "orderSQLiteSaveQueue", Promise.resolve());
89
+ /** 按 storageKey 记录最近一次 SQLite 写入来源与时间,用于去重 */
90
+ _defineProperty(_assertThisInitialized(_this), "recentSqliteWriteByStorageKey", new Map());
91
+ /** 最近一次 SSE 全量拉取完成时间 */
92
+ _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
63
93
  return _this;
64
94
  }
95
+
96
+ /**
97
+ * 广播订单变更事件,兼容全量列表订阅并额外携带本次变更订单。
98
+ *
99
+ * @example
100
+ * await this.emitOrdersChanged([freshOrder], 'pubsub.bodyUpsert')
101
+ */
65
102
  _createClass(OrderModule, [{
66
- key: "initialize",
67
- value: function () {
68
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
69
- var _options$initialState;
70
- var appPlugin, app, _this$store$createdAt, coreData, today, operatingDayBoundary, boundaryTime, boundaryStart, boundaryEnd;
103
+ key: "emitOrdersChanged",
104
+ value: (function () {
105
+ var _emitOrdersChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
106
+ var _this2 = this;
107
+ var changedOrders,
108
+ source,
109
+ payload,
110
+ _args = arguments;
71
111
  return _regeneratorRuntime().wrap(function _callee$(_context) {
72
112
  while (1) switch (_context.prev = _context.next) {
113
+ case 0:
114
+ changedOrders = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
115
+ source = _args.length > 1 ? _args[1] : undefined;
116
+ console.log('触发emitOrdersChanged');
117
+ payload = {
118
+ list: this.store.list,
119
+ changedOrders: changedOrders.map(function (order) {
120
+ return _this2.normalizeOrderForMemoryList(order);
121
+ }),
122
+ source: source
123
+ };
124
+ _context.next = 6;
125
+ return this.core.effects.emit(OrderHooks.onOrdersChanged, payload);
126
+ case 6:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }, _callee, this);
131
+ }));
132
+ function emitOrdersChanged() {
133
+ return _emitOrdersChanged.apply(this, arguments);
134
+ }
135
+ return emitOrdersChanged;
136
+ }())
137
+ }, {
138
+ key: "initialize",
139
+ value: function () {
140
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
141
+ var _options$initialState,
142
+ _this3 = this;
143
+ var appPlugin, app;
144
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
145
+ while (1) switch (_context2.prev = _context2.next) {
73
146
  case 0:
74
147
  this.core = core;
75
148
  this.store = options === null || options === void 0 ? void 0 : options.store;
@@ -80,42 +153,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
80
153
  this.dbManager = app.sqlite;
81
154
  this.logger = app.logger;
82
155
  this.storage = app.storage;
83
- coreData = app.data.store.getStore().getDataByModel('core');
84
- if (!((_this$store$createdAt = this.store.createdAtQuery) !== null && _this$store$createdAt !== void 0 && _this$store$createdAt.sales_time_between) && coreData !== null && coreData !== void 0 && coreData.core) {
85
- today = dayjs();
86
- if (coreData !== null && coreData !== void 0 && coreData.core.operating_day_boundary) {
87
- operatingDayBoundary = coreData.core.operating_day_boundary;
88
- if (operatingDayBoundary.type === 'start_time') {
89
- boundaryTime = String(operatingDayBoundary.time || '').trim();
90
- boundaryStart = dayjs("".concat(today.format('YYYY-MM-DD'), " ").concat(boundaryTime));
91
- boundaryEnd = boundaryStart.add(1, 'day');
92
- if (boundaryStart.isValid()) {
93
- this.store.createdAtQuery = {
94
- sales_time_between: [boundaryStart.format('YYYY-MM-DD HH:mm:ss'), boundaryEnd.format('YYYY-MM-DD HH:mm:ss')]
95
- };
96
- } else {
97
- // 边界时间异常时回退到自然日,避免 createdAtQuery 为空导致后续查询异常
98
- this.store.createdAtQuery = {
99
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
100
- };
101
- }
102
- } else {
103
- this.store.createdAtQuery = {
104
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
105
- };
106
- }
107
- } else {
108
- // TODO: 这里后续可能需要使用店铺营业时间查询
109
- this.store.createdAtQuery = {
110
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
111
- };
112
- }
113
- }
156
+ this.updateCreateStore();
114
157
  }
115
158
  if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
116
- this.store.list = options.initialState.list;
159
+ this.store.list = options.initialState.list.map(function (order) {
160
+ return _this3.normalizeOrderForMemoryList(order);
161
+ });
117
162
  this.syncOrdersMap();
118
- this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
163
+ this.emitOrdersChanged([], 'initialState');
119
164
  } else {
120
165
  this.store.list = [];
121
166
  this.store.map = new Map();
@@ -129,9 +174,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
129
174
  });
130
175
  case 10:
131
176
  case "end":
132
- return _context.stop();
177
+ return _context2.stop();
133
178
  }
134
- }, _callee, this);
179
+ }, _callee2, this);
135
180
  }));
136
181
  function initialize(_x, _x2) {
137
182
  return _initialize.apply(this, arguments);
@@ -139,10 +184,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
139
184
  return initialize;
140
185
  }()
141
186
  /**
142
- * 记录信息日志
143
- * @param title 日志标题
144
- * @param metadata 日志元数据
145
- */
187
+ * 记录信息日志
188
+ * @param title 日志标题
189
+ * @param metadata 日志元数据
190
+ */
146
191
  }, {
147
192
  key: "logInfo",
148
193
  value: function logInfo(title, metadata) {
@@ -179,32 +224,439 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
179
224
  // 日志记录失败不影响主流程
180
225
  }
181
226
  }
227
+ }, {
228
+ key: "logWarning",
229
+ value: function logWarning(title, metadata) {
230
+ try {
231
+ if (this.logger) {
232
+ this.logger.addLog({
233
+ type: 'warning',
234
+ title: "[OrderServerModule] ".concat(title),
235
+ metadata: metadata || {}
236
+ });
237
+ }
238
+ } catch (_unused3) {
239
+ // 日志记录失败不影响主流程
240
+ }
241
+ }
242
+
243
+ /**
244
+ * 在订单进入内存或 SQLite 前统一压缩子项强身份重复并补齐协议 UID。
245
+ * 仅记录计数与订单标识,不输出商品、预约、支付或客户明细。
246
+ */
247
+ }, {
248
+ key: "normalizeOrderCollectionsForIngress",
249
+ value: function normalizeOrderCollectionsForIngress(order, source) {
250
+ var result = normalizeOrderCollections(order);
251
+ var kinds = ['product', 'booking', 'payment'];
252
+ var hasChanges = kinds.some(function (kind) {
253
+ var stats = result.stats[kind];
254
+ return stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
255
+ });
256
+ if (hasChanges) {
257
+ var _order$order_id, _external_sale_number;
258
+ var summarize = function summarize(stats) {
259
+ return {
260
+ backfilled_uid_count: stats.backfilledUidCount,
261
+ collapsed_duplicate_count: stats.collapsedDuplicateCount,
262
+ uid_conflict_count: stats.uidConflictCount,
263
+ anonymous_row_count: stats.anonymousRowCount
264
+ };
265
+ };
266
+ var context = {
267
+ source: source,
268
+ order_id: (_order$order_id = order === null || order === void 0 ? void 0 : order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
269
+ external_sale_number: (_external_sale_number = order === null || order === void 0 ? void 0 : order.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : null,
270
+ products: summarize(result.stats.product),
271
+ bookings: summarize(result.stats.booking),
272
+ payments: summarize(result.stats.payment)
273
+ };
274
+ var hasUnsafeIdentity = kinds.some(function (kind) {
275
+ var stats = result.stats[kind];
276
+ return stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
277
+ });
278
+ if (hasUnsafeIdentity) {
279
+ this.logWarning('订单子项身份存在冲突或匿名行', context);
280
+ } else {
281
+ this.logInfo('订单子项身份已规范化', context);
282
+ }
283
+ }
284
+ return result.order;
285
+ }
286
+
287
+ /**
288
+ * incoming 决定权威成员集合;同一持久化行仍从 existing 补齐 incoming 省略的本地展示字段。
289
+ */
290
+ }, {
291
+ key: "mergeAuthoritativeOrderCollection",
292
+ value: function mergeAuthoritativeOrderCollection(field, existing, incoming) {
293
+ var uidRemaps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
294
+ var kind = ORDER_COLLECTION_KIND_BY_FIELD[field];
295
+ var existingItems = Array.isArray(existing) ? existing : [];
296
+ return incoming.map(function (incomingItem) {
297
+ var existingItem = existingItems.find(function (item) {
298
+ return isSameOrderCollectionItem(kind, item, incomingItem);
299
+ });
300
+ if (!existingItem) return cloneDeep(incomingItem);
301
+ var mergedItem = mergeOrderCollectionItems(kind, existingItem, incomingItem);
302
+ var mergedUid = getOrderCollectionUid(kind, mergedItem);
303
+ if (mergedUid) {
304
+ var _iterator = _createForOfIteratorHelper(new Set([getOrderCollectionReferenceUid(kind, existingItem), getOrderCollectionReferenceUid(kind, incomingItem)])),
305
+ _step;
306
+ try {
307
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
308
+ var from = _step.value;
309
+ if (!from || from === mergedUid) continue;
310
+ uidRemaps.push({
311
+ kind: kind,
312
+ from: from,
313
+ to: mergedUid,
314
+ persistentId: getOrderCollectionPersistentId(kind, incomingItem) || getOrderCollectionPersistentId(kind, existingItem)
315
+ });
316
+ }
317
+ } catch (err) {
318
+ _iterator.e(err);
319
+ } finally {
320
+ _iterator.f();
321
+ }
322
+ }
323
+ return mergedItem;
324
+ });
325
+ }
326
+ }, {
327
+ key: "reconcileOverwriteOrderCollections",
328
+ value: function reconcileOverwriteOrderCollections(existing, incoming) {
329
+ var reconciled = cloneDeep(incoming);
330
+ var existingRecord = existing;
331
+ var incomingRecord = incoming;
332
+ var uidRemaps = [];
333
+ for (var _i = 0, _ORDER_AUTHORITATIVE_ = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i < _ORDER_AUTHORITATIVE_.length; _i++) {
334
+ var field = _ORDER_AUTHORITATIVE_[_i];
335
+ if (!Array.isArray(incomingRecord[field])) continue;
336
+ reconciled[field] = this.mergeAuthoritativeOrderCollection(field, existingRecord[field], incomingRecord[field], uidRemaps);
337
+ }
338
+ return this.normalizeOrderCollectionsForIngress(applyOrderCollectionUidRemaps(reconciled, uidRemaps), 'overwriteExistingOrder.reconciled');
339
+ }
340
+
341
+ /**
342
+ * 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
343
+ *
344
+ * @example
345
+ * this.recordRecentSqliteWrite('upsertOrdersFromRemote', orders)
346
+ */
347
+ }, {
348
+ key: "recordRecentSqliteWrite",
349
+ value: function recordRecentSqliteWrite(source, orders) {
350
+ var now = Date.now();
351
+ var _iterator2 = _createForOfIteratorHelper(orders),
352
+ _step2;
353
+ try {
354
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
355
+ var order = _step2.value;
356
+ var storageKey = this.getOrderStorageKey(order);
357
+ if (!storageKey) continue;
358
+ this.recentSqliteWriteByStorageKey.set(storageKey, {
359
+ source: source,
360
+ ts: now
361
+ });
362
+ }
363
+ } catch (err) {
364
+ _iterator2.e(err);
365
+ } finally {
366
+ _iterator2.f();
367
+ }
368
+ }
369
+
370
+ /**
371
+ * 过滤 pubsub 触发的冗余 SQLite patch(业务 API 刚写入过的 update 回声)。
372
+ *
373
+ * @example
374
+ * const { toWrite, skipped } = this.filterRedundantPatchOrders('pubsub.bodyUpsert', orders, mergeActions)
375
+ */
376
+ }, {
377
+ key: "filterRedundantPatchOrders",
378
+ value: function filterRedundantPatchOrders(source, orders, mergeActions) {
379
+ var eligibleSkipSources = new Set(['pubsub.bodyUpsert', 'pubsub.httpRefresh']);
380
+ if (!eligibleSkipSources.has(source)) {
381
+ return {
382
+ toWrite: orders,
383
+ skipped: []
384
+ };
385
+ }
386
+ var now = Date.now();
387
+ var toWrite = [];
388
+ var skipped = [];
389
+ var _iterator3 = _createForOfIteratorHelper(orders),
390
+ _step3;
391
+ try {
392
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
393
+ var order = _step3.value;
394
+ var storageKey = this.getOrderStorageKey(order);
395
+ if (!storageKey) {
396
+ toWrite.push(order);
397
+ continue;
398
+ }
399
+ var orderKey = order.order_id !== undefined && order.order_id !== null ? this.getIdKey(order.order_id) : '';
400
+ var mergeAction = orderKey ? mergeActions[orderKey] : undefined;
401
+
402
+ // 新增单必须落库,不参与去重
403
+ if (mergeAction === 'insert') {
404
+ toWrite.push(order);
405
+ continue;
406
+ }
407
+ var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
408
+ if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
409
+ var _order$order_id2;
410
+ skipped.push({
411
+ orderId: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
412
+ storageKey: storageKey,
413
+ reason: 'skip_pubsub_echo_after_business_write',
414
+ lastSource: recent.source,
415
+ elapsedMs: now - recent.ts
416
+ });
417
+ continue;
418
+ }
419
+ toWrite.push(order);
420
+ }
421
+ } catch (err) {
422
+ _iterator3.e(err);
423
+ } finally {
424
+ _iterator3.f();
425
+ }
426
+ return {
427
+ toWrite: toWrite,
428
+ skipped: skipped
429
+ };
430
+ }
431
+
432
+ /**
433
+ * 过滤 pubsub HTTP 增量拉取 ids:本地刚由业务 API 写入的单可跳过 HTTP。
434
+ *
435
+ * @example
436
+ * const ids = this.filterRedundantHttpRefreshIds([99331, 99332])
437
+ */
438
+ }, {
439
+ key: "filterRedundantHttpRefreshIds",
440
+ value: function filterRedundantHttpRefreshIds(ids) {
441
+ var now = Date.now();
442
+ var toFetch = [];
443
+ var skipped = [];
444
+ var _iterator4 = _createForOfIteratorHelper(ids),
445
+ _step4;
446
+ try {
447
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
448
+ var id = _step4.value;
449
+ var existing = this.getOrderByOrderId(id);
450
+ if (!existing) {
451
+ toFetch.push(id);
452
+ continue;
453
+ }
454
+ var storageKey = this.getOrderStorageKey(existing);
455
+ var recent = storageKey ? this.recentSqliteWriteByStorageKey.get(storageKey) : undefined;
456
+ if (recent && recent.source === 'upsertOrdersFromRemote' && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
457
+ skipped.push({
458
+ orderId: id,
459
+ lastSource: recent.source,
460
+ elapsedMs: now - recent.ts
461
+ });
462
+ continue;
463
+ }
464
+ toFetch.push(id);
465
+ }
466
+ } catch (err) {
467
+ _iterator4.e(err);
468
+ } finally {
469
+ _iterator4.f();
470
+ }
471
+ return {
472
+ toFetch: toFetch,
473
+ skipped: skipped
474
+ };
475
+ }
476
+
477
+ /**
478
+ * 解析 pubsub 消息会走哪条同步分支,便于对照为何触发 HTTP 重拉或 body 直写。
479
+ *
480
+ * @example
481
+ * this.resolveSyncMessageRoute(msg)
482
+ * // => { route: 'httpRefresh.batchIds', ... }
483
+ */
484
+ }, {
485
+ key: "resolveSyncMessageRoute",
486
+ value: function resolveSyncMessageRoute(msg) {
487
+ var _msg$id, _msg$relation_order_i, _normalizedBody$order5;
488
+ var hasBatchIds = Array.isArray(msg.ids) && msg.ids.length > 0;
489
+ var singleIdRaw = (_msg$id = msg.id) !== null && _msg$id !== void 0 ? _msg$id : msg.order_id;
490
+ var hasSingleId = !hasBatchIds && singleIdRaw !== undefined && singleIdRaw !== null;
491
+ var normalizedBody = this.normalizeOrderSyncPayload(msg.body || msg.data);
492
+ if (hasBatchIds) {
493
+ var _normalizedBody$order;
494
+ return {
495
+ route: 'httpRefresh.batchIds',
496
+ hasBatchIds: true,
497
+ hasSingleId: false,
498
+ hasNormalizedBody: !!normalizedBody,
499
+ singleId: null,
500
+ batchIds: msg.ids || [],
501
+ bodyOrderId: (_normalizedBody$order = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order !== void 0 ? _normalizedBody$order : null
502
+ };
503
+ }
504
+ if (hasSingleId && normalizedBody) {
505
+ var _normalizedBody$order2;
506
+ return {
507
+ route: 'bodyUpsert',
508
+ hasBatchIds: false,
509
+ hasSingleId: true,
510
+ hasNormalizedBody: true,
511
+ singleId: singleIdRaw,
512
+ batchIds: [],
513
+ bodyOrderId: (_normalizedBody$order2 = normalizedBody.order_id) !== null && _normalizedBody$order2 !== void 0 ? _normalizedBody$order2 : null
514
+ };
515
+ }
516
+ if (hasSingleId) {
517
+ var _normalizedBody$order3;
518
+ return {
519
+ route: 'httpRefresh.singleId',
520
+ hasBatchIds: false,
521
+ hasSingleId: true,
522
+ hasNormalizedBody: !!normalizedBody,
523
+ singleId: singleIdRaw,
524
+ batchIds: [],
525
+ bodyOrderId: (_normalizedBody$order3 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order3 !== void 0 ? _normalizedBody$order3 : null
526
+ };
527
+ }
528
+ if ((_msg$relation_order_i = msg.relation_order_ids) !== null && _msg$relation_order_i !== void 0 && _msg$relation_order_i.length) {
529
+ var _normalizedBody$order4;
530
+ return {
531
+ route: 'httpRefresh.relationIds',
532
+ hasBatchIds: false,
533
+ hasSingleId: false,
534
+ hasNormalizedBody: !!normalizedBody,
535
+ singleId: null,
536
+ batchIds: msg.relation_order_ids,
537
+ bodyOrderId: (_normalizedBody$order4 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order4 !== void 0 ? _normalizedBody$order4 : null
538
+ };
539
+ }
540
+ return {
541
+ route: 'noop',
542
+ hasBatchIds: false,
543
+ hasSingleId: false,
544
+ hasNormalizedBody: !!normalizedBody,
545
+ singleId: null,
546
+ batchIds: [],
547
+ bodyOrderId: (_normalizedBody$order5 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order5 !== void 0 ? _normalizedBody$order5 : null
548
+ };
549
+ }
550
+ }, {
551
+ key: "updateCreateStore",
552
+ value: function updateCreateStore() {
553
+ var appPlugin = this.core.getPlugin('app');
554
+ var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
555
+ if (app) {
556
+ var coreData = app.data.store.getStore().getDataByModel('core');
557
+ if (coreData !== null && coreData !== void 0 && coreData.core) {
558
+ var today = dayjs();
559
+ if (coreData !== null && coreData !== void 0 && coreData.core.operating_day_boundary) {
560
+ var operatingDayBoundary = coreData.core.operating_day_boundary;
561
+ if (operatingDayBoundary.type === 'start_time') {
562
+ var boundaryTime = String(operatingDayBoundary.time || '').trim();
563
+ var boundaryStart = dayjs("".concat(today.format('YYYY-MM-DD'), " ").concat(boundaryTime));
564
+ if (boundaryStart.isValid()) {
565
+ var isAfterBoundary = today.isAfter(boundaryStart);
566
+ var queryStart = isAfterBoundary ? today.startOf('day') : today.subtract(1, 'day').startOf('day');
567
+ var queryEnd = isAfterBoundary ? today.add(1, 'day').endOf('day') : today.endOf('day');
568
+ this.store.createdAtQuery = {
569
+ sales_time_between: [queryStart.format('YYYY-MM-DD HH:mm:ss'), queryEnd.format('YYYY-MM-DD HH:mm:ss')]
570
+ };
571
+ } else {
572
+ // 边界时间异常时回退到自然日,避免 createdAtQuery 为空导致后续查询异常
573
+ this.store.createdAtQuery = {
574
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
575
+ };
576
+ }
577
+ } else {
578
+ this.store.createdAtQuery = {
579
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
580
+ };
581
+ }
582
+ } else {
583
+ // TODO: 这里后续可能需要使用店铺营业时间查询
584
+ this.store.createdAtQuery = {
585
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
586
+ };
587
+ }
588
+ }
589
+ }
590
+ }
591
+ }, {
592
+ key: "getOrderSyncThrottleMs",
593
+ value: function getOrderSyncThrottleMs() {
594
+ var raw = localStorage.getItem(ORDER_SYNC_THROTTLE_MS_STORAGE_KEY);
595
+ if (raw !== null) {
596
+ var parsed = Number(raw);
597
+ if (Number.isFinite(parsed) && parsed >= 0) return parsed;
598
+ }
599
+ return DEFAULT_ORDER_SYNC_THROTTLE_MS;
600
+ }
182
601
  }, {
183
602
  key: "preload",
184
603
  value: function () {
185
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
186
- var orders;
187
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
188
- while (1) switch (_context2.prev = _context2.next) {
604
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
605
+ var _this4 = this;
606
+ var getData;
607
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
608
+ while (1) switch (_context4.prev = _context4.next) {
189
609
  case 0:
190
- _context2.next = 2;
191
- return this.loadOrdersByServer();
610
+ // const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
611
+ // // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
612
+ // if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
613
+ // this.store.list = cloneDeep(cachedOrders)
614
+ // this.syncOrdersMap()
615
+ // this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list)
616
+ // return
617
+ // }
618
+ // if (hasPulledInCurrentWindow) {
619
+ // this.logInfo('当天已完成全量订单拉取,跳过本次全量拉取', {
620
+ // lastFullFetchAt: this.getStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY),
621
+ // })
622
+ // return
623
+ // }
624
+ getData = /*#__PURE__*/function () {
625
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
626
+ var orders;
627
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
628
+ while (1) switch (_context3.prev = _context3.next) {
629
+ case 0:
630
+ _context3.next = 2;
631
+ return _this4.loadOrdersByServer();
632
+ case 2:
633
+ orders = _context3.sent;
634
+ if (!(orders.length === 0)) {
635
+ _context3.next = 5;
636
+ break;
637
+ }
638
+ return _context3.abrupt("return");
639
+ case 5:
640
+ _this4.store.list = cloneDeep(orders);
641
+ _this4.syncOrdersMap();
642
+ _this4.emitOrdersChanged([], 'preload');
643
+ _this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
644
+ case 9:
645
+ case "end":
646
+ return _context3.stop();
647
+ }
648
+ }, _callee3);
649
+ }));
650
+ return function getData() {
651
+ return _ref.apply(this, arguments);
652
+ };
653
+ }();
654
+ getData();
192
655
  case 2:
193
- orders = _context2.sent;
194
- if (!(orders.length === 0)) {
195
- _context2.next = 5;
196
- break;
197
- }
198
- return _context2.abrupt("return");
199
- case 5:
200
- this.store.list = cloneDeep(orders);
201
- this.syncOrdersMap();
202
- this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
203
- case 8:
204
656
  case "end":
205
- return _context2.stop();
657
+ return _context4.stop();
206
658
  }
207
- }, _callee2, this);
659
+ }, _callee4);
208
660
  }));
209
661
  function preload() {
210
662
  return _preload.apply(this, arguments);
@@ -222,72 +674,620 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
222
674
  return this.store.map.get(this.getIdKey(id));
223
675
  }
224
676
 
225
- /** 按 order_id 查询(推荐) */
677
+ /** 按 order_id 查询内存订单。 */
226
678
  }, {
227
679
  key: "getOrderByOrderId",
228
680
  value: function getOrderByOrderId(orderId) {
229
681
  return this.store.map.get(this.getIdKey(orderId));
230
682
  }
683
+ }, {
684
+ key: "getLocalOrderFromMemoryByLookup",
685
+ value: function getLocalOrderFromMemoryByLookup(lookup) {
686
+ var _this5 = this;
687
+ var key = this.getIdKey(lookup);
688
+ var memoryOrderById = this.store.map.get(key);
689
+ if (memoryOrderById) return memoryOrderById;
690
+ var memoryOrder = this.store.list.find(function (order) {
691
+ return _this5.isOrderLookupMatch(order, key);
692
+ });
693
+ return memoryOrder || null;
694
+ }
695
+ }, {
696
+ key: "getLocalOrderByLookup",
697
+ value: function () {
698
+ var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
699
+ var _this6 = this;
700
+ var key, memoryOrderById, memoryOrder, orders, localOrder;
701
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
702
+ while (1) switch (_context5.prev = _context5.next) {
703
+ case 0:
704
+ key = this.getIdKey(lookup);
705
+ memoryOrderById = this.store.map.get(key);
706
+ if (!memoryOrderById) {
707
+ _context5.next = 4;
708
+ break;
709
+ }
710
+ return _context5.abrupt("return", memoryOrderById);
711
+ case 4:
712
+ memoryOrder = this.store.list.find(function (order) {
713
+ return _this6.isOrderLookupMatch(order, key);
714
+ });
715
+ if (!memoryOrder) {
716
+ _context5.next = 7;
717
+ break;
718
+ }
719
+ return _context5.abrupt("return", memoryOrder);
720
+ case 7:
721
+ _context5.next = 9;
722
+ return this.loadOrdersFromSQLite();
723
+ case 9:
724
+ orders = _context5.sent;
725
+ localOrder = orders.find(function (order) {
726
+ return _this6.isOrderLookupMatch(order, key);
727
+ });
728
+ if (localOrder) {
729
+ _context5.next = 13;
730
+ break;
731
+ }
732
+ return _context5.abrupt("return", null);
733
+ case 13:
734
+ this.store.list = orders.map(function (order) {
735
+ return _this6.normalizeOrderForMemoryList(order);
736
+ });
737
+ this.syncOrdersMap();
738
+ return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
739
+ case 16:
740
+ case "end":
741
+ return _context5.stop();
742
+ }
743
+ }, _callee5, this);
744
+ }));
745
+ function getLocalOrderByLookup(_x3) {
746
+ return _getLocalOrderByLookup.apply(this, arguments);
747
+ }
748
+ return getLocalOrderByLookup;
749
+ }()
231
750
  }, {
232
751
  key: "loadOrdersByServer",
233
752
  value: function () {
234
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
235
- var orderList, data;
236
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
237
- while (1) switch (_context3.prev = _context3.next) {
753
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
754
+ var _this$store,
755
+ _this7 = this;
756
+ var orderList, data, mergedOrders, memoryOrders;
757
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
758
+ while (1) switch (_context6.prev = _context6.next) {
238
759
  case 0:
239
760
  orderList = [];
761
+ this.logInfo('loadOrdersByServer-开始', {
762
+ hasOrderDataSource: !!this.orderDataSource,
763
+ query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
764
+ });
240
765
  if (!this.orderDataSource) {
241
- _context3.next = 13;
766
+ _context6.next = 17;
242
767
  break;
243
768
  }
244
- _context3.prev = 2;
245
- _context3.next = 5;
769
+ _context6.prev = 3;
770
+ _context6.next = 6;
246
771
  return this.orderDataSource.run({
247
- http: {
772
+ sse: {
248
773
  query: this.store.createdAtQuery
249
774
  }
250
775
  });
251
- case 5:
252
- data = _context3.sent;
776
+ case 6:
777
+ data = _context6.sent;
253
778
  orderList = data || [];
779
+ this.logInfo('loadOrdersByServer-SSE拉取成功', {
780
+ count: orderList.length
781
+ });
254
782
  this.markOrderPulledAtNow();
255
- _context3.next = 13;
783
+ this.lastServerFullFetchAtMs = Date.now();
784
+ _context6.next = 17;
256
785
  break;
257
- case 10:
258
- _context3.prev = 10;
259
- _context3.t0 = _context3["catch"](2);
260
- orderList = [];
261
786
  case 13:
262
- _context3.next = 15;
263
- return this.saveOrdersToSQLite(orderList);
264
- case 15:
265
- _context3.next = 17;
266
- return this.core.effects.emit(OrderHooks.onOrdersLoaded, orderList);
787
+ _context6.prev = 13;
788
+ _context6.t0 = _context6["catch"](3);
789
+ this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
790
+ return _context6.abrupt("return", this.store.list);
267
791
  case 17:
268
- return _context3.abrupt("return", orderList);
269
- case 18:
792
+ _context6.next = 19;
793
+ return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
794
+ case 19:
795
+ mergedOrders = _context6.sent;
796
+ memoryOrders = mergedOrders.map(function (order) {
797
+ return _this7.normalizeOrderForMemoryList(order);
798
+ });
799
+ this.logInfo('loadOrdersByServer-结束', {
800
+ count: memoryOrders.length
801
+ });
802
+ _context6.next = 24;
803
+ return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
804
+ case 24:
805
+ return _context6.abrupt("return", memoryOrders);
806
+ case 25:
270
807
  case "end":
271
- return _context3.stop();
808
+ return _context6.stop();
272
809
  }
273
- }, _callee3, this, [[2, 10]]);
810
+ }, _callee6, this, [[3, 13]]);
274
811
  }));
275
812
  function loadOrdersByServer() {
276
813
  return _loadOrdersByServer.apply(this, arguments);
277
814
  }
278
815
  return loadOrdersByServer;
279
816
  }()
817
+ /**
818
+ * 静默全量刷新:后台重新拉取全量 SSE 订单数据并更新本地
819
+ * 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件
820
+ * @returns 刷新后的订单列表
821
+ */
822
+ }, {
823
+ key: "silentRefresh",
824
+ value: (function () {
825
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
826
+ var startTime, elapsedSinceFullFetch, orders, errorMessage;
827
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
828
+ while (1) switch (_context7.prev = _context7.next) {
829
+ case 0:
830
+ startTime = Date.now();
831
+ elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
832
+ if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
833
+ _context7.next = 4;
834
+ break;
835
+ }
836
+ return _context7.abrupt("return", this.store.list);
837
+ case 4:
838
+ this.logInfo('silentRefresh 开始');
839
+ _context7.prev = 5;
840
+ // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
841
+ this.updateCreateStore();
842
+ _context7.next = 9;
843
+ return this.loadOrdersByServer();
844
+ case 9:
845
+ orders = _context7.sent;
846
+ if (!(orders.length > 0)) {
847
+ _context7.next = 19;
848
+ break;
849
+ }
850
+ this.store.list = cloneDeep(orders);
851
+ this.syncOrdersMap();
852
+ this.emitOrdersChanged([], 'silentRefresh');
853
+ _context7.next = 16;
854
+ return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
855
+ case 16:
856
+ this.logInfo('silentRefresh 完成', {
857
+ orderCount: orders.length,
858
+ duration: "".concat(Date.now() - startTime, "ms")
859
+ });
860
+ _context7.next = 20;
861
+ break;
862
+ case 19:
863
+ this.logInfo('silentRefresh: 服务器未返回数据');
864
+ case 20:
865
+ return _context7.abrupt("return", this.store.list);
866
+ case 23:
867
+ _context7.prev = 23;
868
+ _context7.t0 = _context7["catch"](5);
869
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
870
+ this.logError('silentRefresh 失败', {
871
+ duration: "".concat(Date.now() - startTime, "ms"),
872
+ error: errorMessage
873
+ });
874
+ return _context7.abrupt("return", this.store.list);
875
+ case 28:
876
+ case "end":
877
+ return _context7.stop();
878
+ }
879
+ }, _callee7, this, [[5, 23]]);
880
+ }));
881
+ function silentRefresh() {
882
+ return _silentRefresh.apply(this, arguments);
883
+ }
884
+ return silentRefresh;
885
+ }())
280
886
  }, {
281
- key: "getOrdersByResourceId",
282
- value: function getOrdersByResourceId(resourceId) {
283
- var _this2 = this;
284
- var ids = this.resourceIdIndex.get(String(resourceId)) || [];
285
- return ids.map(function (id) {
286
- return _this2.store.map.get(id);
287
- }).filter(function (order) {
288
- return !!order;
887
+ key: "normalizeOrderForMemoryList",
888
+ value: function normalizeOrderForMemoryList(order) {
889
+ var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'normalizeOrderForMemoryList';
890
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, source);
891
+ var externalSaleNumber = normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.external_sale_number;
892
+ if ((normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== undefined && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== null && (normalizedOrder === null || normalizedOrder === void 0 ? void 0 : normalizedOrder.order_id) !== '') {
893
+ return normalizedOrder;
894
+ }
895
+ if (externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '') {
896
+ return normalizedOrder;
897
+ }
898
+ return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
899
+ order_id: externalSaleNumber
289
900
  });
290
901
  }
902
+
903
+ /**
904
+ * 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
905
+ * 适用于"按 order_id 主动刷新本地订单详情"的代理场景。
906
+ */
907
+ }, {
908
+ key: "overwriteExistingOrder",
909
+ value: (function () {
910
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
911
+ var _this8 = this;
912
+ var orderId, key, normalizedFresh, existingOrder, reconciledFresh;
913
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
914
+ while (1) switch (_context8.prev = _context8.next) {
915
+ case 0:
916
+ orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
917
+ if (!(orderId === undefined || orderId === null)) {
918
+ _context8.next = 4;
919
+ break;
920
+ }
921
+ this.logError('overwriteExistingOrder-入参缺少 order_id');
922
+ return _context8.abrupt("return", {
923
+ overwritten: false
924
+ });
925
+ case 4:
926
+ key = this.getIdKey(orderId);
927
+ if (this.store.map.has(key)) {
928
+ _context8.next = 8;
929
+ break;
930
+ }
931
+ this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
932
+ orderId: orderId
933
+ });
934
+ return _context8.abrupt("return", {
935
+ overwritten: false
936
+ });
937
+ case 8:
938
+ this.logInfo('overwriteExistingOrder-开始覆盖', {
939
+ orderId: orderId,
940
+ storeOrderCountBefore: this.store.list.length
941
+ });
942
+ normalizedFresh = this.normalizeOrderForMemoryList(fresh, 'overwriteExistingOrder.incoming');
943
+ existingOrder = this.store.map.get(key);
944
+ reconciledFresh = this.reconcileOverwriteOrderCollections(existingOrder, normalizedFresh);
945
+ this.store.list = this.store.list.map(function (order) {
946
+ var id = order === null || order === void 0 ? void 0 : order.order_id;
947
+ if (id === undefined || id === null) {
948
+ return _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
949
+ }
950
+ return _this8.getIdKey(id) === key ? reconciledFresh : _this8.normalizeOrderForMemoryList(order, 'overwriteExistingOrder.existingMemory');
951
+ });
952
+ this.syncOrdersMap();
953
+ _context8.next = 16;
954
+ return this.updateOrderInSQLite(reconciledFresh, 'overwriteExistingOrder');
955
+ case 16:
956
+ this.logInfo('overwriteExistingOrder-结束', {
957
+ orderId: orderId,
958
+ storeOrderCountAfter: this.store.list.length
959
+ });
960
+ _context8.next = 19;
961
+ return this.emitOrdersChanged([reconciledFresh], 'overwriteExistingOrder');
962
+ case 19:
963
+ return _context8.abrupt("return", {
964
+ overwritten: true
965
+ });
966
+ case 20:
967
+ case "end":
968
+ return _context8.stop();
969
+ }
970
+ }, _callee8, this);
971
+ }));
972
+ function overwriteExistingOrder(_x4) {
973
+ return _overwriteExistingOrder.apply(this, arguments);
974
+ }
975
+ return overwriteExistingOrder;
976
+ }()
977
+ /**
978
+ * 将远端拉取的订单合并进本地 store(已存在则更新,不存在则追加),落库并 emit onOrdersChanged。
979
+ * 供 /update/localOrder 等在「本地尚无该单」时写入新建单。
980
+ */
981
+ )
982
+ }, {
983
+ key: "upsertOrdersFromRemote",
984
+ value: (function () {
985
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
986
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
987
+ while (1) switch (_context9.prev = _context9.next) {
988
+ case 0:
989
+ if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
990
+ _context9.next = 3;
991
+ break;
992
+ }
993
+ this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
994
+ return _context9.abrupt("return");
995
+ case 3:
996
+ this.logInfo('upsertOrdersFromRemote-开始', {
997
+ count: freshOrders.length
998
+ });
999
+ _context9.next = 6;
1000
+ return this.mergeOrdersToStore(freshOrders, 'upsertOrdersFromRemote');
1001
+ case 6:
1002
+ case "end":
1003
+ return _context9.stop();
1004
+ }
1005
+ }, _callee9, this);
1006
+ }));
1007
+ function upsertOrdersFromRemote(_x5) {
1008
+ return _upsertOrdersFromRemote.apply(this, arguments);
1009
+ }
1010
+ return upsertOrdersFromRemote;
1011
+ }())
1012
+ }, {
1013
+ key: "markOrderSyncedByExternalSaleNumber",
1014
+ value: function () {
1015
+ var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1016
+ var _this9 = this,
1017
+ _existing$external_sa,
1018
+ _nextOrder$order_id;
1019
+ var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
1020
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1021
+ while (1) switch (_context10.prev = _context10.next) {
1022
+ case 0:
1023
+ externalSaleNumber = params.externalSaleNumber;
1024
+ if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
1025
+ _context10.next = 4;
1026
+ break;
1027
+ }
1028
+ this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
1029
+ return _context10.abrupt("return", {
1030
+ updated: false
1031
+ });
1032
+ case 4:
1033
+ key = this.getIdKey(externalSaleNumber);
1034
+ targetIndex = this.store.list.findIndex(function (order) {
1035
+ var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
1036
+ if (value === undefined || value === null || value === '') return false;
1037
+ return _this9.getIdKey(value) === key;
1038
+ });
1039
+ if (!(targetIndex < 0)) {
1040
+ _context10.next = 9;
1041
+ break;
1042
+ }
1043
+ this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
1044
+ external_sale_number: externalSaleNumber
1045
+ });
1046
+ return _context10.abrupt("return", {
1047
+ updated: false
1048
+ });
1049
+ case 9:
1050
+ existing = this.store.list[targetIndex];
1051
+ nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
1052
+ external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
1053
+ need_sync: 0
1054
+ }));
1055
+ storageKey = this.getOrderStorageKey(nextOrder) || key;
1056
+ this.store.list = this.store.list.map(function (order, index) {
1057
+ if (index !== targetIndex) return order;
1058
+ return nextOrder;
1059
+ });
1060
+ this.syncOrdersMap();
1061
+ _context10.next = 16;
1062
+ return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
1063
+ case 16:
1064
+ this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
1065
+ external_sale_number: externalSaleNumber,
1066
+ order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
1067
+ });
1068
+ _context10.next = 19;
1069
+ return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
1070
+ case 19:
1071
+ return _context10.abrupt("return", {
1072
+ updated: true,
1073
+ order: nextOrder
1074
+ });
1075
+ case 20:
1076
+ case "end":
1077
+ return _context10.stop();
1078
+ }
1079
+ }, _callee10, this);
1080
+ }));
1081
+ function markOrderSyncedByExternalSaleNumber(_x6) {
1082
+ return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
1083
+ }
1084
+ return markOrderSyncedByExternalSaleNumber;
1085
+ }()
1086
+ /**
1087
+ * 将本地待同步订单按 SQLite storage key 合并进 store 并落库。
1088
+ * checkout 离线兜底可能没有 order_id,但通常会有 external_sale_number。
1089
+ */
1090
+ }, {
1091
+ key: "upsertPendingSyncOrders",
1092
+ value: (function () {
1093
+ var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
1094
+ var _this10 = this;
1095
+ var pendingMap, memoryPendingMap, _iterator5, _step5, order, normalizedOrder, storageKey, mergeActions, updatedList, identityKeyToIndex, index, _iterator6, _step6, key, _iterator7, _step7, _step7$value, _storageKey, pendingOrder, matchIndex, existingOrder, mergedOrder, pendingSnapshot, insertIndex, patchedOrders;
1096
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1097
+ while (1) switch (_context11.prev = _context11.next) {
1098
+ case 0:
1099
+ if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
1100
+ _context11.next = 3;
1101
+ break;
1102
+ }
1103
+ this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
1104
+ return _context11.abrupt("return");
1105
+ case 3:
1106
+ pendingMap = new Map();
1107
+ memoryPendingMap = new Map();
1108
+ _iterator5 = _createForOfIteratorHelper(pendingOrders);
1109
+ _context11.prev = 6;
1110
+ _iterator5.s();
1111
+ case 8:
1112
+ if ((_step5 = _iterator5.n()).done) {
1113
+ _context11.next = 18;
1114
+ break;
1115
+ }
1116
+ order = _step5.value;
1117
+ normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'upsertPendingSyncOrders.incoming');
1118
+ storageKey = this.getOrderStorageKey(normalizedOrder);
1119
+ if (storageKey) {
1120
+ _context11.next = 14;
1121
+ break;
1122
+ }
1123
+ return _context11.abrupt("continue", 16);
1124
+ case 14:
1125
+ pendingMap.set(storageKey, normalizedOrder);
1126
+ memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(normalizedOrder, 'upsertPendingSyncOrders.memory'));
1127
+ case 16:
1128
+ _context11.next = 8;
1129
+ break;
1130
+ case 18:
1131
+ _context11.next = 23;
1132
+ break;
1133
+ case 20:
1134
+ _context11.prev = 20;
1135
+ _context11.t0 = _context11["catch"](6);
1136
+ _iterator5.e(_context11.t0);
1137
+ case 23:
1138
+ _context11.prev = 23;
1139
+ _iterator5.f();
1140
+ return _context11.finish(23);
1141
+ case 26:
1142
+ if (!(pendingMap.size === 0)) {
1143
+ _context11.next = 29;
1144
+ break;
1145
+ }
1146
+ this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1147
+ count: pendingOrders.length
1148
+ });
1149
+ return _context11.abrupt("return");
1150
+ case 29:
1151
+ this.logInfo('upsertPendingSyncOrders-开始', {
1152
+ count: pendingMap.size
1153
+ });
1154
+ mergeActions = {};
1155
+ updatedList = this.store.list.map(function (order) {
1156
+ return _this10.normalizeOrderForMemoryList(order, 'upsertPendingSyncOrders.existingMemory');
1157
+ }); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
1158
+ // 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
1159
+ identityKeyToIndex = new Map();
1160
+ for (index = 0; index < updatedList.length; index += 1) {
1161
+ _iterator6 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
1162
+ try {
1163
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1164
+ key = _step6.value;
1165
+ // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1166
+ if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1167
+ }
1168
+ } catch (err) {
1169
+ _iterator6.e(err);
1170
+ } finally {
1171
+ _iterator6.f();
1172
+ }
1173
+ }
1174
+ _iterator7 = _createForOfIteratorHelper(memoryPendingMap.entries());
1175
+ _context11.prev = 35;
1176
+ _iterator7.s();
1177
+ case 37:
1178
+ if ((_step7 = _iterator7.n()).done) {
1179
+ _context11.next = 55;
1180
+ break;
1181
+ }
1182
+ _step7$value = _slicedToArray(_step7.value, 2), _storageKey = _step7$value[0], pendingOrder = _step7$value[1];
1183
+ matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(pendingOrder));
1184
+ if (!(matchIndex >= 0)) {
1185
+ _context11.next = 49;
1186
+ break;
1187
+ }
1188
+ existingOrder = updatedList[matchIndex];
1189
+ mergedOrder = this.mergeOrderRecords(existingOrder, pendingOrder);
1190
+ updatedList[matchIndex] = mergedOrder;
1191
+ pendingSnapshot = pendingMap.get(_storageKey);
1192
+ if (pendingSnapshot) {
1193
+ pendingMap.set(_storageKey, this.reconcileOverwriteOrderCollections(existingOrder, pendingSnapshot));
1194
+ }
1195
+ // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
1196
+ this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
1197
+ mergeActions[_storageKey] = 'update';
1198
+ return _context11.abrupt("continue", 53);
1199
+ case 49:
1200
+ insertIndex = updatedList.length;
1201
+ updatedList.push(pendingOrder);
1202
+ this.registerOrderIdentityKeys(identityKeyToIndex, pendingOrder, insertIndex);
1203
+ mergeActions[_storageKey] = 'insert';
1204
+ case 53:
1205
+ _context11.next = 37;
1206
+ break;
1207
+ case 55:
1208
+ _context11.next = 60;
1209
+ break;
1210
+ case 57:
1211
+ _context11.prev = 57;
1212
+ _context11.t1 = _context11["catch"](35);
1213
+ _iterator7.e(_context11.t1);
1214
+ case 60:
1215
+ _context11.prev = 60;
1216
+ _iterator7.f();
1217
+ return _context11.finish(60);
1218
+ case 63:
1219
+ patchedOrders = _toConsumableArray(pendingMap.values()); // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
1220
+ this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
1221
+ this.syncOrdersMap();
1222
+ _context11.next = 68;
1223
+ return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
1224
+ case 68:
1225
+ this.logInfo('upsertPendingSyncOrders-结束', {
1226
+ count: patchedOrders.length,
1227
+ storeOrderCountAfter: this.store.list.length
1228
+ });
1229
+ _context11.next = 71;
1230
+ return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1231
+ case 71:
1232
+ case "end":
1233
+ return _context11.stop();
1234
+ }
1235
+ }, _callee11, this, [[6, 20, 23, 26], [35, 57, 60, 63]]);
1236
+ }));
1237
+ function upsertPendingSyncOrders(_x7) {
1238
+ return _upsertPendingSyncOrders.apply(this, arguments);
1239
+ }
1240
+ return upsertPendingSyncOrders;
1241
+ }()
1242
+ /**
1243
+ * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
1244
+ */
1245
+ )
1246
+ }, {
1247
+ key: "fetchOrdersBySSE",
1248
+ value: (function () {
1249
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1250
+ var query,
1251
+ data,
1252
+ _args12 = arguments;
1253
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1254
+ while (1) switch (_context12.prev = _context12.next) {
1255
+ case 0:
1256
+ query = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1257
+ if (this.orderDataSource) {
1258
+ _context12.next = 3;
1259
+ break;
1260
+ }
1261
+ return _context12.abrupt("return", []);
1262
+ case 3:
1263
+ _context12.prev = 3;
1264
+ _context12.next = 6;
1265
+ return this.orderDataSource.run({
1266
+ sse: {
1267
+ query: query
1268
+ }
1269
+ });
1270
+ case 6:
1271
+ data = _context12.sent;
1272
+ return _context12.abrupt("return", data || []);
1273
+ case 10:
1274
+ _context12.prev = 10;
1275
+ _context12.t0 = _context12["catch"](3);
1276
+ this.logError('fetchOrdersBySSE-失败', {
1277
+ error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0)
1278
+ });
1279
+ return _context12.abrupt("return", []);
1280
+ case 14:
1281
+ case "end":
1282
+ return _context12.stop();
1283
+ }
1284
+ }, _callee12, this, [[3, 10]]);
1285
+ }));
1286
+ function fetchOrdersBySSE() {
1287
+ return _fetchOrdersBySSE.apply(this, arguments);
1288
+ }
1289
+ return fetchOrdersBySSE;
1290
+ }())
291
1291
  }, {
292
1292
  key: "getRoutes",
293
1293
  value: function getRoutes() {
@@ -301,6 +1301,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
301
1301
  clearTimeout(this.syncTimer);
302
1302
  this.syncTimer = undefined;
303
1303
  }
1304
+ this.isProcessingSyncBatch = false;
304
1305
  this.pendingSyncMessages = [];
305
1306
  if ((_this$orderDataSource = this.orderDataSource) !== null && _this$orderDataSource !== void 0 && _this$orderDataSource.destroy) this.orderDataSource.destroy();
306
1307
  _get(_getPrototypeOf(OrderModule.prototype), "destroy", this).call(this);
@@ -308,72 +1309,104 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
308
1309
  }, {
309
1310
  key: "syncOrdersMap",
310
1311
  value: function syncOrdersMap() {
311
- var _this3 = this;
312
1312
  this.store.map.clear();
313
- this.resourceIdIndex.clear();
314
- var _iterator = _createForOfIteratorHelper(this.store.list),
315
- _step;
1313
+ var _iterator8 = _createForOfIteratorHelper(this.store.list),
1314
+ _step8;
316
1315
  try {
317
- var _loop = function _loop() {
318
- var order = _step.value;
319
- var id = order.order_id;
320
- if (id === undefined || id === null) return 1; // continue
321
- _this3.store.map.set(_this3.getIdKey(id), order);
322
- var resourceIds = _this3.extractResourceIds(order);
323
- var _iterator2 = _createForOfIteratorHelper(resourceIds),
324
- _step2;
325
- try {
326
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
327
- var resourceId = _step2.value;
328
- var key = String(resourceId);
329
- var existing = _this3.resourceIdIndex.get(key) || [];
330
- if (existing.some(function (eid) {
331
- return _this3.getIdKey(eid) === _this3.getIdKey(id);
332
- })) continue;
333
- existing.push(id);
334
- _this3.resourceIdIndex.set(key, existing);
335
- }
336
- } catch (err) {
337
- _iterator2.e(err);
338
- } finally {
339
- _iterator2.f();
340
- }
341
- };
342
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
343
- if (_loop()) continue;
1316
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1317
+ var order = _step8.value;
1318
+ var primaryIdentity = this.getOrderMapKey(order);
1319
+ if (!primaryIdentity) continue;
1320
+ this.store.map.set(primaryIdentity, order);
344
1321
  }
345
1322
  } catch (err) {
346
- _iterator.e(err);
1323
+ _iterator8.e(err);
347
1324
  } finally {
348
- _iterator.f();
1325
+ _iterator8.f();
349
1326
  }
350
1327
  }
351
1328
  }, {
352
- key: "extractResourceIds",
353
- value: function extractResourceIds(order) {
354
- var ids = new Set();
355
- var visitResources = function visitResources(resources) {
356
- if (!Array.isArray(resources)) return;
357
- resources.forEach(function (resource) {
358
- var rid = resource === null || resource === void 0 ? void 0 : resource.relation_id;
359
- if (rid !== undefined && rid !== null && rid !== '') ids.add(String(rid));
360
- if (Array.isArray(resource === null || resource === void 0 ? void 0 : resource.children)) visitResources(resource.children);
361
- });
362
- };
363
- if (Array.isArray(order === null || order === void 0 ? void 0 : order.bookings)) {
364
- order.bookings.forEach(function (booking) {
365
- return visitResources((booking === null || booking === void 0 ? void 0 : booking.resources) || []);
366
- });
1329
+ key: "getOrderMapKey",
1330
+ value: function getOrderMapKey(order) {
1331
+ if (!order) return '';
1332
+ if (!this.isBlankIdentityValue(order.order_id)) {
1333
+ return this.getIdKey(order.order_id);
367
1334
  }
368
- return _toConsumableArray(ids);
1335
+ var externalSaleNumber = order.external_sale_number;
1336
+ if (!this.isBlankIdentityValue(externalSaleNumber)) {
1337
+ return this.getIdKey(externalSaleNumber);
1338
+ }
1339
+ return '';
1340
+ }
1341
+ }, {
1342
+ key: "isBlankIdentityValue",
1343
+ value: function isBlankIdentityValue(value) {
1344
+ return value === undefined || value === null || value === '';
1345
+ }
1346
+ }, {
1347
+ key: "getOrderIdentityEntries",
1348
+ value: function getOrderIdentityEntries(order) {
1349
+ var _this11 = this;
1350
+ if (!order) return [];
1351
+ var record = order;
1352
+ var candidates = [{
1353
+ field: 'order_id',
1354
+ value: order.order_id
1355
+ }, {
1356
+ field: 'external_sale_number',
1357
+ value: record.external_sale_number
1358
+ }, {
1359
+ field: 'order_number',
1360
+ value: record.order_number
1361
+ }, {
1362
+ field: 'shop_order_number',
1363
+ value: record.shop_order_number
1364
+ }];
1365
+ var entries = [];
1366
+ var _loop = function _loop() {
1367
+ var candidate = _candidates[_i2];
1368
+ if (_this11.isBlankIdentityValue(candidate.value)) return 0; // continue
1369
+ var key = _this11.getIdKey(candidate.value);
1370
+ if (entries.some(function (entry) {
1371
+ return entry.field === candidate.field && entry.key === key;
1372
+ })) return 0; // continue
1373
+ entries.push({
1374
+ field: candidate.field,
1375
+ key: key
1376
+ });
1377
+ },
1378
+ _ret;
1379
+ for (var _i2 = 0, _candidates = candidates; _i2 < _candidates.length; _i2++) {
1380
+ _ret = _loop();
1381
+ if (_ret === 0) continue;
1382
+ }
1383
+ return entries;
1384
+ }
1385
+ }, {
1386
+ key: "getOrderIdentityKeys",
1387
+ value: function getOrderIdentityKeys(order) {
1388
+ var keys = [];
1389
+ var _iterator9 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1390
+ _step9;
1391
+ try {
1392
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1393
+ var entry = _step9.value;
1394
+ if (!keys.includes(entry.key)) keys.push(entry.key);
1395
+ }
1396
+ } catch (err) {
1397
+ _iterator9.e(err);
1398
+ } finally {
1399
+ _iterator9.f();
1400
+ }
1401
+ return keys;
369
1402
  }
370
1403
  }, {
371
1404
  key: "getOrderDateKey",
372
1405
  value: function getOrderDateKey(order) {
373
1406
  var _order$bookings, _order$bookings2;
374
1407
  var candidates = [order === null || order === void 0 ? void 0 : order.schedule_date, order === null || order === void 0 ? void 0 : order.create_date, order === null || order === void 0 ? void 0 : order.created_at, order === null || order === void 0 || (_order$bookings = order.bookings) === null || _order$bookings === void 0 || (_order$bookings = _order$bookings[0]) === null || _order$bookings === void 0 ? void 0 : _order$bookings.start_date, order === null || order === void 0 || (_order$bookings2 = order.bookings) === null || _order$bookings2 === void 0 || (_order$bookings2 = _order$bookings2[0]) === null || _order$bookings2 === void 0 ? void 0 : _order$bookings2.select_date];
375
- for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
376
- var v = _candidates[_i];
1408
+ for (var _i3 = 0, _candidates2 = candidates; _i3 < _candidates2.length; _i3++) {
1409
+ var v = _candidates2[_i3];
377
1410
  if (!v) continue;
378
1411
  var text = String(v);
379
1412
  if (!text) continue;
@@ -395,137 +1428,226 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
395
1428
  }
396
1429
 
397
1430
  /**
398
- * 初始化 pubsub 订阅,监听订单变更
1431
+ * 初始化 pubsub 订阅,监听订单变更(纯订阅,不拉数据;全量 SSE 由 loadOrdersByServer 负责)
399
1432
  */
400
1433
  }, {
401
1434
  key: "setupOrderSync",
402
1435
  value: function setupOrderSync() {
403
- var _this4 = this;
1436
+ var _this12 = this;
404
1437
  if (!this.orderDataSource) return;
405
- var shouldSkipHttpPull = this.hasPulledOrdersToday();
406
- var syncPayload = {
1438
+ this.orderDataSource.run({
407
1439
  pubsub: {
408
1440
  callback: function callback(res) {
409
- var message = _this4.normalizeOrderSyncMessage(res);
1441
+ var _message$id, _message$order_id, _message$type;
1442
+ console.log('orderDataSource', res);
1443
+ var pubsubReceivedAt = Date.now();
1444
+ var message = _this12.normalizeOrderSyncMessage(res);
410
1445
  if (!message) return;
411
- _this4.pendingSyncMessages.push(message);
412
- if (_this4.syncTimer) clearTimeout(_this4.syncTimer);
413
- _this4.syncTimer = setTimeout(function () {
414
- _this4.processOrderSyncMessages();
415
- }, _this4.ORDER_SYNC_DEBOUNCE_MS);
1446
+ message._pubsubReceivedAt = pubsubReceivedAt;
1447
+ _this12.pendingSyncMessages.push(message);
1448
+ var throttleMs = _this12.getOrderSyncThrottleMs();
1449
+ var routeInfo = _this12.resolveSyncMessageRoute(message);
1450
+ _this12.logInfo('orderSync-收到消息并入队', {
1451
+ id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
1452
+ order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
1453
+ type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
1454
+ pendingCount: _this12.pendingSyncMessages.length,
1455
+ throttleMs: throttleMs,
1456
+ pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
1457
+ fullMessage: JSON.stringify(message)
1458
+ });
1459
+ _this12.scheduleOrderSyncThrottle();
416
1460
  }
417
1461
  }
418
- };
419
- syncPayload.http = {
420
- query: this.store.createdAtQuery,
421
- skipHttp: shouldSkipHttpPull
422
- };
423
- this.orderDataSource.run(syncPayload).then(function () {
424
- if (!shouldSkipHttpPull) _this4.markOrderPulledAtNow();
425
1462
  }).catch(function () {
426
1463
  // 忽略同步初始化异常,避免影响主流程
427
1464
  });
428
1465
  }
429
1466
 
430
1467
  /**
431
- * 处理防抖后的同步消息批次
1468
+ * 调度订单同步节流窗口(leading-edge throttle):
1469
+ * - 空闲状态下收到的第一条消息立即触发批处理,无需等待;
1470
+ * - 首条处理后进入冷却窗口,窗口期间的后续消息聚合,窗口结束后批量处理;
1471
+ * - 若当前批处理执行中,则由批处理结束后决定是否开启下一轮窗口。
1472
+ */
1473
+ }, {
1474
+ key: "scheduleOrderSyncThrottle",
1475
+ value: function scheduleOrderSyncThrottle() {
1476
+ var _this13 = this;
1477
+ if (this.isProcessingSyncBatch) return;
1478
+ if (this.isIdlePhase) {
1479
+ this.isIdlePhase = false;
1480
+ this.logInfo('orderSync-首条消息立即触发处理');
1481
+ void this.flushOrderSyncMessagesByThrottle();
1482
+ return;
1483
+ }
1484
+ if (this.syncTimer) return;
1485
+ var throttleMs = this.getOrderSyncThrottleMs();
1486
+ this.syncTimer = setTimeout(function () {
1487
+ _this13.syncTimer = undefined;
1488
+ void _this13.flushOrderSyncMessagesByThrottle();
1489
+ }, throttleMs);
1490
+ }
1491
+
1492
+ /**
1493
+ * 执行一次节流批处理并在需要时续约下一轮窗口。
1494
+ * 批处理完成且无后续消息时恢复空闲状态,下一条消息将立即触发。
1495
+ */
1496
+ }, {
1497
+ key: "flushOrderSyncMessagesByThrottle",
1498
+ value: (function () {
1499
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1500
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1501
+ while (1) switch (_context13.prev = _context13.next) {
1502
+ case 0:
1503
+ if (!this.isProcessingSyncBatch) {
1504
+ _context13.next = 2;
1505
+ break;
1506
+ }
1507
+ return _context13.abrupt("return");
1508
+ case 2:
1509
+ if (!(this.pendingSyncMessages.length === 0)) {
1510
+ _context13.next = 5;
1511
+ break;
1512
+ }
1513
+ this.isIdlePhase = true;
1514
+ return _context13.abrupt("return");
1515
+ case 5:
1516
+ this.isProcessingSyncBatch = true;
1517
+ _context13.prev = 6;
1518
+ _context13.next = 9;
1519
+ return this.processOrderSyncMessages();
1520
+ case 9:
1521
+ _context13.prev = 9;
1522
+ this.isProcessingSyncBatch = false;
1523
+ if (this.pendingSyncMessages.length > 0) {
1524
+ this.scheduleOrderSyncThrottle();
1525
+ } else {
1526
+ this.isIdlePhase = true;
1527
+ }
1528
+ return _context13.finish(9);
1529
+ case 13:
1530
+ case "end":
1531
+ return _context13.stop();
1532
+ }
1533
+ }, _callee13, this, [[6,, 9, 13]]);
1534
+ }));
1535
+ function flushOrderSyncMessagesByThrottle() {
1536
+ return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
1537
+ }
1538
+ return flushOrderSyncMessagesByThrottle;
1539
+ }()
1540
+ /**
1541
+ * 处理节流窗口内聚合后的同步消息批次
432
1542
  *
433
1543
  * 后端统一发送 change 消息,不再区分新增/编辑/删除。
434
1544
  * - 单条(id/order_id):若携带 body/data 则直接 upsert 到本地
435
1545
  * - 批量(ids):通过 HTTP 按 ids 增量拉取,再 merge 到本地
1546
+ *
1547
+ * @example
1548
+ * // pending 队列中存在 8 条消息时,仅处理一次批次并统一 merge
1549
+ * await this.processOrderSyncMessages()
436
1550
  */
1551
+ )
437
1552
  }, {
438
1553
  key: "processOrderSyncMessages",
439
1554
  value: (function () {
440
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
441
- var messages, upsertOrders, refreshIds, _iterator3, _step3, _msg$id, _msg$relation_order_i, msg, hasBatchIds, singleId, hasSingleId, rawBody, normalizedBody, uniqueRefreshIds, upsertList, freshOrders;
442
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
443
- while (1) switch (_context4.prev = _context4.next) {
1555
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1556
+ var _this14 = this;
1557
+ var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
1558
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1559
+ while (1) switch (_context14.prev = _context14.next) {
444
1560
  case 0:
445
1561
  messages = _toConsumableArray(this.pendingSyncMessages);
446
1562
  this.pendingSyncMessages = [];
447
1563
  if (!(messages.length === 0)) {
448
- _context4.next = 4;
1564
+ _context14.next = 4;
449
1565
  break;
450
1566
  }
451
- return _context4.abrupt("return");
1567
+ return _context14.abrupt("return");
452
1568
  case 4:
1569
+ batchProcessStartAt = Date.now();
1570
+ earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
1571
+ var _m$_pubsubReceivedAt;
1572
+ return (_m$_pubsubReceivedAt = m._pubsubReceivedAt) !== null && _m$_pubsubReceivedAt !== void 0 ? _m$_pubsubReceivedAt : batchProcessStartAt;
1573
+ })));
1574
+ this.logInfo('processOrderSyncMessages-开始', {
1575
+ messageCount: messages.length,
1576
+ earliestReceivedAt: new Date(earliestReceivedAt).toISOString(),
1577
+ batchProcessStartAt: new Date(batchProcessStartAt).toISOString(),
1578
+ waitDurationMs: batchProcessStartAt - earliestReceivedAt
1579
+ });
453
1580
  upsertOrders = new Map();
454
1581
  refreshIds = [];
455
- _iterator3 = _createForOfIteratorHelper(messages);
456
- _context4.prev = 7;
457
- _iterator3.s();
458
- case 9:
459
- if ((_step3 = _iterator3.n()).done) {
460
- _context4.next = 22;
461
- break;
462
- }
463
- msg = _step3.value;
464
- hasBatchIds = Array.isArray(msg.ids) && msg.ids.length > 0;
465
- singleId = (_msg$id = msg.id) !== null && _msg$id !== void 0 ? _msg$id : msg.order_id;
466
- hasSingleId = !hasBatchIds && singleId !== undefined && singleId !== null;
467
- rawBody = msg.body || msg.data;
468
- normalizedBody = this.normalizeOrderSyncPayload(rawBody);
469
- if (!(hasSingleId && normalizedBody)) {
470
- _context4.next = 19;
471
- break;
472
- }
473
- upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
474
- return _context4.abrupt("continue", 20);
475
- case 19:
476
- if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.ids));else if (hasSingleId) refreshIds.push(singleId);else if ((_msg$relation_order_i = msg.relation_order_ids) !== null && _msg$relation_order_i !== void 0 && _msg$relation_order_i.length) refreshIds.push.apply(refreshIds, _toConsumableArray(msg.relation_order_ids));
477
- case 20:
478
- _context4.next = 9;
479
- break;
480
- case 22:
481
- _context4.next = 27;
482
- break;
483
- case 24:
484
- _context4.prev = 24;
485
- _context4.t0 = _context4["catch"](7);
486
- _iterator3.e(_context4.t0);
487
- case 27:
488
- _context4.prev = 27;
489
- _iterator3.f();
490
- return _context4.finish(27);
491
- case 30:
1582
+ messages.forEach(function (msg, msgIndex) {
1583
+ var routeInfo = _this14.resolveSyncMessageRoute(msg);
1584
+ var hasBatchIds = routeInfo.hasBatchIds;
1585
+ var singleId = routeInfo.singleId;
1586
+ var hasSingleId = routeInfo.hasSingleId;
1587
+ var normalizedBody = _this14.normalizeOrderSyncPayload(msg.body || msg.data);
1588
+ if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
1589
+ upsertOrders.set(_this14.getIdKey(normalizedBody.order_id), normalizedBody);
1590
+ return;
1591
+ }
1592
+ if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
1593
+ });
492
1594
  uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
493
1595
  upsertList = _toConsumableArray(upsertOrders.values());
1596
+ this.logInfo('processOrderSyncMessages-去重完成', {
1597
+ upsertCount: upsertList.length,
1598
+ refreshIdCount: uniqueRefreshIds.length
1599
+ });
494
1600
  if (!(upsertList.length > 0)) {
495
- _context4.next = 35;
1601
+ _context14.next = 16;
496
1602
  break;
497
1603
  }
498
- _context4.next = 35;
499
- return this.mergeOrdersToStore(upsertList);
500
- case 35:
1604
+ _context14.next = 16;
1605
+ return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
1606
+ case 16:
501
1607
  if (!(uniqueRefreshIds.length > 0)) {
502
- _context4.next = 42;
1608
+ _context14.next = 28;
503
1609
  break;
504
1610
  }
505
- _context4.next = 38;
506
- return this.fetchOrdersByHttp(uniqueRefreshIds);
507
- case 38:
508
- freshOrders = _context4.sent;
1611
+ _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
1612
+ if (skipped.length > 0) {}
1613
+ if (!(toFetch.length > 0)) {
1614
+ _context14.next = 28;
1615
+ break;
1616
+ }
1617
+ _context14.next = 22;
1618
+ return this.fetchOrdersByHttp(toFetch);
1619
+ case 22:
1620
+ freshOrders = _context14.sent;
509
1621
  if (!(freshOrders.length > 0)) {
510
- _context4.next = 42;
1622
+ _context14.next = 28;
511
1623
  break;
512
1624
  }
513
- _context4.next = 42;
514
- return this.mergeOrdersToStore(freshOrders);
515
- case 42:
1625
+ _context14.next = 26;
1626
+ return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
1627
+ case 26:
1628
+ _context14.next = 28;
1629
+ break;
1630
+ case 28:
516
1631
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
517
- _context4.next = 44;
1632
+ _context14.next = 30;
518
1633
  break;
519
1634
  }
520
- return _context4.abrupt("return");
521
- case 44:
522
- _context4.next = 46;
1635
+ return _context14.abrupt("return");
1636
+ case 30:
1637
+ batchProcessEndAt = Date.now();
1638
+ this.logInfo('processOrderSyncMessages-结束', {
1639
+ upsertCount: upsertList.length,
1640
+ refreshIdCount: uniqueRefreshIds.length,
1641
+ batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
1642
+ totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
1643
+ });
1644
+ _context14.next = 34;
523
1645
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
524
- case 46:
1646
+ case 34:
525
1647
  case "end":
526
- return _context4.stop();
1648
+ return _context14.stop();
527
1649
  }
528
- }, _callee4, this, [[7, 24, 27, 30]]);
1650
+ }, _callee14, this);
529
1651
  }));
530
1652
  function processOrderSyncMessages() {
531
1653
  return _processOrderSyncMessages.apply(this, arguments);
@@ -533,35 +1655,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
533
1655
  return processOrderSyncMessages;
534
1656
  }()
535
1657
  /**
536
- * 通过 HTTP 按 ids 增量拉取订单
1658
+ * 通过 HTTP 按 ids 批量拉取订单详情(走 orderDataSource)。
1659
+ *
1660
+ * - 优先使用 `orderDataSource.fetchOrdersByIds`(如适配器实现了该方法)
1661
+ * - 否则回退到 `orderDataSource.run({ http: { query: { ids } } })`
1662
+ * - 失败统一返回空数组(由调用方按"返回缺失的 id" 判断单笔失败)
1663
+ *
1664
+ * @example
1665
+ * const fresh = await orderModule.fetchOrdersByHttp(['96971', '96972'])
537
1666
  */
538
1667
  )
539
1668
  }, {
540
1669
  key: "fetchOrdersByHttp",
541
1670
  value: (function () {
542
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(ids) {
543
- var _orderList, orderList;
544
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
545
- while (1) switch (_context5.prev = _context5.next) {
1671
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
1672
+ var _orderList, orderList;
1673
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1674
+ while (1) switch (_context15.prev = _context15.next) {
546
1675
  case 0:
547
1676
  if (!(!this.orderDataSource || ids.length === 0)) {
548
- _context5.next = 2;
1677
+ _context15.next = 2;
549
1678
  break;
550
1679
  }
551
- return _context5.abrupt("return", []);
1680
+ return _context15.abrupt("return", []);
552
1681
  case 2:
553
- _context5.prev = 2;
1682
+ _context15.prev = 2;
554
1683
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
555
- _context5.next = 8;
1684
+ _context15.next = 8;
556
1685
  break;
557
1686
  }
558
- _context5.next = 6;
1687
+ _context15.next = 6;
559
1688
  return this.orderDataSource.fetchOrdersByIds(ids);
560
1689
  case 6:
561
- _orderList = _context5.sent;
562
- return _context5.abrupt("return", _orderList || []);
1690
+ _orderList = _context15.sent;
1691
+ return _context15.abrupt("return", _orderList || []);
563
1692
  case 8:
564
- _context5.next = 10;
1693
+ _context15.next = 10;
565
1694
  return this.orderDataSource.run({
566
1695
  http: {
567
1696
  query: {
@@ -570,19 +1699,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
570
1699
  }
571
1700
  });
572
1701
  case 10:
573
- orderList = _context5.sent;
574
- return _context5.abrupt("return", orderList || []);
1702
+ orderList = _context15.sent;
1703
+ return _context15.abrupt("return", orderList || []);
575
1704
  case 14:
576
- _context5.prev = 14;
577
- _context5.t0 = _context5["catch"](2);
578
- return _context5.abrupt("return", []);
1705
+ _context15.prev = 14;
1706
+ _context15.t0 = _context15["catch"](2);
1707
+ return _context15.abrupt("return", []);
579
1708
  case 17:
580
1709
  case "end":
581
- return _context5.stop();
1710
+ return _context15.stop();
582
1711
  }
583
- }, _callee5, this, [[2, 14]]);
1712
+ }, _callee15, this, [[2, 14]]);
584
1713
  }));
585
- function fetchOrdersByHttp(_x3) {
1714
+ function fetchOrdersByHttp(_x8) {
586
1715
  return _fetchOrdersByHttp.apply(this, arguments);
587
1716
  }
588
1717
  return fetchOrdersByHttp;
@@ -594,82 +1723,256 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
594
1723
  }, {
595
1724
  key: "mergeOrdersToStore",
596
1725
  value: (function () {
597
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(freshOrders) {
598
- var _this5 = this;
599
- var freshMap, _iterator4, _step4, order, id, updatedList, _iterator5, _step5, _order;
600
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
601
- while (1) switch (_context6.prev = _context6.next) {
1726
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
1727
+ var _this15 = this;
1728
+ var storeOrderCountBefore, normalizedFreshOrders, _iterator10, _step10, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator11, _step11, key, _iterator12, _step12, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, existingOrder, _ref2, _existingOrder$order_, _ref3, _external_sale_number2, _existingOrder$paymen, _fresh$payment_status, _existingOrder$need_s, _fresh$need_sync, mergedOrder, insertIndex, insertCount, updateCount;
1729
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1730
+ while (1) switch (_context16.prev = _context16.next) {
602
1731
  case 0:
603
- freshMap = new Map();
604
- _iterator4 = _createForOfIteratorHelper(freshOrders);
605
- _context6.prev = 2;
606
- _iterator4.s();
607
- case 4:
608
- if ((_step4 = _iterator4.n()).done) {
609
- _context6.next = 12;
1732
+ storeOrderCountBefore = this.store.list.length;
1733
+ this.logInfo('mergeOrdersToStore-开始', {
1734
+ freshOrderCount: freshOrders.length,
1735
+ storeOrderCountBefore: storeOrderCountBefore,
1736
+ source: source
1737
+ });
1738
+ this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
1739
+ normalizedFreshOrders = [];
1740
+ _iterator10 = _createForOfIteratorHelper(freshOrders);
1741
+ _context16.prev = 5;
1742
+ _iterator10.s();
1743
+ case 7:
1744
+ if ((_step10 = _iterator10.n()).done) {
1745
+ _context16.next = 15;
610
1746
  break;
611
1747
  }
612
- order = _step4.value;
1748
+ order = _step10.value;
613
1749
  id = order === null || order === void 0 ? void 0 : order.order_id;
614
1750
  if (!(id === undefined || id === null)) {
615
- _context6.next = 9;
1751
+ _context16.next = 12;
616
1752
  break;
617
1753
  }
618
- return _context6.abrupt("continue", 10);
619
- case 9:
620
- freshMap.set(this.getIdKey(id), order);
621
- case 10:
622
- _context6.next = 4;
623
- break;
1754
+ return _context16.abrupt("continue", 13);
624
1755
  case 12:
625
- _context6.next = 17;
1756
+ normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
1757
+ case 13:
1758
+ _context16.next = 7;
1759
+ break;
1760
+ case 15:
1761
+ _context16.next = 20;
626
1762
  break;
627
- case 14:
628
- _context6.prev = 14;
629
- _context6.t0 = _context6["catch"](2);
630
- _iterator4.e(_context6.t0);
631
1763
  case 17:
632
- _context6.prev = 17;
633
- _iterator4.f();
634
- return _context6.finish(17);
1764
+ _context16.prev = 17;
1765
+ _context16.t0 = _context16["catch"](5);
1766
+ _iterator10.e(_context16.t0);
635
1767
  case 20:
1768
+ _context16.prev = 20;
1769
+ _iterator10.f();
1770
+ return _context16.finish(20);
1771
+ case 23:
1772
+ // 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
1773
+ uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
1774
+ uniqueFreshCount = uniqueFreshOrders.length;
1775
+ patchedOrders = [];
1776
+ mergeActions = {};
636
1777
  updatedList = this.store.list.map(function (order) {
637
- var id = order.order_id;
638
- if (id === undefined || id === null) return order;
639
- var key = _this5.getIdKey(id);
640
- if (!freshMap.has(key)) return order;
641
- var fresh = freshMap.get(key);
642
- freshMap.delete(key);
643
- return fresh;
644
- });
645
- _iterator5 = _createForOfIteratorHelper(freshMap.values());
646
- try {
647
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
648
- _order = _step5.value;
649
- updatedList.push(_order);
1778
+ return _this15.normalizeOrderForMemoryList(order, "".concat(source, ".existingMemory"));
1779
+ }); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
1780
+ // 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
1781
+ // 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
1782
+ identityKeyToIndex = new Map();
1783
+ for (index = 0; index < updatedList.length; index += 1) {
1784
+ identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
1785
+ _iterator11 = _createForOfIteratorHelper(identityKeys);
1786
+ try {
1787
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
1788
+ key = _step11.value;
1789
+ // 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
1790
+ if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
1791
+ }
1792
+ } catch (err) {
1793
+ _iterator11.e(err);
1794
+ } finally {
1795
+ _iterator11.f();
650
1796
  }
651
- } catch (err) {
652
- _iterator5.e(err);
653
- } finally {
654
- _iterator5.f();
655
1797
  }
656
- this.store.list = updatedList;
1798
+ _iterator12 = _createForOfIteratorHelper(uniqueFreshOrders);
1799
+ _context16.prev = 31;
1800
+ _iterator12.s();
1801
+ case 33:
1802
+ if ((_step12 = _iterator12.n()).done) {
1803
+ _context16.next = 57;
1804
+ break;
1805
+ }
1806
+ fresh = _step12.value;
1807
+ freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
1808
+ matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
1809
+ storageKey = this.getOrderStorageKey(fresh);
1810
+ mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
1811
+ if (!(matchIndex >= 0)) {
1812
+ _context16.next = 50;
1813
+ break;
1814
+ }
1815
+ existingOrder = updatedList[matchIndex];
1816
+ if (!(this.isPendingSyncOrder(existingOrder) && this.isRemoteEchoMergeSource(source))) {
1817
+ _context16.next = 44;
1818
+ break;
1819
+ }
1820
+ this.logInfo('mergeOrdersToStore-跳过 pending 订单远端覆盖', {
1821
+ source: source,
1822
+ order_id: (_ref2 = (_existingOrder$order_ = existingOrder.order_id) !== null && _existingOrder$order_ !== void 0 ? _existingOrder$order_ : fresh.order_id) !== null && _ref2 !== void 0 ? _ref2 : null,
1823
+ external_sale_number: (_ref3 = (_external_sale_number2 = existingOrder.external_sale_number) !== null && _external_sale_number2 !== void 0 ? _external_sale_number2 : fresh.external_sale_number) !== null && _ref3 !== void 0 ? _ref3 : null,
1824
+ local_payment_status: (_existingOrder$paymen = existingOrder.payment_status) !== null && _existingOrder$paymen !== void 0 ? _existingOrder$paymen : null,
1825
+ remote_payment_status: (_fresh$payment_status = fresh.payment_status) !== null && _fresh$payment_status !== void 0 ? _fresh$payment_status : null,
1826
+ local_need_sync: (_existingOrder$need_s = existingOrder.need_sync) !== null && _existingOrder$need_s !== void 0 ? _existingOrder$need_s : null,
1827
+ remote_need_sync: (_fresh$need_sync = fresh.need_sync) !== null && _fresh$need_sync !== void 0 ? _fresh$need_sync : null,
1828
+ reason: 'protect_pending_sync_order_from_remote_echo'
1829
+ });
1830
+ return _context16.abrupt("continue", 55);
1831
+ case 44:
1832
+ mergedOrder = this.mergeOrderRecords(existingOrder, fresh);
1833
+ updatedList[matchIndex] = mergedOrder;
1834
+ // 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
1835
+ // 供同批后续 fresh 命中同一槽位,避免重复插入
1836
+ this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
1837
+ patchedOrders.push(mergedOrder);
1838
+ if (mergeKey) mergeActions[mergeKey] = 'update';
1839
+ return _context16.abrupt("continue", 55);
1840
+ case 50:
1841
+ insertIndex = updatedList.length;
1842
+ updatedList.push(fresh);
1843
+ this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
1844
+ patchedOrders.push(fresh);
1845
+ if (mergeKey) mergeActions[mergeKey] = 'insert';
1846
+ case 55:
1847
+ _context16.next = 33;
1848
+ break;
1849
+ case 57:
1850
+ _context16.next = 62;
1851
+ break;
1852
+ case 59:
1853
+ _context16.prev = 59;
1854
+ _context16.t1 = _context16["catch"](31);
1855
+ _iterator12.e(_context16.t1);
1856
+ case 62:
1857
+ _context16.prev = 62;
1858
+ _iterator12.f();
1859
+ return _context16.finish(62);
1860
+ case 65:
1861
+ insertCount = Object.values(mergeActions).filter(function (v) {
1862
+ return v === 'insert';
1863
+ }).length;
1864
+ updateCount = Object.values(mergeActions).filter(function (v) {
1865
+ return v === 'update';
1866
+ }).length;
1867
+ this.logInfo('mergeOrdersToStore-合并完成', {
1868
+ insertCount: insertCount,
1869
+ updateCount: updateCount,
1870
+ storeOrderCountAfter: this.store.list.length
1871
+ });
1872
+ // 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;
1873
+ // 仅在自检开关开启时做一次兜底校验。
1874
+ this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
657
1875
  this.syncOrdersMap();
658
- _context6.next = 27;
659
- return this.saveOrdersToSQLite(this.store.list);
660
- case 27:
661
- this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
662
- case 28:
1876
+ _context16.next = 72;
1877
+ return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1878
+ case 72:
1879
+ this.logInfo('mergeOrdersToStore-结束', {
1880
+ uniqueFreshCount: uniqueFreshCount,
1881
+ storeOrderCountAfter: this.store.list.length,
1882
+ insertCount: insertCount,
1883
+ updateCount: updateCount
1884
+ });
1885
+ _context16.next = 75;
1886
+ return this.emitOrdersChanged(patchedOrders, source);
1887
+ case 75:
663
1888
  case "end":
664
- return _context6.stop();
1889
+ return _context16.stop();
665
1890
  }
666
- }, _callee6, this, [[2, 14, 17, 20]]);
1891
+ }, _callee16, this, [[5, 17, 20, 23], [31, 59, 62, 65]]);
667
1892
  }));
668
- function mergeOrdersToStore(_x4) {
1893
+ function mergeOrdersToStore(_x9, _x10) {
669
1894
  return _mergeOrdersToStore.apply(this, arguments);
670
1895
  }
671
1896
  return mergeOrdersToStore;
672
- }())
1897
+ }()
1898
+ /**
1899
+ * 在身份索引中查找与目标订单共享任一身份键的已存在订单下标。
1900
+ * 返回所有命中键里最小的下标,等价于原 findOrderIndexByIdentity 的「取首个匹配」语义。
1901
+ *
1902
+ * @example
1903
+ * const idx = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys)
1904
+ */
1905
+ )
1906
+ }, {
1907
+ key: "lookupOrderIndexByIdentityKeys",
1908
+ value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
1909
+ var matchIndex = -1;
1910
+ var _iterator13 = _createForOfIteratorHelper(identityKeys),
1911
+ _step13;
1912
+ try {
1913
+ for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1914
+ var key = _step13.value;
1915
+ var index = identityKeyToIndex.get(key);
1916
+ if (index === undefined) continue;
1917
+ if (matchIndex < 0 || index < matchIndex) matchIndex = index;
1918
+ }
1919
+ } catch (err) {
1920
+ _iterator13.e(err);
1921
+ } finally {
1922
+ _iterator13.f();
1923
+ }
1924
+ return matchIndex;
1925
+ }
1926
+ }, {
1927
+ key: "isRemoteEchoMergeSource",
1928
+ value: function isRemoteEchoMergeSource(source) {
1929
+ return source === 'pubsub.bodyUpsert' || source === 'pubsub.httpRefresh';
1930
+ }
1931
+
1932
+ /**
1933
+ * 将订单的全部身份键登记到索引并指向其在列表中的下标。
1934
+ * 合并后订单新增的身份字段(如挂单同步后拿到 order_id)也会被登记。
1935
+ *
1936
+ * @example
1937
+ * this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex)
1938
+ */
1939
+ }, {
1940
+ key: "registerOrderIdentityKeys",
1941
+ value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
1942
+ var identityKeys = this.getOrderIdentityMatchKeys(order);
1943
+ var _iterator14 = _createForOfIteratorHelper(identityKeys),
1944
+ _step14;
1945
+ try {
1946
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1947
+ var key = _step14.value;
1948
+ identityKeyToIndex.set(key, index);
1949
+ }
1950
+ } catch (err) {
1951
+ _iterator14.e(err);
1952
+ } finally {
1953
+ _iterator14.f();
1954
+ }
1955
+ }
1956
+
1957
+ /**
1958
+ * 合并热路径去重兜底:默认直接返回原列表(增量索引已保证无重复)。
1959
+ * 仅当 ORDER_MERGE_SELF_CHECK 开启时,额外做一次全表压缩并在发现残留重复时告警。
1960
+ */
1961
+ }, {
1962
+ key: "runOrderStoreSelfCheck",
1963
+ value: function runOrderStoreSelfCheck(orders, source) {
1964
+ if (!ORDER_MERGE_SELF_CHECK) return orders;
1965
+ var _this$compactOrderLis = this.compactOrderListByIdentity(orders, source),
1966
+ list = _this$compactOrderLis.list,
1967
+ removedCount = _this$compactOrderLis.removedCount;
1968
+ if (removedCount > 0) {
1969
+ this.logWarning('合并自检发现残留重复订单,已压缩', {
1970
+ source: source,
1971
+ removedCount: removedCount
1972
+ });
1973
+ }
1974
+ return list;
1975
+ }
673
1976
  }, {
674
1977
  key: "normalizeOrderSyncMessage",
675
1978
  value: function normalizeOrderSyncMessage(res) {
@@ -702,17 +2005,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
702
2005
  key: "uniqueOrderIds",
703
2006
  value: function uniqueOrderIds(ids) {
704
2007
  var idMap = new Map();
705
- var _iterator6 = _createForOfIteratorHelper(ids),
706
- _step6;
2008
+ var _iterator15 = _createForOfIteratorHelper(ids),
2009
+ _step15;
707
2010
  try {
708
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
709
- var id = _step6.value;
2011
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2012
+ var id = _step15.value;
710
2013
  idMap.set(this.getIdKey(id), id);
711
2014
  }
712
2015
  } catch (err) {
713
- _iterator6.e(err);
2016
+ _iterator15.e(err);
714
2017
  } finally {
715
- _iterator6.f();
2018
+ _iterator15.f();
716
2019
  }
717
2020
  return _toConsumableArray(idMap.values());
718
2021
  }
@@ -721,6 +2024,238 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
721
2024
  value: function getIdKey(id) {
722
2025
  return String(id);
723
2026
  }
2027
+ }, {
2028
+ key: "isOrderLookupMatch",
2029
+ value: function isOrderLookupMatch(order, lookupKey) {
2030
+ var _this16 = this;
2031
+ if (!order || !lookupKey) return false;
2032
+ var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
2033
+ return candidates.some(function (value) {
2034
+ if (value === undefined || value === null || value === '') return false;
2035
+ return _this16.getIdKey(value) === lookupKey;
2036
+ });
2037
+ }
2038
+
2039
+ /**
2040
+ * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
2041
+ *
2042
+ * @example
2043
+ * const key = this.getOrderStorageKey({ order_id: 1001, external_sale_number: 'S-1001' })
2044
+ * // => 'S-1001'
2045
+ */
2046
+ }, {
2047
+ key: "getOrderStorageKey",
2048
+ value: function getOrderStorageKey(order) {
2049
+ var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
2050
+ if (externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '') {
2051
+ return String(externalSaleNumber);
2052
+ }
2053
+ var orderId = order === null || order === void 0 ? void 0 : order.order_id;
2054
+ if (orderId !== undefined && orderId !== null && orderId !== '') {
2055
+ return String(orderId);
2056
+ }
2057
+ return '';
2058
+ }
2059
+ }, {
2060
+ key: "getOrderIdentityMatchKeys",
2061
+ value: function getOrderIdentityMatchKeys(order) {
2062
+ return this.getOrderIdentityEntries(order).map(function (entry) {
2063
+ return "".concat(entry.field, ":").concat(entry.key);
2064
+ });
2065
+ }
2066
+ }, {
2067
+ key: "doOrdersShareIdentity",
2068
+ value: function doOrdersShareIdentity(left, right) {
2069
+ var leftKeys = new Set(this.getOrderIdentityMatchKeys(left));
2070
+ if (leftKeys.size === 0) return false;
2071
+ return this.getOrderIdentityMatchKeys(right).some(function (key) {
2072
+ return leftKeys.has(key);
2073
+ });
2074
+ }
2075
+ }, {
2076
+ key: "findOrderIndexByIdentity",
2077
+ value: function findOrderIndexByIdentity(orders, target) {
2078
+ var _this17 = this;
2079
+ if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
2080
+ return orders.findIndex(function (order) {
2081
+ return _this17.doOrdersShareIdentity(order, target);
2082
+ });
2083
+ }
2084
+ }, {
2085
+ key: "getOrderCompletenessScore",
2086
+ value: function getOrderCompletenessScore(order) {
2087
+ var record = order;
2088
+ var score = this.isPendingSyncOrder(order) ? 0 : 100;
2089
+ if (!this.isBlankIdentityValue(order.order_id) && order.order_id !== record.external_sale_number) score += 30;
2090
+ score += this.getOrderIdentityMatchKeys(order).length * 5;
2091
+ if (Array.isArray(order.products)) score += Math.min(order.products.length, 10);
2092
+ if (Array.isArray(order.bookings)) score += Math.min(order.bookings.length, 10);
2093
+ if (Array.isArray(order.payments)) score += Math.min(order.payments.length, 10);
2094
+ if (record.updated_at) score += 1;
2095
+ return score;
2096
+ }
2097
+ }, {
2098
+ key: "pickPreferredOrder",
2099
+ value: function pickPreferredOrder(left, right) {
2100
+ var leftScore = this.getOrderCompletenessScore(left);
2101
+ var rightScore = this.getOrderCompletenessScore(right);
2102
+ if (rightScore >= leftScore) return right;
2103
+ return left;
2104
+ }
2105
+ }, {
2106
+ key: "mergeOrderRecords",
2107
+ value: function mergeOrderRecords(existing, incoming) {
2108
+ var preferred = this.pickPreferredOrder(existing, incoming);
2109
+ var secondary = preferred === existing ? incoming : existing;
2110
+ var merged = _objectSpread(_objectSpread({}, secondary), preferred);
2111
+ var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
2112
+ var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'note', 'customer_id', 'customer_name', 'customer', 'holder', 'contacts_info', 'phone', 'email', 'relation_forms'];
2113
+ var mergedRecord = merged;
2114
+ var preferredRecord = preferred;
2115
+ var secondaryRecord = secondary;
2116
+ var existingRecord = existing;
2117
+ var incomingRecord = incoming;
2118
+ var childUidRemaps = [];
2119
+ for (var _i4 = 0, _fieldsToPreserve = fieldsToPreserve; _i4 < _fieldsToPreserve.length; _i4++) {
2120
+ var field = _fieldsToPreserve[_i4];
2121
+ if (!this.isBlankIdentityValue(preferredRecord[field])) {
2122
+ mergedRecord[field] = preferredRecord[field];
2123
+ continue;
2124
+ }
2125
+ if (!this.isBlankIdentityValue(secondaryRecord[field])) {
2126
+ mergedRecord[field] = secondaryRecord[field];
2127
+ }
2128
+ }
2129
+ for (var _i5 = 0, _incomingPatchFields = incomingPatchFields; _i5 < _incomingPatchFields.length; _i5++) {
2130
+ var _field = _incomingPatchFields[_i5];
2131
+ if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
2132
+ if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
2133
+ if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
2134
+ mergedRecord[_field] = cloneDeep(incomingRecord[_field]);
2135
+ }
2136
+
2137
+ // 子项数组遵循完整快照语义:incoming 自有且为数组(包括 [])时权威替换;
2138
+ // 字段缺席或不是数组时视为稀疏 patch,继续保留 existing。
2139
+ for (var _i6 = 0, _ORDER_AUTHORITATIVE_2 = ORDER_AUTHORITATIVE_COLLECTION_FIELDS; _i6 < _ORDER_AUTHORITATIVE_2.length; _i6++) {
2140
+ var _field2 = _ORDER_AUTHORITATIVE_2[_i6];
2141
+ if (Array.isArray(incomingRecord[_field2])) {
2142
+ mergedRecord[_field2] = this.mergeAuthoritativeOrderCollection(_field2, existingRecord[_field2], incomingRecord[_field2], childUidRemaps);
2143
+ continue;
2144
+ }
2145
+ if (Object.prototype.hasOwnProperty.call(existingRecord, _field2)) {
2146
+ mergedRecord[_field2] = cloneDeep(existingRecord[_field2]);
2147
+ } else {
2148
+ delete mergedRecord[_field2];
2149
+ }
2150
+ }
2151
+ if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
2152
+ merged.need_sync = 0;
2153
+ }
2154
+ return this.normalizeOrderCollectionsForIngress(applyOrderCollectionUidRemaps(merged, childUidRemaps), 'mergeOrderRecords');
2155
+ }
2156
+ }, {
2157
+ key: "summarizeDuplicateOrders",
2158
+ value: function summarizeDuplicateOrders(orders) {
2159
+ var groups = new Map();
2160
+ var _iterator16 = _createForOfIteratorHelper(orders),
2161
+ _step16;
2162
+ try {
2163
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2164
+ var order = _step16.value;
2165
+ var _iterator17 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
2166
+ _step17;
2167
+ try {
2168
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2169
+ var key = _step17.value;
2170
+ var group = groups.get(key) || [];
2171
+ group.push(order);
2172
+ groups.set(key, group);
2173
+ }
2174
+ } catch (err) {
2175
+ _iterator17.e(err);
2176
+ } finally {
2177
+ _iterator17.f();
2178
+ }
2179
+ }
2180
+ } catch (err) {
2181
+ _iterator16.e(err);
2182
+ } finally {
2183
+ _iterator16.f();
2184
+ }
2185
+ return _toConsumableArray(groups.entries()).filter(function (_ref4) {
2186
+ var _ref5 = _slicedToArray(_ref4, 2),
2187
+ group = _ref5[1];
2188
+ return group.length > 1;
2189
+ }).slice(0, 20).map(function (_ref6) {
2190
+ var _ref7 = _slicedToArray(_ref6, 2),
2191
+ key = _ref7[0],
2192
+ group = _ref7[1];
2193
+ return {
2194
+ key: key,
2195
+ count: group.length,
2196
+ orders: group.map(function (order) {
2197
+ var _order$order_id3, _external_sale_number3, _shop_order_number, _shop_full_order_numb, _order$need_sync;
2198
+ return {
2199
+ order_id: (_order$order_id3 = order.order_id) !== null && _order$order_id3 !== void 0 ? _order$order_id3 : null,
2200
+ external_sale_number: (_external_sale_number3 = order.external_sale_number) !== null && _external_sale_number3 !== void 0 ? _external_sale_number3 : null,
2201
+ shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
2202
+ shop_full_order_number: (_shop_full_order_numb = order.shop_full_order_number) !== null && _shop_full_order_numb !== void 0 ? _shop_full_order_numb : null,
2203
+ need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
2204
+ };
2205
+ })
2206
+ };
2207
+ });
2208
+ }
2209
+ }, {
2210
+ key: "logDuplicateOrders",
2211
+ value: function logDuplicateOrders(source, orders) {
2212
+ var duplicateGroups = this.summarizeDuplicateOrders(orders);
2213
+ if (duplicateGroups.length === 0) return;
2214
+ this.logWarning('检测到重复订单身份键', {
2215
+ source: source,
2216
+ duplicateGroupCount: duplicateGroups.length,
2217
+ duplicateGroups: duplicateGroups
2218
+ });
2219
+ }
2220
+ }, {
2221
+ key: "compactOrderListByIdentity",
2222
+ value: function compactOrderListByIdentity(orders, source) {
2223
+ var list = [];
2224
+ var removedCount = 0;
2225
+ var _iterator18 = _createForOfIteratorHelper(orders),
2226
+ _step18;
2227
+ try {
2228
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2229
+ var order = _step18.value;
2230
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, "".concat(source, ".order"));
2231
+ var matchIndex = this.findOrderIndexByIdentity(list, normalizedOrder);
2232
+ if (matchIndex < 0) {
2233
+ list.push(normalizedOrder);
2234
+ continue;
2235
+ }
2236
+ list[matchIndex] = this.mergeOrderRecords(list[matchIndex], normalizedOrder);
2237
+ removedCount += 1;
2238
+ }
2239
+ } catch (err) {
2240
+ _iterator18.e(err);
2241
+ } finally {
2242
+ _iterator18.f();
2243
+ }
2244
+ if (removedCount > 0) {
2245
+ this.logWarning('订单列表重复项已压缩', {
2246
+ source: source,
2247
+ beforeCount: orders.length,
2248
+ afterCount: list.length,
2249
+ removedCount: removedCount
2250
+ });
2251
+ } else {
2252
+ this.logDuplicateOrders(source, orders);
2253
+ }
2254
+ return {
2255
+ list: list,
2256
+ removedCount: removedCount
2257
+ };
2258
+ }
724
2259
 
725
2260
  /**
726
2261
  * 当前订单拉取窗口:
@@ -730,9 +2265,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
730
2265
  }, {
731
2266
  key: "getCurrentPullWindow",
732
2267
  value: function getCurrentPullWindow() {
733
- var _this$store;
2268
+ var _this$store2;
734
2269
  var now = dayjs();
735
- var range = (_this$store = this.store) === null || _this$store === void 0 || (_this$store = _this$store.createdAtQuery) === null || _this$store === void 0 ? void 0 : _this$store.sales_time_between;
2270
+ var range = (_this$store2 = this.store) === null || _this$store2 === void 0 || (_this$store2 = _this$store2.createdAtQuery) === null || _this$store2 === void 0 ? void 0 : _this$store2.sales_time_between;
736
2271
  if (Array.isArray(range) && range.length >= 2) {
737
2272
  var _startAt = dayjs(range[0]);
738
2273
  var endExclusiveAt = dayjs(range[1]);
@@ -778,7 +2313,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
778
2313
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
779
2314
  return globalThis.localStorage.getItem(key);
780
2315
  }
781
- } catch (_unused5) {
2316
+ } catch (_unused6) {
782
2317
  // 忽略存储异常,避免影响主流程
783
2318
  }
784
2319
  return null;
@@ -795,39 +2330,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
795
2330
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
796
2331
  globalThis.localStorage.setItem(key, value);
797
2332
  }
798
- } catch (_unused6) {
2333
+ } catch (_unused7) {
799
2334
  // 忽略存储异常,避免影响主流程
800
2335
  }
801
2336
  }
802
2337
  }, {
803
2338
  key: "loadOrdersFromSQLite",
804
2339
  value: function () {
805
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
2340
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2341
+ var _this18 = this;
806
2342
  var orders;
807
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
808
- while (1) switch (_context7.prev = _context7.next) {
2343
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2344
+ while (1) switch (_context17.prev = _context17.next) {
809
2345
  case 0:
810
2346
  if (this.dbManager) {
811
- _context7.next = 2;
2347
+ _context17.next = 2;
812
2348
  break;
813
2349
  }
814
- return _context7.abrupt("return", []);
2350
+ return _context17.abrupt("return", []);
815
2351
  case 2:
816
- _context7.prev = 2;
817
- _context7.next = 5;
2352
+ _context17.prev = 2;
2353
+ _context17.next = 5;
818
2354
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
819
2355
  case 5:
820
- orders = _context7.sent;
821
- return _context7.abrupt("return", orders || []);
2356
+ orders = _context17.sent;
2357
+ return _context17.abrupt("return", (orders || []).map(function (order) {
2358
+ return _this18.normalizeOrderCollectionsForIngress(order, 'loadOrdersFromSQLite');
2359
+ }));
822
2360
  case 9:
823
- _context7.prev = 9;
824
- _context7.t0 = _context7["catch"](2);
825
- return _context7.abrupt("return", []);
2361
+ _context17.prev = 9;
2362
+ _context17.t0 = _context17["catch"](2);
2363
+ return _context17.abrupt("return", []);
826
2364
  case 12:
827
2365
  case "end":
828
- return _context7.stop();
2366
+ return _context17.stop();
829
2367
  }
830
- }, _callee7, this, [[2, 9]]);
2368
+ }, _callee17, this, [[2, 9]]);
831
2369
  }));
832
2370
  function loadOrdersFromSQLite() {
833
2371
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -835,82 +2373,493 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
835
2373
  return loadOrdersFromSQLite;
836
2374
  }()
837
2375
  }, {
838
- key: "saveOrdersToSQLite",
839
- value: function () {
840
- var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderList) {
841
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
842
- while (1) switch (_context8.prev = _context8.next) {
2376
+ key: "isPendingSyncOrder",
2377
+ value: function isPendingSyncOrder(order) {
2378
+ return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
2379
+ }
2380
+ }, {
2381
+ key: "normalizeRemoteSyncedOrder",
2382
+ value: function normalizeRemoteSyncedOrder(order) {
2383
+ var normalizedOrder = this.normalizeOrderCollectionsForIngress(order, 'normalizeRemoteSyncedOrder');
2384
+ if (this.isPendingSyncOrder(normalizedOrder)) return normalizedOrder;
2385
+ return _objectSpread(_objectSpread({}, normalizedOrder), {}, {
2386
+ need_sync: 0
2387
+ });
2388
+ }
2389
+ }, {
2390
+ key: "mergeRemoteSnapshotWithPendingOrders",
2391
+ value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
2392
+ var _this19 = this;
2393
+ var merged = remoteOrders.map(function (order) {
2394
+ return _this19.normalizeRemoteSyncedOrder(order);
2395
+ });
2396
+ var _iterator19 = _createForOfIteratorHelper(existingOrders),
2397
+ _step19;
2398
+ try {
2399
+ for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
2400
+ var rawOrder = _step19.value;
2401
+ var order = this.normalizeOrderCollectionsForIngress(rawOrder, 'mergeRemoteSnapshotWithPendingOrders.existingSQLite');
2402
+ if (!this.isPendingSyncOrder(order)) continue;
2403
+ var matchIndex = this.findOrderIndexByIdentity(merged, order);
2404
+ if (matchIndex >= 0) {
2405
+ merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
2406
+ continue;
2407
+ }
2408
+ if (!this.getOrderStorageKey(order)) continue;
2409
+ merged.push(order);
2410
+ }
2411
+ } catch (err) {
2412
+ _iterator19.e(err);
2413
+ } finally {
2414
+ _iterator19.f();
2415
+ }
2416
+ return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
2417
+ }
2418
+
2419
+ /**
2420
+ * 串行执行订单 SQLite 写入任务,避免快照替换与增量 upsert 并发交错。
2421
+ *
2422
+ * @example
2423
+ * await this.runInOrderSQLiteSaveQueue(async () => {
2424
+ * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders)
2425
+ * })
2426
+ */
2427
+ }, {
2428
+ key: "runInOrderSQLiteSaveQueue",
2429
+ value: (function () {
2430
+ var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
2431
+ var queuedTask;
2432
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2433
+ while (1) switch (_context18.prev = _context18.next) {
843
2434
  case 0:
844
- if (this.dbManager) {
845
- _context8.next = 2;
2435
+ queuedTask = this.orderSQLiteSaveQueue.then(task, task);
2436
+ this.orderSQLiteSaveQueue = queuedTask.then(function () {
2437
+ return undefined;
2438
+ }, function () {
2439
+ return undefined;
2440
+ });
2441
+ return _context18.abrupt("return", queuedTask);
2442
+ case 3:
2443
+ case "end":
2444
+ return _context18.stop();
2445
+ }
2446
+ }, _callee18, this);
2447
+ }));
2448
+ function runInOrderSQLiteSaveQueue(_x11) {
2449
+ return _runInOrderSQLiteSaveQueue.apply(this, arguments);
2450
+ }
2451
+ return runInOrderSQLiteSaveQueue;
2452
+ }()
2453
+ /**
2454
+ * 批量增量 upsert 订单到 SQLite,不清空表;用于 pubsub / HTTP 增量合并。
2455
+ *
2456
+ * @example
2457
+ * await this.patchOrdersInSQLite(freshOrders)
2458
+ */
2459
+ )
2460
+ }, {
2461
+ key: "patchOrdersInSQLite",
2462
+ value: (function () {
2463
+ var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
2464
+ var _this20 = this;
2465
+ var mergeActions,
2466
+ ordersSnapshot,
2467
+ _this$filterRedundant2,
2468
+ toWrite,
2469
+ skipped,
2470
+ compactedToWrite,
2471
+ _args20 = arguments;
2472
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2473
+ while (1) switch (_context20.prev = _context20.next) {
2474
+ case 0:
2475
+ mergeActions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2476
+ if (!(!this.dbManager || orders.length === 0)) {
2477
+ _context20.next = 3;
846
2478
  break;
847
2479
  }
848
- return _context8.abrupt("return");
849
- case 2:
850
- _context8.prev = 2;
851
- _context8.next = 5;
852
- return this.dbManager.clear(INDEXDB_STORE_NAME);
853
- case 5:
854
- if (!(orderList.length === 0)) {
855
- _context8.next = 7;
2480
+ return _context20.abrupt("return");
2481
+ case 3:
2482
+ ordersSnapshot = cloneDeep(orders).map(function (order) {
2483
+ return _this20.normalizeOrderCollectionsForIngress(order, "".concat(source, ".sqliteIngress"));
2484
+ }).filter(function (order) {
2485
+ return _this20.getOrderStorageKey(order);
2486
+ });
2487
+ if (!(ordersSnapshot.length === 0)) {
2488
+ _context20.next = 6;
856
2489
  break;
857
2490
  }
858
- return _context8.abrupt("return");
859
- case 7:
860
- _context8.next = 9;
861
- return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
2491
+ return _context20.abrupt("return");
2492
+ case 6:
2493
+ _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
2494
+ if (!(toWrite.length === 0)) {
2495
+ _context20.next = 9;
2496
+ break;
2497
+ }
2498
+ return _context20.abrupt("return");
862
2499
  case 9:
863
- _context8.next = 14;
2500
+ compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
2501
+ if (!(compactedToWrite.length === 0)) {
2502
+ _context20.next = 12;
2503
+ break;
2504
+ }
2505
+ return _context20.abrupt("return");
2506
+ case 12:
2507
+ _context20.prev = 12;
2508
+ _context20.next = 15;
2509
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2510
+ var writeMethod, _iterator20, _step20, order;
2511
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2512
+ while (1) switch (_context19.prev = _context19.next) {
2513
+ case 0:
2514
+ writeMethod = 'none';
2515
+ _this20.logInfo('patchOrdersInSQLite-开始', {
2516
+ source: source,
2517
+ count: compactedToWrite.length,
2518
+ dedupedCount: skipped.length
2519
+ });
2520
+ if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
2521
+ _context19.next = 8;
2522
+ break;
2523
+ }
2524
+ writeMethod = 'bulkUpdate';
2525
+ _context19.next = 6;
2526
+ return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2527
+ case 6:
2528
+ _context19.next = 33;
2529
+ break;
2530
+ case 8:
2531
+ if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
2532
+ _context19.next = 14;
2533
+ break;
2534
+ }
2535
+ writeMethod = 'bulkAdd';
2536
+ _context19.next = 12;
2537
+ return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2538
+ case 12:
2539
+ _context19.next = 33;
2540
+ break;
2541
+ case 14:
2542
+ if (!(typeof _this20.dbManager.update === 'function')) {
2543
+ _context19.next = 33;
2544
+ break;
2545
+ }
2546
+ writeMethod = 'update';
2547
+ _iterator20 = _createForOfIteratorHelper(compactedToWrite);
2548
+ _context19.prev = 17;
2549
+ _iterator20.s();
2550
+ case 19:
2551
+ if ((_step20 = _iterator20.n()).done) {
2552
+ _context19.next = 25;
2553
+ break;
2554
+ }
2555
+ order = _step20.value;
2556
+ _context19.next = 23;
2557
+ return _this20.dbManager.update(INDEXDB_STORE_NAME, order);
2558
+ case 23:
2559
+ _context19.next = 19;
2560
+ break;
2561
+ case 25:
2562
+ _context19.next = 30;
2563
+ break;
2564
+ case 27:
2565
+ _context19.prev = 27;
2566
+ _context19.t0 = _context19["catch"](17);
2567
+ _iterator20.e(_context19.t0);
2568
+ case 30:
2569
+ _context19.prev = 30;
2570
+ _iterator20.f();
2571
+ return _context19.finish(30);
2572
+ case 33:
2573
+ _this20.recordRecentSqliteWrite(source, compactedToWrite);
2574
+ _this20.logInfo('patchOrdersInSQLite-完成', {
2575
+ source: source,
2576
+ count: compactedToWrite.length,
2577
+ writeMethod: writeMethod,
2578
+ dedupedCount: skipped.length
2579
+ });
2580
+ case 35:
2581
+ case "end":
2582
+ return _context19.stop();
2583
+ }
2584
+ }, _callee19, null, [[17, 27, 30, 33]]);
2585
+ })));
2586
+ case 15:
2587
+ _context20.next = 20;
2588
+ break;
2589
+ case 17:
2590
+ _context20.prev = 17;
2591
+ _context20.t0 = _context20["catch"](12);
2592
+ this.logError('增量保存订单到 SQLite 失败', {
2593
+ error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
2594
+ orderCount: ordersSnapshot.length
2595
+ });
2596
+ case 20:
2597
+ case "end":
2598
+ return _context20.stop();
2599
+ }
2600
+ }, _callee20, this, [[12, 17]]);
2601
+ }));
2602
+ function patchOrdersInSQLite(_x12, _x13) {
2603
+ return _patchOrdersInSQLite.apply(this, arguments);
2604
+ }
2605
+ return patchOrdersInSQLite;
2606
+ }()
2607
+ /**
2608
+ * 单条 upsert 订单到 SQLite;用于 overwriteExistingOrder 等单条覆盖场景。
2609
+ *
2610
+ * @example
2611
+ * await this.updateOrderInSQLite(freshOrder)
2612
+ */
2613
+ )
2614
+ }, {
2615
+ key: "updateOrderInSQLite",
2616
+ value: (function () {
2617
+ var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
2618
+ var _this21 = this;
2619
+ var orderSnapshot, _orderSnapshot$order_3;
2620
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2621
+ while (1) switch (_context22.prev = _context22.next) {
2622
+ case 0:
2623
+ if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
2624
+ _context22.next = 2;
2625
+ break;
2626
+ }
2627
+ return _context22.abrupt("return");
2628
+ case 2:
2629
+ orderSnapshot = this.normalizeOrderCollectionsForIngress(cloneDeep(order), "".concat(source, ".sqliteIngress"));
2630
+ _context22.prev = 3;
2631
+ _context22.next = 6;
2632
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2633
+ var _orderSnapshot$order_, _orderSnapshot$order_2;
2634
+ var writeMethod;
2635
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2636
+ while (1) switch (_context21.prev = _context21.next) {
2637
+ case 0:
2638
+ writeMethod = 'none';
2639
+ _this21.logInfo('updateOrderInSQLite-开始', {
2640
+ source: source,
2641
+ orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2642
+ storageKey: _this21.getOrderStorageKey(orderSnapshot)
2643
+ });
2644
+ if (!(typeof _this21.dbManager.update === 'function')) {
2645
+ _context21.next = 8;
2646
+ break;
2647
+ }
2648
+ writeMethod = 'update';
2649
+ _context21.next = 6;
2650
+ return _this21.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2651
+ case 6:
2652
+ _context21.next = 18;
2653
+ break;
2654
+ case 8:
2655
+ if (!(typeof _this21.dbManager.bulkUpdate === 'function')) {
2656
+ _context21.next = 14;
2657
+ break;
2658
+ }
2659
+ writeMethod = 'bulkUpdate';
2660
+ _context21.next = 12;
2661
+ return _this21.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2662
+ case 12:
2663
+ _context21.next = 18;
2664
+ break;
2665
+ case 14:
2666
+ if (!(typeof _this21.dbManager.bulkAdd === 'function')) {
2667
+ _context21.next = 18;
2668
+ break;
2669
+ }
2670
+ writeMethod = 'bulkAdd';
2671
+ _context21.next = 18;
2672
+ return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2673
+ case 18:
2674
+ _this21.recordRecentSqliteWrite(source, [orderSnapshot]);
2675
+ _this21.logInfo('updateOrderInSQLite-完成', {
2676
+ source: source,
2677
+ orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
2678
+ writeMethod: writeMethod
2679
+ });
2680
+ case 20:
2681
+ case "end":
2682
+ return _context21.stop();
2683
+ }
2684
+ }, _callee21);
2685
+ })));
2686
+ case 6:
2687
+ _context22.next = 11;
864
2688
  break;
2689
+ case 8:
2690
+ _context22.prev = 8;
2691
+ _context22.t0 = _context22["catch"](3);
2692
+ this.logError('单条保存订单到 SQLite 失败', {
2693
+ error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
2694
+ orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
2695
+ });
865
2696
  case 11:
866
- _context8.prev = 11;
867
- _context8.t0 = _context8["catch"](2);
868
- // SQLite 异常,避免影响主流程
869
- this.logError('保存订单到 SQLite 失败', {
870
- error: _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0),
871
- orderList: orderList.length
2697
+ case "end":
2698
+ return _context22.stop();
2699
+ }
2700
+ }, _callee22, this, [[3, 8]]);
2701
+ }));
2702
+ function updateOrderInSQLite(_x14, _x15) {
2703
+ return _updateOrderInSQLite.apply(this, arguments);
2704
+ }
2705
+ return updateOrderInSQLite;
2706
+ }()
2707
+ /**
2708
+ * 全量快照替换 orders 表(clear + bulkAdd),用于 SSE 全量拉取与营业日窗口裁剪。
2709
+ *
2710
+ * @example
2711
+ * await this.replaceOrdersSnapshotInSQLite(orderList)
2712
+ */
2713
+ )
2714
+ }, {
2715
+ key: "replaceOrdersSnapshotInSQLite",
2716
+ value: (function () {
2717
+ var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
2718
+ var _this22 = this;
2719
+ var remoteSnapshot, mergedSnapshot;
2720
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2721
+ while (1) switch (_context24.prev = _context24.next) {
2722
+ case 0:
2723
+ if (this.dbManager) {
2724
+ _context24.next = 2;
2725
+ break;
2726
+ }
2727
+ return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
2728
+ return _this22.normalizeRemoteSyncedOrder(order);
2729
+ }), "".concat(source, ".snapshotNoDb")).list);
2730
+ case 2:
2731
+ remoteSnapshot = cloneDeep(orderList).map(function (order) {
2732
+ return _this22.normalizeOrderCollectionsForIngress(order, "".concat(source, ".remoteIngress"));
872
2733
  });
873
- case 14:
2734
+ mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
2735
+ return _this22.normalizeRemoteSyncedOrder(order);
2736
+ }), "".concat(source, ".remoteSnapshot")).list;
2737
+ _context24.prev = 4;
2738
+ _context24.next = 7;
2739
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2740
+ var existingOrders, orderListSnapshot;
2741
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2742
+ while (1) switch (_context23.prev = _context23.next) {
2743
+ case 0:
2744
+ if (!(typeof _this22.dbManager.getAll === 'function')) {
2745
+ _context23.next = 6;
2746
+ break;
2747
+ }
2748
+ _context23.next = 3;
2749
+ return _this22.dbManager.getAll(INDEXDB_STORE_NAME);
2750
+ case 3:
2751
+ _context23.t0 = _context23.sent;
2752
+ _context23.next = 7;
2753
+ break;
2754
+ case 6:
2755
+ _context23.t0 = [];
2756
+ case 7:
2757
+ existingOrders = _context23.t0;
2758
+ orderListSnapshot = _this22.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2759
+ mergedSnapshot = _this22.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2760
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2761
+ source: source,
2762
+ count: mergedSnapshot.length,
2763
+ remoteCount: remoteSnapshot.length,
2764
+ preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
2765
+ });
2766
+ _context23.next = 13;
2767
+ return _this22.dbManager.clear(INDEXDB_STORE_NAME);
2768
+ case 13:
2769
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2770
+ count: mergedSnapshot.length
2771
+ });
2772
+ if (!(mergedSnapshot.length === 0)) {
2773
+ _context23.next = 16;
2774
+ break;
2775
+ }
2776
+ return _context23.abrupt("return");
2777
+ case 16:
2778
+ _context23.next = 18;
2779
+ return _this22.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2780
+ case 18:
2781
+ _this22.recordRecentSqliteWrite(source, mergedSnapshot);
2782
+ _this22.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2783
+ source: source,
2784
+ count: mergedSnapshot.length
2785
+ });
2786
+ case 20:
2787
+ case "end":
2788
+ return _context23.stop();
2789
+ }
2790
+ }, _callee23);
2791
+ })));
2792
+ case 7:
2793
+ _context24.next = 12;
2794
+ break;
2795
+ case 9:
2796
+ _context24.prev = 9;
2797
+ _context24.t0 = _context24["catch"](4);
2798
+ this.logError('全量保存订单到 SQLite 失败', {
2799
+ error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
2800
+ orderList: remoteSnapshot.length
2801
+ });
2802
+ case 12:
2803
+ return _context24.abrupt("return", mergedSnapshot);
2804
+ case 13:
874
2805
  case "end":
875
- return _context8.stop();
2806
+ return _context24.stop();
876
2807
  }
877
- }, _callee8, this, [[2, 11]]);
2808
+ }, _callee24, this, [[4, 9]]);
878
2809
  }));
879
- function saveOrdersToSQLite(_x5) {
880
- return _saveOrdersToSQLite.apply(this, arguments);
2810
+ function replaceOrdersSnapshotInSQLite(_x16, _x17) {
2811
+ return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
881
2812
  }
882
- return saveOrdersToSQLite;
2813
+ return replaceOrdersSnapshotInSQLite;
883
2814
  }()
2815
+ /**
2816
+ * 清空订单模块的内存数据和本地 SQLite 订单表。
2817
+ *
2818
+ * @example
2819
+ * await orderModule.clear()
2820
+ */
2821
+ )
884
2822
  }, {
885
2823
  key: "clear",
886
- value: function () {
887
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
888
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
889
- while (1) switch (_context9.prev = _context9.next) {
2824
+ value: (function () {
2825
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2826
+ var _this23 = this;
2827
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2828
+ while (1) switch (_context26.prev = _context26.next) {
890
2829
  case 0:
891
2830
  this.store.list = [];
892
2831
  this.store.map = new Map();
893
- this.resourceIdIndex.clear();
894
2832
  if (!this.dbManager) {
895
- _context9.next = 6;
2833
+ _context26.next = 5;
896
2834
  break;
897
2835
  }
898
- _context9.next = 6;
899
- return this.dbManager.clear(INDEXDB_STORE_NAME);
900
- case 6:
2836
+ _context26.next = 5;
2837
+ return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2838
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2839
+ while (1) switch (_context25.prev = _context25.next) {
2840
+ case 0:
2841
+ _context25.next = 2;
2842
+ return _this23.dbManager.clear(INDEXDB_STORE_NAME);
2843
+ case 2:
2844
+ case "end":
2845
+ return _context25.stop();
2846
+ }
2847
+ }, _callee25);
2848
+ })));
2849
+ case 5:
901
2850
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
902
- this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
903
- case 8:
2851
+ this.emitOrdersChanged([], 'clear');
2852
+ case 7:
904
2853
  case "end":
905
- return _context9.stop();
2854
+ return _context26.stop();
906
2855
  }
907
- }, _callee9, this);
2856
+ }, _callee26, this);
908
2857
  }));
909
2858
  function clear() {
910
2859
  return _clear.apply(this, arguments);
911
2860
  }
912
2861
  return clear;
913
- }()
2862
+ }())
914
2863
  }]);
915
2864
  return OrderModule;
916
2865
  }(BaseModule);