148 lines
5.0 KiB
JavaScript
148 lines
5.0 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 创建库存盘点主表 wms_stock_check。
|
||
*
|
||
* 字段:仓库隔离 warehouse_id、盘点单号 check_no(PD+YYYYMMDD+6位序号,唯一)、
|
||
* 盘点名称 title、盘点范围类型 type(all全盘/store按货主/goods按商品/location按库位)、
|
||
* 盘点方式 mode(open明盘/blind盲盘)、货主 store_id、范围条件快照 scope_snapshot(JSON)、
|
||
* 状态 status(pending/in_progress/checked/confirmed/completed/cancelled)、
|
||
* 明细盘点状态 detail_status(none_checked/partial_checked/all_checked)、
|
||
* 盘点日期 check_date、起止时间 start_time/end_time、创建人 creator_id/creator_name、
|
||
* 汇总 total_items/checked_items/diff_items、备注 remark。
|
||
*
|
||
* 索引:
|
||
* uk_check_no(单号唯一)
|
||
* idx_warehouse_check_date(仓库+盘点日期隔离查询)
|
||
* idx_warehouse_status(仓库+状态)
|
||
* idx_store_id / idx_creator_id
|
||
*/
|
||
|
||
const TABLE_NAME = 'wms_stock_check';
|
||
|
||
module.exports = {
|
||
// eslint-disable-next-line no-unused-vars
|
||
async up(queryInterface, Sequelize) {
|
||
const { BIGINT, STRING, INTEGER, DATE, JSON: JSON_TYPE } = 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(数据隔离维度)',
|
||
},
|
||
check_no: {
|
||
type: STRING(50),
|
||
allowNull: false,
|
||
comment: '盘点单号,唯一,生成规则:PD+YYYYMMDD+6位序号',
|
||
},
|
||
title: {
|
||
type: STRING(200),
|
||
allowNull: true,
|
||
comment: '盘点名称/主题,非必填',
|
||
},
|
||
type: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
defaultValue: 'all',
|
||
comment: '盘点范围类型:all=全盘,store=按货主,goods=按商品,location=按库位',
|
||
},
|
||
mode: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
defaultValue: 'open',
|
||
comment: '盘点方式:open=明盘(可见账面数量),blind=盲盘(不可见账面数量)',
|
||
},
|
||
store_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: true,
|
||
comment: '货主ID,按货主盘点时必填(type=store)',
|
||
},
|
||
scope_snapshot: {
|
||
type: JSON_TYPE,
|
||
allowNull: true,
|
||
comment: '盘点范围条件快照(JSON),如商品ID列表/库位ID列表,供盘点对比与追溯',
|
||
},
|
||
status: {
|
||
type: STRING(20),
|
||
allowNull: false,
|
||
defaultValue: 'pending',
|
||
comment: '盘点状态:pending=待盘点,in_progress=盘点中,checked=已盘待确认,confirmed=已确认,completed=已完成,cancelled=已取消',
|
||
},
|
||
detail_status: {
|
||
type: STRING(30),
|
||
allowNull: false,
|
||
defaultValue: 'none_checked',
|
||
comment: '明细盘点进度:none_checked=未盘,partial_checked=部分已盘,all_checked=全部已盘',
|
||
},
|
||
check_date: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '盘点日期',
|
||
},
|
||
start_time: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '实际开始时间',
|
||
},
|
||
end_time: {
|
||
type: DATE,
|
||
allowNull: true,
|
||
comment: '实际结束时间',
|
||
},
|
||
creator_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '创建人账户ID',
|
||
},
|
||
creator_name: {
|
||
type: STRING(50),
|
||
allowNull: true,
|
||
comment: '创建人名称快照',
|
||
},
|
||
total_items: {
|
||
type: INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '明细行数(盘点任务总行数)',
|
||
},
|
||
checked_items: {
|
||
type: INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '已盘行数',
|
||
},
|
||
diff_items: {
|
||
type: INTEGER(11),
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '差异行数(账面与实盘不一致的行数)',
|
||
},
|
||
remark: {
|
||
type: STRING(500),
|
||
allowNull: true,
|
||
comment: '备注',
|
||
},
|
||
created_at: { type: DATE, allowNull: false },
|
||
updated_at: { type: DATE, allowNull: false },
|
||
});
|
||
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'check_no' ], { unique: true, name: 'uk_check_no' });
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'check_date' ], { name: 'idx_warehouse_check_date' });
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'warehouse_id', 'status' ], { name: 'idx_warehouse_status' });
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'store_id' ], { name: 'idx_store_id' });
|
||
await queryInterface.addIndex(TABLE_NAME, [ 'creator_id' ], { name: 'idx_creator_id' });
|
||
},
|
||
|
||
// eslint-disable-next-line no-unused-vars
|
||
async down(queryInterface, Sequelize) {
|
||
await queryInterface.dropTable(TABLE_NAME);
|
||
},
|
||
};
|