Files
klp-oa/script/sql/mysql/stock.sql
2025-10-28 14:57:04 +08:00

72 lines
4.4 KiB
SQL
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.

DROP TABLE IF EXISTS `wms_stock`;
create table wms_stock
(
stock_id bigint auto_increment comment '主键ID'
primary key,
warehouse_id bigint not null comment '仓库/库区/库位ID',
item_id bigint not null comment '物品ID指向原材料或产品主键',
item_type varchar(20) not null comment '物品类型raw_material/product',
batch_no varchar(50) null comment '批次号(可选)',
remark varchar(255) null comment '备注',
del_flag tinyint(1) default 0 not null comment '删除标志0=正常1=已删除)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
create_by varchar(50) null comment '创建人',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
update_by varchar(50) null comment '更新人',
constraint fk_stock_warehouse
foreign key (warehouse_id) references wms_warehouse (warehouse_id)
)
comment '库存表:原材料-钢卷-库区的存放关系' charset = utf8mb4;
create index idx_stock_warehouse
on wms_stock (warehouse_id);
create table wms_material_coil
(
coil_id bigint auto_increment comment '主键ID'
primary key,
enter_coil_no varchar(50) not null comment '入场钢卷号(年份后两位+月份+当月第几个如25100001、25102422',
current_coil_no varchar(50) not null comment '当前钢卷号(入场钢卷号和当前钢卷号可能不同)',
supplier_coil_no varchar(50) null comment '厂家原料卷号',
data_type tinyint(1) default 1 not null comment '数据类型0=历史1=现存)',
warehouse_id bigint null comment '所在库区ID',
next_warehouse_id bigint null comment '下一库区ID',
qrcode_record_id bigint null comment '关联二维码IDwms_generate_record.record_id',
team varchar(50) null comment '班组',
has_merge_split tinyint(1) default 0 not null comment '是否合卷/分卷0=否1=分卷2=合卷)',
parent_coil_nos varchar(500) null comment '父卷号(合卷或分卷时用,逗号分隔)',
item_id bigint not null comment '物品ID指向原材料或产品主键',
item_type varchar(20) not null comment '物品类型raw_material/product',
weight decimal(10,2) null comment '重量',
status tinyint(1) default 0 null comment '状态0=在库1=在途2=已出库)',
remark varchar(255) null comment '备注',
del_flag tinyint(1) default 0 not null comment '删除标志0=正常1=已删除)',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
create_by varchar(50) null comment '创建人',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
update_by varchar(50) null comment '更新人',
constraint uk_enter_coil_no
unique (enter_coil_no) comment '入场钢卷号唯一约束',
constraint fk_coil_warehouse
foreign key (warehouse_id) references wms_warehouse (warehouse_id),
constraint fk_coil_next_warehouse
foreign key (next_warehouse_id) references wms_warehouse (warehouse_id),
constraint fk_coil_qrcode
foreign key (qrcode_record_id) references wms_generate_record (record_id)
)
comment '钢卷物料表' charset = utf8mb4;
create index idx_coil_current_no
on wms_material_coil (current_coil_no);
create index idx_coil_type
on wms_material_coil (data_type);
create index idx_coil_warehouse
on wms_material_coil (warehouse_id);