699ea6e8
杨鑫
完善打印逻辑
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
categoryName: str(o, "categoryName", "CategoryName", "None") || "None",
templateText: str(o, "templateText", "TemplateText", ""),
printedAt: str(o, "printedAt", "PrintedAt", ""),
printedByName: str(o, "printedByName", "PrintedByName", "None") || "None",
locationText: str(o, "locationText", "LocationText", "None") || "None",
locationId: str(o, "locationId", "LocationId", ""),
expiryDateText: str(o, "expiryDateText", "ExpiryDateText", "None") || "None",
};
}
function buildPrintLogQuery(
input: ReportsPrintLogQueryInput,
opts: { includePaging: boolean } = { includePaging: true }
) {
const q: Record<string, unknown> = {
Sorting: input.sorting,
PartnerId: input.partnerId,
GroupId: input.groupId,
LocationId: input.locationId,
StartDate: input.startDate,
EndDate: input.endDate,
Keyword: input.keyword,
};
if (opts.includePaging) {
q.SkipCount = input.skipCount;
q.MaxResultCount = input.maxResultCount;
}
return q;
}
export async function getReportsPrintLogList(
input: ReportsPrintLogQueryInput,
signal?: AbortSignal
): Promise<ReportsPrintLogListResult> {
const raw = await api.requestJson<unknown>({
path: `${REPORTS_PREFIX}/print-log-list`,
method: "GET",
query: buildPrintLogQuery(input, { includePaging: true }),
signal,
});
const o = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
const itemsRaw = o.items ?? o.Items;
const list = Array.isArray(itemsRaw) ? itemsRaw.map(normPrintItem) : [];
const total = num(o, "totalCount", "TotalCount", list.length);
return { items: list, totalCount: total };
}
function normLabelSlice(x: unknown): { name: string; count: number } | null {
if (!x || typeof x !== "object") return null;
const o = x as Record<string, unknown>;
const name = str(
o,
"categoryName",
"CategoryName",
str(o, "name", "Name", str(o, "labelCategoryName", "LabelCategoryName", "Category"))
);
if (!name.trim()) return null;
const count = num(
o,
"count",
"Count",
num(o, "printCount", "PrintCount", num(o, "totalPrinted", "TotalPrinted", 0))
);
return { name: name.trim(), count };
}
function normTrendPoint(x: unknown): { date: string; count: number } | null {
if (!x || typeof x !== "object") return null;
const o = x as Record<string, unknown>;
const date = str(
o,
"date",
"Date",
str(o, "day", "Day", str(o, "printDate", "PrintDate", ""))
);
if (!date.trim()) return null;
const count = num(o, "count", "Count", num(o, "volume", "Volume", 0));
return { date: date.trim(), count };
}
function normTopProduct(x: unknown) {
if (!x || typeof x !== "object") return null;
const o = x as Record<string, unknown>;
const productName = str(o, "productName", "ProductName", "");
if (!productName.trim()) return null;
return {
productName: productName.trim(),
categoryName: str(o, "categoryName", "CategoryName", "None") || "None",
totalPrinted: num(
o,
"totalPrinted",
"TotalPrinted",
num(o, "printCount", "PrintCount", 0)
),
usagePercent: num(o, "usagePercent", "UsagePercent", 0),
};
}
function normLabelReport(raw: unknown): LabelReportData {
if (!raw || typeof raw !== "object") {
return {
summary: {
totalLabelsPrinted: 0,
totalLabelsPrintedPrevPeriod: 0,
totalLabelsPrintedChangeRate: 0,
hottestCategoryName: "None",
hottestCategoryCount: 0,
topProductName: "None",
topProductCount: 0,
avgDailyPrints: 0,
avgDailyPrintsChangeRate: 0,
},
labelsByCategory: [],
printVolumeTrend: [],
mostUsedProducts: [],
};
}
const root = raw as Record<string, unknown>;
const sumRaw = root.summary ?? root.Summary;
const s = (sumRaw && typeof sumRaw === "object" ? sumRaw : {}) as Record<string, unknown>;
const labelsRaw = root.labelsByCategory ?? root.LabelsByCategory;
const trendRaw = root.printVolumeTrend ?? root.PrintVolumeTrend;
const productsRaw = root.mostUsedProducts ?? root.MostUsedProducts;
const labelsByCategory: { name: string; count: number }[] = [];
if (Array.isArray(labelsRaw)) {
for (const x of labelsRaw) {
const n = normLabelSlice(x);
if (n) labelsByCategory.push(n);
}
}
const printVolumeTrend: { date: string; count: number }[] = [];
if (Array.isArray(trendRaw)) {
for (const x of trendRaw) {
const p = normTrendPoint(x);
if (p) printVolumeTrend.push(p);
}
}
const mostUsedProducts: {
productName: string;
categoryName: string;
totalPrinted: number;
usagePercent: number;
}[] = [];
if (Array.isArray(productsRaw)) {
for (const x of productsRaw) {
const p = normTopProduct(x);
if (p) mostUsedProducts.push(p);
}
}
return {
summary: {
totalLabelsPrinted: num(s, "totalLabelsPrinted", "TotalLabelsPrinted", 0),
totalLabelsPrintedPrevPeriod: num(
s,
"totalLabelsPrintedPrevPeriod",
"TotalLabelsPrintedPrevPeriod",
0
),
totalLabelsPrintedChangeRate: num(
s,
"totalLabelsPrintedChangeRate",
"TotalLabelsPrintedChangeRate",
0
),
hottestCategoryName:
str(
s,
"hottestLabelCategoryName",
"HottestLabelCategoryName",
str(
s,
"mostPopularLabelCategoryName",
"MostPopularLabelCategoryName",
str(s, "hottestCategoryName", "HottestCategoryName", "None")
)
) || "None",
hottestCategoryCount: num(
s,
"hottestLabelCategoryCount",
"HottestLabelCategoryCount",
num(s, "hottestCategoryCount", "HottestCategoryCount", 0)
),
topProductName: str(
s,
"topProductName",
"TopProductName",
str(s, "mostUsedProductName", "MostUsedProductName", "None")
) || "None",
topProductCount: num(s, "topProductCount", "TopProductCount", 0),
avgDailyPrints: num(s, "avgDailyPrints", "AvgDailyPrints", 0),
avgDailyPrintsChangeRate: num(
s,
"avgDailyPrintsChangeRate",
"AvgDailyPrintsChangeRate",
0
),
},
labelsByCategory: labelsByCategory,
printVolumeTrend: printVolumeTrend,
mostUsedProducts: mostUsedProducts,
};
}
function buildLabelReportQuery(input: LabelReportQueryInput) {
return {
PartnerId: input.partnerId,
GroupId: input.groupId,
LocationId: input.locationId,
StartDate: input.startDate,
EndDate: input.endDate,
Keyword: input.keyword,
};
}
export async function getLabelReport(
input: LabelReportQueryInput,
signal?: AbortSignal
): Promise<LabelReportData> {
const raw = await api.requestJson<unknown>({
path: `${REPORTS_PREFIX}/label-report`,
method: "GET",
query: buildLabelReportQuery(input),
signal,
});
return normLabelReport(raw);
}
|
923d50c0
杨鑫
更新bug
|
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
function normTemplatePrintStatItem(raw: unknown): TemplatePrintStatListItem {
if (!raw || typeof raw !== "object") {
return { templateId: null, templateName: "None", printedCount: 0 };
}
const o = raw as Record<string, unknown>;
const tid = str(o, "templateId", "TemplateId", "");
return {
templateId: tid.trim() ? tid : null,
templateName: str(o, "templateName", "TemplateName", "None") || "None",
printedCount: num(o, "printedCount", "PrintedCount", 0),
};
}
function buildTemplatePrintStatQuery(input: TemplatePrintStatQueryInput) {
return {
SkipCount: input.skipCount,
MaxResultCount: input.maxResultCount,
Sorting: input.sorting ?? "PrintedCount desc",
PartnerId: input.partnerId,
GroupId: input.groupId,
LocationId: input.locationId,
StartDate: input.startDate,
EndDate: input.endDate,
Keyword: input.keyword,
};
}
/** 按模板汇总打印数量(`GET /api/app/reports/template-print-stat-list`) */
export async function getTemplatePrintStatList(
input: TemplatePrintStatQueryInput,
signal?: AbortSignal,
): Promise<TemplatePrintStatListResult> {
const raw = await api.requestJson<unknown>({
path: `${REPORTS_PREFIX}/template-print-stat-list`,
method: "GET",
query: buildTemplatePrintStatQuery(input),
signal,
});
const o = (raw && typeof raw === "object" ? raw : {}) as Record<string, unknown>;
const itemsRaw = o.items ?? o.Items;
const list = Array.isArray(itemsRaw) ? itemsRaw.map(normTemplatePrintStatItem) : [];
const total = num(o, "totalCount", "TotalCount", list.length);
return {
items: list,
totalCount: total,
pageIndex: num(o, "pageIndex", "PageIndex", input.skipCount),
pageSize: num(o, "pageSize", "PageSize", input.maxResultCount),
totalPages: num(o, "totalPages", "TotalPages", 0),
};
}
|