fix(openapi/storage): 修复服务命名冲突、完善导入入库收货单占用与入库单详情字段
- openapi.js 重命名为 openapiEntry.js,消除与 openapi/ 目录同名冲突,恢复 ctx.service.openapi.callback 可用,修复 quickInbound API 回传报 Cannot read properties of undefined (reading 'sendWithRetry') - 导入/PDA 入库 commit 新增非绑定模式收货单占用:带 receiving_detail_id 的记录优先按明细扣减,剩余导入量按 stock_id 匹配绑定收货单明细占用并回写收货单入库状态 - storage.entry.get 响应新增 total_order_lines / total_quantity / received_quantity 字段 - 同步 AI_METHOD_ROUTING.md 与 methods/changes 变更记录
This commit is contained in:
parent
adb7405396
commit
f8915a5733
@ -147,7 +147,7 @@ rg "class .*Service|module.exports" app/service/qimenMethods
|
||||
- receive
|
||||
- app/service/main.js (18)
|
||||
- success, fail, normalizeDate, setInfo, getInfo, isPlainObject, normalizeWhereCondition, normalizeWhereParams, extractWhereValues, prepareWhereContext, findQimenAppWithContract, queryFromDatabase, checkAuth, checkApiPermission, extractApiPermissionState, collectApiPermissionValue, setUserContext, systemInit
|
||||
- app/service/openapi.js (9)
|
||||
- app/service/openapiEntry.js (9)
|
||||
- resolveOpenapiMethod, getOpenapiMethodService, resolveOpenapiContract, getInfo, dispatchOpenapiMethod, validateOpenapiParams, parseJsonBody, normalizeSignFields, processRequest
|
||||
- app/service/openapi/callback.js (4)
|
||||
- signCallback, sendWithRetry, sendByAppKey, logCallback
|
||||
|
||||
@ -30,7 +30,7 @@ class OpenapiController extends Controller {
|
||||
const { ctx } = this;
|
||||
|
||||
try {
|
||||
const result = await ctx.service.openapi.processRequest();
|
||||
const result = await ctx.service.openapiEntry.processRequest();
|
||||
if (result.ok) {
|
||||
ctx.status = Number(result.httpStatus) || 200;
|
||||
ctx.body = toSuccess(result.data, result.message || 'ok');
|
||||
|
||||
@ -1156,9 +1156,12 @@ class InboundDirectLogService extends Service {
|
||||
);
|
||||
}
|
||||
|
||||
// 回写收货单和收货明细的入库状态
|
||||
// 回写收货单和收货明细的入库状态(绑定模式:按 receiving_detail_id 优先扣减)
|
||||
await this._syncReceivingStorageStatus({ entryItemIds, transaction });
|
||||
|
||||
// 非绑定模式剩余导入量:按 stock_id 匹配绑定收货单明细占用(绑定模式优先,剩余兜底)
|
||||
await this._applyReceivingStockOccupancy({ entryOrder: eo, directLogs, transaction });
|
||||
|
||||
// 更新入库单状态为 COMPLETED
|
||||
await eo.update({
|
||||
order_status: 'COMPLETED',
|
||||
@ -1682,6 +1685,71 @@ class InboundDirectLogService extends Service {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 非绑定模式收货单占用:导入记录未携带 receiving_detail_id 时,
|
||||
* 将剩余导入量按 stock_id(=收货明细 system_product_id)匹配到绑定收货单明细上,
|
||||
* 依次占用剩余可入数量(actual_quantity - stored_quantity),
|
||||
* 回写 stored_quantity/storage_status 并汇总收货单主表 storage_status。
|
||||
* 携带 receiving_detail_id 的导入记录已由 _syncReceivingStorageStatus 优先处理,
|
||||
* 本方法只处理未携带 receiving_detail_id 的剩余部分(必须先调用前者)。
|
||||
*
|
||||
* @param {Object} params 参数
|
||||
* @param {Object} params.entryOrder 入库单实例
|
||||
* @param {Array<Object>} params.directLogs 入库单下所有未删除的导入/PDA 入库记录
|
||||
* @param {Object} params.transaction Sequelize 事务对象
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
async _applyReceivingStockOccupancy({ entryOrder, directLogs, transaction }) {
|
||||
const { ctx, app } = this;
|
||||
|
||||
// 1. 入库单未绑定收货单 → 跳过
|
||||
const bindings = await ctx.model.EntryOrderReceiving.findAll({
|
||||
where: { entry_order_id: entryOrder.id, deleted_at: null },
|
||||
attributes: [ 'receiving_id' ],
|
||||
raw: true,
|
||||
transaction,
|
||||
});
|
||||
const receivingIds = [ ...new Set((bindings || []).map(b => Number(b.receiving_id)).filter(Boolean)) ];
|
||||
if (receivingIds.length === 0) return;
|
||||
|
||||
// 2. 汇总未携带 receiving_detail_id 的导入量(绑定模式已优先处理,这里只取剩余部分)
|
||||
const stockInboundQtyMap = new Map();
|
||||
for (const log of directLogs) {
|
||||
if (log.receiving_detail_id) continue;
|
||||
const stockId = Number(log.stock_id);
|
||||
const qty = Number(log.quantity) || 0;
|
||||
if (!stockId || qty <= 0) continue;
|
||||
stockInboundQtyMap.set(
|
||||
stockId,
|
||||
{ inboundQty: (stockInboundQtyMap.get(stockId)?.inboundQty || 0) + qty }
|
||||
);
|
||||
}
|
||||
if (stockInboundQtyMap.size === 0) return;
|
||||
|
||||
// 3. 查询绑定收货单明细(事务内读取,stored_quantity 已包含绑定模式扣减结果)
|
||||
const boundDetails = await ctx.model.ReceivingDetail.findAll({
|
||||
where: {
|
||||
receiving_id: { [app.Sequelize.Op.in]: receivingIds },
|
||||
system_product_id: { [app.Sequelize.Op.ne]: null },
|
||||
},
|
||||
attributes: [ 'id', 'receiving_id', 'system_product_id', 'actual_quantity', 'stored_quantity' ],
|
||||
raw: true,
|
||||
transaction,
|
||||
});
|
||||
if (!boundDetails || boundDetails.length === 0) return;
|
||||
|
||||
// 4. 复用 storage.entry 的收货单占用逻辑(与 quickInbound 一致,事务内行锁防并发超分)
|
||||
await ctx.service.systems.storage.entry._applyReceivingInboundUsage({
|
||||
receivingDetailRows: boundDetails,
|
||||
stockInboundQtyMap,
|
||||
transaction,
|
||||
});
|
||||
|
||||
ctx.logger.info(
|
||||
`[InboundDirectLog] 非绑定模式导入已按 stock_id 占用收货单明细,entryOrderId=${entryOrder.id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InboundDirectLogService;
|
||||
|
||||
@ -576,7 +576,9 @@ class EntryService extends Service {
|
||||
* @param {number} data.id 入库单主键 ID(必填)
|
||||
* @param {string} [mode='warehouse'] 查询维度:'warehouse' 按仓库校验权限(默认),'store' 按货主校验权限
|
||||
* @return {Promise<Object>} code/data/message 结构
|
||||
* - data.entryOrder: { id, entry_order_code, order_status, store_remask }
|
||||
* - data.entryOrder: { id, entry_order_code, order_status, total_order_lines, store_remask }
|
||||
* - data.total_quantity: 应入库总数量(明细 planned 之和)
|
||||
* - data.received_quantity: 已入库总数量(明细 completed 之和)
|
||||
* - data.items: [{ id, stock_id, planned, completed, stock, bindings }]
|
||||
* - data.receivingBindings: [{ id, receiving_id, receiving }]
|
||||
*/
|
||||
@ -827,8 +829,11 @@ class EntryService extends Service {
|
||||
id: entryOrder.id,
|
||||
entry_order_code: entryOrder.entry_order_code,
|
||||
order_status: entryOrder.order_status,
|
||||
total_order_lines: entryOrder.total_order_lines,
|
||||
store_remask: (storeWarehouse && storeWarehouse.store_remask) || '',
|
||||
},
|
||||
total_quantity: items.reduce((sum, item) => sum + (Number(item.planned) || 0), 0),
|
||||
received_quantity: items.reduce((sum, item) => sum + (Number(item.completed) || 0), 0),
|
||||
items,
|
||||
receivingBindings,
|
||||
},
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.08.27-openapi-service-conflict-fix",
|
||||
"date": "2026-08-27",
|
||||
"summary": "修复 Egg 服务命名冲突:app/service/openapi.js 重命名为 openapiEntry.js,恢复 ctx.service.openapi.callback 可用",
|
||||
"methods": [],
|
||||
"notes": [
|
||||
"根因:app/service/openapi.js 文件与 app/service/openapi/ 目录同名,Egg ContextLoader 把目录里的 callback/callbackRegistry 挂成 OpenapiService 类的静态属性,实例上不可见,导致运行时 ctx.service.openapi.callback 为 undefined",
|
||||
"修复:openapi.js 重命名为 openapiEntry.js(服务路径 ctx.service.openapiEntry),app/controller/openapi.js 的 processRequest 引用同步更新,AI_METHOD_ROUTING.md 同步",
|
||||
"影响:storage.entry.quickInbound 对 API 来源直入单回传 entry_order_direct_inbound_completed 事件不再报 Cannot read properties of undefined (reading 'sendWithRetry'),库存两段式(先回传后写库)可正常执行"
|
||||
],
|
||||
"type": "fixed"
|
||||
},
|
||||
{
|
||||
"version": "2026.06.04-openapi-04",
|
||||
"date": "2026-06-04",
|
||||
|
||||
@ -1,4 +1,39 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.08.27-storage-entry-get-total-order-lines",
|
||||
"date": "2026-08-27",
|
||||
"type": "enhanced",
|
||||
"summary": "storage.entry.get 响应新增 total_order_lines(entryOrder 内)、total_quantity(应入库总数量)、received_quantity(已入库总数量)字段",
|
||||
"methods": [
|
||||
"storage.entry.get",
|
||||
"storage.entry.getStore"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/storage/entry.js get:返回 data.entryOrder 新增 total_order_lines(直接取 wms_entry_order.total_order_lines)",
|
||||
"data 顶层新增 total_quantity = 明细 planned 之和(应入库总数量)、received_quantity = 明细 completed 之和(已入库总数量)",
|
||||
"getStore 共用同一底层实现,自动获得这些字段",
|
||||
"同步更新 get 方法 JSDoc 注释"
|
||||
],
|
||||
"module": "storage.entry"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.27-directInbound-receiving-stock-occupancy",
|
||||
"date": "2026-08-27",
|
||||
"type": "enhanced",
|
||||
"summary": "storage.entry.commit 导入/PDA 入库支持绑定收货单占用:带 receiving_detail_id 的导入记录优先按明细扣减,未带 receiving_detail_id 的剩余导入量按 stock_id 匹配收货单明细占用并回写收货单入库状态",
|
||||
"methods": [
|
||||
"storage.entry.commit",
|
||||
"storage.directInbound.commit"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/inbound_direct_log.js commit onSuccess 事务内新增 _applyReceivingStockOccupancy:绑定收货单(wms_entry_order_receiving)存在时,汇总未携带 receiving_detail_id 的导入记录数量,按 stock_id(=收货明细 system_product_id)匹配占用",
|
||||
"优先级:携带 receiving_detail_id 的记录先由 _syncReceivingStorageStatus 按明细扣减,随后剩余量复用 storage.entry._applyReceivingInboundUsage 按 stock_id 依次占用收货明细剩余可入数量(actual_quantity - stored_quantity),事务内行锁防并发超分",
|
||||
"占用后回写收货明细 stored_quantity/storage_status(all/partial),并汇总更新收货单主表 storage_status",
|
||||
"未绑定收货单或无剩余导入量时跳过,不影响原有非绑定模式入库行为",
|
||||
"storage.entry._applyReceivingInboundUsage 日志前缀由 [storage.entry.quickInbound] 改为 [storage.entry](方法现被 quickInbound 与 commit 两个流程复用)"
|
||||
],
|
||||
"module": "storage.entry"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.26-wave-batchList-store-id-filter",
|
||||
"date": "2026-08-26",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user