fix(returnUnpack): 拆包视频拼接 CDN 域名,商品复核字段透出与缓存失效修复
- returnUnpack: list/detail/videoList/queryByWaybill 输出 videos[].video_url 自动拼接 http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{path},与 order.packing 同口径 (录制电脑从 wms_print_computer 按 is_recording=true 获取,无录制电脑时保持原始相对路径) - recheckOrder: scanOrder/scanTask 报文 stock 明细新增 need_recheck 字段(缺省 Y) - stock: getStockDetails 双实现透出 need_recheck;saveWarehouseStock/handleBatchChange 更新成功后 显式清除商品详情缓存(bulk update 不触发实例级 afterUpdate hook,修复旧缓存被持续读取) - delivery_order: 订单创建时间统一取服务器当前时间,不采用报文 createTime,避免被平台上报时间覆盖 - 同步 methods/system.json 文档与 methods/changes/system.json 变更记录
This commit is contained in:
parent
763573ee41
commit
705678487d
@ -806,6 +806,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
barcodes: Array.isArray(item.barcodes) ? [ ...item.barcodes ] : [],
|
||||
images: Array.isArray(item.images) ? [ ...item.images ] : [],
|
||||
has_shared_barcode: Boolean(item.has_shared_barcode),
|
||||
need_recheck: String(item.need_recheck || 'Y').trim(),
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
store_id: item.store_id != null ? Number(item.store_id) : 0,
|
||||
owner_code: String(item.owner_code || '').trim(),
|
||||
@ -1481,6 +1482,7 @@ class RecheckOrderService extends OrderBaseService {
|
||||
barcodes,
|
||||
images,
|
||||
has_shared_barcode: hasSharedBarcode,
|
||||
need_recheck: String(stockInfo.need_recheck || 'Y').trim(),
|
||||
plan_qty: Number(item.plan_qty || 0),
|
||||
store_id: stockInfo.store_id != null ? Number(stockInfo.store_id) : 0,
|
||||
owner_code: String(item.owner_code || '').trim(),
|
||||
|
||||
@ -1306,7 +1306,6 @@ class DeliveryOrderService extends Service {
|
||||
orderFlag,
|
||||
sourcePlatformCode,
|
||||
sourcePlatformName,
|
||||
createTime,
|
||||
placeOrderTime,
|
||||
payTime,
|
||||
payNo,
|
||||
@ -1361,7 +1360,8 @@ class DeliveryOrderService extends Service {
|
||||
create_channel: String(createChannel || 'MANUAL').trim().toUpperCase() || 'MANUAL',
|
||||
sys_platform_code: platformSnapshot.sysPlatformCode,
|
||||
sys_platform_name: platformSnapshot.sysPlatformName,
|
||||
create_at: createTime ? new Date(createTime) : new Date(),
|
||||
// 创建时间统一取服务器当前时间,不采用报文 createTime,避免被平台上报时间覆盖
|
||||
create_at: new Date(),
|
||||
place_order_time: placeOrderTime ? new Date(placeOrderTime) : null,
|
||||
pay_time: payTime ? new Date(payTime) : null,
|
||||
pay_no: payNo || sourceOrderCode || '',
|
||||
|
||||
@ -9,6 +9,41 @@ const Service = require('egg').Service;
|
||||
* 所有数据库交互集中在此层,供 systemMethods/returnUnpack.js 调用。
|
||||
*/
|
||||
class ReturnUnpackService extends Service {
|
||||
/**
|
||||
* 获取仓库的录制电脑 ID(带缓存)。
|
||||
* 与 order_packing 一致:从 wms_print_computer 按 is_recording=true 获取。
|
||||
* @param {number} warehouseId 仓库ID
|
||||
* @return {Promise<number|null>} 录制电脑ID,找不到返回 null
|
||||
*/
|
||||
async _getRecordingComputerId(warehouseId) {
|
||||
const cacheKey = `_recordingComputer_${warehouseId}`;
|
||||
if (this[cacheKey] !== undefined) {
|
||||
return this[cacheKey];
|
||||
}
|
||||
const row = await this.ctx.model.PrintComputer.findOne({
|
||||
where: { warehouse_id: warehouseId, is_recording: true, deleted_at: null },
|
||||
attributes: [ 'id' ],
|
||||
raw: true,
|
||||
});
|
||||
this[cacheKey] = row ? row.id : null;
|
||||
return this[cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建视频完整 URL(与 order.packing 一致)。
|
||||
* 格式:http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{videoPath}
|
||||
* @param {number} warehouseId 仓库ID
|
||||
* @param {number|null} recordingComputerId 录制电脑ID
|
||||
* @param {string} videoPath 视频路径
|
||||
* @return {string} 完整 URL
|
||||
*/
|
||||
_buildVideoUrl(warehouseId, recordingComputerId, videoPath) {
|
||||
if (!videoPath || !recordingComputerId) {
|
||||
return videoPath || '';
|
||||
}
|
||||
return `http://w${warehouseId}-c${recordingComputerId}.o.gztbyc.com${videoPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建带业务错误码的异常对象。
|
||||
*
|
||||
@ -660,6 +695,20 @@ class ReturnUnpackService extends Service {
|
||||
raw: false,
|
||||
});
|
||||
|
||||
// 视频地址拼接 CDN 域名(unpack_id 由方法层强制注入且已通过仓库隔离校验)
|
||||
const unpackIdRaw = queryWhere.unpack_id;
|
||||
const unpackId = unpackIdRaw && typeof unpackIdRaw === 'object' ? unpackIdRaw.value : unpackIdRaw;
|
||||
let warehouseId = 0;
|
||||
if (unpackId) {
|
||||
const unpackRow = await ctx.model.ReturnUnpack.findOne({
|
||||
where: { id: Number(unpackId) },
|
||||
attributes: [ 'warehouse_id' ],
|
||||
raw: true,
|
||||
});
|
||||
warehouseId = Number(unpackRow && unpackRow.warehouse_id || 0);
|
||||
}
|
||||
const recordingComputerId = warehouseId > 0 ? await this._getRecordingComputerId(warehouseId) : null;
|
||||
|
||||
const list = rows
|
||||
.map(row => (row && typeof row.toJSON === 'function' ? row.toJSON() : row))
|
||||
.map(row => {
|
||||
@ -667,7 +716,7 @@ class ReturnUnpackService extends Service {
|
||||
return {
|
||||
id: row.id,
|
||||
unpack_id: row.unpack_id,
|
||||
video_url: row.video_url,
|
||||
video_url: this._buildVideoUrl(warehouseId, recordingComputerId, row.video_url),
|
||||
status: row.status || null,
|
||||
camera_id: row.camera_id || null,
|
||||
camera_name: (camera.custom_name || camera.channel_name) || null,
|
||||
@ -827,6 +876,12 @@ class ReturnUnpackService extends Service {
|
||||
raw: true,
|
||||
});
|
||||
|
||||
// 视频地址拼接 CDN 域名(与 order.packing 对齐)
|
||||
const recordingComputerId = await this._getRecordingComputerId(warehouseId);
|
||||
for (const video of videos) {
|
||||
video.video_url = this._buildVideoUrl(warehouseId, recordingComputerId, video.video_url);
|
||||
}
|
||||
|
||||
let received = null;
|
||||
if (unpack.return_received_id) {
|
||||
received = await ctx.model.ReturnReceived.findOne({
|
||||
@ -1297,6 +1352,16 @@ class ReturnUnpackService extends Service {
|
||||
if (Array.isArray(record.videos)) {
|
||||
record.has_video = record.videos.length > 0 ? 1 : 2;
|
||||
record.video_enable = record.videos.some(v => v.video_url && v.status !== 'failed') ? 1 : 2;
|
||||
|
||||
// 视频地址拼接 CDN 域名(与 order.packing 对齐:http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{path})
|
||||
const warehouseId = Number(record.warehouse_id || 0);
|
||||
if (warehouseId > 0) {
|
||||
const recordingComputerId = await this._getRecordingComputerId(warehouseId);
|
||||
record.videos = record.videos.map(v => ({
|
||||
...v,
|
||||
video_url: this._buildVideoUrl(warehouseId, recordingComputerId, v.video_url),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
// camera_ids 归一化为数组(MySQL JSON 列可能返回字符串)
|
||||
|
||||
@ -2663,6 +2663,17 @@ class stockStoreService extends Service {
|
||||
delete_at: null,
|
||||
},
|
||||
});
|
||||
|
||||
// 5.1 清除商品详情缓存(bulk update 不触发实例级 afterUpdate hook)
|
||||
if (affectedRows > 0) {
|
||||
const detailCacheSvc = ctx.service && ctx.service.systems && ctx.service.systems.stockWarehouse;
|
||||
if (detailCacheSvc && typeof detailCacheSvc.invalidateStockDetailCache === 'function') {
|
||||
await Promise.allSettled(
|
||||
ids.map(stockId => detailCacheSvc.invalidateStockDetailCache(Number(stockId), warehouseId))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
message: `成功修改 ${affectedRows} 条记录`,
|
||||
code: 200,
|
||||
@ -3199,6 +3210,13 @@ class stockStoreService extends Service {
|
||||
// 7. 提交事务
|
||||
await transaction.commit();
|
||||
|
||||
// 7.1 清除商品详情缓存(getStockDetails 缓存,bulk update 不触发实例级 afterUpdate hook)
|
||||
try {
|
||||
await service.systems.stockWarehouse.invalidateStockDetailCache(id, warehouseId);
|
||||
} catch (cacheError) {
|
||||
ctx.logger.warn(`saveWarehouseStock 清除商品详情缓存失败: ${cacheError.message}`);
|
||||
}
|
||||
|
||||
// 8. 返回更新后的数据
|
||||
return await this.getInfo({ id });
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class StockWarehouseService extends Service {
|
||||
* @param {Object} [options={}] 选项
|
||||
* @param {number} [options.warehouseId] 仓库ID(优先使用 options.warehouseId,否则兜底 ctx.user.store_id)
|
||||
* @param {number} [options.cacheTTL=300] 缓存过期时间(秒)
|
||||
* @return {Promise<Array<{id: number, item_code: string, item_name: string, sku_property: string, quantity: number, locked_quantity: number, is_batch_mgmt: string, is_shelf_life_mgmt: string, is_images: string, store_id: number, packing_requirements: string, stock_unit: string, image_url: string[], barcodes: Array<{id: number, barcode: string}>}>>} 商品详情列表
|
||||
* @return {Promise<Array<{id: number, item_code: string, item_name: string, sku_property: string, quantity: number, locked_quantity: number, is_batch_mgmt: string, is_shelf_life_mgmt: string, is_images: string, need_recheck: string, store_id: number, packing_requirements: string, stock_unit: string, image_url: string[], barcodes: Array<{id: number, barcode: string}>}>>} 商品详情列表
|
||||
*/
|
||||
async getStockDetails(stockIds, options = {}) {
|
||||
const { ctx, app } = this;
|
||||
@ -79,7 +79,7 @@ class StockWarehouseService extends Service {
|
||||
attributes: [
|
||||
'id', 'item_code', 'item_name', 'sku_property',
|
||||
'quantity', 'locked_quantity', 'is_batch_mgmt',
|
||||
'is_shelf_life_mgmt', 'is_images',
|
||||
'is_shelf_life_mgmt', 'is_images', 'need_recheck',
|
||||
'store_id', 'packing_requirements', 'stock_unit',
|
||||
],
|
||||
raw: true,
|
||||
@ -143,6 +143,7 @@ class StockWarehouseService extends Service {
|
||||
is_batch_mgmt: row.is_batch_mgmt || 'N',
|
||||
is_shelf_life_mgmt: row.is_shelf_life_mgmt || 'N',
|
||||
is_images: row.is_images || 'N',
|
||||
need_recheck: row.need_recheck || 'Y',
|
||||
store_id: row.store_id != null ? Number(row.store_id) : 0,
|
||||
packing_requirements: row.packing_requirements || '',
|
||||
stock_unit: row.stock_unit || '',
|
||||
@ -188,6 +189,10 @@ class StockWarehouseService extends Service {
|
||||
if (cached && !Array.isArray(cached.image_url)) {
|
||||
cached.image_url = [];
|
||||
}
|
||||
// 兼容旧缓存:无 need_recheck 时补默认(需要复核)
|
||||
if (cached && cached.need_recheck == null) {
|
||||
cached.need_recheck = 'Y';
|
||||
}
|
||||
result.push(cached);
|
||||
}
|
||||
} else if (dbResults.has(stockId)) {
|
||||
|
||||
@ -31,7 +31,7 @@ class StockWarehouseService extends Service {
|
||||
* @param {Object} [options={}] 选项
|
||||
* @param {number} [options.warehouseId] 仓库ID(优先使用 options.warehouseId,否则兜底 ctx.user.store_id)
|
||||
* @param {number} [options.cacheTTL=300] 缓存过期时间(秒)
|
||||
* @return {Promise<Array<{id: number, item_code: string, item_name: string, sku_property: string, quantity: number, locked_quantity: number, is_batch_mgmt: string, is_shelf_life_mgmt: string, image_url: string, is_images: string, store_id: number, packing_requirements: string, stock_unit: string, barcodes: Array<{id: number, barcode: string, sku_property: string}>}>>} 商品详情列表
|
||||
* @return {Promise<Array<{id: number, item_code: string, item_name: string, sku_property: string, quantity: number, locked_quantity: number, is_batch_mgmt: string, is_shelf_life_mgmt: string, image_url: string, is_images: string, need_recheck: string, store_id: number, packing_requirements: string, stock_unit: string, barcodes: Array<{id: number, barcode: string, sku_property: string}>}>>} 商品详情列表
|
||||
*/
|
||||
async getStockDetails(stockIds, options = {}) {
|
||||
const { ctx, app } = this;
|
||||
@ -77,6 +77,7 @@ class StockWarehouseService extends Service {
|
||||
'id', 'item_code', 'item_name', 'sku_property',
|
||||
'quantity', 'locked_quantity', 'is_batch_mgmt',
|
||||
'is_shelf_life_mgmt', 'image_url', 'is_images',
|
||||
'need_recheck',
|
||||
'store_id', 'packing_requirements', 'stock_unit',
|
||||
],
|
||||
raw: true,
|
||||
@ -116,6 +117,7 @@ class StockWarehouseService extends Service {
|
||||
is_shelf_life_mgmt: row.is_shelf_life_mgmt || 'N',
|
||||
image_url: row.image_url || '',
|
||||
is_images: row.is_images || 'N',
|
||||
need_recheck: row.need_recheck || 'Y',
|
||||
store_id: row.store_id != null ? Number(row.store_id) : 0,
|
||||
packing_requirements: row.packing_requirements || '',
|
||||
stock_unit: row.stock_unit || '',
|
||||
@ -153,6 +155,10 @@ class StockWarehouseService extends Service {
|
||||
const cached = cacheHits.get(stockId);
|
||||
// 空标记(防穿透缓存)跳过
|
||||
if (cached !== null && cached !== undefined) {
|
||||
// 兼容旧缓存:无 need_recheck 时补默认(需要复核)
|
||||
if (cached.need_recheck == null) {
|
||||
cached.need_recheck = 'Y';
|
||||
}
|
||||
result.push(cached);
|
||||
}
|
||||
} else if (dbResults.has(stockId)) {
|
||||
|
||||
@ -1,4 +1,54 @@
|
||||
[
|
||||
{
|
||||
"version": "2026.08.23-returnUnpack.video-url-cdn-domain",
|
||||
"date": "2026-08-23",
|
||||
"type": "fixed",
|
||||
"summary": "修复拆包视频地址未拼接 CDN 域名的问题:returnUnpack.list / returnUnpack.detail / returnUnpack.videoList / returnUnpack.queryByWaybill 输出的 videos[].video_url 此前直接返回相对路径(如 /recordings/...),与 order.packing 输出完整 URL 的口径不一致。现在按打包侧相同规则拼接 http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{path}(录制电脑从 wms_print_computer 按 is_recording=true 获取,无录制电脑时保持原始路径)。",
|
||||
"methods": [
|
||||
"returnUnpack.list",
|
||||
"returnUnpack.detail",
|
||||
"returnUnpack.videoList"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/return_unpack.js 新增 _getRecordingComputerId/_buildVideoUrl(与 order_packing.js 同口径,带实例级缓存)",
|
||||
"_enrichRow 视频派生块内对 videos[].video_url 拼接域名(覆盖 list/detail/submit 输出)",
|
||||
"videoList 按 unpack_id 反查 warehouse_id 后拼接;queryByWaybill(inbox 查退回)的 videos 同样拼接",
|
||||
"同步更新 methods/system.json 中 returnUnpack.list 与 returnUnpack.detail 的响应字段描述"
|
||||
],
|
||||
"module": "returnUnpack"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.23-stock.warehouse-cache-invalidate-on-update",
|
||||
"date": "2026-08-23",
|
||||
"type": "fixed",
|
||||
"summary": "修复商品资料更新后 getStockDetails 详情缓存未清除的问题:saveWarehouseStock/handleBatchChange 使用 StockWarehouse.update 批量更新(不触发实例级 afterUpdate hook),导致 cache:stock_detail:{warehouseId}:{stockId} 旧数据在 TTL 内持续被读取(如 need_recheck 修改后复核扫描仍返回旧值)。现在两个编辑入口更新成功后显式调用 stockWarehouse.invalidateStockDetailCache 清除对应缓存。",
|
||||
"methods": [
|
||||
"stock.warehouse.saveWarehouseStock",
|
||||
"stock.warehouse.handleBatchChange"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systems/stock_store.js saveWarehouseStock 提交事务后调用 service.systems.stockWarehouse.invalidateStockDetailCache(id, warehouseId)(失败仅告警不阻断主流程)",
|
||||
"同文件 handleBatchChange 批量更新后按 ids 批量清除详情缓存(Promise.allSettled,失败不阻断返回)",
|
||||
"实证验证:更新后 Redis 缓存 key 被删除,复核扫描/统一查询立即读取到新值"
|
||||
],
|
||||
"module": "stock"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.23-recheckOrder.stock-need-recheck",
|
||||
"date": "2026-08-23",
|
||||
"type": "enhanced",
|
||||
"summary": "order.recheckOrder.scanOrder / scanTask 返回报文的 stock 明细新增 need_recheck 字段(Y=需要复核,N=不需要复核,缺省 Y):散单路径 enrichOrdersWithStock 组装与团购路径 buildGroupWaveList 的 stocks 映射均透出,供前端按商品判断是否免复核。",
|
||||
"methods": [
|
||||
"order.recheckOrder.scanOrder",
|
||||
"order.recheckOrder.scanTask"
|
||||
],
|
||||
"notes": [
|
||||
"app/service/systemMethods/order/recheckOrder.js enrichOrdersWithStock stock 对象新增 need_recheck(取 getStockDetails 返回值,缺省 'Y')",
|
||||
"同文件 buildGroupWaveList 的 stocks 映射新增 need_recheck",
|
||||
"同步更新 methods/system.json 中 scanOrder 的 stock children 与 scanTask 的 stock 字段描述"
|
||||
],
|
||||
"module": "order"
|
||||
},
|
||||
{
|
||||
"version": "2026.08.23-stock.warehouse-need-recheck",
|
||||
"date": "2026-08-23",
|
||||
|
||||
@ -36958,7 +36958,7 @@
|
||||
"name": "list",
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"description": "拆包单列表,每条含主表字段 + is_original_return 派生字段 + 格式化时间字段 + camera_ids 数组 + 视频派生字段 has_video(1=有视频记录/2=无)与 video_enable(1=录像可用/2=不可用)+ videos 视频数组(id/video_url/status/camera_id/camera_name)"
|
||||
"description": "拆包单列表,每条含主表字段 + is_original_return 派生字段 + 格式化时间字段 + camera_ids 数组 + 视频派生字段 has_video(1=有视频记录/2=无)与 video_enable(1=录像可用/2=不可用)+ videos 视频数组(id/video_url/status/camera_id/camera_name),video_url 自动拼接 CDN 域名前缀 http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{path}(录制电脑从 wms_print_computer 按 is_recording=true 获取,无录制电脑时返回原始相对路径)"
|
||||
},
|
||||
{
|
||||
"name": "pagination",
|
||||
@ -37095,7 +37095,7 @@
|
||||
"name": "record",
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"description": "主表完整记录(含 details 明细、videos 视频、returnReceived 退回收到单关联与格式化时间字段)"
|
||||
"description": "主表完整记录(含 details 明细、videos 视频(video_url 自动拼接 CDN 域名前缀 http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{path})、returnReceived 退回收到单关联与格式化时间字段)"
|
||||
},
|
||||
{
|
||||
"name": "related",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user