feat(panel): 新增 touchLastChangeAt 公共方法,拣货/复核/打包完成时通知大屏刷新(0.3.292)

This commit is contained in:
liufumingren 2026-10-12 23:38:53 +08:00
parent 75333b2eb6
commit ef933bc353
6 changed files with 57 additions and 1 deletions

View File

@ -1794,6 +1794,9 @@ class RecheckOrderService extends OrderBaseService {
// 若全部完成则更新波次状态为复核完成(wave_status=5),使波次从 batchList 中消失
await this._tryCompleteWaveIfAllOrdersRechecked(orderId, order.wave_id, warehouseId, operator, now);
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return {
order_id: orderId,
waybill_no: waybillNo,
@ -2013,6 +2016,9 @@ class RecheckOrderService extends OrderBaseService {
now,
});
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return {
wave_id: normalizedWaveId,
success_count: normalOrders.length,
@ -4251,6 +4257,9 @@ class RecheckOrderService extends OrderBaseService {
}
}
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return {
success: successOrders,
failed: failedOrders,
@ -4444,6 +4453,9 @@ class RecheckOrderService extends OrderBaseService {
}
}
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return {
success: allSuccessOrders,
failed: allFailedOrders,

View File

@ -2559,6 +2559,9 @@ class PickSystemService extends Service {
});
}
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return {
task_id: taskId,
mode,

View File

@ -31,6 +31,29 @@ class WarehousePanelService extends Service {
return `${PANEL_CACHE_KEY_PREFIX}:lastChangeAt:${warehouseId}`;
}
/**
* 通知面板数据已变化(公共方法):更新对应仓库的最后更新时间戳,供大屏增量轮询感知新数据。
* 只写时间戳(整值替换,data 自然失效),面板接口下次拉取时会查库重建数据。
* 供拣货完成/复核完成/打包完成等业务写路径调用;失败仅告警不影响主流程。
*
* @param {number|string} warehouseId 仓库 ID
* @return {Promise<number>} 写入的时间戳(Unix 秒);失败返回 0
*/
async touchLastChangeAt(warehouseId) {
try {
const key = this.getPanelCacheKey(Number(warehouseId));
const nowTs = Math.floor(Date.now() / 1000);
await this.app.setCacheAsync(key, { last_change_at: nowTs }, PANEL_CACHE_TTL_SECONDS);
return nowTs;
} catch (error) {
const logger = this.ctx.logger;
if (logger && typeof logger.warn === 'function') {
logger.warn(`[WarehousePanel] 更新最后更新时间失败 warehouseId=${warehouseId}: ${error && error.message}`);
}
return 0;
}
}
/**
* 读取仓库自然日开始时间(wms_store.subject_config.day_start_time)。
*

View File

@ -772,6 +772,9 @@ class WorkbenchService extends Service {
}
}
// 通知仓库面板刷新(大屏增量更新,失败不影响主流程)
await this.service.systems.warehousePanel.touchLastChangeAt(Number(warehouseId));
return orderPackStatus;
}

View File

@ -1,4 +1,18 @@
[
{
"version": "0.3.292",
"date": "2026-10-12",
"type": "updated",
"summary": "index.getWarehousePanelData 新增面板刷新公共方法 touchLastChangeAt(warehouseId),并接入拣货完成/复核完成/打包完成路径(0.3.291 → 0.3.292)",
"methods": [
"index.getWarehousePanelData"
],
"notes": [
"变更内容:WarehousePanelService 新增公共方法 touchLastChangeAt(warehouseId)——更新对应仓库面板缓存键的最后更新时间戳(只写时间戳整值替换、TTL 300 秒、失败仅告警返回 0),供各业务写路径通知大屏刷新;已接入:拣货完成 systems/pick.js#wavePickTaskComplete、复核完成 systemMethods/order/recheckOrder.js#confirmRecheck / confirmRecheckByWaveId / batchQuickRecheck / batchQuickRecheckByWave、打包完成 systems/workbench.js#_updateOrderPackStatus(覆盖所有打包结束路径)。",
"代码依据:app/service/systems/warehouse_panel.js#touchLastChangeAt(新增)+ 3 个文件 6 处调用点;ESLint 0 错误(workbench.js 存在预先存在的 class-field 解析告警与本次无关)。",
"文档变更范围:methods/system.json 的 module=index 分组仅更新 index.getWarehousePanelData 一条(notes 新增外部驱动公共方法说明);根版本 0.3.291 → 0.3.292、updatedAt 保持 2026-10-12;methods/changes/system.json 新增本条(插入数组首位);其余 method 未改动。"
]
},
{
"version": "0.3.291",
"date": "2026-10-12",

View File

@ -1,7 +1,7 @@
{
"module": "system",
"description": "系统接口标准入口,method 对应系统内置方法,全部使用 POST 请求,参数统一放在 body 内",
"version": "0.3.291",
"version": "0.3.292",
"updatedAt": "2026-10-12",
"headers": [
{
@ -2626,6 +2626,7 @@
],
"errors": [],
"notes": [
"外部驱动公共方法(本次新增):app/service/systems/warehouse_panel.js#touchLastChangeAt(warehouseId)——业务数据变化时调用一行即可更新该仓库面板最后更新时间戳(只写时间戳整值替换、TTL 300 秒,失败仅告警不影响主流程);已接入拣货完成(systems/pick.js#wavePickTaskComplete)、复核完成(systemMethods/order/recheckOrder.js#confirmRecheck/confirmRecheckByWaveId/batchQuickRecheck/batchQuickRecheckByWave)、打包完成(systems/workbench.js#_updateOrderPackStatus,覆盖工作台手动结束/新任务关闭旧任务/超时自动结束等全部打包结束路径)。",
"缓存键 index:warehousePanel:lastChangeAt:{warehouseId},值为 { last_change_at, data },TTL 300 秒。拉取逻辑:缓存有最后更新时间且传入时间戳未过期 → is_change=false + 空 data 不查库;时间戳过期且缓存有数据 → 直接输出缓存数据;时间戳过期但缓存无数据(外部只驱动了时间戳)→ 查库拉数据补入缓存并保留外部时间戳;缓存无最后更新时间(未命中/过期)→ 查库拉数据并设置最后更新时间",
"最后更新时间一般由外部驱动:业务数据变化时由外部写入缓存键的 last_change_at(只写时间戳即可,数据由本接口下次拉取时补入)",
"未输出字段(数据源或口径未定):履约链路第 7 环节退件签收、stageOverview 质检卡、收货/上架卡的 today/abnormal、weeklyEfficiency 的 throughput/max",