@be-link/ecommerce-plan-allocation-service-node-sdk 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/enum.d.ts CHANGED
@@ -50,13 +50,13 @@ export declare namespace ENUM {
50
50
  enum STATUS {
51
51
  PENDING = "PENDING",
52
52
  PARTIAL = "PARTIAL",
53
- RECEIVED = "RECEIVED",
53
+ SHIPPED = "SHIPPED",
54
54
  EARLY_COMPLETED = "EARLY_COMPLETED"
55
55
  }
56
56
  enum STATUS_CHINESE {
57
57
  PENDING = "\u5F85\u53D1\u8D27",
58
58
  PARTIAL = "\u90E8\u5206\u53D1\u8D27",
59
- RECEIVED = "\u5DF2\u53D1\u8D27",
59
+ SHIPPED = "\u5DF2\u53D1\u8D27",
60
60
  EARLY_COMPLETED = "\u63D0\u524D\u5B8C\u6210"
61
61
  }
62
62
  /** 错误消息常量 */
@@ -69,9 +69,9 @@ export declare namespace ENUM {
69
69
  };
70
70
  /** 状态转换规则 */
71
71
  const STATUS_TRANSITIONS: {
72
- readonly PENDING: readonly ["PARTIAL", "RECEIVED", "EARLY_COMPLETED"];
73
- readonly PARTIAL: readonly ["RECEIVED", "EARLY_COMPLETED"];
74
- readonly RECEIVED: readonly [];
72
+ readonly PENDING: readonly ["PARTIAL", "SHIPPED", "EARLY_COMPLETED"];
73
+ readonly PARTIAL: readonly ["SHIPPED", "EARLY_COMPLETED"];
74
+ readonly SHIPPED: readonly [];
75
75
  readonly EARLY_COMPLETED: readonly [];
76
76
  };
77
77
  }
package/enum.js CHANGED
@@ -62,14 +62,14 @@ var ENUM;
62
62
  (function (STATUS) {
63
63
  STATUS["PENDING"] = "PENDING";
64
64
  STATUS["PARTIAL"] = "PARTIAL";
65
- STATUS["RECEIVED"] = "RECEIVED";
65
+ STATUS["SHIPPED"] = "SHIPPED";
66
66
  STATUS["EARLY_COMPLETED"] = "EARLY_COMPLETED";
67
67
  })(STATUS = ALLOCATION_ORDER_ENUM.STATUS || (ALLOCATION_ORDER_ENUM.STATUS = {}));
68
68
  let STATUS_CHINESE;
69
69
  (function (STATUS_CHINESE) {
70
70
  STATUS_CHINESE["PENDING"] = "\u5F85\u53D1\u8D27";
71
71
  STATUS_CHINESE["PARTIAL"] = "\u90E8\u5206\u53D1\u8D27";
72
- STATUS_CHINESE["RECEIVED"] = "\u5DF2\u53D1\u8D27";
72
+ STATUS_CHINESE["SHIPPED"] = "\u5DF2\u53D1\u8D27";
73
73
  STATUS_CHINESE["EARLY_COMPLETED"] = "\u63D0\u524D\u5B8C\u6210";
74
74
  })(STATUS_CHINESE = ALLOCATION_ORDER_ENUM.STATUS_CHINESE || (ALLOCATION_ORDER_ENUM.STATUS_CHINESE = {}));
75
75
  /** 错误消息常量 */
@@ -82,9 +82,9 @@ var ENUM;
82
82
  };
83
83
  /** 状态转换规则 */
84
84
  ALLOCATION_ORDER_ENUM.STATUS_TRANSITIONS = {
85
- PENDING: ['PARTIAL', 'RECEIVED', 'EARLY_COMPLETED'],
86
- PARTIAL: ['RECEIVED', 'EARLY_COMPLETED'],
87
- RECEIVED: [],
85
+ PENDING: ['PARTIAL', 'SHIPPED', 'EARLY_COMPLETED'],
86
+ PARTIAL: ['SHIPPED', 'EARLY_COMPLETED'],
87
+ SHIPPED: [],
88
88
  EARLY_COMPLETED: [],
89
89
  };
90
90
  })(ALLOCATION_ORDER_ENUM = ENUM.ALLOCATION_ORDER_ENUM || (ENUM.ALLOCATION_ORDER_ENUM = {}));
package/index.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  export { allocationService } from './modules/allocation/service';
2
2
  export type { Service as AllocationServiceTypes } from './modules/allocation/types';
3
+ export { logisticsService } from './modules/logistics/service';
4
+ export type { Service as LogisticsServiceTypes } from './modules/logistics/types';
5
+ export { ENUM as DEMO_ENUM } from './enum';
6
+ export { allocationOrderService } from './modules/allocationOrder/service';
7
+ export { AllocationOrderTypes } from './modules/allocationOrder/types';
3
8
  export { storeStockInService } from './modules/storeStockIn/service';
4
9
  export { StoreStockInTypes } from './modules/storeStockIn/types';
5
10
  export { preAllocationOrderService } from './modules/preAllocationOrder/service';
package/index.js CHANGED
@@ -1,14 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENUM = exports.preAllocationOrderService = exports.storeStockInService = exports.allocationService = void 0;
3
+ exports.ENUM = exports.preAllocationOrderService = exports.storeStockInService = exports.allocationOrderService = exports.DEMO_ENUM = exports.logisticsService = exports.allocationService = void 0;
4
4
  var service_1 = require("./modules/allocation/service");
5
5
  Object.defineProperty(exports, "allocationService", { enumerable: true, get: function () { return service_1.allocationService; } });
6
- var service_2 = require("./modules/storeStockIn/service");
7
- Object.defineProperty(exports, "storeStockInService", { enumerable: true, get: function () { return service_2.storeStockInService; } });
8
- var service_3 = require("./modules/preAllocationOrder/service");
9
- Object.defineProperty(exports, "preAllocationOrderService", { enumerable: true, get: function () { return service_3.preAllocationOrderService; } });
6
+ var service_2 = require("./modules/logistics/service");
7
+ Object.defineProperty(exports, "logisticsService", { enumerable: true, get: function () { return service_2.logisticsService; } });
10
8
  var enum_1 = require("./enum");
11
- Object.defineProperty(exports, "ENUM", { enumerable: true, get: function () { return enum_1.ENUM; } });
9
+ Object.defineProperty(exports, "DEMO_ENUM", { enumerable: true, get: function () { return enum_1.ENUM; } });
10
+ var service_3 = require("./modules/allocationOrder/service");
11
+ Object.defineProperty(exports, "allocationOrderService", { enumerable: true, get: function () { return service_3.allocationOrderService; } });
12
+ var service_4 = require("./modules/storeStockIn/service");
13
+ Object.defineProperty(exports, "storeStockInService", { enumerable: true, get: function () { return service_4.storeStockInService; } });
14
+ var service_5 = require("./modules/preAllocationOrder/service");
15
+ Object.defineProperty(exports, "preAllocationOrderService", { enumerable: true, get: function () { return service_5.preAllocationOrderService; } });
16
+ var enum_2 = require("./enum");
17
+ Object.defineProperty(exports, "ENUM", { enumerable: true, get: function () { return enum_2.ENUM; } });
12
18
  // 服务.模块.枚举名称.枚举值 示例: DEMO_ENUM.ORDER_ENUM.STATUS.PENDING
13
19
  // 门店入库单枚举示例: ENUM.STORE_STOCK_IN_ORDER_ENUM.STATUS.PENDING
14
20
  // 预配货单上传枚举示例: ENUM.PRE_ALLOCATION_ORDER_UPLOAD_EXCEL_ENUM.STATUS.PROCESSING
21
+ // 配货单枚举示例: ENUM.ALLOCATION_ORDER_ENUM.STATUS.PENDING
@@ -0,0 +1,47 @@
1
+ import { AllocationOrderTypes } from './types';
2
+ import BaseService from '../BaseService';
3
+ declare class AllocationOrderService extends BaseService implements AllocationOrderTypes.AllocationOrderController {
4
+ protected prefixUrl: string;
5
+ /**
6
+ * 获取配货单列表
7
+ */
8
+ list(request: AllocationOrderTypes.Request.GetList): Promise<AllocationOrderTypes.Response.GetList>;
9
+ /**
10
+ * 获取配货单详情
11
+ */
12
+ detail(request: AllocationOrderTypes.Request.GetDetail): Promise<AllocationOrderTypes.Response.GetDetail>;
13
+ /**
14
+ * 批量更新配货单明细备注
15
+ */
16
+ batchUpdateDetailRemarks(request: AllocationOrderTypes.Request.BatchUpdateDetailRemarks): Promise<void>;
17
+ /**
18
+ * 发货
19
+ */
20
+ ship(request: AllocationOrderTypes.Request.Ship): Promise<void>;
21
+ /**
22
+ * 保存草稿
23
+ */
24
+ saveDraft(request: AllocationOrderTypes.Request.SaveDraft): Promise<void>;
25
+ /**
26
+ * 撤销发货
27
+ */
28
+ cancelShip(request: AllocationOrderTypes.Request.CancelShip): Promise<void>;
29
+ /**
30
+ * 导出配货单Excel
31
+ */
32
+ exportExcel(request: AllocationOrderTypes.Request.ExportExcel): Promise<AllocationOrderTypes.Response.ExportExcel>;
33
+ /**
34
+ * 打印拣货单
35
+ */
36
+ printPickingSheet(request: AllocationOrderTypes.Request.PrintPickingSheet): Promise<AllocationOrderTypes.Response.PrintPickingSheet>;
37
+ /**
38
+ * 打印发货签收单
39
+ */
40
+ printDeliveryReceipt(request: AllocationOrderTypes.Request.PrintDeliveryReceipt): Promise<AllocationOrderTypes.Response.PrintDeliveryReceipt>;
41
+ /**
42
+ * 退回预配货单
43
+ */
44
+ rollbackPre(request: AllocationOrderTypes.Request.RollbackPre): Promise<void>;
45
+ }
46
+ export declare const allocationOrderService: AllocationOrderService;
47
+ export default allocationOrderService;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
+ return function (target, key) { decorator(target, key, paramIndex); }
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.allocationOrderService = void 0;
16
+ const tsoa_1 = require("tsoa");
17
+ const http_1 = require("../../utils/http");
18
+ const BaseService_1 = __importDefault(require("../BaseService"));
19
+ let AllocationOrderService = class AllocationOrderService extends BaseService_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.prefixUrl = '/allocation-order';
23
+ }
24
+ /**
25
+ * 获取配货单列表
26
+ */
27
+ list(request) {
28
+ return (0, http_1.callApi)(this.getApiUrl(this.list), request);
29
+ }
30
+ /**
31
+ * 获取配货单详情
32
+ */
33
+ detail(request) {
34
+ return (0, http_1.callApi)(this.getApiUrl(this.detail), request);
35
+ }
36
+ /**
37
+ * 批量更新配货单明细备注
38
+ */
39
+ batchUpdateDetailRemarks(request) {
40
+ return (0, http_1.callApi)(this.getApiUrl(this.batchUpdateDetailRemarks), request);
41
+ }
42
+ /**
43
+ * 发货
44
+ */
45
+ ship(request) {
46
+ return (0, http_1.callApi)(this.getApiUrl(this.ship), request);
47
+ }
48
+ /**
49
+ * 保存草稿
50
+ */
51
+ saveDraft(request) {
52
+ return (0, http_1.callApi)(this.getApiUrl(this.saveDraft), request);
53
+ }
54
+ /**
55
+ * 撤销发货
56
+ */
57
+ cancelShip(request) {
58
+ return (0, http_1.callApi)(this.getApiUrl(this.cancelShip), request);
59
+ }
60
+ /**
61
+ * 导出配货单Excel
62
+ */
63
+ exportExcel(request) {
64
+ return (0, http_1.callApi)(this.getApiUrl(this.exportExcel), request);
65
+ }
66
+ /**
67
+ * 打印拣货单
68
+ */
69
+ printPickingSheet(request) {
70
+ return (0, http_1.callApi)(this.getApiUrl(this.printPickingSheet), request);
71
+ }
72
+ /**
73
+ * 打印发货签收单
74
+ */
75
+ printDeliveryReceipt(request) {
76
+ return (0, http_1.callApi)(this.getApiUrl(this.printDeliveryReceipt), request);
77
+ }
78
+ /**
79
+ * 退回预配货单
80
+ */
81
+ rollbackPre(request) {
82
+ return (0, http_1.callApi)(this.getApiUrl(this.rollbackPre), request);
83
+ }
84
+ };
85
+ __decorate([
86
+ (0, tsoa_1.Post)('list'),
87
+ __param(0, (0, tsoa_1.Body)())
88
+ ], AllocationOrderService.prototype, "list", null);
89
+ __decorate([
90
+ (0, tsoa_1.Post)('detail'),
91
+ __param(0, (0, tsoa_1.Body)())
92
+ ], AllocationOrderService.prototype, "detail", null);
93
+ __decorate([
94
+ (0, tsoa_1.Post)('batch-update-detail-remarks'),
95
+ __param(0, (0, tsoa_1.Body)())
96
+ ], AllocationOrderService.prototype, "batchUpdateDetailRemarks", null);
97
+ __decorate([
98
+ (0, tsoa_1.Post)('ship'),
99
+ __param(0, (0, tsoa_1.Body)())
100
+ ], AllocationOrderService.prototype, "ship", null);
101
+ __decorate([
102
+ (0, tsoa_1.Post)('save-draft'),
103
+ __param(0, (0, tsoa_1.Body)())
104
+ ], AllocationOrderService.prototype, "saveDraft", null);
105
+ __decorate([
106
+ (0, tsoa_1.Post)('cancel-ship'),
107
+ __param(0, (0, tsoa_1.Body)())
108
+ ], AllocationOrderService.prototype, "cancelShip", null);
109
+ __decorate([
110
+ (0, tsoa_1.Post)('export-excel'),
111
+ __param(0, (0, tsoa_1.Body)())
112
+ ], AllocationOrderService.prototype, "exportExcel", null);
113
+ __decorate([
114
+ (0, tsoa_1.Post)('print-picking-sheet'),
115
+ __param(0, (0, tsoa_1.Body)())
116
+ ], AllocationOrderService.prototype, "printPickingSheet", null);
117
+ __decorate([
118
+ (0, tsoa_1.Post)('print-delivery-receipt'),
119
+ __param(0, (0, tsoa_1.Body)())
120
+ ], AllocationOrderService.prototype, "printDeliveryReceipt", null);
121
+ __decorate([
122
+ (0, tsoa_1.Post)('rollback-pre'),
123
+ __param(0, (0, tsoa_1.Body)())
124
+ ], AllocationOrderService.prototype, "rollbackPre", null);
125
+ AllocationOrderService = __decorate([
126
+ (0, tsoa_1.Route)('AllocationOrder'),
127
+ (0, tsoa_1.Tags)('allocationOrder')
128
+ ], AllocationOrderService);
129
+ exports.allocationOrderService = new AllocationOrderService();
130
+ exports.default = exports.allocationOrderService;
@@ -0,0 +1,330 @@
1
+ import { ENUM } from '../../enum';
2
+ export declare namespace AllocationOrderTypes {
3
+ namespace Entity {
4
+ /**
5
+ * 配货单主表实体
6
+ */
7
+ interface AllocationOrder {
8
+ id: string;
9
+ createdAt: number;
10
+ updatedAt: number;
11
+ deletedAt: number;
12
+ stockInOrderId: string;
13
+ pickingAt: number;
14
+ storeId: string;
15
+ warehouseId: string;
16
+ status: ENUM.ALLOCATION_ORDER_ENUM.STATUS;
17
+ shouldNum: number;
18
+ realNum: number;
19
+ creator: string;
20
+ updater: string;
21
+ shippedAt: number | null;
22
+ estimatedArrivalAt: number | null;
23
+ needNextHandle: number;
24
+ remark: string | null;
25
+ }
26
+ /**
27
+ * 配货单扩展实体(包含关联数据)
28
+ */
29
+ interface AllocationOrderWithExtension extends AllocationOrder {
30
+ storeName?: string;
31
+ warehouseName?: string;
32
+ deliveryMode?: number;
33
+ regionName?: string;
34
+ }
35
+ /**
36
+ * 配货单明细实体
37
+ */
38
+ interface AllocationOrderDetail {
39
+ id: string;
40
+ createdAt: number;
41
+ updatedAt: number;
42
+ deletedAt: number;
43
+ allocationOrderId: string;
44
+ storeId: string;
45
+ productId: string;
46
+ skuId: string;
47
+ skuCode: string;
48
+ pickingNum: number;
49
+ shippedNum: number;
50
+ remainNum: number;
51
+ nextPickingNum: number;
52
+ shouldPickNum: number;
53
+ pickingRemark: string | null;
54
+ shippingRemark: string | null;
55
+ }
56
+ /**
57
+ * 配货单明细扩展实体(包含商品信息)
58
+ */
59
+ interface AllocationOrderDetailWithProduct extends AllocationOrderDetail {
60
+ productName: string;
61
+ specName: string;
62
+ storageMethod: string;
63
+ classification: string;
64
+ }
65
+ /**
66
+ * 发货项
67
+ */
68
+ interface ShipItem {
69
+ detailId: string;
70
+ shippedNum: number;
71
+ pickingRemark?: string;
72
+ shippingRemark?: string;
73
+ }
74
+ /**
75
+ * 草稿项
76
+ */
77
+ interface DraftItem {
78
+ detailId: string;
79
+ shippedNum: number;
80
+ pickingRemark?: string;
81
+ shippingRemark?: string;
82
+ }
83
+ }
84
+ namespace Request {
85
+ /**
86
+ * 获取配货单列表请求
87
+ */
88
+ interface GetList {
89
+ pageIndex: number;
90
+ pageSize: number;
91
+ id?: string;
92
+ pickingAtStart?: number;
93
+ pickingAtEnd?: number;
94
+ shippedAtStart?: number;
95
+ shippedAtEnd?: number;
96
+ productIds?: string[];
97
+ skuCodes?: string[];
98
+ warehouseIds?: string[];
99
+ storeIds?: string[];
100
+ deliveryMode?: number;
101
+ status?: string;
102
+ }
103
+ /**
104
+ * 获取配货单详情请求
105
+ */
106
+ interface GetDetail {
107
+ allocationOrderId: string;
108
+ pageIndex: number;
109
+ pageSize: number;
110
+ productIds?: string[];
111
+ skuCodes?: string[];
112
+ minRemainNum?: number;
113
+ maxRemainNum?: number;
114
+ }
115
+ /**
116
+ * 批量更新明细备注请求
117
+ */
118
+ interface BatchUpdateDetailRemarks {
119
+ orderId: string;
120
+ operator: string;
121
+ items: {
122
+ detailId: string;
123
+ pickingRemark?: string;
124
+ shippingRemark?: string;
125
+ }[];
126
+ }
127
+ /**
128
+ * 发货请求
129
+ */
130
+ interface Ship {
131
+ allocationId: string;
132
+ items: Entity.ShipItem[];
133
+ operator: string;
134
+ }
135
+ /**
136
+ * 保存草稿请求
137
+ */
138
+ interface SaveDraft {
139
+ allocationId: string;
140
+ items: Entity.DraftItem[];
141
+ operator: string;
142
+ }
143
+ /**
144
+ * 撤销发货请求
145
+ */
146
+ interface CancelShip {
147
+ allocationId: string;
148
+ operator?: string;
149
+ }
150
+ /**
151
+ * 导出配货单Excel请求
152
+ */
153
+ interface ExportExcel {
154
+ pageIndex: number;
155
+ pageSize: number;
156
+ ids?: string[];
157
+ pickingAtStart?: number;
158
+ pickingAtEnd?: number;
159
+ shippedAtStart?: number;
160
+ shippedAtEnd?: number;
161
+ productIds?: string[];
162
+ skuCodes?: string[];
163
+ storeIds?: string[];
164
+ warehouseIds?: string[];
165
+ deliveryMode?: number;
166
+ status?: string;
167
+ }
168
+ /**
169
+ * 打印拣货单请求
170
+ */
171
+ interface PrintPickingSheet {
172
+ pageIndex: number;
173
+ pageSize: number;
174
+ ids?: string[];
175
+ pickingAtStart?: number;
176
+ pickingAtEnd?: number;
177
+ shippedAtStart?: number;
178
+ shippedAtEnd?: number;
179
+ productIds?: string[];
180
+ skuCodes?: string[];
181
+ storeIds?: string[];
182
+ warehouseIds?: string[];
183
+ deliveryMode?: number;
184
+ status?: string;
185
+ }
186
+ /**
187
+ * 打印发货签收单请求
188
+ */
189
+ interface PrintDeliveryReceipt {
190
+ orderIds: string[];
191
+ }
192
+ /**
193
+ * 退回预配货单请求
194
+ */
195
+ interface RollbackPre {
196
+ pickingAt?: number;
197
+ orderIds?: string[];
198
+ operator?: string;
199
+ }
200
+ }
201
+ namespace Response {
202
+ /**
203
+ * 获取配货单列表响应
204
+ */
205
+ interface GetList {
206
+ total: number;
207
+ list: Entity.AllocationOrderWithExtension[];
208
+ totalCount: number;
209
+ pendingCount: number;
210
+ partialCount: number;
211
+ shippedCount: number;
212
+ }
213
+ /**
214
+ * 获取配货单详情响应
215
+ */
216
+ interface GetDetail {
217
+ order: Entity.AllocationOrder;
218
+ details: Entity.AllocationOrderDetailWithProduct[];
219
+ total: number;
220
+ }
221
+ /**
222
+ * 导出Excel项目接口
223
+ */
224
+ interface ExportExcelItem {
225
+ 单号?: string;
226
+ 建议配货日期?: string;
227
+ 仓库?: string;
228
+ 门店?: string;
229
+ 门店地址?: string;
230
+ 门店联系电话?: string;
231
+ 商品应发?: number;
232
+ 商品实发?: number;
233
+ 发货时间?: string;
234
+ 配送模式?: string;
235
+ 状态?: string;
236
+ productId?: string;
237
+ skuId?: string;
238
+ 商品名称?: string;
239
+ 规格名称?: string;
240
+ 规格编码?: string;
241
+ 库位信息?: string;
242
+ 储藏方式?: string;
243
+ 商品分类?: string;
244
+ 配货数量?: number;
245
+ 应拣数量?: number;
246
+ 已发数量?: number;
247
+ 剩余待发数量?: number;
248
+ 配货备注?: string;
249
+ 发货备注?: string;
250
+ }
251
+ /**
252
+ * 导出Excel响应接口
253
+ */
254
+ interface ExportExcel {
255
+ data: ExportExcelItem[];
256
+ headerMap: string[];
257
+ }
258
+ /**
259
+ * 打印拣货单项目接口(按商品聚合)
260
+ */
261
+ interface PrintPickingSheetItem {
262
+ 商品名称?: string;
263
+ 规格名称?: string;
264
+ 规格编码?: string;
265
+ 商品分类?: string;
266
+ 储藏方式?: string;
267
+ 库位信息?: string;
268
+ 总计应拣数量?: number;
269
+ [storeName: string]: string | number | undefined;
270
+ }
271
+ /**
272
+ * 打印拣货单响应接口
273
+ */
274
+ interface PrintPickingSheet {
275
+ data: PrintPickingSheetItem[];
276
+ headerMap: string[];
277
+ }
278
+ /**
279
+ * 发货签收单商品项
280
+ */
281
+ interface DeliveryReceiptItem {
282
+ productName?: string;
283
+ specName?: string;
284
+ skuCode?: string;
285
+ classification?: string;
286
+ storageMethod?: string;
287
+ shippedQuantity?: number;
288
+ receivedQuantity?: number;
289
+ pickingRemark?: string;
290
+ shippingRemark?: string;
291
+ }
292
+ /**
293
+ * 发货签收单数据
294
+ */
295
+ interface DeliveryReceiptData {
296
+ allocationOrderId: string;
297
+ pickingDate?: string;
298
+ warehouseName?: string;
299
+ storeRemark: string;
300
+ deliveryMode?: string;
301
+ storeName?: string;
302
+ storePhone?: string;
303
+ storeAddress?: string;
304
+ driverNotice?: string;
305
+ qrCodeUrl?: string;
306
+ items: DeliveryReceiptItem[];
307
+ }
308
+ /**
309
+ * 打印发货签收单响应接口
310
+ */
311
+ interface PrintDeliveryReceipt {
312
+ list: DeliveryReceiptData[];
313
+ }
314
+ }
315
+ /**
316
+ * 配货单控制器接口
317
+ */
318
+ interface AllocationOrderController {
319
+ list(request: Request.GetList): Promise<Response.GetList>;
320
+ detail(request: Request.GetDetail): Promise<Response.GetDetail>;
321
+ batchUpdateDetailRemarks(request: Request.BatchUpdateDetailRemarks): Promise<void>;
322
+ ship(request: Request.Ship): Promise<void>;
323
+ saveDraft(request: Request.SaveDraft): Promise<void>;
324
+ cancelShip(request: Request.CancelShip): Promise<void>;
325
+ exportExcel(request: Request.ExportExcel): Promise<Response.ExportExcel>;
326
+ printPickingSheet(request: Request.PrintPickingSheet): Promise<Response.PrintPickingSheet>;
327
+ printDeliveryReceipt(request: Request.PrintDeliveryReceipt): Promise<Response.PrintDeliveryReceipt>;
328
+ rollbackPre(request: Request.RollbackPre): Promise<void>;
329
+ }
330
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -2,12 +2,12 @@ import { Service } from './types';
2
2
  import BaseService from '../BaseService';
3
3
  declare class LogisticsService extends BaseService implements Service.LogisticsController {
4
4
  protected prefixUrl: string;
5
- batchImportWaybill(request: Service.Request.BatchImportWaybill): Promise<void>;
5
+ batchImportWaybill(request: Service.Request.BatchImportWaybill): Promise<Service.Response.BatchImportWaybill>;
6
6
  getWaybillList(request: Service.Request.GetWaybillList): Promise<Service.Response.GetWaybillList>;
7
7
  writeWaybill(request: Service.Request.WriteWaybill): Promise<void>;
8
8
  getCarrierList(request: Service.Request.GetCarrierList): Promise<Service.Response.GetCarrierList>;
9
9
  getStoreStockInOrderList(request: Service.Request.GetStoreStockInOrderList): Promise<Service.Response.GetStoreStockInOrderList>;
10
- getStoreStockInOrderDetailList(request: Service.Request.GetStoreStockInOrderDetailList): Promise<Service.Response.GetStoreStockInOrderDetailList>;
10
+ getStoreStockInOrderDetail(request: Service.Request.GetStoreStockInOrderDetail): Promise<Service.Response.GetStoreStockInOrderDetail>;
11
11
  getStoreStockInOrderLogisticsList(request: Service.Request.GetStoreStockInOrderLogisticsList): Promise<Service.Response.GetStoreStockInOrderLogisticsList>;
12
12
  getProductList(request: Service.Request.GetProductList): Promise<Service.Response.GetProductList>;
13
13
  }
@@ -36,8 +36,8 @@ let LogisticsService = class LogisticsService extends BaseService_1.default {
36
36
  getStoreStockInOrderList(request) {
37
37
  return (0, http_1.callApi)(this.getApiUrl(this.getStoreStockInOrderList), request);
38
38
  }
39
- getStoreStockInOrderDetailList(request) {
40
- return (0, http_1.callApi)(this.getApiUrl(this.getStoreStockInOrderDetailList), request);
39
+ getStoreStockInOrderDetail(request) {
40
+ return (0, http_1.callApi)(this.getApiUrl(this.getStoreStockInOrderDetail), request);
41
41
  }
42
42
  getStoreStockInOrderLogisticsList(request) {
43
43
  return (0, http_1.callApi)(this.getApiUrl(this.getStoreStockInOrderLogisticsList), request);
@@ -72,10 +72,10 @@ __decorate([
72
72
  __param(0, (0, tsoa_1.Body)())
73
73
  ], LogisticsService.prototype, "getStoreStockInOrderList", null);
74
74
  __decorate([
75
- (0, tsoa_1.OperationId)('门店入库单详情商品列表'),
76
- (0, tsoa_1.Post)('get-store-stock-in-order-detail-list'),
75
+ (0, tsoa_1.OperationId)('门店入库单详情'),
76
+ (0, tsoa_1.Post)('get-store-stock-in-order-detail'),
77
77
  __param(0, (0, tsoa_1.Body)())
78
- ], LogisticsService.prototype, "getStoreStockInOrderDetailList", null);
78
+ ], LogisticsService.prototype, "getStoreStockInOrderDetail", null);
79
79
  __decorate([
80
80
  (0, tsoa_1.OperationId)('门店入库单运货单物流信息列表'),
81
81
  (0, tsoa_1.Post)('get-store-stock-in-order-logistics-list'),
@@ -1,10 +1,13 @@
1
1
  import { GetTrackingInfoAccepted } from '@be-link/17trak-api-sdk';
2
2
  import { FastifyRequest } from 'fastify';
3
+ import type { ProductServiceTypes } from '@be-link/ecommerce-product-service-node-sdk';
3
4
  export declare namespace Service {
4
5
  /** 物流信息实体 */
5
6
  interface Logistics {
6
7
  /** 运货单ID */
7
8
  id: string;
9
+ /** 门店ID */
10
+ storeId: string;
8
11
  /** 配货单ID */
9
12
  allocationOrderId: string;
10
13
  /** 门店入库单ID */
@@ -27,26 +30,61 @@ export declare namespace Service {
27
30
  subscribeMessage: string;
28
31
  /** 订阅时间 */
29
32
  subscribeTime: number;
33
+ /** 操作人(导入/写入人) */
34
+ operator?: string;
35
+ /** 创建时间 */
36
+ createdAt?: number;
37
+ /** 更新时间 */
38
+ updatedAt?: number;
39
+ /** 门店名称(扩展字段,从门店服务补充) */
40
+ storeName?: string;
41
+ /** 快递公司名称(扩展字段,从 Carriers 表补充) */
42
+ carrierName?: string;
30
43
  }
31
44
  /** 入库单详情 */
32
45
  interface StockInOrder {
46
+ /** 入库单ID */
47
+ id: string;
48
+ /** 物流信息 */
33
49
  logistics: string;
50
+ /** 供应商名称 */
34
51
  supplyName: string;
52
+ /** 仓库ID */
35
53
  warehouseId: string;
54
+ /** 门店ID */
36
55
  storeId: string;
56
+ /** 配货单ID */
57
+ allocationOrderId: string;
58
+ /** 创建人 */
37
59
  creator: string;
60
+ /** 更新人 */
38
61
  updater: string;
62
+ /** 类型:WAREHOUSE:仓库, STORE:门店 */
39
63
  type: string;
64
+ /** 状态 PENDING:待收货, PARTIAL:部分收货, RECEIVED:已收货, EARLY_COMPLETED:提前完成 */
40
65
  status: string;
66
+ /** 物流状态:0-没有物流信息、1-已入库、2-已到店、3-配送中 */
41
67
  logisticStatus: number;
68
+ /** 收货时间 */
42
69
  receivedAt: number;
70
+ /** 应收数量 */
43
71
  receivableQuantity: number;
72
+ /** 实收数量 */
44
73
  receivedQuantity: number;
74
+ /** 备注 */
45
75
  remark: string;
76
+ /** 扩展字段 */
46
77
  extra: any;
78
+ /** 删除时间 */
47
79
  deletedAt: number;
48
- }
49
- interface Product {
80
+ /** 创建时间 */
81
+ createdAt: number;
82
+ /** 更新时间 */
83
+ updatedAt: number;
84
+ /** 批次编码(从 EcsDistributionBatch 表查询,targetId 对应入库单 id) */
85
+ code?: string;
86
+ /** 商品列表(参考 getProductList 返回的商品信息) */
87
+ products?: ProductServiceTypes.Response.queryProductList['list'];
50
88
  }
51
89
  namespace Request {
52
90
  /** 批量导入运货单 */
@@ -68,6 +106,10 @@ export declare namespace Service {
68
106
  storeStockInOrderId?: string;
69
107
  /** 快递公司编码 */
70
108
  carrier?: number;
109
+ /** 订阅状态:0-未订阅、1-订阅失败、2-取消订阅、3-已订阅、4-订阅中 */
110
+ subscribeStatus?: number;
111
+ /** 操作人 */
112
+ operator?: string;
71
113
  }
72
114
  /** 配货单单独写入运货单 */
73
115
  interface WriteWaybill {
@@ -101,15 +143,13 @@ export declare namespace Service {
101
143
  start?: number;
102
144
  /** 入库单生成日期-介于结束时间 */
103
145
  end?: string;
146
+ /** 商品名称 */
147
+ productName?: string;
104
148
  }
105
- /** 门店入库单详情商品列表 */
106
- interface GetStoreStockInOrderDetailList {
149
+ /** 门店入库单详情 */
150
+ interface GetStoreStockInOrderDetail {
107
151
  /** 门店入库单ID */
108
152
  storeStockInOrderId: string;
109
- /** 页码 */
110
- pageIndex: number;
111
- /** 每页数量 */
112
- pageSize?: number;
113
153
  }
114
154
  /** 门店入库单运货单物流信息列表 */
115
155
  interface GetStoreStockInOrderLogisticsList {
@@ -127,6 +167,13 @@ export declare namespace Service {
127
167
  }
128
168
  }
129
169
  namespace Response {
170
+ /** 批量导入运货单结果 */
171
+ interface BatchImportWaybill {
172
+ /** 系统中已存在且满足条件的配货单ID列表 */
173
+ successAllocationOrderIds: string[];
174
+ /** 系统中不存在(或不满足条件)的配货单ID列表 */
175
+ failedAllocationOrderIds: string[];
176
+ }
130
177
  /** 运货单列表 */
131
178
  interface GetWaybillList {
132
179
  /** 运货单总数 */
@@ -149,7 +196,7 @@ export declare namespace Service {
149
196
  data: StockInOrder[];
150
197
  }
151
198
  /** 门店入库单详情 */
152
- interface GetStoreStockInOrderDetailList {
199
+ interface GetStoreStockInOrderDetail {
153
200
  /** 入库单详情 */
154
201
  stockInOrder: StockInOrder;
155
202
  }
@@ -158,7 +205,7 @@ export declare namespace Service {
158
205
  /** 总数 */
159
206
  total: number;
160
207
  /** 商品列表 */
161
- data: Product[];
208
+ data: ProductServiceTypes.Response.queryProductList['list'];
162
209
  }
163
210
  /** 门店入库单运货单物流信息列表 */
164
211
  interface GetStoreStockInOrderLogisticsList {
@@ -168,7 +215,7 @@ export declare namespace Service {
168
215
  }
169
216
  interface LogisticsController {
170
217
  /** 批量导入运货单 */
171
- batchImportWaybill(request: Request.BatchImportWaybill, req?: FastifyRequest): Promise<void>;
218
+ batchImportWaybill(request: Request.BatchImportWaybill, req?: FastifyRequest): Promise<Response.BatchImportWaybill>;
172
219
  /** 查询运货单列表 */
173
220
  getWaybillList(request: Request.GetWaybillList, req?: FastifyRequest): Promise<Response.GetWaybillList>;
174
221
  /** 配货单单独写入运货单 */
@@ -177,8 +224,8 @@ export declare namespace Service {
177
224
  getCarrierList(request: Request.GetCarrierList, req?: FastifyRequest): Promise<Response.GetCarrierList>;
178
225
  /** 门店入库单列表 */
179
226
  getStoreStockInOrderList(request: Request.GetStoreStockInOrderList, req?: FastifyRequest): Promise<Response.GetStoreStockInOrderList>;
180
- /** 门店入库单详情商品列表 */
181
- getStoreStockInOrderDetailList(request: Request.GetStoreStockInOrderDetailList, req?: FastifyRequest): Promise<Response.GetStoreStockInOrderDetailList>;
227
+ /** 门店入库单详情 */
228
+ getStoreStockInOrderDetail(request: Request.GetStoreStockInOrderDetail, req?: FastifyRequest): Promise<Response.GetStoreStockInOrderDetail>;
182
229
  /** 门店入库单运货单物流信息列表 */
183
230
  getStoreStockInOrderLogisticsList(request: Request.GetStoreStockInOrderLogisticsList, req?: FastifyRequest): Promise<Response.GetStoreStockInOrderLogisticsList>;
184
231
  /** 门店入库单商品列表 */
@@ -7,7 +7,7 @@ declare class StoreStockInService extends BaseService implements StoreStockInTyp
7
7
  list(request: StoreStockInTypes.Request.GetList): Promise<StoreStockInTypes.Response.GetList>;
8
8
  earlyComplete(request: StoreStockInTypes.Request.EarlyComplete): Promise<void>;
9
9
  delete(request: StoreStockInTypes.Request.Delete): Promise<void>;
10
- detailList(request: StoreStockInTypes.Request.IDetailList): Promise<StoreStockInTypes.Response.IDetailList>;
10
+ exportExcel(request: StoreStockInTypes.Request.ExportExcel): Promise<StoreStockInTypes.Response.ExportExcel>;
11
11
  getStockInProducts(request: StoreStockInTypes.Request.GetStockInProducts): Promise<StoreStockInTypes.Response.GetStockInProducts>;
12
12
  }
13
13
  export declare const storeStockInService: StoreStockInService;
@@ -36,8 +36,8 @@ let StoreStockInService = class StoreStockInService extends BaseService_1.defaul
36
36
  delete(request) {
37
37
  return (0, http_1.callApi)(this.getApiUrl(this.delete), request);
38
38
  }
39
- detailList(request) {
40
- return (0, http_1.callApi)(this.getApiUrl(this.detailList), request);
39
+ exportExcel(request) {
40
+ return (0, http_1.callApi)(this.getApiUrl(this.exportExcel), request);
41
41
  }
42
42
  getStockInProducts(request) {
43
43
  return (0, http_1.callApi)(this.getApiUrl(this.getStockInProducts), request);
@@ -64,9 +64,9 @@ __decorate([
64
64
  __param(0, (0, tsoa_1.Body)())
65
65
  ], StoreStockInService.prototype, "delete", null);
66
66
  __decorate([
67
- (0, tsoa_1.Post)('detail-list'),
67
+ (0, tsoa_1.Post)('export-excel'),
68
68
  __param(0, (0, tsoa_1.Body)())
69
- ], StoreStockInService.prototype, "detailList", null);
69
+ ], StoreStockInService.prototype, "exportExcel", null);
70
70
  __decorate([
71
71
  (0, tsoa_1.Post)('get-stock-in-products'),
72
72
  __param(0, (0, tsoa_1.Body)())
@@ -101,8 +101,8 @@ export declare namespace StoreStockInTypes {
101
101
  id: string;
102
102
  operator?: string;
103
103
  }
104
- /** 查询入库单详情列表请求 */
105
- interface IDetailList {
104
+ /** 导出入库单Excel请求 */
105
+ interface ExportExcel {
106
106
  pageIndex: number;
107
107
  pageSize: number;
108
108
  ids?: string[];
@@ -141,8 +141,8 @@ export declare namespace StoreStockInTypes {
141
141
  receivedCount: number;
142
142
  earlyCompletedCount: number;
143
143
  }
144
- /** 详情列表项目接口 */
145
- interface IDetailListItem {
144
+ /** 导出Excel项目接口 */
145
+ interface ExportExcelItem {
146
146
  单号?: string;
147
147
  仓库?: string;
148
148
  门店?: string;
@@ -166,9 +166,9 @@ export declare namespace StoreStockInTypes {
166
166
  配货备注?: string;
167
167
  发货备注?: string;
168
168
  }
169
- /** 详情列表响应接口 */
170
- interface IDetailList {
171
- data: IDetailListItem[];
169
+ /** 导出Excel响应接口 */
170
+ interface ExportExcel {
171
+ data: ExportExcelItem[];
172
172
  headerMap: string[];
173
173
  }
174
174
  /** 入库单商品项 */
@@ -199,8 +199,8 @@ export declare namespace StoreStockInTypes {
199
199
  earlyComplete(request: StoreStockInTypes.Request.EarlyComplete): Promise<void>;
200
200
  /** 删除入库单 */
201
201
  delete(request: StoreStockInTypes.Request.Delete): Promise<void>;
202
- /** 获取详情列表 */
203
- detailList(request: StoreStockInTypes.Request.IDetailList): Promise<StoreStockInTypes.Response.IDetailList>;
202
+ /** 导出入库单Excel */
203
+ exportExcel(request: StoreStockInTypes.Request.ExportExcel): Promise<StoreStockInTypes.Response.ExportExcel>;
204
204
  /** 店长查看入库单商品数据 */
205
205
  getStockInProducts(request: StoreStockInTypes.Request.GetStockInProducts): Promise<StoreStockInTypes.Response.GetStockInProducts>;
206
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/ecommerce-plan-allocation-service-node-sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "EcommercePlanAllocationService Node.js SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,10 @@
1
+ declare module '@fastify/request-context' {
2
+ interface RequestContextData {
3
+ requestId?: string;
4
+ traceMessageId?: string;
5
+ pandoraUserId?: string;
6
+ beLinkUserId?: string;
7
+ pandoraRoleId?: string;
8
+ }
9
+ }
10
+ export declare function callApi<T extends (...args: any[]) => Promise<any>>(url: string, request?: Parameters<T>[0]): Promise<Awaited<ReturnType<T>>>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.callApi = callApi;
40
+ const axios_1 = __importDefault(require("axios"));
41
+ const uuid_1 = require("uuid");
42
+ const axios_retry_1 = __importDefault(require("axios-retry"));
43
+ const request_context_1 = require("@fastify/request-context");
44
+ (0, axios_retry_1.default)(axios_1.default, {
45
+ retries: 1,
46
+ retryCondition(error) {
47
+ return error.response?.status === 502;
48
+ },
49
+ retryDelay: (retryCount) => {
50
+ console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`);
51
+ return retryCount * 500;
52
+ },
53
+ onRetry(retryCount, error, requestConfig) {
54
+ console.info(`retryCount: ${retryCount}, onRetry: ${error.message}, requestHeader: ${JSON.stringify(requestConfig.headers)}`);
55
+ },
56
+ });
57
+ async function callApi(url, request) {
58
+ const requestId = request_context_1.requestContext.get('requestId') || request_context_1.requestContext.get('traceMessageId') || (0, uuid_1.v4)();
59
+ const pandoraUserId = request_context_1.requestContext.get('pandoraUserId') || '';
60
+ const pandoraRoleId = request_context_1.requestContext.get('pandoraRoleId') || '';
61
+ const beLinkUserId = request_context_1.requestContext.get('beLinkUserId') || '';
62
+ try {
63
+ console.info(`准备发起ecommerce-plan-allocation-service请求[${requestId}]: ${url}, 参数: ${JSON.stringify(request)}`);
64
+ const response = await axios_1.default.post(url, request || {}, {
65
+ headers: {
66
+ 'x-request-id': requestId,
67
+ 'x-belink-pandora-userid': pandoraUserId,
68
+ 'x-belink-userid': beLinkUserId,
69
+ 'x-belink-pandora-roleid': pandoraRoleId,
70
+ },
71
+ });
72
+ const responseData = response.data;
73
+ return responseData.data;
74
+ }
75
+ catch (error) {
76
+ const axiosError = error;
77
+ if (axiosError.response) {
78
+ const response = axiosError.response;
79
+ const data = response.data;
80
+ console.error(`ecommerce-plan-allocation-service 异常: ${axiosError.message},requestId: ${requestId}`);
81
+ console.info('响应信息', data.message);
82
+ console.error('异常堆栈', JSON.stringify(error.stack));
83
+ throw error;
84
+ }
85
+ // 调用dns模块解析url
86
+ const dns = await Promise.resolve().then(() => __importStar(require('dns')));
87
+ const dnsPromise = new Promise((resolve, reject) => {
88
+ const lookupRes = dns.lookup(url, (err, address) => {
89
+ if (err) {
90
+ console.error(err.message);
91
+ reject(err);
92
+ }
93
+ console.info(`lookup: ${JSON.stringify(lookupRes)}`);
94
+ resolve(address);
95
+ });
96
+ });
97
+ try {
98
+ const address = await dnsPromise;
99
+ console.info(`address: ${JSON.stringify(address)}`);
100
+ }
101
+ catch (error) {
102
+ console.info(`error: ${JSON.stringify(error)}`);
103
+ }
104
+ console.error(`ecommerce-plan-allocation-service 未知异常: ${axiosError.message}`, error.stack);
105
+ throw error;
106
+ }
107
+ }
package/utils/http.d.ts CHANGED
@@ -5,6 +5,7 @@ declare module '@fastify/request-context' {
5
5
  pandoraUserId?: string;
6
6
  beLinkUserId?: string;
7
7
  pandoraRoleId?: string;
8
+ realIp?: string;
8
9
  }
9
10
  }
10
11
  export declare function callApi<T extends (...args: any[]) => Promise<any>>(url: string, request?: Parameters<T>[0]): Promise<Awaited<ReturnType<T>>>;
package/utils/http.js CHANGED
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -41,67 +8,101 @@ const axios_1 = __importDefault(require("axios"));
41
8
  const uuid_1 = require("uuid");
42
9
  const axios_retry_1 = __importDefault(require("axios-retry"));
43
10
  const request_context_1 = require("@fastify/request-context");
11
+ const http_1 = __importDefault(require("http"));
12
+ const https_1 = __importDefault(require("https"));
13
+ // HTTP 连接池配置 - 支持 2000 QPS(响应时间 2秒)
14
+ const HTTP_CONFIG = {
15
+ maxSockets: 3000, // 每个 host 最大并发连接数
16
+ maxFreeSockets: 1000, // 保持空闲连接数(减少连接重建开销)
17
+ maxTotalSockets: 10000, // 所有 host 总连接数上限(支持多个服务同时调用)
18
+ keepAliveMsecs: 60000, // 保持连接60秒
19
+ timeout: 5000, // socket超时5秒
20
+ requestTimeout: 5000, // 请求超时5秒
21
+ retries: 0, // 不重试(失败直接返回)
22
+ retryBaseDelay: 200, // 基础重试延迟200ms
23
+ };
24
+ // 配置 HTTP/HTTPS Agent 以支持高并发连接池和 keepAlive
25
+ const httpAgent = new http_1.default.Agent({
26
+ keepAlive: true,
27
+ keepAliveMsecs: HTTP_CONFIG.keepAliveMsecs,
28
+ maxSockets: HTTP_CONFIG.maxSockets,
29
+ maxFreeSockets: HTTP_CONFIG.maxFreeSockets,
30
+ maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
31
+ timeout: HTTP_CONFIG.timeout,
32
+ scheduling: 'lifo', // 后进先出调度(优先复用热连接,提高连接复用效率)
33
+ });
34
+ const httpsAgent = new https_1.default.Agent({
35
+ keepAlive: true,
36
+ keepAliveMsecs: HTTP_CONFIG.keepAliveMsecs,
37
+ maxSockets: HTTP_CONFIG.maxSockets,
38
+ maxFreeSockets: HTTP_CONFIG.maxFreeSockets,
39
+ maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
40
+ timeout: HTTP_CONFIG.timeout,
41
+ scheduling: 'lifo', // 后进先出调度(优先复用热连接,提高连接复用效率)
42
+ });
43
+ // 配置 axios 默认使用这些 agent
44
+ axios_1.default.defaults.httpAgent = httpAgent;
45
+ axios_1.default.defaults.httpsAgent = httpsAgent;
46
+ axios_1.default.defaults.timeout = HTTP_CONFIG.requestTimeout;
47
+ axios_1.default.defaults.maxRedirects = 3; // 限制重定向次数
48
+ axios_1.default.defaults.maxContentLength = 50 * 1024 * 1024; // 50MB 最大响应大小
49
+ // 高并发场景下的智能重试配置
44
50
  (0, axios_retry_1.default)(axios_1.default, {
45
- retries: 1,
51
+ retries: HTTP_CONFIG.retries,
46
52
  retryCondition(error) {
47
- return error.response?.status === 502;
48
- },
49
- retryDelay: (retryCount) => {
50
- console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`);
51
- return retryCount * 500;
53
+ // 重试临时错误和特定的网络错误
54
+ const status = error.response?.status;
55
+ const isNetworkError = error.code === 'ECONNRESET' ||
56
+ error.code === 'ETIMEDOUT' ||
57
+ error.code === 'ECONNREFUSED' ||
58
+ error.code === 'ENOTFOUND' ||
59
+ error.code === 'ENETUNREACH' ||
60
+ error.code === 'EAI_AGAIN';
61
+ const isServerError = status === 502 || status === 503 || status === 504;
62
+ const isRateLimited = status === 429;
63
+ const isTimeout = error.code === 'ECONNABORTED' || error.message?.includes('timeout');
64
+ return isNetworkError || isServerError || isRateLimited || isTimeout;
52
65
  },
53
- onRetry(retryCount, error, requestConfig) {
54
- console.info(`retryCount: ${retryCount}, onRetry: ${error.message}, requestHeader: ${JSON.stringify(requestConfig.headers)}`);
66
+ retryDelay: (retryCount, error) => {
67
+ // 指数退避 + 抖动
68
+ const status = error.response?.status;
69
+ // 如果是限流错误,延迟更长
70
+ if (status === 429) {
71
+ const retryAfter = error.response?.headers['retry-after'];
72
+ if (retryAfter) {
73
+ return parseInt(retryAfter) * 1000;
74
+ }
75
+ return 1000 + Math.random() * 1000; // 1-2秒
76
+ }
77
+ // 指数退避:200ms, 400ms, 800ms...
78
+ const exponentialDelay = HTTP_CONFIG.retryBaseDelay * Math.pow(2, retryCount - 1);
79
+ const jitter = Math.random() * 100; // 0-100ms 抖动
80
+ return Math.min(exponentialDelay + jitter, 3000); // 最多延迟3秒
55
81
  },
82
+ shouldResetTimeout: true, // 重试时重置超时
56
83
  });
57
84
  async function callApi(url, request) {
58
- const requestId = request_context_1.requestContext.get('requestId') || request_context_1.requestContext.get('traceMessageId') || (0, uuid_1.v4)();
59
- const pandoraUserId = request_context_1.requestContext.get('pandoraUserId') || '';
60
- const pandoraRoleId = request_context_1.requestContext.get('pandoraRoleId') || '';
61
- const beLinkUserId = request_context_1.requestContext.get('beLinkUserId') || '';
62
- try {
63
- console.info(`准备发起ecommerce-plan-allocation-service请求[${requestId}]: ${url}, 参数: ${JSON.stringify(request)}`);
64
- const response = await axios_1.default.post(url, request || {}, {
65
- headers: {
66
- 'x-request-id': requestId,
67
- 'x-belink-pandora-userid': pandoraUserId,
68
- 'x-belink-userid': beLinkUserId,
69
- 'x-belink-pandora-roleid': pandoraRoleId,
70
- },
71
- });
72
- const responseData = response.data;
73
- return responseData.data;
74
- }
75
- catch (error) {
76
- const axiosError = error;
77
- if (axiosError.response) {
78
- const response = axiosError.response;
79
- const data = response.data;
80
- console.error(`ecommerce-plan-allocation-service 异常: ${axiosError.message},requestId: ${requestId}`);
81
- console.info('响应信息', data.message);
82
- console.error('异常堆栈', JSON.stringify(error.stack));
83
- throw error;
84
- }
85
- // 调用dns模块解析url
86
- const dns = await Promise.resolve().then(() => __importStar(require('dns')));
87
- const dnsPromise = new Promise((resolve, reject) => {
88
- const lookupRes = dns.lookup(url, (err, address) => {
89
- if (err) {
90
- console.error(err.message);
91
- reject(err);
92
- }
93
- console.info(`lookup: ${JSON.stringify(lookupRes)}`);
94
- resolve(address);
95
- });
96
- });
97
- try {
98
- const address = await dnsPromise;
99
- console.info(`address: ${JSON.stringify(address)}`);
100
- }
101
- catch (error) {
102
- console.info(`error: ${JSON.stringify(error)}`);
103
- }
104
- console.error(`ecommerce-plan-allocation-service 未知异常: ${axiosError.message}`, error.stack);
105
- throw error;
106
- }
85
+ // 获取请求上下文
86
+ const ctx = request_context_1.requestContext.get('requestId') ? request_context_1.requestContext : null;
87
+ const requestId = ctx?.get('requestId') || ctx?.get('traceMessageId') || (0, uuid_1.v4)();
88
+ const pandoraUserId = ctx?.get('pandoraUserId') || '';
89
+ const beLinkUserId = ctx?.get('beLinkUserId') || '';
90
+ const pandoraRoleId = ctx?.get('pandoraRoleId') || '';
91
+ const realIp = ctx?.get('realIp') || '';
92
+ const response = await axios_1.default.post(url, request || {}, {
93
+ headers: {
94
+ 'x-request-id': requestId,
95
+ 'x-belink-pandora-userid': pandoraUserId,
96
+ 'x-belink-userid': beLinkUserId,
97
+ 'x-belink-pandora-roleid': pandoraRoleId,
98
+ 'x-real-ip': realIp,
99
+ Connection: 'keep-alive',
100
+ 'Content-Type': 'application/json;charset=utf-8',
101
+ },
102
+ timeout: HTTP_CONFIG.requestTimeout,
103
+ httpAgent,
104
+ httpsAgent,
105
+ });
106
+ const responseData = response.data;
107
+ return responseData.data;
107
108
  }