211 lines
13 KiB
SQL
211 lines
13 KiB
SQL
create table wms_process_plan
|
||
(
|
||
plan_id bigint not null comment '主键'
|
||
primary key,
|
||
version_id bigint not null comment '规程版本ID',
|
||
segment_type varchar(32) not null comment '段类型(INLET/PROCESS/OUTLET)',
|
||
segment_name varchar(100) null comment '段名称',
|
||
point_name varchar(200) not null comment '点位名称',
|
||
point_code varchar(64) not null comment '点位编码',
|
||
sort_order int default 0 not null comment '排序',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
update_by varchar(64) null comment '更新人',
|
||
update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除)',
|
||
remark varchar(500) null comment '备注',
|
||
constraint uk_plan_version_point_code
|
||
unique (version_id, point_code)
|
||
)
|
||
comment '方案点位表';
|
||
|
||
create index idx_plan_sort
|
||
on wms_process_plan (version_id, sort_order);
|
||
|
||
create index idx_plan_version
|
||
on wms_process_plan (version_id);
|
||
|
||
create table wms_process_plan_param
|
||
(
|
||
param_id bigint not null comment '主键'
|
||
primary key,
|
||
plan_id bigint not null comment '方案点位ID',
|
||
param_code varchar(64) not null comment '参数编码',
|
||
param_name varchar(200) not null comment '参数名称',
|
||
target_value decimal(24, 6) null comment '设定值(L1预设值)',
|
||
lower_limit decimal(24, 6) null comment '下限(首次检测实际最小值)',
|
||
upper_limit decimal(24, 6) null comment '上限(首次检测实际最大值)',
|
||
unit varchar(32) null comment '单位',
|
||
actual_src_id varchar(64) null comment '实际值来源钢卷号(首次写入时的ENCOILID)',
|
||
preset_src_id varchar(64) null comment 'L1设定值来源钢卷号(首次写入时的COILID)',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
update_by varchar(64) null comment '更新人',
|
||
update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除)',
|
||
remark varchar(500) null comment '备注',
|
||
constraint uk_plan_param_code
|
||
unique (plan_id, param_code)
|
||
)
|
||
comment '方案参数表';
|
||
|
||
create index idx_plan_param_plan
|
||
on wms_process_plan_param (plan_id);
|
||
|
||
create table wms_process_spec
|
||
(
|
||
spec_id bigint auto_increment comment '主键'
|
||
primary key,
|
||
spec_code varchar(64) not null comment '规程编号',
|
||
spec_name varchar(200) not null comment '规程名称',
|
||
spec_type varchar(32) default 'PROCESS' not null comment '类型(PROCESS=工艺规程,STANDARD=标准)',
|
||
line_id bigint not null comment '产线ID',
|
||
product_type varchar(100) null comment '产品类型',
|
||
is_enabled tinyint default 1 not null comment '是否启用(0否1是)',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
update_by varchar(64) null comment '更新人',
|
||
update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除,与全局逻辑删除配置一致)',
|
||
remark varchar(500) null comment '备注',
|
||
constraint uk_wms_process_spec_code
|
||
unique (spec_code)
|
||
)
|
||
comment '规程主表';
|
||
|
||
create index idx_wms_process_spec_line
|
||
on wms_process_spec (line_id);
|
||
|
||
create index idx_wms_process_spec_type
|
||
on wms_process_spec (spec_type);
|
||
|
||
create table wms_process_spec_version
|
||
(
|
||
version_id bigint not null comment '主键'
|
||
primary key,
|
||
spec_id bigint not null comment '规程主表ID',
|
||
version_code varchar(64) not null comment '版本号',
|
||
is_active tinyint default 0 not null comment '是否当前生效(0否1是)',
|
||
status varchar(32) default 'DRAFT' not null comment '状态(DRAFT草稿/PUBLISHED已发布/OBSOLETE作废等)',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
update_by varchar(64) null comment '更新人',
|
||
update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除)',
|
||
remark varchar(500) null comment '备注',
|
||
constraint uk_spec_version_code
|
||
unique (spec_id, version_code)
|
||
)
|
||
comment '规程版本表';
|
||
|
||
create index idx_spec_version_active
|
||
on wms_process_spec_version (spec_id, is_active);
|
||
|
||
create index idx_spec_version_spec
|
||
on wms_process_spec_version (spec_id);
|
||
|
||
-- ─────────────────────────────────────────────────────────────
|
||
-- 钢卷服役记录表:记录哪些钢卷经过了某版本规程的检测/生产
|
||
-- ─────────────────────────────────────────────────────────────
|
||
create table wms_process_coil_record
|
||
(
|
||
record_id bigint not null comment '主键'
|
||
primary key,
|
||
version_id bigint not null comment '规程版本ID',
|
||
coil_id varchar(64) not null comment '出口钢卷号(EXCOILID)',
|
||
en_coil_id varchar(64) null comment '入口钢卷号(ENCOILID)',
|
||
has_anomaly tinyint default 0 not null comment '本次是否检测到参数异常(0否1是)',
|
||
anomaly_cnt int default 0 not null comment '异常参数数量',
|
||
process_time datetime null comment '检测时间',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
update_by varchar(64) null comment '更新人',
|
||
update_time datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP comment '更新时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除)',
|
||
remark varchar(500) null comment '备注',
|
||
constraint uk_coil_version
|
||
unique (version_id, coil_id)
|
||
)
|
||
comment '版本钢卷服役记录表';
|
||
|
||
create index idx_coil_record_version
|
||
on wms_process_coil_record (version_id);
|
||
|
||
create index idx_coil_record_coil
|
||
on wms_process_coil_record (coil_id);
|
||
|
||
create index idx_coil_record_anomaly
|
||
on wms_process_coil_record (version_id, has_anomaly);
|
||
|
||
-- ─────────────────────────────────────────────────────────────
|
||
-- 工艺参数异常记录表:持久化每次检测到的超限/欠限异常
|
||
-- ─────────────────────────────────────────────────────────────
|
||
create table wms_process_anomaly
|
||
(
|
||
anomaly_id bigint not null comment '主键'
|
||
primary key,
|
||
version_id bigint not null comment '规程版本ID',
|
||
plan_id bigint not null comment '方案点位ID',
|
||
param_id bigint null comment '参数ID(wms_process_plan_param)',
|
||
coil_id varchar(64) not null comment '触发异常的出口钢卷号',
|
||
en_coil_id varchar(64) null comment '入口钢卷号',
|
||
param_code varchar(64) not null comment '参数编码',
|
||
param_name varchar(200) null comment '参数名称',
|
||
unit varchar(32) null comment '单位',
|
||
anomaly_type varchar(32) not null comment '异常类型: OVER_MAX/UNDER_MIN/BOTH',
|
||
stored_target decimal(24, 6) null comment '规程中存储的设定值',
|
||
stored_upper decimal(24, 6) null comment '规程中存储的上限',
|
||
stored_lower decimal(24, 6) null comment '规程中存储的下限',
|
||
actual_target decimal(24, 6) null comment '本次L1实际设定值',
|
||
actual_max decimal(24, 6) null comment '本次实际最大值',
|
||
actual_min decimal(24, 6) null comment '本次实际最小值',
|
||
deviation_max decimal(24, 6) null comment '最大值偏差(actual_max - stored_upper, 正值表示超上限)',
|
||
deviation_min decimal(24, 6) null comment '最小值偏差(actual_min - stored_lower, 负值表示低于下限)',
|
||
detected_at datetime null comment '异常检测时间',
|
||
create_by varchar(64) null comment '创建人',
|
||
create_time datetime default CURRENT_TIMESTAMP null comment '创建时间',
|
||
del_flag tinyint default 0 not null comment '删除标志(0正常2删除)',
|
||
remark varchar(500) null comment '备注'
|
||
)
|
||
comment '工艺参数异常记录表';
|
||
|
||
create index idx_anomaly_version
|
||
on wms_process_anomaly (version_id);
|
||
|
||
create index idx_anomaly_coil
|
||
on wms_process_anomaly (coil_id);
|
||
|
||
create index idx_anomaly_param
|
||
on wms_process_anomaly (version_id, param_code);
|
||
|
||
create index idx_anomaly_detected
|
||
on wms_process_anomaly (detected_at);
|
||
|
||
-- ─────────────────────────────────────────────────────────────
|
||
-- 存量数据迁移(为 wms_process_plan_param 新增列打补丁)
|
||
-- 已有库执行此 ALTER,新建库直接用上方 CREATE TABLE 即可
|
||
-- ─────────────────────────────────────────────────────────────
|
||
-- ALTER TABLE wms_process_plan_param
|
||
-- ADD COLUMN actual_src_id varchar(64) null comment '实际值来源钢卷号(首次写入时的ENCOILID)' AFTER unit,
|
||
-- ADD COLUMN preset_src_id varchar(64) null comment 'L1设定值来源钢卷号(首次写入时的COILID)' AFTER actual_src_id;
|
||
|
||
create table wms_process_task
|
||
(
|
||
task_id bigint auto_increment comment '工艺任务ID'
|
||
primary key,
|
||
plan_id bigint not null comment '关联生产计划ID',
|
||
process_id bigint not null comment '所需工艺ID',
|
||
product_id bigint not null comment '对应产品ID',
|
||
task_quantity int not null comment '任务数量',
|
||
task_status varchar(20) default 'pending' null comment '任务状态:pending-待处理/processing-处理中/completed-已完成',
|
||
sequence int not null comment '工艺顺序',
|
||
del_flag tinyint(1) default 0 not null comment '删除标志(0=正常,1=已删除)',
|
||
remark varchar(255) null comment '备注',
|
||
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 '更新人'
|
||
)
|
||
comment '工艺任务表(生产计划所需工艺任务)' row_format = DYNAMIC;
|
||
|