WMS_MAIN/database/migrations/20260702-seed-receipt-default-template.js
liufumingren 34273c166b 1
2026-07-02 22:08:47 +08:00

43 lines
1.7 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';
/**
* 入库单 A5 默认打印模板(ENTRY_ORDER 业务类型)数据清理迁移。
*
* 背景:
* 旧版本 migration 已创建了一个格式正确的入库单模板(id=20,扁平化 content/field_code/bold/fontSize 风格)。
* 本 migration 后来又插入了一个格式错误的模板(id=21,使用了 label+style 包装,与渲染引擎不兼容)。
*
* 本迁移的作用:
* - 删除格式错误的重复模板 id=21(如果存在)
* - 保留下一个格式正确的模板(id=20)继续使用
*
* 渲染引擎解析逻辑见 app/service/systemMethods/print.js(customize 分支):
* - 直接读取 item.content / item.fontSize / item.bold / item.textAlign 等扁平化属性
* - 有 field_code 的元素用 data[field_code] 值覆盖 content
* - 不支持 label / style 对象包装
*/
const TABLE = 'wms_print_template';
module.exports.up = async queryInterface => {
const { sequelize } = queryInterface;
// 删除格式错误的重复模板(id=21,使用了 label+style 包装格式)
// 保留格式正确的模板 id=20(扁平化 content/field_code/bold/fontSize 风格)
const [ duplicate ] = await sequelize.query(
`SELECT id FROM \`${TABLE}\` WHERE id = 21 AND business_type = 'ENTRY_ORDER' AND template_name = '入库单A5模板' AND warehouse_id IS NULL AND delete_at IS NULL LIMIT 1`,
{ type: sequelize.QueryTypes.SELECT }
);
if (duplicate) {
await sequelize.query(
`DELETE FROM \`${TABLE}\` WHERE id = 21`,
{ type: sequelize.QueryTypes.DELETE }
);
}
};
module.exports.down = async () => {
// down 不回滚:删除 id=21 是一条清理操作,不需要恢复
};