WMS_MAIN/database/migrations/20260813150000-create-wms-number-sequence.js
liufumingren 38b29be776 feat: 新增退回拆包模块(returnUnpack)与序列表原子取号
- 新增 wms_return_unpack 主表/明细/视频 与 wms_return_query_log 表(model + 迁移)
- 新增序列表 wms_number_sequence,单号取号改为 INSERT...ON DUPLICATE KEY 原子递增(含历史 seed 对齐)
- 补齐 wms_order_delivery 基表缺失 25 列(修复 Unknown column)
- 权限固定 ID 540-549 + 角色授权迁移
- 修复 returnReceived.create 出参 record 包装;修复 afterSale 发件人查询列名(name→company_name)
- detail 接口按设计走 548 权限校验
2026-08-13 21:40:50 +08:00

64 lines
1.9 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';
/**
* 创建业务单号序列表 wms_number_sequence。
*
* 用途:按「仓库 + 业务类型 + 日期」维度原子分配单号序号,
* 取代「查当日最大序号+1」的并发撞号方案。
* 取号 SQL:INSERT ... ON DUPLICATE KEY UPDATE current_seq = LAST_INSERT_ID(current_seq + 1)
* (同连接内再 SELECT LAST_INSERT_ID() 取回本次分配序号)。
*
* 索引:uk_warehouse_biz_date(仓库+业务类型+日期 唯一,原子取号的幂等键)。
*/
const TABLE_NAME = 'wms_number_sequence';
module.exports = {
// eslint-disable-next-line no-unused-vars
async up(queryInterface, Sequelize) {
const { BIGINT, STRING, INTEGER, CHAR, DATE } = Sequelize;
await queryInterface.createTable(TABLE_NAME, {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '主键',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(序号隔离维度)',
},
biz_type: {
type: STRING(30),
allowNull: false,
comment: '业务类型,如 return_unpack(退回拆包单号)',
},
date_part: {
type: CHAR(8),
allowNull: false,
comment: '日期片段 YYYYMMDD',
},
current_seq: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '当前已分配序号(原子递增)',
},
created_at: { type: DATE, allowNull: false },
updated_at: { type: DATE, allowNull: false },
});
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'biz_type', 'date_part' ], {
unique: true,
name: 'uk_warehouse_biz_date',
});
},
// eslint-disable-next-line no-unused-vars
async down(queryInterface, Sequelize) {
await queryInterface.dropTable(TABLE_NAME);
},
};