'use strict'; /** * 报表模板定义 Model。 * 报表采用「配置驱动」:name/type(注册方法 key)/file_name(导出文件名模板)/fields(勾选字段), * 唯一性由主键 id 承担,新报表只需加配置行,免发版。 * * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize; const ReportDefinition = app.model.define('report_definition', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键', }, name: { type: STRING(100), allowNull: false, comment: '报表名称', }, type: { type: STRING(50), allowNull: false, comment: '报表类型(内置查询器注册 key,如 stockFlow)', }, file_name: { type: STRING(200), allowNull: false, comment: '导出文件名模板(支持 {date} 占位,如 7日出入库_{date}.xlsx)', }, fields: { type: app.Sequelize.JSON, allowNull: true, comment: '勾选的字段 key 数组(列头/合并/样式/格式化由类型硬编码字段规格决定)', }, is_enabled: { type: TINYINT(1), allowNull: false, defaultValue: 1, comment: '是否启用:0=停用 1=启用', }, remark: { type: STRING(500), allowNull: true, comment: '备注', }, created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, updated_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '更新时间', }, deleted_at: { type: DATE, allowNull: true, comment: '软删除时间', }, }, { tableName: 'wms_report_definition', freezeTableName: true, underscored: true, timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', deletedAt: 'deleted_at', paranoid: true, comment: '报表模板定义表', indexes: [ { name: 'idx_deleted_at', fields: [ 'deleted_at' ] }, ], }); return ReportDefinition; };