'use strict'; /** * 收货未入库提醒定时任务。 * * 每 5 分钟在单 worker 中扫描一次:对仓库设置中开启「收货未入库提醒」 * (`subject_config.receiving_pending_inbound_notice.enabled`)的仓库, * 在到达其配置的提醒时间(notice_time,默认 08:30)时执行当日提醒。 * * - 超时区间同样来自仓库设置:创建时间超过 min_hours(默认 24)且不足 max_hours(默认 48) * 仍未完成入库的收货单会被提醒;提醒时间与区间均可在仓库设置中调整。 * - 绑定了货主的收货单通知货主收货群(未配群回退仓库客服群),未绑定货主的通知仓库客服群。 * - 提醒时间匹配带 10 分钟宽限(覆盖调度抖动),并用「仓库 + 日期」当日锁保证一天只提醒一次; * 执行异常会释放当日锁,宽限窗口内的下一轮会重试。 */ module.exports = { schedule: { interval: '5m', type: 'worker', immediate: false, disable: false, }, /** * 执行收货未入库提醒扫描。 * * @param {Object} ctx Egg 上下文。 * @return {Promise} 无返回值。 */ async task(ctx) { if (ctx.app._receivingPendingNoticeRunning) { return; } ctx.app._receivingPendingNoticeRunning = true; try { const summary = await ctx.service.systems.receivingPendingNotice.execute(); // 无仓库命中提醒时间时不刷日志,避免每 5 分钟噪音 if (summary && summary.executedWarehouseCount > 0) { ctx.logger.info( `[receiving-pending-notice] 本轮提醒完成:开启仓库 ${summary.checkedWarehouseCount},` + `执行 ${summary.executedWarehouseCount},未入库 ${summary.pendingCount} 单,` + `发送 ${summary.sentCount},失败 ${summary.failedCount},回退客服群 ${summary.fallbackCount || 0}` ); } } catch (error) { ctx.logger.error(`[receiving-pending-notice] 任务执行失败: ${error.message}`); } finally { ctx.app._receivingPendingNoticeRunning = false; } }, };