58 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const sevenDayStockFlow = require('./sevenDayStockFlow');
/**
* 报表内置查询器注册表。
* key 对应 wms_report_definition.type;
* 新增查询器时在此登记,签名统一为
* async ({ ctx, storeId, warehouseId, params }) => ({ windows, rows, meta })。
* 每个查询器需在模块上挂载静态字段清单 `fields`(如 module.exports.fields)
* 与缺省窗口参数 `defaultWindow`,供报表引擎 report.meta / report.definition.typeList 读取。
* 注意:该对象会作为 service 模块导出,egg 加载器需要在其上挂载
* `Symbol(EGG_LOADER_ITEM_FULLPATH)` 等内部符号,因此禁止对导出对象使用
* Object.freeze / Object.seal / Object.preventExtensions。
* @type {Object<string, Function>}
*/
const QUERIES = {
stockFlow: sevenDayStockFlow,
};
/**
* 注册表描述元数据:key/title/description/window/fields。
* @type {Array<{key: string, title: string, description: string, window: Object, fields: Array<Object>}>}
*/
const DESCRIPTIONS = [
{
key: 'stockFlow',
title: '库存变化以及补货报表',
description: '按日窗口聚合出入库流水与正品库存,输出每 SKU 每日出/入库、可用/总库存、'
+ '锁定数、待出、日均出/入库、预计可售天数、建议补货量与库存预警',
window: {
...(sevenDayStockFlow.defaultWindow || { dayCount: 7, cutoverHour: 7 }),
},
fields: (Array.isArray(sevenDayStockFlow.fields) ? sevenDayStockFlow.fields : []).map(field => ({ ...field })),
},
];
/**
* 输出注册表可读描述(含全量字段清单),供 report.definition.typeList / report.meta 复用。
* 返回副本,避免调用方误改注册表元数据。
* @return {Array<{key: string, title: string, description: string, window: Object, fields: Array<Object>}>} 注册描述列表
*/
function describe() {
return DESCRIPTIONS.map(entry => ({
...entry,
window: { ...(entry.window || {}) },
fields: (Array.isArray(entry.fields) ? entry.fields : []).map(field => ({
...field,
children: Array.isArray(field.children) ? field.children.map(child => ({ ...child })) : undefined,
})),
}));
}
// egg 加载器要求导出对象可扩展,describe 作为方法属性挂在 QUERIES 上
QUERIES.describe = describe;
module.exports = QUERIES;