perf(waybill): getprintdata 支持只传一个 printHistoryId,并按 id 定位避免全表扫描
- 只传 printHistoryId(单值/数组)时,用取号落库的 platform_host + dbname + account_id
直接回源 PrintHistory/LoadPrintData,WMS 不用知道域名与分区
- 记录定位改为 (waybill_code IN …) OR (print_history_ids LIKE '%"id":"…"%'),
避免直传 id 时按主体全表扫描
- 文档补最简用法
实测:{ printHistoryId: "10000078656212" } → 运单号 770357408441408、dbname y/2wUDWCZOk=、
print_data 7888 字符、documentID 770357408441408。
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ccd007005a
commit
07a27a5bbd
@ -382,8 +382,9 @@ WMS 真正要打印时,调 `deliveryorder.getprintdata` 换一份新的(OMS
|
||||
| 项 | 说明 |
|
||||
|---|---|
|
||||
| 方法 | `deliveryorder.getprintdata` |
|
||||
| 入参(推荐) | `{ "caiNiaoAuthInfoIds": [ 6838859 ], "waybillCodes": [ "770357408441408" ] }` |
|
||||
| 入参(可选直传) | `{ "printHistoryIds": [ "10000078656212" ] }`(命中即跳过按运单号查库) |
|
||||
| 入参(最简) | `{ "printHistoryId": "10000078656212" }` —— 只给一个打印记录ID即可,OMS 用取号时落库的域名 + 分区 + 打单账号直接回源 |
|
||||
| 入参(推荐批量) | `{ "caiNiaoAuthInfoIds": [ 6838859 ], "waybillCodes": [ "770357408441408" ] }` |
|
||||
| 入参(可选直传) | `{ "printHistoryIds": [ "10000078656212", "…" ] }`(数组,命中即跳过按运单号查库) |
|
||||
| 出参 | `{ total, success, failed, expires_in, results: [ … ] }`,`expires_in` 固定 600 秒 |
|
||||
| 单条结果 | `waybill_code, success, message, print_history_id, template_id, cai_niao_auth_info_id, dbname, print_data, printer_config, document` |
|
||||
|
||||
@ -405,6 +406,11 @@ OMS 用它 + 运单号定位到那次取号的打印记录(`waybill_fetch_reco
|
||||
> 📌 **取号响应也会返回 `print_history_ids` / `print_history_id`**(见 §4.2),WMS 可按需落库;
|
||||
> 但打印前换 params 时**不要求** WMS 传它 —— 传「`caiNiaoAuthInfoIds` + `waybillCodes`」由 OMS 查库即可,
|
||||
> 想省一次查库时再直传 `printHistoryIds`。两者以 OMS 库里的记录为准(重打会新增打印记录)。
|
||||
>
|
||||
> 📌 **只传一个打印记录ID就够了**(实测):`{ "printHistoryId": "10000078656212" }` →
|
||||
> OMS 从自己库里取出该记录对应的**域名(`platform_host`)+ 分区(`dbname`)+ 打单账号**,直接回源
|
||||
> `PrintHistory/LoadPrintData` 拿新的 params,返回 `print_data`(实测 7888 字符)与拆好的 `document`。
|
||||
> 也就是说 WMS 不需要知道域名/分区,店铺标识与运单号也不是必填。
|
||||
|
||||
```sql
|
||||
-- 打印前换 params 时 OMS 内部按这条定位(同一个运单号多次取号取最新一条)
|
||||
|
||||
@ -154,7 +154,8 @@ const METHODS = {
|
||||
*
|
||||
* 报文示例:
|
||||
* { "caiNiaoAuthInfoIds": [ 6838859 ], "waybillCodes": [ "770357408441408" ] }
|
||||
* { "printHistoryIds": [ "10000078656212" ] } // 直传打印记录ID,命中即跳过查库
|
||||
* { "printHistoryId": "10000078656212" } // 最简:只给一个打印记录ID,域名/分区取自己落库的
|
||||
* { "printHistoryIds": [ "10000078656212" ] } // 直传打印记录ID数组,命中即跳过按运单号查库
|
||||
* 返回 data:{ total, success, failed, expires_in, results: [ { waybill_code, success, print_data, printer_config, document, ... } ] }
|
||||
* @param {Object} ctx egg context
|
||||
* @param {Object} payload 调用上下文
|
||||
|
||||
@ -165,9 +165,17 @@ async function getPrintData(ctx, { principalId, warehouseId, data, requestId })
|
||||
return { ok: false, message: `单次最多换取 ${MAX_BATCH} 个运单号的打印数据` };
|
||||
}
|
||||
|
||||
// 定位取号记录:运单号走索引;直传打印记录ID时按 JSON 里的 id 匹配(避免全表扫描)
|
||||
const where = { principal_id: principalId, status: 1 };
|
||||
if (shopIds.length) where.cai_niao_auth_info_id = { [Op.in]: shopIds };
|
||||
if (waybillCodes.length) where.waybill_code = { [Op.in]: waybillCodes };
|
||||
const conditions = [];
|
||||
if (waybillCodes.length) conditions.push({ waybill_code: { [Op.in]: waybillCodes } });
|
||||
if (historyIds.length) {
|
||||
conditions.push({
|
||||
[Op.or]: historyIds.map(id => ({ print_history_ids: { [Op.like]: `%"id":"${id}"%` } })),
|
||||
});
|
||||
}
|
||||
where[Op.or] = conditions;
|
||||
const records = await ctx.model.WaybillFetchRecord.findAll({
|
||||
where,
|
||||
order: [[ 'id', 'DESC' ]],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user