liufumingren a4cadeb83b feat: 库内确定拦截订单明细报表与拦截时间口径调整
- 新增通用报表注册类型 interceptOrder(库内确定拦截订单明细):以配送表 dispath_time 为时间基准,统计昨日自然日(不含当天,可用 params.bizDate 指定更早日期补数)intercept_status=intercepted_at_warehouse 的订单,按商品明细展开;列 = 订单导出 item 模式去掉商品图片(46 列)+ 平台交易单号 / 通知拦截时间 / 库内确定拦截时间,共 49 列
- intercept_time 口径统一为「最近一次发起拦截的通知时刻」:发起拦截首次写入不覆盖(新增 app/lib/intercept_time.js 与 qimen/openapi/inbox/pendingOrder 四处改造)、库内拦截确认与退回入库不再覆盖、取消/解除拦截与订单克隆重置置空;库内确定拦截时刻改用配送表 dispath_time
- 报表导出文件名模板新增 {time}(生成时刻 HHmmss)/ {datetime} / {timestamp} 占位符({date} 语义不变),避免同一天多次投递/导出同一报表时 COS 同名覆盖与 CDN 旧内容回源
- 文档同步:methods/system.json 0.3.104 -> 0.3.109(report.generate / report.definition.* 契约与拦截时间口径说明)、methods/changes/system.json 新增 4 条变更记录、docs/report-config-guide.md 新增 2.2 节、字段清单与文件名占位符说明
- 回归与实测:test/report_*.cjs 13 个文件 + test/intercept_time_lifecycle.cjs 全部通过,ESLint 0 error;开发库投递计划实测(19:40 / 20:25 两条计划投递成功或仅文本通知环境依赖失败,文件名均带时分秒、导出列与定义勾选一致)
2026-09-10 20:59:39 +08:00

138 lines
5.0 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 MainService = require('../../main');
/**
* 系统方法层:report.definition(报表定义管理接口包装层)。
* 仅做出口包装与参数解构,业务逻辑下沉 systems/report。
*/
class ReportDefinitionMethodService extends MainService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
// typeList 为只读公共元数据:免权限/免鉴权/免日志(与 report 模块免权限只读接口惯例一致),仍要求登录;
// save/list/delete 属定义管理类操作:不声明免权限,仅通配符角色(超级管理员/仓库管理员)可用,
// 后续由 wms_permission 同步流程按需授权,不扩大任何角色授权范围
const _noNeedRight = 'typeList';
const _noNeedLog = 'typeList';
const _noNeedAuth = 'typeList';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 查询报表类型注册清单(内置查询器 + 标题/描述/窗口参数 + 全量字段清单)。
* 免权限只读(仅登录),供前端报表配置页渲染类型下拉与字段勾选。
* @param {Object} data 请求体(无必填参数,兼容空对象)
* @return {Promise<Object>} 统一 success 包装,data 为 { list: Array<Object> } 注册类型清单
*/
async typeList(data = {}) {
void data;
const { service } = this;
const types = await service.systems.report.listRegisteredTypes();
return this.success('ok', {
list: types,
});
}
/**
* 新增/更新报表定义(按 id upsert:未传 id 视为新增,未传字段不覆盖)。
* @param {Object} data 请求体
* @param {number} [data.id] 报表定义ID(正整数;不传视为新增)
* @param {string} data.name 报表名称(必填,≤100)
* @param {string} data.type 报表类型(注册方法 key,如 stockFlow;新增必填)
* @param {string} data.file_name 导出文件名模板(支持 {date}/{time}/{datetime}/{timestamp};新增必填,≤200,兼容 fileName)
* @param {Array<string>} data.fields 勾选字段 key 数组(新增必填,须为该类型注册字段子集)
* @param {number} [data.is_enabled] 是否启用(0/1)
* @param {string} [data.remark] 备注(≤500)
* @return {Promise<Object>} 统一 success 包装,data 为保存后的报表定义视图
*/
async save(data = {}) {
const { service } = this;
const {
id,
name,
type,
file_name: fileNameSnake,
fileName: fileNameCamel,
fields,
is_enabled: isEnabled,
remark,
} = data;
// 仅附加入参中存在的字段(undefined 不进入参数对象),保持「未传不覆盖」语义
const saveArgs = { id, name, type };
const normalizedFileName = fileNameCamel !== undefined ? fileNameCamel : fileNameSnake;
if (normalizedFileName !== undefined) {
saveArgs.fileName = normalizedFileName;
}
if (fields !== undefined) {
saveArgs.fields = fields;
}
if (isEnabled !== undefined) {
saveArgs.isEnabled = isEnabled;
}
if (remark !== undefined) {
saveArgs.remark = remark;
}
try {
const result = await service.systems.report.saveDefinition(saveArgs);
return this.success('ok', result);
} catch (error) {
return this.fail(error.message || '报表定义保存失败');
}
}
/**
* 分页查询报表定义列表。
* @param {Object} data 请求体
* @param {Object} [data.where] 查询条件(name 模糊关键字、type/is_enabled 精确)
* @param {Object} [data.pagination] 分页 { page, pageSize }
* @param {Object} [data.sort] 排序 { sortField, sortOrder }(白名单:id/name/type/is_enabled/created_at/updated_at)
* @return {Promise<Object>} 统一 success 包装,data 为 { list, total, page, pageSize }
*/
async list(data = {}) {
const { service } = this;
const { whereValue = {} } = this.prepareWhereContext(data);
const {
name: nameKeyword,
type,
is_enabled: isEnabled,
} = whereValue;
const { pagination = {}, sort = {} } = data;
try {
const result = await service.systems.report.listDefinitions({
nameKeyword,
type,
isEnabled,
pagination,
sort,
});
return this.success('ok', result);
} catch (error) {
return this.fail(error.message || '报表定义列表查询失败');
}
}
/**
* 软删除报表定义(存在启用中的投递计划引用时拦截)。
* @param {Object} data 请求体
* @param {number} data.id 报表定义ID(必填,正整数)
* @return {Promise<Object>} 统一 success 包装,data 为 { id, deleted }
*/
async delete(data = {}) {
const { service } = this;
const { id } = data;
try {
const result = await service.systems.report.deleteDefinition({ id });
return this.success('ok', result);
} catch (error) {
return this.fail(error.message || '报表定义删除失败');
}
}
}
module.exports = ReportDefinitionMethodService;