@pisell/pisellos 2.2.243 → 2.2.244

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 (315) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +2 -3
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/utils.js +4 -7
  4. package/dist/modules/Cart/utils/cartProduct.js +3 -24
  5. package/dist/modules/Cart/utils/changePrice.js +11 -11
  6. package/dist/modules/Customer/index.d.ts +0 -20
  7. package/dist/modules/Customer/index.js +83 -172
  8. package/dist/modules/Customer/types.d.ts +0 -2
  9. package/dist/modules/Discount/index.js +3 -4
  10. package/dist/modules/Discount/types.d.ts +0 -1
  11. package/dist/modules/OpenData/index.d.ts +0 -8
  12. package/dist/modules/OpenData/index.js +17 -37
  13. package/dist/modules/Order/index.d.ts +18 -268
  14. package/dist/modules/Order/index.js +757 -3306
  15. package/dist/modules/Order/types.d.ts +31 -279
  16. package/dist/modules/Order/types.js +0 -38
  17. package/dist/modules/Order/utils.d.ts +5 -147
  18. package/dist/modules/Order/utils.js +103 -746
  19. package/dist/modules/Payment/index.d.ts +13 -10
  20. package/dist/modules/Payment/index.js +837 -467
  21. package/dist/modules/Payment/types.d.ts +0 -2
  22. package/dist/modules/Payment/utils.js +1 -2
  23. package/dist/modules/Payment/walletpass.js +7 -14
  24. package/dist/modules/ProductList/index.d.ts +12 -16
  25. package/dist/modules/ProductList/index.js +59 -133
  26. package/dist/modules/ProductList/types.d.ts +0 -14
  27. package/dist/modules/Quotation/index.d.ts +1 -0
  28. package/dist/modules/Quotation/index.js +22 -25
  29. package/dist/modules/Rules/index.d.ts +0 -4
  30. package/dist/modules/Rules/index.js +69 -93
  31. package/dist/modules/Rules/types.d.ts +0 -1
  32. package/dist/modules/SalesSummary/index.d.ts +25 -8
  33. package/dist/modules/SalesSummary/index.js +35 -86
  34. package/dist/modules/SalesSummary/types.d.ts +1 -4
  35. package/dist/modules/SalesSummary/utils.d.ts +25 -2
  36. package/dist/modules/SalesSummary/utils.js +162 -794
  37. package/dist/modules/Schedule/index.d.ts +0 -7
  38. package/dist/modules/Schedule/index.js +2 -24
  39. package/dist/modules/Summary/index.js +3 -4
  40. package/dist/modules/index.d.ts +0 -2
  41. package/dist/modules/index.js +1 -3
  42. package/dist/plugins/request.d.ts +0 -1
  43. package/dist/server/index.d.ts +1 -204
  44. package/dist/server/index.js +928 -3658
  45. package/dist/server/modules/index.d.ts +0 -2
  46. package/dist/server/modules/index.js +0 -2
  47. package/dist/server/modules/order/index.d.ts +4 -120
  48. package/dist/server/modules/order/index.js +483 -1779
  49. package/dist/server/modules/order/types.d.ts +3 -32
  50. package/dist/server/modules/order/types.js +0 -8
  51. package/dist/server/modules/order/utils/filterBookings.js +3 -26
  52. package/dist/server/modules/order/utils/filterOrders.js +8 -23
  53. package/dist/server/modules/products/index.d.ts +7 -34
  54. package/dist/server/modules/products/index.js +317 -631
  55. package/dist/server/modules/resource/index.d.ts +0 -2
  56. package/dist/server/modules/resource/index.js +3 -29
  57. package/dist/server/modules/schedule/index.d.ts +4 -4
  58. package/dist/server/modules/schedule/index.js +88 -111
  59. package/dist/solution/BaseSales/index.d.ts +9 -131
  60. package/dist/solution/BaseSales/index.js +447 -1944
  61. package/dist/solution/BaseSales/types.d.ts +6 -76
  62. package/dist/solution/BaseSales/types.js +4 -5
  63. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  64. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -105
  65. package/dist/solution/BaseSales/utils.d.ts +1 -1
  66. package/dist/solution/BaseSales/utils.js +21 -62
  67. package/dist/solution/BookingByStep/index.d.ts +1 -1
  68. package/dist/solution/BookingTicket/index.d.ts +10 -270
  69. package/dist/solution/BookingTicket/index.js +237 -1772
  70. package/dist/solution/BookingTicket/types.d.ts +1 -118
  71. package/dist/solution/BookingTicket/types.js +2 -41
  72. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  73. package/dist/solution/BookingTicket/utils/bookingStatus.js +0 -70
  74. package/dist/solution/BookingTicket/utils/cartView.d.ts +1 -9
  75. package/dist/solution/BookingTicket/utils/cartView.js +7 -94
  76. package/dist/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  77. package/dist/solution/BookingTicket/utils/scan/index.js +8 -20
  78. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  79. package/dist/solution/Checkout/index.d.ts +0 -1
  80. package/dist/solution/Checkout/index.js +9 -10
  81. package/dist/solution/RegisterAndLogin/config.js +10 -2
  82. package/dist/solution/ScanOrder/index.d.ts +3 -9
  83. package/dist/solution/ScanOrder/index.js +134 -241
  84. package/dist/solution/ScanOrder/types.d.ts +5 -9
  85. package/dist/solution/ScanOrder/types.js +3 -2
  86. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  87. package/dist/solution/ScanOrder/utils.js +22 -84
  88. package/dist/solution/VenueBooking/index.d.ts +2 -5
  89. package/dist/solution/VenueBooking/index.js +59 -110
  90. package/dist/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  91. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  92. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  93. package/dist/types/index.d.ts +0 -10
  94. package/lib/model/strategy/adapter/promotion/evaluator.js +1 -2
  95. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  96. package/lib/model/strategy/adapter/walletPass/utils.js +2 -3
  97. package/lib/modules/Cart/utils/cartProduct.js +3 -20
  98. package/lib/modules/Cart/utils/changePrice.js +20 -12
  99. package/lib/modules/Customer/index.d.ts +0 -20
  100. package/lib/modules/Customer/index.js +11 -64
  101. package/lib/modules/Customer/types.d.ts +0 -2
  102. package/lib/modules/Discount/index.js +1 -5
  103. package/lib/modules/Discount/types.d.ts +0 -1
  104. package/lib/modules/OpenData/index.d.ts +0 -8
  105. package/lib/modules/OpenData/index.js +5 -19
  106. package/lib/modules/Order/index.d.ts +18 -268
  107. package/lib/modules/Order/index.js +344 -2149
  108. package/lib/modules/Order/types.d.ts +31 -279
  109. package/lib/modules/Order/types.js +0 -1
  110. package/lib/modules/Order/utils.d.ts +5 -147
  111. package/lib/modules/Order/utils.js +46 -614
  112. package/lib/modules/Payment/index.d.ts +13 -10
  113. package/lib/modules/Payment/index.js +150 -18
  114. package/lib/modules/Payment/types.d.ts +0 -2
  115. package/lib/modules/Payment/utils.js +1 -2
  116. package/lib/modules/Payment/walletpass.js +3 -7
  117. package/lib/modules/ProductList/index.d.ts +12 -16
  118. package/lib/modules/ProductList/index.js +4 -41
  119. package/lib/modules/ProductList/types.d.ts +0 -14
  120. package/lib/modules/Quotation/index.d.ts +1 -0
  121. package/lib/modules/Quotation/index.js +16 -19
  122. package/lib/modules/Rules/index.d.ts +0 -4
  123. package/lib/modules/Rules/index.js +120 -136
  124. package/lib/modules/Rules/types.d.ts +0 -1
  125. package/lib/modules/SalesSummary/index.d.ts +25 -8
  126. package/lib/modules/SalesSummary/index.js +4 -30
  127. package/lib/modules/SalesSummary/types.d.ts +1 -4
  128. package/lib/modules/SalesSummary/utils.d.ts +25 -2
  129. package/lib/modules/SalesSummary/utils.js +91 -645
  130. package/lib/modules/Schedule/index.d.ts +0 -7
  131. package/lib/modules/Schedule/index.js +1 -17
  132. package/lib/modules/Summary/index.js +4 -5
  133. package/lib/modules/index.d.ts +0 -2
  134. package/lib/modules/index.js +1 -5
  135. package/lib/plugins/request.d.ts +0 -1
  136. package/lib/server/index.d.ts +1 -204
  137. package/lib/server/index.js +57 -1888
  138. package/lib/server/modules/index.d.ts +0 -2
  139. package/lib/server/modules/index.js +0 -3
  140. package/lib/server/modules/order/index.d.ts +4 -120
  141. package/lib/server/modules/order/index.js +142 -919
  142. package/lib/server/modules/order/types.d.ts +3 -32
  143. package/lib/server/modules/order/utils/filterBookings.js +5 -24
  144. package/lib/server/modules/order/utils/filterOrders.js +6 -15
  145. package/lib/server/modules/products/index.d.ts +7 -34
  146. package/lib/server/modules/products/index.js +54 -189
  147. package/lib/server/modules/resource/index.d.ts +0 -2
  148. package/lib/server/modules/resource/index.js +3 -27
  149. package/lib/server/modules/schedule/index.d.ts +4 -4
  150. package/lib/server/modules/schedule/index.js +40 -47
  151. package/lib/solution/BaseSales/index.d.ts +9 -131
  152. package/lib/solution/BaseSales/index.js +63 -1106
  153. package/lib/solution/BaseSales/types.d.ts +6 -76
  154. package/lib/solution/BaseSales/types.js +1 -3
  155. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +0 -1
  156. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +18 -106
  157. package/lib/solution/BaseSales/utils.d.ts +1 -1
  158. package/lib/solution/BaseSales/utils.js +10 -54
  159. package/lib/solution/BookingByStep/index.d.ts +1 -1
  160. package/lib/solution/BookingTicket/index.d.ts +10 -270
  161. package/lib/solution/BookingTicket/index.js +29 -922
  162. package/lib/solution/BookingTicket/types.d.ts +1 -118
  163. package/lib/solution/BookingTicket/types.js +0 -11
  164. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +0 -40
  165. package/lib/solution/BookingTicket/utils/bookingStatus.js +2 -44
  166. package/lib/solution/BookingTicket/utils/cartView.d.ts +1 -9
  167. package/lib/solution/BookingTicket/utils/cartView.js +6 -61
  168. package/lib/solution/BookingTicket/utils/scan/index.d.ts +0 -5
  169. package/lib/solution/BookingTicket/utils/scan/index.js +3 -17
  170. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  171. package/lib/solution/Checkout/index.d.ts +0 -1
  172. package/lib/solution/Checkout/index.js +2 -1
  173. package/lib/solution/RegisterAndLogin/config.js +10 -2
  174. package/lib/solution/ScanOrder/index.d.ts +3 -9
  175. package/lib/solution/ScanOrder/index.js +70 -153
  176. package/lib/solution/ScanOrder/types.d.ts +5 -9
  177. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  178. package/lib/solution/ScanOrder/utils.js +17 -83
  179. package/lib/solution/VenueBooking/index.d.ts +2 -5
  180. package/lib/solution/VenueBooking/index.js +17 -54
  181. package/lib/solution/VenueBooking/sales-section-4-annotated.json +2 -0
  182. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  183. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  184. package/lib/types/index.d.ts +0 -10
  185. package/package.json +1 -1
  186. package/dist/modules/BookingContext/index.d.ts +0 -48
  187. package/dist/modules/BookingContext/index.js +0 -566
  188. package/dist/modules/BookingContext/types.d.ts +0 -102
  189. package/dist/modules/BookingContext/types.js +0 -51
  190. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  191. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -284
  192. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  193. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -145
  194. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  195. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -218
  196. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  197. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  198. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  199. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  200. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  201. package/dist/modules/BookingContext/utils/index.js +0 -11
  202. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  203. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  204. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  205. package/dist/modules/BookingContext/utils/orderLineDisplay.js +0 -36
  206. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  207. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  208. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  209. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  210. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  211. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  212. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  213. package/dist/modules/BookingContext/utils/resources.js +0 -486
  214. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  215. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  216. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  217. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  218. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  219. package/dist/modules/Order/utils/manualProductDiscount.js +0 -210
  220. package/dist/modules/SurchargeList/index.d.ts +0 -16
  221. package/dist/modules/SurchargeList/index.js +0 -162
  222. package/dist/modules/SurchargeList/types.d.ts +0 -11
  223. package/dist/modules/SurchargeList/types.js +0 -1
  224. package/dist/server/modules/payment/index.d.ts +0 -28
  225. package/dist/server/modules/payment/index.js +0 -305
  226. package/dist/server/modules/payment/types.d.ts +0 -9
  227. package/dist/server/modules/payment/types.js +0 -1
  228. package/dist/server/test.json +0 -713
  229. package/dist/server/utils/small-ticket.d.ts +0 -71
  230. package/dist/server/utils/small-ticket.js +0 -830
  231. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  232. package/dist/solution/BaseSales/utils/cartPromotion.js +0 -1438
  233. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  234. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  235. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  236. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  237. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  238. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +0 -95
  239. package/dist/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  240. package/dist/solution/BookingTicket/utils/exampleData.js +0 -183
  241. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  242. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -438
  243. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  244. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -399
  245. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  246. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -56
  247. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  248. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +0 -150
  249. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  250. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +0 -78
  251. package/lib/modules/BookingContext/index.d.ts +0 -48
  252. package/lib/modules/BookingContext/index.js +0 -368
  253. package/lib/modules/BookingContext/types.d.ts +0 -102
  254. package/lib/modules/BookingContext/types.js +0 -34
  255. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  256. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -276
  257. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  258. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -151
  259. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -76
  260. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -201
  261. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  262. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  263. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  264. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  265. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  266. package/lib/modules/BookingContext/utils/index.js +0 -43
  267. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  268. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  269. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +0 -1
  270. package/lib/modules/BookingContext/utils/orderLineDisplay.js +0 -56
  271. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  272. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  273. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  274. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  275. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  276. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  277. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  278. package/lib/modules/BookingContext/utils/resources.js +0 -377
  279. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  280. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  281. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  282. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  283. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  284. package/lib/modules/Order/utils/manualProductDiscount.js +0 -206
  285. package/lib/modules/SurchargeList/index.d.ts +0 -16
  286. package/lib/modules/SurchargeList/index.js +0 -89
  287. package/lib/modules/SurchargeList/types.d.ts +0 -11
  288. package/lib/modules/SurchargeList/types.js +0 -17
  289. package/lib/server/modules/payment/index.d.ts +0 -28
  290. package/lib/server/modules/payment/index.js +0 -192
  291. package/lib/server/modules/payment/types.d.ts +0 -9
  292. package/lib/server/modules/payment/types.js +0 -17
  293. package/lib/server/test.json +0 -713
  294. package/lib/server/utils/small-ticket.d.ts +0 -71
  295. package/lib/server/utils/small-ticket.js +0 -781
  296. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +0 -287
  297. package/lib/solution/BaseSales/utils/cartPromotion.js +0 -992
  298. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  299. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  300. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -117
  301. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
  302. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +0 -35
  303. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +0 -125
  304. package/lib/solution/BookingTicket/utils/exampleData.d.ts +0 -123
  305. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  306. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +0 -185
  307. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +0 -254
  308. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -36
  309. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +0 -168
  310. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -32
  311. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +0 -51
  312. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +0 -21
  313. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +0 -127
  314. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +0 -23
  315. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +0 -85
@@ -1,14 +1,10 @@
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; }
1
3
  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; }
6
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
5
  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."); }
8
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
7
  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; }
12
8
  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; } } }; }
13
9
  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); }
14
10
  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; }
@@ -42,12 +38,6 @@ var INDEXDB_STORE_NAME = 'orders';
42
38
  var ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY = 'server_order_last_full_fetch_at';
43
39
  var ORDER_SYNC_THROTTLE_MS_STORAGE_KEY = 'order_sync_throttle_ms';
44
40
  var DEFAULT_ORDER_SYNC_THROTTLE_MS = 2000;
45
- /** pubsub 回声写入去重窗口:业务 API 刚写入后,跳过同单 SQLite patch */
46
- var ORDER_SQLITE_DEDUPE_MS = 15000;
47
- /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
48
- var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
49
- /** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
50
- var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
51
41
 
52
42
  /**
53
43
  * Order 模块 - 基础框架
@@ -73,64 +63,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
73
63
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
74
64
  // LoggerManager 实例
75
65
  _defineProperty(_assertThisInitialized(_this), "storage", void 0);
76
- _defineProperty(_assertThisInitialized(_this), "orderSQLiteSaveQueue", Promise.resolve());
77
- /** 按 storageKey 记录最近一次 SQLite 写入来源与时间,用于去重 */
78
- _defineProperty(_assertThisInitialized(_this), "recentSqliteWriteByStorageKey", new Map());
79
- /** 最近一次 SSE 全量拉取完成时间 */
80
- _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
81
66
  return _this;
82
67
  }
83
-
84
- /**
85
- * 广播订单变更事件,兼容全量列表订阅并额外携带本次变更订单。
86
- *
87
- * @example
88
- * await this.emitOrdersChanged([freshOrder], 'pubsub.bodyUpsert')
89
- */
90
68
  _createClass(OrderModule, [{
91
- key: "emitOrdersChanged",
92
- value: (function () {
93
- var _emitOrdersChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
94
- var _this2 = this;
95
- var changedOrders,
96
- source,
97
- payload,
98
- _args = arguments;
99
- return _regeneratorRuntime().wrap(function _callee$(_context) {
100
- while (1) switch (_context.prev = _context.next) {
101
- case 0:
102
- changedOrders = _args.length > 0 && _args[0] !== undefined ? _args[0] : [];
103
- source = _args.length > 1 ? _args[1] : undefined;
104
- console.log('触发emitOrdersChanged');
105
- payload = {
106
- list: this.store.list,
107
- changedOrders: changedOrders.map(function (order) {
108
- return _this2.normalizeOrderForMemoryList(order);
109
- }),
110
- source: source
111
- };
112
- _context.next = 6;
113
- return this.core.effects.emit(OrderHooks.onOrdersChanged, payload);
114
- case 6:
115
- case "end":
116
- return _context.stop();
117
- }
118
- }, _callee, this);
119
- }));
120
- function emitOrdersChanged() {
121
- return _emitOrdersChanged.apply(this, arguments);
122
- }
123
- return emitOrdersChanged;
124
- }())
125
- }, {
126
69
  key: "initialize",
127
70
  value: function () {
128
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(core, options) {
129
- var _options$initialState,
130
- _this3 = this;
131
- var appPlugin, app, _this$store$createdAt, coreData, today, operatingDayBoundary, boundaryTime, boundaryStart, isAfterBoundary, queryStart, queryEnd;
132
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
133
- while (1) switch (_context2.prev = _context2.next) {
71
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
72
+ var _options$initialState;
73
+ var appPlugin, app;
74
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
75
+ while (1) switch (_context.prev = _context.next) {
134
76
  case 0:
135
77
  this.core = core;
136
78
  this.store = options === null || options === void 0 ? void 0 : options.store;
@@ -141,46 +83,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
141
83
  this.dbManager = app.sqlite;
142
84
  this.logger = app.logger;
143
85
  this.storage = app.storage;
144
- coreData = app.data.store.getStore().getDataByModel('core');
145
- 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) {
146
- today = dayjs();
147
- if (coreData !== null && coreData !== void 0 && coreData.core.operating_day_boundary) {
148
- operatingDayBoundary = coreData.core.operating_day_boundary;
149
- if (operatingDayBoundary.type === 'start_time') {
150
- boundaryTime = String(operatingDayBoundary.time || '').trim();
151
- boundaryStart = dayjs("".concat(today.format('YYYY-MM-DD'), " ").concat(boundaryTime));
152
- if (boundaryStart.isValid()) {
153
- isAfterBoundary = today.isAfter(boundaryStart);
154
- queryStart = isAfterBoundary ? today.startOf('day') : today.subtract(1, 'day').startOf('day');
155
- queryEnd = isAfterBoundary ? today.add(1, 'day').endOf('day') : today.endOf('day');
156
- this.store.createdAtQuery = {
157
- sales_time_between: [queryStart.format('YYYY-MM-DD HH:mm:ss'), queryEnd.format('YYYY-MM-DD HH:mm:ss')]
158
- };
159
- } else {
160
- // 边界时间异常时回退到自然日,避免 createdAtQuery 为空导致后续查询异常
161
- this.store.createdAtQuery = {
162
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
163
- };
164
- }
165
- } else {
166
- this.store.createdAtQuery = {
167
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
168
- };
169
- }
170
- } else {
171
- // TODO: 这里后续可能需要使用店铺营业时间查询
172
- this.store.createdAtQuery = {
173
- sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
174
- };
175
- }
176
- }
86
+ this.updateCreateStore();
177
87
  }
178
88
  if (Array.isArray(options === null || options === void 0 || (_options$initialState = options.initialState) === null || _options$initialState === void 0 ? void 0 : _options$initialState.list)) {
179
- this.store.list = options.initialState.list.map(function (order) {
180
- return _this3.normalizeOrderForMemoryList(order);
181
- });
89
+ this.store.list = options.initialState.list;
182
90
  this.syncOrdersMap();
183
- this.emitOrdersChanged([], 'initialState');
91
+ this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
184
92
  } else {
185
93
  this.store.list = [];
186
94
  this.store.map = new Map();
@@ -194,9 +102,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
194
102
  });
195
103
  case 10:
196
104
  case "end":
197
- return _context2.stop();
105
+ return _context.stop();
198
106
  }
199
- }, _callee2, this);
107
+ }, _callee, this);
200
108
  }));
201
109
  function initialize(_x, _x2) {
202
110
  return _initialize.apply(this, arguments);
@@ -245,229 +153,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
245
153
  }
246
154
  }
247
155
  }, {
248
- key: "logWarning",
249
- value: function logWarning(title, metadata) {
250
- try {
251
- if (this.logger) {
252
- this.logger.addLog({
253
- type: 'warning',
254
- title: "[OrderServerModule] ".concat(title),
255
- metadata: metadata || {}
256
- });
257
- }
258
- } catch (_unused3) {
259
- // 日志记录失败不影响主流程
260
- }
261
- }
262
-
263
- /**
264
- * 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
265
- *
266
- * @example
267
- * this.recordRecentSqliteWrite('upsertOrdersFromRemote', orders)
268
- */
269
- }, {
270
- key: "recordRecentSqliteWrite",
271
- value: function recordRecentSqliteWrite(source, orders) {
272
- var now = Date.now();
273
- var _iterator = _createForOfIteratorHelper(orders),
274
- _step;
275
- try {
276
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
277
- var order = _step.value;
278
- var storageKey = this.getOrderStorageKey(order);
279
- if (!storageKey) continue;
280
- this.recentSqliteWriteByStorageKey.set(storageKey, {
281
- source: source,
282
- ts: now
283
- });
284
- }
285
- } catch (err) {
286
- _iterator.e(err);
287
- } finally {
288
- _iterator.f();
289
- }
290
- }
291
-
292
- /**
293
- * 过滤 pubsub 触发的冗余 SQLite patch(业务 API 刚写入过的 update 回声)。
294
- *
295
- * @example
296
- * const { toWrite, skipped } = this.filterRedundantPatchOrders('pubsub.bodyUpsert', orders, mergeActions)
297
- */
298
- }, {
299
- key: "filterRedundantPatchOrders",
300
- value: function filterRedundantPatchOrders(source, orders, mergeActions) {
301
- var eligibleSkipSources = new Set(['pubsub.bodyUpsert', 'pubsub.httpRefresh']);
302
- if (!eligibleSkipSources.has(source)) {
303
- return {
304
- toWrite: orders,
305
- skipped: []
306
- };
307
- }
308
- var now = Date.now();
309
- var toWrite = [];
310
- var skipped = [];
311
- var _iterator2 = _createForOfIteratorHelper(orders),
312
- _step2;
313
- try {
314
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
315
- var order = _step2.value;
316
- var storageKey = this.getOrderStorageKey(order);
317
- if (!storageKey) {
318
- toWrite.push(order);
319
- continue;
320
- }
321
- var orderKey = order.order_id !== undefined && order.order_id !== null ? this.getIdKey(order.order_id) : '';
322
- var mergeAction = orderKey ? mergeActions[orderKey] : undefined;
323
-
324
- // 新增单必须落库,不参与去重
325
- if (mergeAction === 'insert') {
326
- toWrite.push(order);
327
- continue;
328
- }
329
- var recent = this.recentSqliteWriteByStorageKey.get(storageKey);
330
- if (recent && ORDER_BUSINESS_WRITE_SOURCES.has(recent.source) && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
331
- var _order$order_id;
332
- skipped.push({
333
- orderId: (_order$order_id = order.order_id) !== null && _order$order_id !== void 0 ? _order$order_id : null,
334
- storageKey: storageKey,
335
- reason: 'skip_pubsub_echo_after_business_write',
336
- lastSource: recent.source,
337
- elapsedMs: now - recent.ts
338
- });
339
- continue;
340
- }
341
- toWrite.push(order);
342
- }
343
- } catch (err) {
344
- _iterator2.e(err);
345
- } finally {
346
- _iterator2.f();
347
- }
348
- return {
349
- toWrite: toWrite,
350
- skipped: skipped
351
- };
352
- }
353
-
354
- /**
355
- * 过滤 pubsub HTTP 增量拉取 ids:本地刚由业务 API 写入的单可跳过 HTTP。
356
- *
357
- * @example
358
- * const ids = this.filterRedundantHttpRefreshIds([99331, 99332])
359
- */
360
- }, {
361
- key: "filterRedundantHttpRefreshIds",
362
- value: function filterRedundantHttpRefreshIds(ids) {
363
- var now = Date.now();
364
- var toFetch = [];
365
- var skipped = [];
366
- var _iterator3 = _createForOfIteratorHelper(ids),
367
- _step3;
368
- try {
369
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
370
- var id = _step3.value;
371
- var existing = this.getOrderByOrderId(id);
372
- if (!existing) {
373
- toFetch.push(id);
374
- continue;
375
- }
376
- var storageKey = this.getOrderStorageKey(existing);
377
- var recent = storageKey ? this.recentSqliteWriteByStorageKey.get(storageKey) : undefined;
378
- if (recent && recent.source === 'upsertOrdersFromRemote' && now - recent.ts < ORDER_SQLITE_DEDUPE_MS) {
379
- skipped.push({
380
- orderId: id,
381
- lastSource: recent.source,
382
- elapsedMs: now - recent.ts
383
- });
384
- continue;
156
+ key: "updateCreateStore",
157
+ value: function updateCreateStore() {
158
+ var appPlugin = this.core.getPlugin('app');
159
+ var app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
160
+ if (app) {
161
+ var _this$store$createdAt;
162
+ var coreData = app.data.store.getStore().getDataByModel('core');
163
+ 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) {
164
+ var today = dayjs();
165
+ if (coreData !== null && coreData !== void 0 && coreData.core.operating_day_boundary) {
166
+ var operatingDayBoundary = coreData.core.operating_day_boundary;
167
+ if (operatingDayBoundary.type === 'start_time') {
168
+ var boundaryTime = String(operatingDayBoundary.time || '').trim();
169
+ var boundaryStart = dayjs("".concat(today.format('YYYY-MM-DD'), " ").concat(boundaryTime));
170
+ if (boundaryStart.isValid()) {
171
+ var isAfterBoundary = today.isAfter(boundaryStart);
172
+ var queryStart = isAfterBoundary ? today.startOf('day') : today.subtract(1, 'day').startOf('day');
173
+ var queryEnd = isAfterBoundary ? today.add(1, 'day').endOf('day') : today.endOf('day');
174
+ this.store.createdAtQuery = {
175
+ sales_time_between: [queryStart.format('YYYY-MM-DD HH:mm:ss'), queryEnd.format('YYYY-MM-DD HH:mm:ss')]
176
+ };
177
+ } else {
178
+ // 边界时间异常时回退到自然日,避免 createdAtQuery 为空导致后续查询异常
179
+ this.store.createdAtQuery = {
180
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
181
+ };
182
+ }
183
+ } else {
184
+ this.store.createdAtQuery = {
185
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
186
+ };
187
+ }
188
+ } else {
189
+ // TODO: 这里后续可能需要使用店铺营业时间查询
190
+ this.store.createdAtQuery = {
191
+ sales_time_between: [today.startOf('day').format('YYYY-MM-DD HH:mm:ss'), today.endOf('day').format('YYYY-MM-DD HH:mm:ss')]
192
+ };
385
193
  }
386
- toFetch.push(id);
387
194
  }
388
- } catch (err) {
389
- _iterator3.e(err);
390
- } finally {
391
- _iterator3.f();
392
- }
393
- return {
394
- toFetch: toFetch,
395
- skipped: skipped
396
- };
397
- }
398
-
399
- /**
400
- * 解析 pubsub 消息会走哪条同步分支,便于对照为何触发 HTTP 重拉或 body 直写。
401
- *
402
- * @example
403
- * this.resolveSyncMessageRoute(msg)
404
- * // => { route: 'httpRefresh.batchIds', ... }
405
- */
406
- }, {
407
- key: "resolveSyncMessageRoute",
408
- value: function resolveSyncMessageRoute(msg) {
409
- var _msg$id, _msg$relation_order_i, _normalizedBody$order5;
410
- var hasBatchIds = Array.isArray(msg.ids) && msg.ids.length > 0;
411
- var singleIdRaw = (_msg$id = msg.id) !== null && _msg$id !== void 0 ? _msg$id : msg.order_id;
412
- var hasSingleId = !hasBatchIds && singleIdRaw !== undefined && singleIdRaw !== null;
413
- var normalizedBody = this.normalizeOrderSyncPayload(msg.body || msg.data);
414
- if (hasBatchIds) {
415
- var _normalizedBody$order;
416
- return {
417
- route: 'httpRefresh.batchIds',
418
- hasBatchIds: true,
419
- hasSingleId: false,
420
- hasNormalizedBody: !!normalizedBody,
421
- singleId: null,
422
- batchIds: msg.ids || [],
423
- bodyOrderId: (_normalizedBody$order = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order !== void 0 ? _normalizedBody$order : null
424
- };
425
- }
426
- if (hasSingleId && normalizedBody) {
427
- var _normalizedBody$order2;
428
- return {
429
- route: 'bodyUpsert',
430
- hasBatchIds: false,
431
- hasSingleId: true,
432
- hasNormalizedBody: true,
433
- singleId: singleIdRaw,
434
- batchIds: [],
435
- bodyOrderId: (_normalizedBody$order2 = normalizedBody.order_id) !== null && _normalizedBody$order2 !== void 0 ? _normalizedBody$order2 : null
436
- };
437
- }
438
- if (hasSingleId) {
439
- var _normalizedBody$order3;
440
- return {
441
- route: 'httpRefresh.singleId',
442
- hasBatchIds: false,
443
- hasSingleId: true,
444
- hasNormalizedBody: !!normalizedBody,
445
- singleId: singleIdRaw,
446
- batchIds: [],
447
- bodyOrderId: (_normalizedBody$order3 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order3 !== void 0 ? _normalizedBody$order3 : null
448
- };
449
- }
450
- if ((_msg$relation_order_i = msg.relation_order_ids) !== null && _msg$relation_order_i !== void 0 && _msg$relation_order_i.length) {
451
- var _normalizedBody$order4;
452
- return {
453
- route: 'httpRefresh.relationIds',
454
- hasBatchIds: false,
455
- hasSingleId: false,
456
- hasNormalizedBody: !!normalizedBody,
457
- singleId: null,
458
- batchIds: msg.relation_order_ids,
459
- bodyOrderId: (_normalizedBody$order4 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order4 !== void 0 ? _normalizedBody$order4 : null
460
- };
461
195
  }
462
- return {
463
- route: 'noop',
464
- hasBatchIds: false,
465
- hasSingleId: false,
466
- hasNormalizedBody: !!normalizedBody,
467
- singleId: null,
468
- batchIds: [],
469
- bodyOrderId: (_normalizedBody$order5 = normalizedBody === null || normalizedBody === void 0 ? void 0 : normalizedBody.order_id) !== null && _normalizedBody$order5 !== void 0 ? _normalizedBody$order5 : null
470
- };
471
196
  }
472
197
  }, {
473
198
  key: "getOrderSyncThrottleMs",
@@ -482,12 +207,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
482
207
  }, {
483
208
  key: "preload",
484
209
  value: function () {
485
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
486
- var _this4 = this;
210
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
211
+ var _this2 = this;
487
212
  var getData;
488
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
489
- while (1) switch (_context4.prev = _context4.next) {
213
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
214
+ while (1) switch (_context3.prev = _context3.next) {
490
215
  case 0:
216
+ // const cachedOrders = await this.loadOrdersFromSQLite()
491
217
  // const hasPulledInCurrentWindow = this.hasPulledOrdersToday()
492
218
  // // 仅当缓存属于当前统计窗口时才直接复用,避免跨天/跨营业日窗口继续使用旧数据
493
219
  // if (cachedOrders.length > 0 && hasPulledInCurrentWindow) {
@@ -503,30 +229,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
503
229
  // return
504
230
  // }
505
231
  getData = /*#__PURE__*/function () {
506
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
232
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
507
233
  var orders;
508
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
509
- while (1) switch (_context3.prev = _context3.next) {
234
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
235
+ while (1) switch (_context2.prev = _context2.next) {
510
236
  case 0:
511
- _context3.next = 2;
512
- return _this4.loadOrdersByServer();
237
+ _context2.next = 2;
238
+ return _this2.loadOrdersByServer();
513
239
  case 2:
514
- orders = _context3.sent;
240
+ orders = _context2.sent;
515
241
  if (!(orders.length === 0)) {
516
- _context3.next = 5;
242
+ _context2.next = 5;
517
243
  break;
518
244
  }
519
- return _context3.abrupt("return");
245
+ return _context2.abrupt("return");
520
246
  case 5:
521
- _this4.store.list = cloneDeep(orders);
522
- _this4.syncOrdersMap();
523
- _this4.emitOrdersChanged([], 'preload');
524
- _this4.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
247
+ _this2.store.list = cloneDeep(orders);
248
+ _this2.syncOrdersMap();
249
+ _this2.core.effects.emit(OrderHooks.onOrdersChanged, _this2.store.list);
250
+ _this2.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
525
251
  case 9:
526
252
  case "end":
527
- return _context3.stop();
253
+ return _context2.stop();
528
254
  }
529
- }, _callee3);
255
+ }, _callee2);
530
256
  }));
531
257
  return function getData() {
532
258
  return _ref.apply(this, arguments);
@@ -535,9 +261,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
535
261
  getData();
536
262
  case 2:
537
263
  case "end":
538
- return _context4.stop();
264
+ return _context3.stop();
539
265
  }
540
- }, _callee4);
266
+ }, _callee3);
541
267
  }));
542
268
  function preload() {
543
269
  return _preload.apply(this, arguments);
@@ -555,88 +281,68 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
555
281
  return this.store.map.get(this.getIdKey(id));
556
282
  }
557
283
 
558
- /** 按 order_id 查询内存订单。 */
284
+ /** 按 order_id 查询(推荐) */
559
285
  }, {
560
286
  key: "getOrderByOrderId",
561
287
  value: function getOrderByOrderId(orderId) {
562
288
  return this.store.map.get(this.getIdKey(orderId));
563
289
  }
564
290
  }, {
565
- key: "getLocalOrderFromMemoryByLookup",
566
- value: function getLocalOrderFromMemoryByLookup(lookup) {
567
- var _this5 = this;
568
- var key = this.getIdKey(lookup);
569
- var memoryOrderById = this.store.map.get(key);
570
- if (memoryOrderById) return memoryOrderById;
571
- var memoryOrder = this.store.list.find(function (order) {
572
- return _this5.isOrderLookupMatch(order, key);
573
- });
574
- return memoryOrder || null;
575
- }
576
- }, {
577
- key: "getLocalOrderByLookup",
291
+ key: "getLocalOrderByOrderId",
578
292
  value: function () {
579
- var _getLocalOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(lookup) {
580
- var _this6 = this;
581
- var key, memoryOrderById, memoryOrder, orders, localOrder;
582
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
583
- while (1) switch (_context5.prev = _context5.next) {
293
+ var _getLocalOrderByOrderId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(orderId) {
294
+ var _this3 = this;
295
+ var key, memoryOrder, orders, localOrder;
296
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
297
+ while (1) switch (_context4.prev = _context4.next) {
584
298
  case 0:
585
- key = this.getIdKey(lookup);
586
- memoryOrderById = this.store.map.get(key);
587
- if (!memoryOrderById) {
588
- _context5.next = 4;
589
- break;
590
- }
591
- return _context5.abrupt("return", memoryOrderById);
592
- case 4:
593
- memoryOrder = this.store.list.find(function (order) {
594
- return _this6.isOrderLookupMatch(order, key);
595
- });
299
+ key = this.getIdKey(orderId);
300
+ memoryOrder = this.store.map.get(key);
596
301
  if (!memoryOrder) {
597
- _context5.next = 7;
302
+ _context4.next = 4;
598
303
  break;
599
304
  }
600
- return _context5.abrupt("return", memoryOrder);
601
- case 7:
602
- _context5.next = 9;
305
+ return _context4.abrupt("return", memoryOrder);
306
+ case 4:
307
+ _context4.next = 6;
603
308
  return this.loadOrdersFromSQLite();
604
- case 9:
605
- orders = _context5.sent;
309
+ case 6:
310
+ orders = _context4.sent;
606
311
  localOrder = orders.find(function (order) {
607
- return _this6.isOrderLookupMatch(order, key);
312
+ var shopOrderNumber = order === null || order === void 0 ? void 0 : order.shop_order_number;
313
+ if (shopOrderNumber && _this3.getIdKey(shopOrderNumber) === key) return true;
314
+ var id = order === null || order === void 0 ? void 0 : order.order_id;
315
+ if (id === undefined || id === null) return false;
316
+ return _this3.getIdKey(id) === key;
608
317
  });
609
318
  if (localOrder) {
610
- _context5.next = 13;
319
+ _context4.next = 10;
611
320
  break;
612
321
  }
613
- return _context5.abrupt("return", null);
614
- case 13:
615
- this.store.list = orders.map(function (order) {
616
- return _this6.normalizeOrderForMemoryList(order);
617
- });
322
+ return _context4.abrupt("return", null);
323
+ case 10:
324
+ this.store.list = orders;
618
325
  this.syncOrdersMap();
619
- return _context5.abrupt("return", this.normalizeOrderForMemoryList(localOrder));
620
- case 16:
326
+ return _context4.abrupt("return", localOrder);
327
+ case 13:
621
328
  case "end":
622
- return _context5.stop();
329
+ return _context4.stop();
623
330
  }
624
- }, _callee5, this);
331
+ }, _callee4, this);
625
332
  }));
626
- function getLocalOrderByLookup(_x3) {
627
- return _getLocalOrderByLookup.apply(this, arguments);
333
+ function getLocalOrderByOrderId(_x3) {
334
+ return _getLocalOrderByOrderId.apply(this, arguments);
628
335
  }
629
- return getLocalOrderByLookup;
336
+ return getLocalOrderByOrderId;
630
337
  }()
631
338
  }, {
632
339
  key: "loadOrdersByServer",
633
340
  value: function () {
634
- var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
635
- var _this$store,
636
- _this7 = this;
637
- var orderList, data, mergedOrders, memoryOrders;
638
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
639
- while (1) switch (_context6.prev = _context6.next) {
341
+ var _loadOrdersByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
342
+ var _this$store;
343
+ var orderList, data;
344
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
345
+ while (1) switch (_context5.prev = _context5.next) {
640
346
  case 0:
641
347
  orderList = [];
642
348
  this.logInfo('loadOrdersByServer-开始', {
@@ -644,51 +350,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
644
350
  query: ((_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.createdAtQuery) || null
645
351
  });
646
352
  if (!this.orderDataSource) {
647
- _context6.next = 17;
353
+ _context5.next = 16;
648
354
  break;
649
355
  }
650
- _context6.prev = 3;
651
- _context6.next = 6;
356
+ _context5.prev = 3;
357
+ _context5.next = 6;
652
358
  return this.orderDataSource.run({
653
359
  sse: {
654
360
  query: this.store.createdAtQuery
655
361
  }
656
362
  });
657
363
  case 6:
658
- data = _context6.sent;
364
+ data = _context5.sent;
659
365
  orderList = data || [];
660
366
  this.logInfo('loadOrdersByServer-SSE拉取成功', {
661
367
  count: orderList.length
662
368
  });
663
369
  this.markOrderPulledAtNow();
664
- this.lastServerFullFetchAtMs = Date.now();
665
- _context6.next = 17;
370
+ _context5.next = 16;
666
371
  break;
667
- case 13:
668
- _context6.prev = 13;
669
- _context6.t0 = _context6["catch"](3);
670
- this.logInfo('loadOrdersByServer-SSE拉取失败,保持当前内存订单');
671
- return _context6.abrupt("return", this.store.list);
672
- case 17:
673
- _context6.next = 19;
674
- return this.replaceOrdersSnapshotInSQLite(orderList, 'loadOrdersByServer');
675
- case 19:
676
- mergedOrders = _context6.sent;
677
- memoryOrders = mergedOrders.map(function (order) {
678
- return _this7.normalizeOrderForMemoryList(order);
679
- });
372
+ case 12:
373
+ _context5.prev = 12;
374
+ _context5.t0 = _context5["catch"](3);
375
+ orderList = [];
376
+ this.logInfo('loadOrdersByServer-SSE拉取失败,回退为空数组');
377
+ case 16:
378
+ _context5.next = 18;
379
+ return this.saveOrdersToSQLite(orderList);
380
+ case 18:
680
381
  this.logInfo('loadOrdersByServer-结束', {
681
- count: memoryOrders.length
382
+ count: orderList.length
682
383
  });
683
- _context6.next = 24;
684
- return this.core.effects.emit(OrderHooks.onOrdersLoaded, memoryOrders);
685
- case 24:
686
- return _context6.abrupt("return", memoryOrders);
687
- case 25:
384
+ _context5.next = 21;
385
+ return this.core.effects.emit(OrderHooks.onOrdersLoaded, orderList);
386
+ case 21:
387
+ return _context5.abrupt("return", orderList);
388
+ case 22:
688
389
  case "end":
689
- return _context6.stop();
390
+ return _context5.stop();
690
391
  }
691
- }, _callee6, this, [[3, 13]]);
392
+ }, _callee5, this, [[3, 12]]);
692
393
  }));
693
394
  function loadOrdersByServer() {
694
395
  return _loadOrdersByServer.apply(this, arguments);
@@ -703,59 +404,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
703
404
  }, {
704
405
  key: "silentRefresh",
705
406
  value: (function () {
706
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
707
- var startTime, elapsedSinceFullFetch, orders, errorMessage;
708
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
709
- while (1) switch (_context7.prev = _context7.next) {
407
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
408
+ var startTime, orders, errorMessage;
409
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
410
+ while (1) switch (_context6.prev = _context6.next) {
710
411
  case 0:
711
412
  startTime = Date.now();
712
- elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
713
- if (!(this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS)) {
714
- _context7.next = 4;
715
- break;
716
- }
717
- return _context7.abrupt("return", this.store.list);
718
- case 4:
719
413
  this.logInfo('silentRefresh 开始');
720
- _context7.prev = 5;
721
- _context7.next = 8;
414
+ _context6.prev = 2;
415
+ // 刷新前,需要更新当前营业日边界(store.createdAtQuery)
416
+ this.updateCreateStore();
417
+ _context6.next = 6;
722
418
  return this.loadOrdersByServer();
723
- case 8:
724
- orders = _context7.sent;
419
+ case 6:
420
+ orders = _context6.sent;
725
421
  if (!(orders.length > 0)) {
726
- _context7.next = 18;
422
+ _context6.next = 16;
727
423
  break;
728
424
  }
729
425
  this.store.list = cloneDeep(orders);
730
426
  this.syncOrdersMap();
731
- this.emitOrdersChanged([], 'silentRefresh');
732
- _context7.next = 15;
427
+ this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
428
+ _context6.next = 13;
733
429
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
734
- case 15:
430
+ case 13:
735
431
  this.logInfo('silentRefresh 完成', {
736
432
  orderCount: orders.length,
737
433
  duration: "".concat(Date.now() - startTime, "ms")
738
434
  });
739
- _context7.next = 19;
435
+ _context6.next = 17;
740
436
  break;
741
- case 18:
437
+ case 16:
742
438
  this.logInfo('silentRefresh: 服务器未返回数据');
743
- case 19:
744
- return _context7.abrupt("return", this.store.list);
745
- case 22:
746
- _context7.prev = 22;
747
- _context7.t0 = _context7["catch"](5);
748
- errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
439
+ case 17:
440
+ return _context6.abrupt("return", this.store.list);
441
+ case 20:
442
+ _context6.prev = 20;
443
+ _context6.t0 = _context6["catch"](2);
444
+ errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
749
445
  this.logError('silentRefresh 失败', {
750
446
  duration: "".concat(Date.now() - startTime, "ms"),
751
447
  error: errorMessage
752
448
  });
753
- return _context7.abrupt("return", this.store.list);
754
- case 27:
449
+ return _context6.abrupt("return", this.store.list);
450
+ case 25:
755
451
  case "end":
756
- return _context7.stop();
452
+ return _context6.stop();
757
453
  }
758
- }, _callee7, this, [[5, 22]]);
454
+ }, _callee6, this, [[2, 20]]);
759
455
  }));
760
456
  function silentRefresh() {
761
457
  return _silentRefresh.apply(this, arguments);
@@ -765,28 +461,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
765
461
  }, {
766
462
  key: "getOrdersByResourceId",
767
463
  value: function getOrdersByResourceId(resourceId) {
768
- var _this8 = this;
464
+ var _this4 = this;
769
465
  var ids = this.resourceIdIndex.get(String(resourceId)) || [];
770
466
  return ids.map(function (id) {
771
- return _this8.store.map.get(id);
467
+ return _this4.store.map.get(id);
772
468
  }).filter(function (order) {
773
469
  return !!order;
774
470
  });
775
471
  }
776
- }, {
777
- key: "normalizeOrderForMemoryList",
778
- value: function normalizeOrderForMemoryList(order) {
779
- var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
780
- if ((order === null || order === void 0 ? void 0 : order.order_id) !== undefined && (order === null || order === void 0 ? void 0 : order.order_id) !== null && (order === null || order === void 0 ? void 0 : order.order_id) !== '') {
781
- return order;
782
- }
783
- if (externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '') {
784
- return order;
785
- }
786
- return _objectSpread(_objectSpread({}, order), {}, {
787
- order_id: externalSaleNumber
788
- });
789
- }
790
472
 
791
473
  /**
792
474
  * 仅覆盖本地已存在的订单;不存在则直接跳过,不落库、不 emit。
@@ -795,31 +477,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
795
477
  }, {
796
478
  key: "overwriteExistingOrder",
797
479
  value: (function () {
798
- var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
799
- var _this9 = this;
480
+ var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(fresh) {
481
+ var _this5 = this;
800
482
  var orderId, key;
801
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
802
- while (1) switch (_context8.prev = _context8.next) {
483
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
484
+ while (1) switch (_context7.prev = _context7.next) {
803
485
  case 0:
804
486
  orderId = fresh === null || fresh === void 0 ? void 0 : fresh.order_id;
805
487
  if (!(orderId === undefined || orderId === null)) {
806
- _context8.next = 4;
488
+ _context7.next = 4;
807
489
  break;
808
490
  }
809
491
  this.logError('overwriteExistingOrder-入参缺少 order_id');
810
- return _context8.abrupt("return", {
492
+ return _context7.abrupt("return", {
811
493
  overwritten: false
812
494
  });
813
495
  case 4:
814
496
  key = this.getIdKey(orderId);
815
497
  if (this.store.map.has(key)) {
816
- _context8.next = 8;
498
+ _context7.next = 8;
817
499
  break;
818
500
  }
819
501
  this.logInfo('overwriteExistingOrder-本地不存在该订单,跳过', {
820
502
  orderId: orderId
821
503
  });
822
- return _context8.abrupt("return", {
504
+ return _context7.abrupt("return", {
823
505
  overwritten: false
824
506
  });
825
507
  case 8:
@@ -830,27 +512,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
830
512
  this.store.list = this.store.list.map(function (order) {
831
513
  var id = order === null || order === void 0 ? void 0 : order.order_id;
832
514
  if (id === undefined || id === null) return order;
833
- return _this9.getIdKey(id) === key ? fresh : order;
515
+ return _this5.getIdKey(id) === key ? fresh : order;
834
516
  });
835
517
  this.syncOrdersMap();
836
- _context8.next = 13;
837
- return this.updateOrderInSQLite(fresh, 'overwriteExistingOrder');
518
+ _context7.next = 13;
519
+ return this.saveOrdersToSQLite(this.store.list);
838
520
  case 13:
839
521
  this.logInfo('overwriteExistingOrder-结束', {
840
522
  orderId: orderId,
841
523
  storeOrderCountAfter: this.store.list.length
842
524
  });
843
- _context8.next = 16;
844
- return this.emitOrdersChanged([fresh], 'overwriteExistingOrder');
525
+ _context7.next = 16;
526
+ return this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
845
527
  case 16:
846
- return _context8.abrupt("return", {
528
+ return _context7.abrupt("return", {
847
529
  overwritten: true
848
530
  });
849
531
  case 17:
850
532
  case "end":
851
- return _context8.stop();
533
+ return _context7.stop();
852
534
  }
853
- }, _callee8, this);
535
+ }, _callee7, this);
854
536
  }));
855
537
  function overwriteExistingOrder(_x4) {
856
538
  return _overwriteExistingOrder.apply(this, arguments);
@@ -865,294 +547,82 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
865
547
  }, {
866
548
  key: "upsertOrdersFromRemote",
867
549
  value: (function () {
868
- var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(freshOrders) {
869
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
870
- while (1) switch (_context9.prev = _context9.next) {
550
+ var _upsertOrdersFromRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(freshOrders) {
551
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
552
+ while (1) switch (_context8.prev = _context8.next) {
871
553
  case 0:
872
554
  if (freshOrders !== null && freshOrders !== void 0 && freshOrders.length) {
873
- _context9.next = 3;
555
+ _context8.next = 3;
874
556
  break;
875
557
  }
876
558
  this.logInfo('upsertOrdersFromRemote-订单列表为空', {});
877
- return _context9.abrupt("return");
559
+ return _context8.abrupt("return");
878
560
  case 3:
879
561
  this.logInfo('upsertOrdersFromRemote-开始', {
880
562
  count: freshOrders.length
881
563
  });
882
- _context9.next = 6;
883
- return this.mergeOrdersToStore(freshOrders, 'upsertOrdersFromRemote');
564
+ _context8.next = 6;
565
+ return this.mergeOrdersToStore(freshOrders);
884
566
  case 6:
885
567
  case "end":
886
- return _context9.stop();
568
+ return _context8.stop();
887
569
  }
888
- }, _callee9, this);
570
+ }, _callee8, this);
889
571
  }));
890
572
  function upsertOrdersFromRemote(_x5) {
891
573
  return _upsertOrdersFromRemote.apply(this, arguments);
892
574
  }
893
575
  return upsertOrdersFromRemote;
894
- }())
576
+ }()
577
+ /**
578
+ * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
579
+ */
580
+ )
895
581
  }, {
896
- key: "markOrderSyncedByExternalSaleNumber",
897
- value: function () {
898
- var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
899
- var _this10 = this,
900
- _existing$external_sa,
901
- _nextOrder$order_id;
902
- var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
903
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
904
- while (1) switch (_context10.prev = _context10.next) {
582
+ key: "fetchOrdersBySSE",
583
+ value: (function () {
584
+ var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
585
+ var query,
586
+ data,
587
+ _args9 = arguments;
588
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
589
+ while (1) switch (_context9.prev = _context9.next) {
905
590
  case 0:
906
- externalSaleNumber = params.externalSaleNumber;
907
- if (!(externalSaleNumber === undefined || externalSaleNumber === null || externalSaleNumber === '')) {
908
- _context10.next = 4;
909
- break;
910
- }
911
- this.logError('markOrderSyncedByExternalSaleNumber-缺少 external_sale_number');
912
- return _context10.abrupt("return", {
913
- updated: false
914
- });
915
- case 4:
916
- key = this.getIdKey(externalSaleNumber);
917
- targetIndex = this.store.list.findIndex(function (order) {
918
- var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
919
- if (value === undefined || value === null || value === '') return false;
920
- return _this10.getIdKey(value) === key;
921
- });
922
- if (!(targetIndex < 0)) {
923
- _context10.next = 9;
591
+ query = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
592
+ if (this.orderDataSource) {
593
+ _context9.next = 3;
924
594
  break;
925
595
  }
926
- this.logInfo('markOrderSyncedByExternalSaleNumber-本地订单不存在,跳过', {
927
- external_sale_number: externalSaleNumber
928
- });
929
- return _context10.abrupt("return", {
930
- updated: false
931
- });
932
- case 9:
933
- existing = this.store.list[targetIndex];
934
- nextOrder = this.normalizeRemoteSyncedOrder(_objectSpread(_objectSpread(_objectSpread({}, existing), params.patch || {}), {}, {
935
- external_sale_number: (_existing$external_sa = existing.external_sale_number) !== null && _existing$external_sa !== void 0 ? _existing$external_sa : externalSaleNumber,
936
- need_sync: 0
937
- }));
938
- storageKey = this.getOrderStorageKey(nextOrder) || key;
939
- this.store.list = this.store.list.map(function (order, index) {
940
- if (index !== targetIndex) return order;
941
- return nextOrder;
942
- });
943
- this.syncOrdersMap();
944
- _context10.next = 16;
945
- return this.patchOrdersInSQLite([nextOrder], 'markOrderSyncedByExternalSaleNumber', _defineProperty({}, storageKey, 'update'));
946
- case 16:
947
- this.logInfo('markOrderSyncedByExternalSaleNumber-完成', {
948
- external_sale_number: externalSaleNumber,
949
- order_id: (_nextOrder$order_id = nextOrder.order_id) !== null && _nextOrder$order_id !== void 0 ? _nextOrder$order_id : null
596
+ return _context9.abrupt("return", []);
597
+ case 3:
598
+ _context9.prev = 3;
599
+ _context9.next = 6;
600
+ return this.orderDataSource.run({
601
+ sse: {
602
+ query: query
603
+ }
950
604
  });
951
- _context10.next = 19;
952
- return this.emitOrdersChanged([nextOrder], 'markOrderSyncedByExternalSaleNumber');
953
- case 19:
954
- return _context10.abrupt("return", {
955
- updated: true,
956
- order: nextOrder
605
+ case 6:
606
+ data = _context9.sent;
607
+ return _context9.abrupt("return", data || []);
608
+ case 10:
609
+ _context9.prev = 10;
610
+ _context9.t0 = _context9["catch"](3);
611
+ this.logError('fetchOrdersBySSE-失败', {
612
+ error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
957
613
  });
958
- case 20:
614
+ return _context9.abrupt("return", []);
615
+ case 14:
959
616
  case "end":
960
- return _context10.stop();
617
+ return _context9.stop();
961
618
  }
962
- }, _callee10, this);
619
+ }, _callee9, this, [[3, 10]]);
963
620
  }));
964
- function markOrderSyncedByExternalSaleNumber(_x6) {
965
- return _markOrderSyncedByExternalSaleNumber.apply(this, arguments);
621
+ function fetchOrdersBySSE() {
622
+ return _fetchOrdersBySSE.apply(this, arguments);
966
623
  }
967
- return markOrderSyncedByExternalSaleNumber;
968
- }()
969
- /**
970
- * 将本地待同步订单按 SQLite storage key 合并进 store 并落库。
971
- * checkout 离线兜底可能没有 order_id,但通常会有 external_sale_number。
972
- */
973
- }, {
974
- key: "upsertPendingSyncOrders",
975
- value: (function () {
976
- var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
977
- var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, _iterator5, _step5, _step5$value, _storageKey, pendingOrder, matchIndex, _iterator6, _step6, _step6$value, _storageKey2, _order;
978
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
979
- while (1) switch (_context11.prev = _context11.next) {
980
- case 0:
981
- if (pendingOrders !== null && pendingOrders !== void 0 && pendingOrders.length) {
982
- _context11.next = 3;
983
- break;
984
- }
985
- this.logInfo('upsertPendingSyncOrders-订单列表为空', {});
986
- return _context11.abrupt("return");
987
- case 3:
988
- pendingMap = new Map();
989
- memoryPendingMap = new Map();
990
- _iterator4 = _createForOfIteratorHelper(pendingOrders);
991
- _context11.prev = 6;
992
- _iterator4.s();
993
- case 8:
994
- if ((_step4 = _iterator4.n()).done) {
995
- _context11.next = 17;
996
- break;
997
- }
998
- order = _step4.value;
999
- storageKey = this.getOrderStorageKey(order);
1000
- if (storageKey) {
1001
- _context11.next = 13;
1002
- break;
1003
- }
1004
- return _context11.abrupt("continue", 15);
1005
- case 13:
1006
- pendingMap.set(storageKey, order);
1007
- memoryPendingMap.set(storageKey, this.normalizeOrderForMemoryList(order));
1008
- case 15:
1009
- _context11.next = 8;
1010
- break;
1011
- case 17:
1012
- _context11.next = 22;
1013
- break;
1014
- case 19:
1015
- _context11.prev = 19;
1016
- _context11.t0 = _context11["catch"](6);
1017
- _iterator4.e(_context11.t0);
1018
- case 22:
1019
- _context11.prev = 22;
1020
- _iterator4.f();
1021
- return _context11.finish(22);
1022
- case 25:
1023
- if (!(pendingMap.size === 0)) {
1024
- _context11.next = 28;
1025
- break;
1026
- }
1027
- this.logError('upsertPendingSyncOrders-订单缺少可落库标识', {
1028
- count: pendingOrders.length
1029
- });
1030
- return _context11.abrupt("return");
1031
- case 28:
1032
- this.logInfo('upsertPendingSyncOrders-开始', {
1033
- count: pendingMap.size
1034
- });
1035
- patchedOrders = _toConsumableArray(pendingMap.values());
1036
- mergeActions = {};
1037
- updatedList = _toConsumableArray(this.store.list);
1038
- _iterator5 = _createForOfIteratorHelper(memoryPendingMap.entries());
1039
- _context11.prev = 33;
1040
- _iterator5.s();
1041
- case 35:
1042
- if ((_step5 = _iterator5.n()).done) {
1043
- _context11.next = 46;
1044
- break;
1045
- }
1046
- _step5$value = _slicedToArray(_step5.value, 2), _storageKey = _step5$value[0], pendingOrder = _step5$value[1];
1047
- matchIndex = this.findOrderIndexByIdentity(updatedList, pendingOrder);
1048
- if (!(matchIndex < 0)) {
1049
- _context11.next = 40;
1050
- break;
1051
- }
1052
- return _context11.abrupt("continue", 44);
1053
- case 40:
1054
- updatedList[matchIndex] = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder);
1055
- pendingMap.delete(_storageKey);
1056
- memoryPendingMap.delete(_storageKey);
1057
- mergeActions[_storageKey] = 'update';
1058
- case 44:
1059
- _context11.next = 35;
1060
- break;
1061
- case 46:
1062
- _context11.next = 51;
1063
- break;
1064
- case 48:
1065
- _context11.prev = 48;
1066
- _context11.t1 = _context11["catch"](33);
1067
- _iterator5.e(_context11.t1);
1068
- case 51:
1069
- _context11.prev = 51;
1070
- _iterator5.f();
1071
- return _context11.finish(51);
1072
- case 54:
1073
- _iterator6 = _createForOfIteratorHelper(memoryPendingMap.entries());
1074
- try {
1075
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1076
- _step6$value = _slicedToArray(_step6.value, 2), _storageKey2 = _step6$value[0], _order = _step6$value[1];
1077
- mergeActions[_storageKey2] = 'insert';
1078
- updatedList.push(_order);
1079
- }
1080
- } catch (err) {
1081
- _iterator6.e(err);
1082
- } finally {
1083
- _iterator6.f();
1084
- }
1085
- this.store.list = this.compactOrderListByIdentity(updatedList, 'upsertPendingSyncOrders.store').list;
1086
- this.syncOrdersMap();
1087
- _context11.next = 60;
1088
- return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
1089
- case 60:
1090
- this.logInfo('upsertPendingSyncOrders-结束', {
1091
- count: patchedOrders.length,
1092
- storeOrderCountAfter: this.store.list.length
1093
- });
1094
- _context11.next = 63;
1095
- return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
1096
- case 63:
1097
- case "end":
1098
- return _context11.stop();
1099
- }
1100
- }, _callee11, this, [[6, 19, 22, 25], [33, 48, 51, 54]]);
1101
- }));
1102
- function upsertPendingSyncOrders(_x7) {
1103
- return _upsertPendingSyncOrders.apply(this, arguments);
1104
- }
1105
- return upsertPendingSyncOrders;
1106
- }()
1107
- /**
1108
- * 通过 SSE 按自定义 query 拉取订单(支持 select/with 精简字段)
1109
- */
1110
- )
1111
- }, {
1112
- key: "fetchOrdersBySSE",
1113
- value: (function () {
1114
- var _fetchOrdersBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1115
- var query,
1116
- data,
1117
- _args12 = arguments;
1118
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1119
- while (1) switch (_context12.prev = _context12.next) {
1120
- case 0:
1121
- query = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1122
- if (this.orderDataSource) {
1123
- _context12.next = 3;
1124
- break;
1125
- }
1126
- return _context12.abrupt("return", []);
1127
- case 3:
1128
- _context12.prev = 3;
1129
- _context12.next = 6;
1130
- return this.orderDataSource.run({
1131
- sse: {
1132
- query: query
1133
- }
1134
- });
1135
- case 6:
1136
- data = _context12.sent;
1137
- return _context12.abrupt("return", data || []);
1138
- case 10:
1139
- _context12.prev = 10;
1140
- _context12.t0 = _context12["catch"](3);
1141
- this.logError('fetchOrdersBySSE-失败', {
1142
- error: _context12.t0 instanceof Error ? _context12.t0.message : String(_context12.t0)
1143
- });
1144
- return _context12.abrupt("return", []);
1145
- case 14:
1146
- case "end":
1147
- return _context12.stop();
1148
- }
1149
- }, _callee12, this, [[3, 10]]);
1150
- }));
1151
- function fetchOrdersBySSE() {
1152
- return _fetchOrdersBySSE.apply(this, arguments);
1153
- }
1154
- return fetchOrdersBySSE;
1155
- }())
624
+ return fetchOrdersBySSE;
625
+ }())
1156
626
  }, {
1157
627
  key: "getRoutes",
1158
628
  value: function getRoutes() {
@@ -1174,120 +644,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1174
644
  }, {
1175
645
  key: "syncOrdersMap",
1176
646
  value: function syncOrdersMap() {
1177
- var _this11 = this;
647
+ var _this6 = this;
1178
648
  this.store.map.clear();
1179
649
  this.resourceIdIndex.clear();
1180
- var _iterator7 = _createForOfIteratorHelper(this.store.list),
1181
- _step7;
650
+ var _iterator = _createForOfIteratorHelper(this.store.list),
651
+ _step;
1182
652
  try {
1183
653
  var _loop = function _loop() {
1184
- var order = _step7.value;
1185
- var primaryIdentity = _this11.getOrderMapKey(order);
1186
- if (!primaryIdentity) return 1; // continue
1187
- _this11.store.map.set(primaryIdentity, order);
1188
- var resourceIds = _this11.extractResourceIds(order);
1189
- var _iterator8 = _createForOfIteratorHelper(resourceIds),
1190
- _step8;
654
+ var order = _step.value;
655
+ var id = order.order_id;
656
+ if (id === undefined || id === null) return 1; // continue
657
+ _this6.store.map.set(_this6.getIdKey(id), order);
658
+ var resourceIds = _this6.extractResourceIds(order);
659
+ var _iterator2 = _createForOfIteratorHelper(resourceIds),
660
+ _step2;
1191
661
  try {
1192
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1193
- var resourceId = _step8.value;
662
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
663
+ var resourceId = _step2.value;
1194
664
  var key = String(resourceId);
1195
- var existing = _this11.resourceIdIndex.get(key) || [];
665
+ var existing = _this6.resourceIdIndex.get(key) || [];
1196
666
  if (existing.some(function (eid) {
1197
- return _this11.getIdKey(eid) === primaryIdentity;
667
+ return _this6.getIdKey(eid) === _this6.getIdKey(id);
1198
668
  })) continue;
1199
- existing.push(primaryIdentity);
1200
- _this11.resourceIdIndex.set(key, existing);
669
+ existing.push(id);
670
+ _this6.resourceIdIndex.set(key, existing);
1201
671
  }
1202
672
  } catch (err) {
1203
- _iterator8.e(err);
673
+ _iterator2.e(err);
1204
674
  } finally {
1205
- _iterator8.f();
675
+ _iterator2.f();
1206
676
  }
1207
677
  };
1208
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
678
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1209
679
  if (_loop()) continue;
1210
680
  }
1211
681
  } catch (err) {
1212
- _iterator7.e(err);
1213
- } finally {
1214
- _iterator7.f();
1215
- }
1216
- }
1217
- }, {
1218
- key: "getOrderMapKey",
1219
- value: function getOrderMapKey(order) {
1220
- if (!order) return '';
1221
- if (!this.isBlankIdentityValue(order.order_id)) {
1222
- return this.getIdKey(order.order_id);
1223
- }
1224
- var externalSaleNumber = order.external_sale_number;
1225
- if (!this.isBlankIdentityValue(externalSaleNumber)) {
1226
- return this.getIdKey(externalSaleNumber);
1227
- }
1228
- return '';
1229
- }
1230
- }, {
1231
- key: "isBlankIdentityValue",
1232
- value: function isBlankIdentityValue(value) {
1233
- return value === undefined || value === null || value === '';
1234
- }
1235
- }, {
1236
- key: "getOrderIdentityEntries",
1237
- value: function getOrderIdentityEntries(order) {
1238
- var _this12 = this;
1239
- if (!order) return [];
1240
- var record = order;
1241
- var candidates = [{
1242
- field: 'order_id',
1243
- value: order.order_id
1244
- }, {
1245
- field: 'external_sale_number',
1246
- value: record.external_sale_number
1247
- }, {
1248
- field: 'order_number',
1249
- value: record.order_number
1250
- }, {
1251
- field: 'shop_order_number',
1252
- value: record.shop_order_number
1253
- }];
1254
- var entries = [];
1255
- var _loop2 = function _loop2() {
1256
- var candidate = _candidates[_i];
1257
- if (_this12.isBlankIdentityValue(candidate.value)) return 0; // continue
1258
- var key = _this12.getIdKey(candidate.value);
1259
- if (entries.some(function (entry) {
1260
- return entry.field === candidate.field && entry.key === key;
1261
- })) return 0; // continue
1262
- entries.push({
1263
- field: candidate.field,
1264
- key: key
1265
- });
1266
- },
1267
- _ret;
1268
- for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
1269
- _ret = _loop2();
1270
- if (_ret === 0) continue;
1271
- }
1272
- return entries;
1273
- }
1274
- }, {
1275
- key: "getOrderIdentityKeys",
1276
- value: function getOrderIdentityKeys(order) {
1277
- var keys = [];
1278
- var _iterator9 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
1279
- _step9;
1280
- try {
1281
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1282
- var entry = _step9.value;
1283
- if (!keys.includes(entry.key)) keys.push(entry.key);
1284
- }
1285
- } catch (err) {
1286
- _iterator9.e(err);
682
+ _iterator.e(err);
1287
683
  } finally {
1288
- _iterator9.f();
684
+ _iterator.f();
1289
685
  }
1290
- return keys;
1291
686
  }
1292
687
  }, {
1293
688
  key: "extractResourceIds",
@@ -1313,8 +708,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1313
708
  value: function getOrderDateKey(order) {
1314
709
  var _order$bookings, _order$bookings2;
1315
710
  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];
1316
- for (var _i2 = 0, _candidates2 = candidates; _i2 < _candidates2.length; _i2++) {
1317
- var v = _candidates2[_i2];
711
+ for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
712
+ var v = _candidates[_i];
1318
713
  if (!v) continue;
1319
714
  var text = String(v);
1320
715
  if (!text) continue;
@@ -1341,30 +736,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1341
736
  }, {
1342
737
  key: "setupOrderSync",
1343
738
  value: function setupOrderSync() {
1344
- var _this13 = this;
739
+ var _this7 = this;
1345
740
  if (!this.orderDataSource) return;
1346
741
  this.orderDataSource.run({
1347
742
  pubsub: {
1348
743
  callback: function callback(res) {
1349
744
  var _message$id, _message$order_id, _message$type;
1350
- console.log('orderDataSource', res);
745
+ console.log('orderDataSource');
1351
746
  var pubsubReceivedAt = Date.now();
1352
- var message = _this13.normalizeOrderSyncMessage(res);
747
+ var message = _this7.normalizeOrderSyncMessage(res);
1353
748
  if (!message) return;
1354
749
  message._pubsubReceivedAt = pubsubReceivedAt;
1355
- _this13.pendingSyncMessages.push(message);
1356
- var throttleMs = _this13.getOrderSyncThrottleMs();
1357
- var routeInfo = _this13.resolveSyncMessageRoute(message);
1358
- _this13.logInfo('orderSync-收到消息并入队', {
750
+ _this7.pendingSyncMessages.push(message);
751
+ var throttleMs = _this7.getOrderSyncThrottleMs();
752
+ _this7.logInfo('orderSync-收到消息并入队', {
1359
753
  id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
1360
754
  order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
1361
755
  type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
1362
- pendingCount: _this13.pendingSyncMessages.length,
756
+ pendingCount: _this7.pendingSyncMessages.length,
1363
757
  throttleMs: throttleMs,
1364
- pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
1365
- fullMessage: JSON.stringify(message)
758
+ pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString()
1366
759
  });
1367
- _this13.scheduleOrderSyncThrottle();
760
+ _this7.scheduleOrderSyncThrottle();
1368
761
  }
1369
762
  }
1370
763
  }).catch(function () {
@@ -1381,7 +774,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1381
774
  }, {
1382
775
  key: "scheduleOrderSyncThrottle",
1383
776
  value: function scheduleOrderSyncThrottle() {
1384
- var _this14 = this;
777
+ var _this8 = this;
1385
778
  if (this.isProcessingSyncBatch) return;
1386
779
  if (this.isIdlePhase) {
1387
780
  this.isIdlePhase = false;
@@ -1392,8 +785,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1392
785
  if (this.syncTimer) return;
1393
786
  var throttleMs = this.getOrderSyncThrottleMs();
1394
787
  this.syncTimer = setTimeout(function () {
1395
- _this14.syncTimer = undefined;
1396
- void _this14.flushOrderSyncMessagesByThrottle();
788
+ _this8.syncTimer = undefined;
789
+ void _this8.flushOrderSyncMessagesByThrottle();
1397
790
  }, throttleMs);
1398
791
  }
1399
792
 
@@ -1404,41 +797,41 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1404
797
  }, {
1405
798
  key: "flushOrderSyncMessagesByThrottle",
1406
799
  value: (function () {
1407
- var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1408
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1409
- while (1) switch (_context13.prev = _context13.next) {
800
+ var _flushOrderSyncMessagesByThrottle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
801
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
802
+ while (1) switch (_context10.prev = _context10.next) {
1410
803
  case 0:
1411
804
  if (!this.isProcessingSyncBatch) {
1412
- _context13.next = 2;
805
+ _context10.next = 2;
1413
806
  break;
1414
807
  }
1415
- return _context13.abrupt("return");
808
+ return _context10.abrupt("return");
1416
809
  case 2:
1417
810
  if (!(this.pendingSyncMessages.length === 0)) {
1418
- _context13.next = 5;
811
+ _context10.next = 5;
1419
812
  break;
1420
813
  }
1421
814
  this.isIdlePhase = true;
1422
- return _context13.abrupt("return");
815
+ return _context10.abrupt("return");
1423
816
  case 5:
1424
817
  this.isProcessingSyncBatch = true;
1425
- _context13.prev = 6;
1426
- _context13.next = 9;
818
+ _context10.prev = 6;
819
+ _context10.next = 9;
1427
820
  return this.processOrderSyncMessages();
1428
821
  case 9:
1429
- _context13.prev = 9;
822
+ _context10.prev = 9;
1430
823
  this.isProcessingSyncBatch = false;
1431
824
  if (this.pendingSyncMessages.length > 0) {
1432
825
  this.scheduleOrderSyncThrottle();
1433
826
  } else {
1434
827
  this.isIdlePhase = true;
1435
828
  }
1436
- return _context13.finish(9);
829
+ return _context10.finish(9);
1437
830
  case 13:
1438
831
  case "end":
1439
- return _context13.stop();
832
+ return _context10.stop();
1440
833
  }
1441
- }, _callee13, this, [[6,, 9, 13]]);
834
+ }, _callee10, this, [[6,, 9, 13]]);
1442
835
  }));
1443
836
  function flushOrderSyncMessagesByThrottle() {
1444
837
  return _flushOrderSyncMessagesByThrottle.apply(this, arguments);
@@ -1460,19 +853,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1460
853
  }, {
1461
854
  key: "processOrderSyncMessages",
1462
855
  value: (function () {
1463
- var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1464
- var _this15 = this;
1465
- var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
1466
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1467
- while (1) switch (_context14.prev = _context14.next) {
856
+ var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
857
+ var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, _iterator3, _step3, _msg$id, _msg$relation_order_i, msg, hasBatchIds, singleId, hasSingleId, rawBody, normalizedBody, uniqueRefreshIds, upsertList, freshOrders, batchProcessEndAt;
858
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
859
+ while (1) switch (_context11.prev = _context11.next) {
1468
860
  case 0:
1469
861
  messages = _toConsumableArray(this.pendingSyncMessages);
1470
862
  this.pendingSyncMessages = [];
1471
863
  if (!(messages.length === 0)) {
1472
- _context14.next = 4;
864
+ _context11.next = 4;
1473
865
  break;
1474
866
  }
1475
- return _context14.abrupt("return");
867
+ return _context11.abrupt("return");
1476
868
  case 4:
1477
869
  batchProcessStartAt = Date.now();
1478
870
  earliestReceivedAt = Math.min.apply(Math, _toConsumableArray(messages.map(function (m) {
@@ -1487,18 +879,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1487
879
  });
1488
880
  upsertOrders = new Map();
1489
881
  refreshIds = [];
1490
- messages.forEach(function (msg, msgIndex) {
1491
- var routeInfo = _this15.resolveSyncMessageRoute(msg);
1492
- var hasBatchIds = routeInfo.hasBatchIds;
1493
- var singleId = routeInfo.singleId;
1494
- var hasSingleId = routeInfo.hasSingleId;
1495
- var normalizedBody = _this15.normalizeOrderSyncPayload(msg.body || msg.data);
1496
- if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
1497
- upsertOrders.set(_this15.getIdKey(normalizedBody.order_id), normalizedBody);
1498
- return;
1499
- }
1500
- 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));
1501
- });
882
+ _iterator3 = _createForOfIteratorHelper(messages);
883
+ _context11.prev = 10;
884
+ _iterator3.s();
885
+ case 12:
886
+ if ((_step3 = _iterator3.n()).done) {
887
+ _context11.next = 25;
888
+ break;
889
+ }
890
+ msg = _step3.value;
891
+ hasBatchIds = Array.isArray(msg.ids) && msg.ids.length > 0;
892
+ singleId = (_msg$id = msg.id) !== null && _msg$id !== void 0 ? _msg$id : msg.order_id;
893
+ hasSingleId = !hasBatchIds && singleId !== undefined && singleId !== null;
894
+ rawBody = msg.body || msg.data;
895
+ normalizedBody = this.normalizeOrderSyncPayload(rawBody);
896
+ if (!(hasSingleId && normalizedBody)) {
897
+ _context11.next = 22;
898
+ break;
899
+ }
900
+ upsertOrders.set(this.getIdKey(normalizedBody.order_id), normalizedBody);
901
+ return _context11.abrupt("continue", 23);
902
+ case 22:
903
+ 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));
904
+ case 23:
905
+ _context11.next = 12;
906
+ break;
907
+ case 25:
908
+ _context11.next = 30;
909
+ break;
910
+ case 27:
911
+ _context11.prev = 27;
912
+ _context11.t0 = _context11["catch"](10);
913
+ _iterator3.e(_context11.t0);
914
+ case 30:
915
+ _context11.prev = 30;
916
+ _iterator3.f();
917
+ return _context11.finish(30);
918
+ case 33:
1502
919
  uniqueRefreshIds = this.uniqueOrderIds(refreshIds);
1503
920
  upsertList = _toConsumableArray(upsertOrders.values());
1504
921
  this.logInfo('processOrderSyncMessages-去重完成', {
@@ -1506,42 +923,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1506
923
  refreshIdCount: uniqueRefreshIds.length
1507
924
  });
1508
925
  if (!(upsertList.length > 0)) {
1509
- _context14.next = 16;
926
+ _context11.next = 39;
1510
927
  break;
1511
928
  }
1512
- _context14.next = 16;
1513
- return this.mergeOrdersToStore(upsertList, 'pubsub.bodyUpsert');
1514
- case 16:
929
+ _context11.next = 39;
930
+ return this.mergeOrdersToStore(upsertList);
931
+ case 39:
1515
932
  if (!(uniqueRefreshIds.length > 0)) {
1516
- _context14.next = 28;
1517
- break;
1518
- }
1519
- _this$filterRedundant = this.filterRedundantHttpRefreshIds(uniqueRefreshIds), toFetch = _this$filterRedundant.toFetch, skipped = _this$filterRedundant.skipped;
1520
- if (skipped.length > 0) {}
1521
- if (!(toFetch.length > 0)) {
1522
- _context14.next = 28;
933
+ _context11.next = 46;
1523
934
  break;
1524
935
  }
1525
- _context14.next = 22;
1526
- return this.fetchOrdersByHttp(toFetch);
1527
- case 22:
1528
- freshOrders = _context14.sent;
936
+ _context11.next = 42;
937
+ return this.fetchOrdersByHttp(uniqueRefreshIds);
938
+ case 42:
939
+ freshOrders = _context11.sent;
1529
940
  if (!(freshOrders.length > 0)) {
1530
- _context14.next = 28;
941
+ _context11.next = 46;
1531
942
  break;
1532
943
  }
1533
- _context14.next = 26;
1534
- return this.mergeOrdersToStore(freshOrders, 'pubsub.httpRefresh');
1535
- case 26:
1536
- _context14.next = 28;
1537
- break;
1538
- case 28:
944
+ _context11.next = 46;
945
+ return this.mergeOrdersToStore(freshOrders);
946
+ case 46:
1539
947
  if (!(upsertList.length === 0 && uniqueRefreshIds.length === 0)) {
1540
- _context14.next = 30;
948
+ _context11.next = 48;
1541
949
  break;
1542
950
  }
1543
- return _context14.abrupt("return");
1544
- case 30:
951
+ return _context11.abrupt("return");
952
+ case 48:
1545
953
  batchProcessEndAt = Date.now();
1546
954
  this.logInfo('processOrderSyncMessages-结束', {
1547
955
  upsertCount: upsertList.length,
@@ -1549,13 +957,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1549
957
  batchProcessDurationMs: batchProcessEndAt - batchProcessStartAt,
1550
958
  totalFromPubsubToProcessedMs: batchProcessEndAt - earliestReceivedAt
1551
959
  });
1552
- _context14.next = 34;
960
+ _context11.next = 52;
1553
961
  return this.core.effects.emit(OrderHooks.onOrdersSyncCompleted, null);
1554
- case 34:
962
+ case 52:
1555
963
  case "end":
1556
- return _context14.stop();
964
+ return _context11.stop();
1557
965
  }
1558
- }, _callee14, this);
966
+ }, _callee11, this, [[10, 27, 30, 33]]);
1559
967
  }));
1560
968
  function processOrderSyncMessages() {
1561
969
  return _processOrderSyncMessages.apply(this, arguments);
@@ -1576,29 +984,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1576
984
  }, {
1577
985
  key: "fetchOrdersByHttp",
1578
986
  value: (function () {
1579
- var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
987
+ var _fetchOrdersByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(ids) {
1580
988
  var _orderList, orderList;
1581
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1582
- while (1) switch (_context15.prev = _context15.next) {
989
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
990
+ while (1) switch (_context12.prev = _context12.next) {
1583
991
  case 0:
1584
992
  if (!(!this.orderDataSource || ids.length === 0)) {
1585
- _context15.next = 2;
993
+ _context12.next = 2;
1586
994
  break;
1587
995
  }
1588
- return _context15.abrupt("return", []);
996
+ return _context12.abrupt("return", []);
1589
997
  case 2:
1590
- _context15.prev = 2;
998
+ _context12.prev = 2;
1591
999
  if (!(typeof this.orderDataSource.fetchOrdersByIds === 'function')) {
1592
- _context15.next = 8;
1000
+ _context12.next = 8;
1593
1001
  break;
1594
1002
  }
1595
- _context15.next = 6;
1003
+ _context12.next = 6;
1596
1004
  return this.orderDataSource.fetchOrdersByIds(ids);
1597
1005
  case 6:
1598
- _orderList = _context15.sent;
1599
- return _context15.abrupt("return", _orderList || []);
1006
+ _orderList = _context12.sent;
1007
+ return _context12.abrupt("return", _orderList || []);
1600
1008
  case 8:
1601
- _context15.next = 10;
1009
+ _context12.next = 10;
1602
1010
  return this.orderDataSource.run({
1603
1011
  http: {
1604
1012
  query: {
@@ -1607,19 +1015,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1607
1015
  }
1608
1016
  });
1609
1017
  case 10:
1610
- orderList = _context15.sent;
1611
- return _context15.abrupt("return", orderList || []);
1018
+ orderList = _context12.sent;
1019
+ return _context12.abrupt("return", orderList || []);
1612
1020
  case 14:
1613
- _context15.prev = 14;
1614
- _context15.t0 = _context15["catch"](2);
1615
- return _context15.abrupt("return", []);
1021
+ _context12.prev = 14;
1022
+ _context12.t0 = _context12["catch"](2);
1023
+ return _context12.abrupt("return", []);
1616
1024
  case 17:
1617
1025
  case "end":
1618
- return _context15.stop();
1026
+ return _context12.stop();
1619
1027
  }
1620
- }, _callee15, this, [[2, 14]]);
1028
+ }, _callee12, this, [[2, 14]]);
1621
1029
  }));
1622
- function fetchOrdersByHttp(_x8) {
1030
+ function fetchOrdersByHttp(_x6) {
1623
1031
  return _fetchOrdersByHttp.apply(this, arguments);
1624
1032
  }
1625
1033
  return fetchOrdersByHttp;
@@ -1631,126 +1039,87 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1631
1039
  }, {
1632
1040
  key: "mergeOrdersToStore",
1633
1041
  value: (function () {
1634
- var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
1635
- var normalizedFreshOrders, _iterator10, _step10, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, _iterator11, _step11, fresh, matchIndex, storageKey, mergeKey, mergedOrder, insertCount, updateCount;
1636
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1637
- while (1) switch (_context16.prev = _context16.next) {
1042
+ var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(freshOrders) {
1043
+ var _this9 = this;
1044
+ var freshMap, _iterator4, _step4, order, id, uniqueFreshCount, updatedList, _iterator5, _step5, _order;
1045
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1046
+ while (1) switch (_context13.prev = _context13.next) {
1638
1047
  case 0:
1639
1048
  this.logInfo('mergeOrdersToStore-开始', {
1640
1049
  freshOrderCount: freshOrders.length,
1641
- storeOrderCountBefore: this.store.list.length,
1642
- source: source
1050
+ storeOrderCountBefore: this.store.list.length
1643
1051
  });
1644
- this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
1645
- normalizedFreshOrders = [];
1646
- _iterator10 = _createForOfIteratorHelper(freshOrders);
1647
- _context16.prev = 4;
1648
- _iterator10.s();
1649
- case 6:
1650
- if ((_step10 = _iterator10.n()).done) {
1651
- _context16.next = 14;
1052
+ freshMap = new Map();
1053
+ _iterator4 = _createForOfIteratorHelper(freshOrders);
1054
+ _context13.prev = 3;
1055
+ _iterator4.s();
1056
+ case 5:
1057
+ if ((_step4 = _iterator4.n()).done) {
1058
+ _context13.next = 13;
1652
1059
  break;
1653
1060
  }
1654
- order = _step10.value;
1061
+ order = _step4.value;
1655
1062
  id = order === null || order === void 0 ? void 0 : order.order_id;
1656
1063
  if (!(id === undefined || id === null)) {
1657
- _context16.next = 11;
1064
+ _context13.next = 10;
1658
1065
  break;
1659
1066
  }
1660
- return _context16.abrupt("continue", 12);
1067
+ return _context13.abrupt("continue", 11);
1068
+ case 10:
1069
+ freshMap.set(this.getIdKey(id), order);
1661
1070
  case 11:
1662
- normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
1663
- case 12:
1664
- _context16.next = 6;
1071
+ _context13.next = 5;
1665
1072
  break;
1666
- case 14:
1667
- _context16.next = 19;
1668
- break;
1669
- case 16:
1670
- _context16.prev = 16;
1671
- _context16.t0 = _context16["catch"](4);
1672
- _iterator10.e(_context16.t0);
1673
- case 19:
1674
- _context16.prev = 19;
1675
- _iterator10.f();
1676
- return _context16.finish(19);
1677
- case 22:
1678
- uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
1679
- uniqueFreshCount = uniqueFreshOrders.length;
1680
- patchedOrders = [];
1681
- mergeActions = {};
1682
- updatedList = _toConsumableArray(this.store.list);
1683
- _iterator11 = _createForOfIteratorHelper(uniqueFreshOrders);
1684
- _context16.prev = 28;
1685
- _iterator11.s();
1686
- case 30:
1687
- if ((_step11 = _iterator11.n()).done) {
1688
- _context16.next = 46;
1689
- break;
1690
- }
1691
- fresh = _step11.value;
1692
- matchIndex = this.findOrderIndexByIdentity(updatedList, fresh);
1693
- storageKey = this.getOrderStorageKey(fresh);
1694
- mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
1695
- if (!(matchIndex >= 0)) {
1696
- _context16.next = 41;
1697
- break;
1698
- }
1699
- mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], fresh);
1700
- updatedList[matchIndex] = mergedOrder;
1701
- patchedOrders.push(mergedOrder);
1702
- if (mergeKey) mergeActions[mergeKey] = 'update';
1703
- return _context16.abrupt("continue", 44);
1704
- case 41:
1705
- updatedList.push(fresh);
1706
- patchedOrders.push(fresh);
1707
- if (mergeKey) mergeActions[mergeKey] = 'insert';
1708
- case 44:
1709
- _context16.next = 30;
1710
- break;
1711
- case 46:
1712
- _context16.next = 51;
1073
+ case 13:
1074
+ _context13.next = 18;
1713
1075
  break;
1714
- case 48:
1715
- _context16.prev = 48;
1716
- _context16.t1 = _context16["catch"](28);
1717
- _iterator11.e(_context16.t1);
1718
- case 51:
1719
- _context16.prev = 51;
1720
- _iterator11.f();
1721
- return _context16.finish(51);
1722
- case 54:
1723
- insertCount = Object.values(mergeActions).filter(function (v) {
1724
- return v === 'insert';
1725
- }).length;
1726
- updateCount = Object.values(mergeActions).filter(function (v) {
1727
- return v === 'update';
1728
- }).length;
1729
- this.logInfo('mergeOrdersToStore-合并完成', {
1730
- insertCount: insertCount,
1731
- updateCount: updateCount,
1732
- storeOrderCountAfter: this.store.list.length
1076
+ case 15:
1077
+ _context13.prev = 15;
1078
+ _context13.t0 = _context13["catch"](3);
1079
+ _iterator4.e(_context13.t0);
1080
+ case 18:
1081
+ _context13.prev = 18;
1082
+ _iterator4.f();
1083
+ return _context13.finish(18);
1084
+ case 21:
1085
+ uniqueFreshCount = freshMap.size;
1086
+ updatedList = this.store.list.map(function (order) {
1087
+ var id = order.order_id;
1088
+ if (id === undefined || id === null) return order;
1089
+ var key = _this9.getIdKey(id);
1090
+ if (!freshMap.has(key)) return order;
1091
+ var fresh = freshMap.get(key);
1092
+ freshMap.delete(key);
1093
+ return fresh;
1733
1094
  });
1734
- this.store.list = this.compactOrderListByIdentity(updatedList, "".concat(source, ".store")).list;
1095
+ _iterator5 = _createForOfIteratorHelper(freshMap.values());
1096
+ try {
1097
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1098
+ _order = _step5.value;
1099
+ updatedList.push(_order);
1100
+ }
1101
+ } catch (err) {
1102
+ _iterator5.e(err);
1103
+ } finally {
1104
+ _iterator5.f();
1105
+ }
1106
+ this.store.list = updatedList;
1735
1107
  this.syncOrdersMap();
1736
- _context16.next = 61;
1737
- return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
1738
- case 61:
1108
+ _context13.next = 29;
1109
+ return this.saveOrdersToSQLite(this.store.list);
1110
+ case 29:
1739
1111
  this.logInfo('mergeOrdersToStore-结束', {
1740
1112
  uniqueFreshCount: uniqueFreshCount,
1741
- storeOrderCountAfter: this.store.list.length,
1742
- insertCount: insertCount,
1743
- updateCount: updateCount
1113
+ storeOrderCountAfter: this.store.list.length
1744
1114
  });
1745
- _context16.next = 64;
1746
- return this.emitOrdersChanged(patchedOrders, source);
1747
- case 64:
1115
+ this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
1116
+ case 31:
1748
1117
  case "end":
1749
- return _context16.stop();
1118
+ return _context13.stop();
1750
1119
  }
1751
- }, _callee16, this, [[4, 16, 19, 22], [28, 48, 51, 54]]);
1120
+ }, _callee13, this, [[3, 15, 18, 21]]);
1752
1121
  }));
1753
- function mergeOrdersToStore(_x9, _x10) {
1122
+ function mergeOrdersToStore(_x7) {
1754
1123
  return _mergeOrdersToStore.apply(this, arguments);
1755
1124
  }
1756
1125
  return mergeOrdersToStore;
@@ -1787,17 +1156,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1787
1156
  key: "uniqueOrderIds",
1788
1157
  value: function uniqueOrderIds(ids) {
1789
1158
  var idMap = new Map();
1790
- var _iterator12 = _createForOfIteratorHelper(ids),
1791
- _step12;
1159
+ var _iterator6 = _createForOfIteratorHelper(ids),
1160
+ _step6;
1792
1161
  try {
1793
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1794
- var id = _step12.value;
1162
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1163
+ var id = _step6.value;
1795
1164
  idMap.set(this.getIdKey(id), id);
1796
1165
  }
1797
1166
  } catch (err) {
1798
- _iterator12.e(err);
1167
+ _iterator6.e(err);
1799
1168
  } finally {
1800
- _iterator12.f();
1169
+ _iterator6.f();
1801
1170
  }
1802
1171
  return _toConsumableArray(idMap.values());
1803
1172
  }
@@ -1806,274 +1175,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1806
1175
  value: function getIdKey(id) {
1807
1176
  return String(id);
1808
1177
  }
1809
- }, {
1810
- key: "isOrderLookupMatch",
1811
- value: function isOrderLookupMatch(order, lookupKey) {
1812
- var _this16 = this;
1813
- if (!order || !lookupKey) return false;
1814
- var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
1815
- return candidates.some(function (value) {
1816
- if (value === undefined || value === null || value === '') return false;
1817
- return _this16.getIdKey(value) === lookupKey;
1818
- });
1819
- }
1820
-
1821
- /**
1822
- * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
1823
- *
1824
- * @example
1825
- * const key = this.getOrderStorageKey({ order_id: 1001, external_sale_number: 'S-1001' })
1826
- * // => 'S-1001'
1827
- */
1828
- }, {
1829
- key: "getOrderStorageKey",
1830
- value: function getOrderStorageKey(order) {
1831
- var externalSaleNumber = order === null || order === void 0 ? void 0 : order.external_sale_number;
1832
- if (externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '') {
1833
- return String(externalSaleNumber);
1834
- }
1835
- var orderId = order === null || order === void 0 ? void 0 : order.order_id;
1836
- if (orderId !== undefined && orderId !== null && orderId !== '') {
1837
- return String(orderId);
1838
- }
1839
- return '';
1840
- }
1841
- }, {
1842
- key: "getOrderIdentityMatchKeys",
1843
- value: function getOrderIdentityMatchKeys(order) {
1844
- return this.getOrderIdentityEntries(order).map(function (entry) {
1845
- return "".concat(entry.field, ":").concat(entry.key);
1846
- });
1847
- }
1848
- }, {
1849
- key: "doOrdersShareIdentity",
1850
- value: function doOrdersShareIdentity(left, right) {
1851
- var leftKeys = new Set(this.getOrderIdentityMatchKeys(left));
1852
- if (leftKeys.size === 0) return false;
1853
- return this.getOrderIdentityMatchKeys(right).some(function (key) {
1854
- return leftKeys.has(key);
1855
- });
1856
- }
1857
- }, {
1858
- key: "findOrderIndexByIdentity",
1859
- value: function findOrderIndexByIdentity(orders, target) {
1860
- var _this17 = this;
1861
- if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
1862
- return orders.findIndex(function (order) {
1863
- return _this17.doOrdersShareIdentity(order, target);
1864
- });
1865
- }
1866
- }, {
1867
- key: "getOrderCompletenessScore",
1868
- value: function getOrderCompletenessScore(order) {
1869
- var record = order;
1870
- var score = this.isPendingSyncOrder(order) ? 0 : 100;
1871
- if (!this.isBlankIdentityValue(order.order_id) && order.order_id !== record.external_sale_number) score += 30;
1872
- score += this.getOrderIdentityMatchKeys(order).length * 5;
1873
- if (Array.isArray(order.products)) score += Math.min(order.products.length, 10);
1874
- if (Array.isArray(order.bookings)) score += Math.min(order.bookings.length, 10);
1875
- if (Array.isArray(order.payments)) score += Math.min(order.payments.length, 10);
1876
- if (record.updated_at) score += 1;
1877
- return score;
1878
- }
1879
- }, {
1880
- key: "pickPreferredOrder",
1881
- value: function pickPreferredOrder(left, right) {
1882
- var leftScore = this.getOrderCompletenessScore(left);
1883
- var rightScore = this.getOrderCompletenessScore(right);
1884
- if (rightScore >= leftScore) return right;
1885
- return left;
1886
- }
1887
- }, {
1888
- key: "getProductMergeKey",
1889
- value: function getProductMergeKey(product) {
1890
- var _record$metadata;
1891
- var record = product;
1892
- if (!record) return '';
1893
- var metadataUid = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.unique_identification_number;
1894
- if (!this.isBlankIdentityValue(metadataUid)) return "uid:".concat(String(metadataUid));
1895
- var topLevelUid = record.unique_identification_number;
1896
- if (!this.isBlankIdentityValue(topLevelUid)) return "uid:".concat(String(topLevelUid));
1897
- var bookingUid = record.booking_uid;
1898
- if (!this.isBlankIdentityValue(bookingUid)) return "booking:".concat(String(bookingUid));
1899
- return '';
1900
- }
1901
- }, {
1902
- key: "mergeOrderProductLists",
1903
- value: function mergeOrderProductLists(preferred, secondary) {
1904
- var preferredList = Array.isArray(preferred) ? preferred : [];
1905
- var secondaryList = Array.isArray(secondary) ? secondary : [];
1906
- if (secondaryList.length === 0) return preferredList;
1907
- if (preferredList.length === 0) return secondaryList;
1908
- var seenKeys = new Set();
1909
- var _iterator13 = _createForOfIteratorHelper(preferredList),
1910
- _step13;
1911
- try {
1912
- for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
1913
- var item = _step13.value;
1914
- var key = this.getProductMergeKey(item);
1915
- if (key) seenKeys.add(key);
1916
- }
1917
- } catch (err) {
1918
- _iterator13.e(err);
1919
- } finally {
1920
- _iterator13.f();
1921
- }
1922
- var result = _toConsumableArray(preferredList);
1923
- var _iterator14 = _createForOfIteratorHelper(secondaryList),
1924
- _step14;
1925
- try {
1926
- for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
1927
- var _item = _step14.value;
1928
- var _key = this.getProductMergeKey(_item);
1929
- if (!_key || seenKeys.has(_key)) continue;
1930
- seenKeys.add(_key);
1931
- result.push(cloneDeep(_item));
1932
- }
1933
- } catch (err) {
1934
- _iterator14.e(err);
1935
- } finally {
1936
- _iterator14.f();
1937
- }
1938
- return result;
1939
- }
1940
- }, {
1941
- key: "mergeOrderRecords",
1942
- value: function mergeOrderRecords(existing, incoming) {
1943
- var preferred = this.pickPreferredOrder(existing, incoming);
1944
- var secondary = preferred === existing ? incoming : existing;
1945
- var merged = _objectSpread(_objectSpread({}, secondary), preferred);
1946
- var fieldsToPreserve = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number'];
1947
- var incomingPatchFields = ['payment_status', 'status', 'shipping_status', 'updated_at', 'shop_discount', 'summary', 'payments', 'products', 'bookings'];
1948
- var mergedRecord = merged;
1949
- var preferredRecord = preferred;
1950
- var secondaryRecord = secondary;
1951
- var incomingRecord = incoming;
1952
- for (var _i3 = 0, _fieldsToPreserve = fieldsToPreserve; _i3 < _fieldsToPreserve.length; _i3++) {
1953
- var field = _fieldsToPreserve[_i3];
1954
- if (!this.isBlankIdentityValue(preferredRecord[field])) {
1955
- mergedRecord[field] = preferredRecord[field];
1956
- continue;
1957
- }
1958
- if (!this.isBlankIdentityValue(secondaryRecord[field])) {
1959
- mergedRecord[field] = secondaryRecord[field];
1960
- }
1961
- }
1962
- for (var _i4 = 0, _incomingPatchFields = incomingPatchFields; _i4 < _incomingPatchFields.length; _i4++) {
1963
- var _field = _incomingPatchFields[_i4];
1964
- if (!Object.prototype.hasOwnProperty.call(incomingRecord, _field)) continue;
1965
- if (incomingRecord[_field] === undefined || incomingRecord[_field] === null) continue;
1966
- if (typeof incomingRecord[_field] === 'string' && incomingRecord[_field] === '') continue;
1967
- mergedRecord[_field] = cloneDeep(incomingRecord[_field]);
1968
- }
1969
- mergedRecord.products = this.mergeOrderProductLists(preferredRecord.products, secondaryRecord.products);
1970
- if (!this.isPendingSyncOrder(preferred) || !this.isPendingSyncOrder(secondary)) {
1971
- merged.need_sync = 0;
1972
- }
1973
- return merged;
1974
- }
1975
- }, {
1976
- key: "summarizeDuplicateOrders",
1977
- value: function summarizeDuplicateOrders(orders) {
1978
- var groups = new Map();
1979
- var _iterator15 = _createForOfIteratorHelper(orders),
1980
- _step15;
1981
- try {
1982
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
1983
- var order = _step15.value;
1984
- var _iterator16 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
1985
- _step16;
1986
- try {
1987
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
1988
- var key = _step16.value;
1989
- var group = groups.get(key) || [];
1990
- group.push(order);
1991
- groups.set(key, group);
1992
- }
1993
- } catch (err) {
1994
- _iterator16.e(err);
1995
- } finally {
1996
- _iterator16.f();
1997
- }
1998
- }
1999
- } catch (err) {
2000
- _iterator15.e(err);
2001
- } finally {
2002
- _iterator15.f();
2003
- }
2004
- return _toConsumableArray(groups.entries()).filter(function (_ref2) {
2005
- var _ref3 = _slicedToArray(_ref2, 2),
2006
- group = _ref3[1];
2007
- return group.length > 1;
2008
- }).slice(0, 20).map(function (_ref4) {
2009
- var _ref5 = _slicedToArray(_ref4, 2),
2010
- key = _ref5[0],
2011
- group = _ref5[1];
2012
- return {
2013
- key: key,
2014
- count: group.length,
2015
- orders: group.map(function (order) {
2016
- var _order$order_id2, _external_sale_number, _shop_order_number, _shop_full_order_numb, _order$need_sync;
2017
- return {
2018
- order_id: (_order$order_id2 = order.order_id) !== null && _order$order_id2 !== void 0 ? _order$order_id2 : null,
2019
- external_sale_number: (_external_sale_number = order.external_sale_number) !== null && _external_sale_number !== void 0 ? _external_sale_number : null,
2020
- shop_order_number: (_shop_order_number = order.shop_order_number) !== null && _shop_order_number !== void 0 ? _shop_order_number : null,
2021
- 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,
2022
- need_sync: (_order$need_sync = order.need_sync) !== null && _order$need_sync !== void 0 ? _order$need_sync : null
2023
- };
2024
- })
2025
- };
2026
- });
2027
- }
2028
- }, {
2029
- key: "logDuplicateOrders",
2030
- value: function logDuplicateOrders(source, orders) {
2031
- var duplicateGroups = this.summarizeDuplicateOrders(orders);
2032
- if (duplicateGroups.length === 0) return;
2033
- this.logWarning('检测到重复订单身份键', {
2034
- source: source,
2035
- duplicateGroupCount: duplicateGroups.length,
2036
- duplicateGroups: duplicateGroups
2037
- });
2038
- }
2039
- }, {
2040
- key: "compactOrderListByIdentity",
2041
- value: function compactOrderListByIdentity(orders, source) {
2042
- var list = [];
2043
- var removedCount = 0;
2044
- var _iterator17 = _createForOfIteratorHelper(orders),
2045
- _step17;
2046
- try {
2047
- for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2048
- var order = _step17.value;
2049
- var matchIndex = this.findOrderIndexByIdentity(list, order);
2050
- if (matchIndex < 0) {
2051
- list.push(order);
2052
- continue;
2053
- }
2054
- list[matchIndex] = this.mergeOrderRecords(list[matchIndex], order);
2055
- removedCount += 1;
2056
- }
2057
- } catch (err) {
2058
- _iterator17.e(err);
2059
- } finally {
2060
- _iterator17.f();
2061
- }
2062
- if (removedCount > 0) {
2063
- this.logWarning('订单列表重复项已压缩', {
2064
- source: source,
2065
- beforeCount: orders.length,
2066
- afterCount: list.length,
2067
- removedCount: removedCount
2068
- });
2069
- } else {
2070
- this.logDuplicateOrders(source, orders);
2071
- }
2072
- return {
2073
- list: list,
2074
- removedCount: removedCount
2075
- };
2076
- }
2077
1178
 
2078
1179
  /**
2079
1180
  * 当前订单拉取窗口:
@@ -2131,7 +1232,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2131
1232
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
2132
1233
  return globalThis.localStorage.getItem(key);
2133
1234
  }
2134
- } catch (_unused6) {
1235
+ } catch (_unused5) {
2135
1236
  // 忽略存储异常,避免影响主流程
2136
1237
  }
2137
1238
  return null;
@@ -2148,39 +1249,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2148
1249
  if (typeof globalThis !== 'undefined' && globalThis !== null && globalThis !== void 0 && globalThis.localStorage) {
2149
1250
  globalThis.localStorage.setItem(key, value);
2150
1251
  }
2151
- } catch (_unused7) {
1252
+ } catch (_unused6) {
2152
1253
  // 忽略存储异常,避免影响主流程
2153
1254
  }
2154
1255
  }
2155
1256
  }, {
2156
1257
  key: "loadOrdersFromSQLite",
2157
1258
  value: function () {
2158
- var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1259
+ var _loadOrdersFromSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
2159
1260
  var orders;
2160
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2161
- while (1) switch (_context17.prev = _context17.next) {
1261
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1262
+ while (1) switch (_context14.prev = _context14.next) {
2162
1263
  case 0:
2163
1264
  if (this.dbManager) {
2164
- _context17.next = 2;
1265
+ _context14.next = 2;
2165
1266
  break;
2166
1267
  }
2167
- return _context17.abrupt("return", []);
1268
+ return _context14.abrupt("return", []);
2168
1269
  case 2:
2169
- _context17.prev = 2;
2170
- _context17.next = 5;
1270
+ _context14.prev = 2;
1271
+ _context14.next = 5;
2171
1272
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
2172
1273
  case 5:
2173
- orders = _context17.sent;
2174
- return _context17.abrupt("return", orders || []);
1274
+ orders = _context14.sent;
1275
+ return _context14.abrupt("return", orders || []);
2175
1276
  case 9:
2176
- _context17.prev = 9;
2177
- _context17.t0 = _context17["catch"](2);
2178
- return _context17.abrupt("return", []);
1277
+ _context14.prev = 9;
1278
+ _context14.t0 = _context14["catch"](2);
1279
+ return _context14.abrupt("return", []);
2179
1280
  case 12:
2180
1281
  case "end":
2181
- return _context17.stop();
1282
+ return _context14.stop();
2182
1283
  }
2183
- }, _callee17, this, [[2, 9]]);
1284
+ }, _callee14, this, [[2, 9]]);
2184
1285
  }));
2185
1286
  function loadOrdersFromSQLite() {
2186
1287
  return _loadOrdersFromSQLite.apply(this, arguments);
@@ -2188,488 +1289,91 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2188
1289
  return loadOrdersFromSQLite;
2189
1290
  }()
2190
1291
  }, {
2191
- key: "isPendingSyncOrder",
2192
- value: function isPendingSyncOrder(order) {
2193
- return Number(order === null || order === void 0 ? void 0 : order.need_sync) === 1;
2194
- }
2195
- }, {
2196
- key: "normalizeRemoteSyncedOrder",
2197
- value: function normalizeRemoteSyncedOrder(order) {
2198
- if (this.isPendingSyncOrder(order)) return order;
2199
- return _objectSpread(_objectSpread({}, order), {}, {
2200
- need_sync: 0
2201
- });
2202
- }
2203
- }, {
2204
- key: "mergeRemoteSnapshotWithPendingOrders",
2205
- value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
2206
- var _this18 = this;
2207
- var merged = remoteOrders.map(function (order) {
2208
- return _this18.normalizeRemoteSyncedOrder(order);
2209
- });
2210
- var _iterator18 = _createForOfIteratorHelper(existingOrders),
2211
- _step18;
2212
- try {
2213
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2214
- var order = _step18.value;
2215
- if (!this.isPendingSyncOrder(order)) continue;
2216
- var matchIndex = this.findOrderIndexByIdentity(merged, order);
2217
- if (matchIndex >= 0) {
2218
- merged[matchIndex] = this.mergeOrderRecords(order, merged[matchIndex]);
2219
- continue;
2220
- }
2221
- if (!this.getOrderStorageKey(order)) continue;
2222
- merged.push(order);
2223
- }
2224
- } catch (err) {
2225
- _iterator18.e(err);
2226
- } finally {
2227
- _iterator18.f();
2228
- }
2229
- return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
2230
- }
2231
-
2232
- /**
2233
- * 串行执行订单 SQLite 写入任务,避免快照替换与增量 upsert 并发交错。
2234
- *
2235
- * @example
2236
- * await this.runInOrderSQLiteSaveQueue(async () => {
2237
- * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders)
2238
- * })
2239
- */
2240
- }, {
2241
- key: "runInOrderSQLiteSaveQueue",
2242
- value: (function () {
2243
- var _runInOrderSQLiteSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(task) {
2244
- var queuedTask;
2245
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2246
- while (1) switch (_context18.prev = _context18.next) {
2247
- case 0:
2248
- queuedTask = this.orderSQLiteSaveQueue.then(task, task);
2249
- this.orderSQLiteSaveQueue = queuedTask.then(function () {
2250
- return undefined;
2251
- }, function () {
2252
- return undefined;
2253
- });
2254
- return _context18.abrupt("return", queuedTask);
2255
- case 3:
2256
- case "end":
2257
- return _context18.stop();
2258
- }
2259
- }, _callee18, this);
2260
- }));
2261
- function runInOrderSQLiteSaveQueue(_x11) {
2262
- return _runInOrderSQLiteSaveQueue.apply(this, arguments);
2263
- }
2264
- return runInOrderSQLiteSaveQueue;
2265
- }()
2266
- /**
2267
- * 批量增量 upsert 订单到 SQLite,不清空表;用于 pubsub / HTTP 增量合并。
2268
- *
2269
- * @example
2270
- * await this.patchOrdersInSQLite(freshOrders)
2271
- */
2272
- )
2273
- }, {
2274
- key: "patchOrdersInSQLite",
2275
- value: (function () {
2276
- var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
2277
- var _this19 = this;
2278
- var mergeActions,
2279
- ordersSnapshot,
2280
- _this$filterRedundant2,
2281
- toWrite,
2282
- skipped,
2283
- compactedToWrite,
2284
- _args20 = arguments;
2285
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2286
- while (1) switch (_context20.prev = _context20.next) {
1292
+ key: "saveOrdersToSQLite",
1293
+ value: function () {
1294
+ var _saveOrdersToSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(orderList) {
1295
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1296
+ while (1) switch (_context15.prev = _context15.next) {
2287
1297
  case 0:
2288
- mergeActions = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2289
- if (!(!this.dbManager || orders.length === 0)) {
2290
- _context20.next = 3;
1298
+ if (this.dbManager) {
1299
+ _context15.next = 2;
2291
1300
  break;
2292
1301
  }
2293
- return _context20.abrupt("return");
2294
- case 3:
2295
- ordersSnapshot = cloneDeep(orders).filter(function (order) {
2296
- return _this19.getOrderStorageKey(order);
1302
+ return _context15.abrupt("return");
1303
+ case 2:
1304
+ _context15.prev = 2;
1305
+ this.logInfo('saveOrdersToSQLite-开始', {
1306
+ count: orderList.length
2297
1307
  });
2298
- if (!(ordersSnapshot.length === 0)) {
2299
- _context20.next = 6;
2300
- break;
2301
- }
2302
- return _context20.abrupt("return");
1308
+ _context15.next = 6;
1309
+ return this.dbManager.clear(INDEXDB_STORE_NAME);
2303
1310
  case 6:
2304
- _this$filterRedundant2 = this.filterRedundantPatchOrders(source, ordersSnapshot, mergeActions), toWrite = _this$filterRedundant2.toWrite, skipped = _this$filterRedundant2.skipped;
2305
- if (!(toWrite.length === 0)) {
2306
- _context20.next = 9;
2307
- break;
2308
- }
2309
- return _context20.abrupt("return");
2310
- case 9:
2311
- compactedToWrite = this.compactOrderListByIdentity(toWrite, "".concat(source, ".sqlitePatch")).list;
2312
- if (!(compactedToWrite.length === 0)) {
2313
- _context20.next = 12;
2314
- break;
2315
- }
2316
- return _context20.abrupt("return");
2317
- case 12:
2318
- _context20.prev = 12;
2319
- _context20.next = 15;
2320
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2321
- var writeMethod, _iterator19, _step19, order;
2322
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2323
- while (1) switch (_context19.prev = _context19.next) {
2324
- case 0:
2325
- writeMethod = 'none';
2326
- _this19.logInfo('patchOrdersInSQLite-开始', {
2327
- source: source,
2328
- count: compactedToWrite.length,
2329
- dedupedCount: skipped.length
2330
- });
2331
- if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
2332
- _context19.next = 8;
2333
- break;
2334
- }
2335
- writeMethod = 'bulkUpdate';
2336
- _context19.next = 6;
2337
- return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
2338
- case 6:
2339
- _context19.next = 33;
2340
- break;
2341
- case 8:
2342
- if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
2343
- _context19.next = 14;
2344
- break;
2345
- }
2346
- writeMethod = 'bulkAdd';
2347
- _context19.next = 12;
2348
- return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
2349
- case 12:
2350
- _context19.next = 33;
2351
- break;
2352
- case 14:
2353
- if (!(typeof _this19.dbManager.update === 'function')) {
2354
- _context19.next = 33;
2355
- break;
2356
- }
2357
- writeMethod = 'update';
2358
- _iterator19 = _createForOfIteratorHelper(compactedToWrite);
2359
- _context19.prev = 17;
2360
- _iterator19.s();
2361
- case 19:
2362
- if ((_step19 = _iterator19.n()).done) {
2363
- _context19.next = 25;
2364
- break;
2365
- }
2366
- order = _step19.value;
2367
- _context19.next = 23;
2368
- return _this19.dbManager.update(INDEXDB_STORE_NAME, order);
2369
- case 23:
2370
- _context19.next = 19;
2371
- break;
2372
- case 25:
2373
- _context19.next = 30;
2374
- break;
2375
- case 27:
2376
- _context19.prev = 27;
2377
- _context19.t0 = _context19["catch"](17);
2378
- _iterator19.e(_context19.t0);
2379
- case 30:
2380
- _context19.prev = 30;
2381
- _iterator19.f();
2382
- return _context19.finish(30);
2383
- case 33:
2384
- _this19.recordRecentSqliteWrite(source, compactedToWrite);
2385
- _this19.logInfo('patchOrdersInSQLite-完成', {
2386
- source: source,
2387
- count: compactedToWrite.length,
2388
- writeMethod: writeMethod,
2389
- dedupedCount: skipped.length
2390
- });
2391
- case 35:
2392
- case "end":
2393
- return _context19.stop();
2394
- }
2395
- }, _callee19, null, [[17, 27, 30, 33]]);
2396
- })));
2397
- case 15:
2398
- _context20.next = 20;
2399
- break;
2400
- case 17:
2401
- _context20.prev = 17;
2402
- _context20.t0 = _context20["catch"](12);
2403
- this.logError('增量保存订单到 SQLite 失败', {
2404
- error: _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0),
2405
- orderCount: ordersSnapshot.length
1311
+ this.logInfo('saveOrdersToSQLite-clear完成', {
1312
+ count: orderList.length
2406
1313
  });
2407
- case 20:
2408
- case "end":
2409
- return _context20.stop();
2410
- }
2411
- }, _callee20, this, [[12, 17]]);
2412
- }));
2413
- function patchOrdersInSQLite(_x12, _x13) {
2414
- return _patchOrdersInSQLite.apply(this, arguments);
2415
- }
2416
- return patchOrdersInSQLite;
2417
- }()
2418
- /**
2419
- * 单条 upsert 订单到 SQLite;用于 overwriteExistingOrder 等单条覆盖场景。
2420
- *
2421
- * @example
2422
- * await this.updateOrderInSQLite(freshOrder)
2423
- */
2424
- )
2425
- }, {
2426
- key: "updateOrderInSQLite",
2427
- value: (function () {
2428
- var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
2429
- var _this20 = this;
2430
- var orderSnapshot, _orderSnapshot$order_3;
2431
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2432
- while (1) switch (_context22.prev = _context22.next) {
2433
- case 0:
2434
- if (!(!this.dbManager || !this.getOrderStorageKey(order))) {
2435
- _context22.next = 2;
1314
+ if (!(orderList.length === 0)) {
1315
+ _context15.next = 9;
2436
1316
  break;
2437
1317
  }
2438
- return _context22.abrupt("return");
2439
- case 2:
2440
- orderSnapshot = cloneDeep(order);
2441
- _context22.prev = 3;
2442
- _context22.next = 6;
2443
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2444
- var _orderSnapshot$order_, _orderSnapshot$order_2;
2445
- var writeMethod;
2446
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2447
- while (1) switch (_context21.prev = _context21.next) {
2448
- case 0:
2449
- writeMethod = 'none';
2450
- _this20.logInfo('updateOrderInSQLite-开始', {
2451
- source: source,
2452
- orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
2453
- storageKey: _this20.getOrderStorageKey(orderSnapshot)
2454
- });
2455
- if (!(typeof _this20.dbManager.update === 'function')) {
2456
- _context21.next = 8;
2457
- break;
2458
- }
2459
- writeMethod = 'update';
2460
- _context21.next = 6;
2461
- return _this20.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
2462
- case 6:
2463
- _context21.next = 18;
2464
- break;
2465
- case 8:
2466
- if (!(typeof _this20.dbManager.bulkUpdate === 'function')) {
2467
- _context21.next = 14;
2468
- break;
2469
- }
2470
- writeMethod = 'bulkUpdate';
2471
- _context21.next = 12;
2472
- return _this20.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
2473
- case 12:
2474
- _context21.next = 18;
2475
- break;
2476
- case 14:
2477
- if (!(typeof _this20.dbManager.bulkAdd === 'function')) {
2478
- _context21.next = 18;
2479
- break;
2480
- }
2481
- writeMethod = 'bulkAdd';
2482
- _context21.next = 18;
2483
- return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
2484
- case 18:
2485
- _this20.recordRecentSqliteWrite(source, [orderSnapshot]);
2486
- _this20.logInfo('updateOrderInSQLite-完成', {
2487
- source: source,
2488
- orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
2489
- writeMethod: writeMethod
2490
- });
2491
- case 20:
2492
- case "end":
2493
- return _context21.stop();
2494
- }
2495
- }, _callee21);
2496
- })));
2497
- case 6:
2498
- _context22.next = 11;
2499
- break;
2500
- case 8:
2501
- _context22.prev = 8;
2502
- _context22.t0 = _context22["catch"](3);
2503
- this.logError('单条保存订单到 SQLite 失败', {
2504
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0),
2505
- orderId: (_orderSnapshot$order_3 = orderSnapshot.order_id) !== null && _orderSnapshot$order_3 !== void 0 ? _orderSnapshot$order_3 : null
2506
- });
1318
+ return _context15.abrupt("return");
1319
+ case 9:
1320
+ _context15.next = 11;
1321
+ return this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orderList);
2507
1322
  case 11:
2508
- case "end":
2509
- return _context22.stop();
2510
- }
2511
- }, _callee22, this, [[3, 8]]);
2512
- }));
2513
- function updateOrderInSQLite(_x14, _x15) {
2514
- return _updateOrderInSQLite.apply(this, arguments);
2515
- }
2516
- return updateOrderInSQLite;
2517
- }()
2518
- /**
2519
- * 全量快照替换 orders 表(clear + bulkAdd),用于 SSE 全量拉取与营业日窗口裁剪。
2520
- *
2521
- * @example
2522
- * await this.replaceOrdersSnapshotInSQLite(orderList)
2523
- */
2524
- )
2525
- }, {
2526
- key: "replaceOrdersSnapshotInSQLite",
2527
- value: (function () {
2528
- var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
2529
- var _this21 = this;
2530
- var remoteSnapshot, mergedSnapshot;
2531
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2532
- while (1) switch (_context24.prev = _context24.next) {
2533
- case 0:
2534
- if (this.dbManager) {
2535
- _context24.next = 2;
2536
- break;
2537
- }
2538
- return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
2539
- return _this21.normalizeRemoteSyncedOrder(order);
2540
- }), "".concat(source, ".snapshotNoDb")).list);
2541
- case 2:
2542
- remoteSnapshot = cloneDeep(orderList);
2543
- mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
2544
- return _this21.normalizeRemoteSyncedOrder(order);
2545
- }), "".concat(source, ".remoteSnapshot")).list;
2546
- _context24.prev = 4;
2547
- _context24.next = 7;
2548
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2549
- var existingOrders, orderListSnapshot;
2550
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2551
- while (1) switch (_context23.prev = _context23.next) {
2552
- case 0:
2553
- if (!(typeof _this21.dbManager.getAll === 'function')) {
2554
- _context23.next = 6;
2555
- break;
2556
- }
2557
- _context23.next = 3;
2558
- return _this21.dbManager.getAll(INDEXDB_STORE_NAME);
2559
- case 3:
2560
- _context23.t0 = _context23.sent;
2561
- _context23.next = 7;
2562
- break;
2563
- case 6:
2564
- _context23.t0 = [];
2565
- case 7:
2566
- existingOrders = _context23.t0;
2567
- orderListSnapshot = _this21.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
2568
- mergedSnapshot = _this21.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
2569
- _this21.logInfo('replaceOrdersSnapshotInSQLite-开始', {
2570
- source: source,
2571
- count: mergedSnapshot.length,
2572
- remoteCount: remoteSnapshot.length,
2573
- preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
2574
- });
2575
- _context23.next = 13;
2576
- return _this21.dbManager.clear(INDEXDB_STORE_NAME);
2577
- case 13:
2578
- _this21.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
2579
- count: mergedSnapshot.length
2580
- });
2581
- if (!(mergedSnapshot.length === 0)) {
2582
- _context23.next = 16;
2583
- break;
2584
- }
2585
- return _context23.abrupt("return");
2586
- case 16:
2587
- _context23.next = 18;
2588
- return _this21.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
2589
- case 18:
2590
- _this21.recordRecentSqliteWrite(source, mergedSnapshot);
2591
- _this21.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
2592
- source: source,
2593
- count: mergedSnapshot.length
2594
- });
2595
- case 20:
2596
- case "end":
2597
- return _context23.stop();
2598
- }
2599
- }, _callee23);
2600
- })));
2601
- case 7:
2602
- _context24.next = 12;
1323
+ this.logInfo('saveOrdersToSQLite-bulkAdd完成', {
1324
+ count: orderList.length
1325
+ });
1326
+ _context15.next = 17;
2603
1327
  break;
2604
- case 9:
2605
- _context24.prev = 9;
2606
- _context24.t0 = _context24["catch"](4);
2607
- this.logError('全量保存订单到 SQLite 失败', {
2608
- error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0),
2609
- orderList: remoteSnapshot.length
1328
+ case 14:
1329
+ _context15.prev = 14;
1330
+ _context15.t0 = _context15["catch"](2);
1331
+ // SQLite 异常,避免影响主流程
1332
+ this.logError('保存订单到 SQLite 失败', {
1333
+ error: _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0),
1334
+ orderList: orderList.length
2610
1335
  });
2611
- case 12:
2612
- return _context24.abrupt("return", mergedSnapshot);
2613
- case 13:
1336
+ case 17:
2614
1337
  case "end":
2615
- return _context24.stop();
1338
+ return _context15.stop();
2616
1339
  }
2617
- }, _callee24, this, [[4, 9]]);
1340
+ }, _callee15, this, [[2, 14]]);
2618
1341
  }));
2619
- function replaceOrdersSnapshotInSQLite(_x16, _x17) {
2620
- return _replaceOrdersSnapshotInSQLite.apply(this, arguments);
1342
+ function saveOrdersToSQLite(_x8) {
1343
+ return _saveOrdersToSQLite.apply(this, arguments);
2621
1344
  }
2622
- return replaceOrdersSnapshotInSQLite;
1345
+ return saveOrdersToSQLite;
2623
1346
  }()
2624
- /**
2625
- * 清空订单模块的内存数据和本地 SQLite 订单表。
2626
- *
2627
- * @example
2628
- * await orderModule.clear()
2629
- */
2630
- )
2631
1347
  }, {
2632
1348
  key: "clear",
2633
- value: (function () {
2634
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2635
- var _this22 = this;
2636
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2637
- while (1) switch (_context26.prev = _context26.next) {
1349
+ value: function () {
1350
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1351
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1352
+ while (1) switch (_context16.prev = _context16.next) {
2638
1353
  case 0:
2639
1354
  this.store.list = [];
2640
1355
  this.store.map = new Map();
2641
1356
  this.resourceIdIndex.clear();
2642
1357
  if (!this.dbManager) {
2643
- _context26.next = 6;
1358
+ _context16.next = 6;
2644
1359
  break;
2645
1360
  }
2646
- _context26.next = 6;
2647
- return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2648
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2649
- while (1) switch (_context25.prev = _context25.next) {
2650
- case 0:
2651
- _context25.next = 2;
2652
- return _this22.dbManager.clear(INDEXDB_STORE_NAME);
2653
- case 2:
2654
- case "end":
2655
- return _context25.stop();
2656
- }
2657
- }, _callee25);
2658
- })));
1361
+ _context16.next = 6;
1362
+ return this.dbManager.clear(INDEXDB_STORE_NAME);
2659
1363
  case 6:
2660
1364
  this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
2661
- this.emitOrdersChanged([], 'clear');
1365
+ this.core.effects.emit(OrderHooks.onOrdersChanged, this.store.list);
2662
1366
  case 8:
2663
1367
  case "end":
2664
- return _context26.stop();
1368
+ return _context16.stop();
2665
1369
  }
2666
- }, _callee26, this);
1370
+ }, _callee16, this);
2667
1371
  }));
2668
1372
  function clear() {
2669
1373
  return _clear.apply(this, arguments);
2670
1374
  }
2671
1375
  return clear;
2672
- }())
1376
+ }()
2673
1377
  }]);
2674
1378
  return OrderModule;
2675
1379
  }(BaseModule);