Files
ShiErFeng/shierfeng-fastapi-backend/sql/patches/20260724_pallet_workflow_mysql.sql
T

638 lines
43 KiB
SQL

-- 警告:MySQL DDL 会隐式提交,不能依赖事务整体回滚。
-- 应用前必须完成数据库备份并由 DBA 人工审查;请在维护窗口内分节执行和验证。
-- 本文件仅作为人工增量补丁交付,未自动执行。
-- ==================== DDL:托盘流转业务表 ====================
-- 菌种主数据表
create table if not exists biz_strain (
strain_id bigint(20) not null auto_increment comment '菌种ID',
strain_code varchar(64) not null comment '菌种编码',
strain_name varchar(100) not null comment '菌种名称',
status char(1) not null default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (strain_id),
constraint uq_biz_strain_code unique (strain_code),
constraint ck_biz_strain_status check (status in ('0', '1'))
) engine=innodb comment = '菌种主数据表';
-- 仓库主数据表
create table if not exists biz_warehouse (
warehouse_id bigint(20) not null auto_increment comment '仓库ID',
warehouse_code varchar(64) not null comment '仓库编码',
warehouse_name varchar(100) not null comment '仓库名称',
address varchar(500) comment '仓库地址',
status char(1) not null default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (warehouse_id),
constraint uq_biz_warehouse_code unique (warehouse_code),
constraint ck_biz_warehouse_status check (status in ('0', '1'))
) engine=innodb comment = '仓库主数据表';
-- 客户主数据表
create table if not exists biz_customer (
customer_id bigint(20) not null auto_increment comment '客户ID',
customer_code varchar(64) not null comment '客户编码',
customer_name varchar(100) not null comment '客户名称',
status char(1) not null default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (customer_id),
constraint uq_biz_customer_code unique (customer_code),
constraint ck_biz_customer_status check (status in ('0', '1'))
) engine=innodb comment = '客户主数据表';
-- 客户现场主数据表
create table if not exists biz_customer_site (
site_id bigint(20) not null auto_increment comment '现场ID',
customer_id bigint(20) not null comment '客户ID',
site_code varchar(64) not null comment '现场编码',
site_name varchar(100) not null comment '现场名称',
address varchar(500) comment '现场地址',
status char(1) not null default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (site_id),
constraint uq_biz_customer_site_customer_code unique (customer_id, site_code),
constraint fk_biz_customer_site_customer foreign key (customer_id) references biz_customer (customer_id),
constraint ck_biz_customer_site_status check (status in ('0', '1'))
) engine=innodb comment = '客户现场主数据表';
-- 客户现场产线主数据表
create table if not exists biz_production_line (
line_id bigint(20) not null auto_increment comment '产线ID',
site_id bigint(20) not null comment '现场ID',
line_code varchar(64) not null comment '产线编码',
line_name varchar(100) not null comment '产线名称',
status char(1) not null default '0' comment '状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (line_id),
constraint uq_biz_production_line_site_code unique (site_id, line_code),
constraint fk_biz_production_line_site foreign key (site_id) references biz_customer_site (site_id),
constraint ck_biz_production_line_status check (status in ('0', '1'))
) engine=innodb comment = '客户现场产线主数据表';
-- 托盘资产主数据表
create table if not exists biz_pallet (
pallet_id bigint(20) not null auto_increment comment '托盘ID',
pallet_code varchar(64) not null comment '托盘编号',
qr_token varchar(128) not null comment '二维码固定标识',
capacity_packages int not null comment '容量包数',
asset_status char(1) not null default '0' comment '资产状态(0正常 1停用)',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (pallet_id),
constraint uq_biz_pallet_code unique (pallet_code),
constraint uq_biz_pallet_qr_token unique (qr_token),
constraint ck_biz_pallet_capacity_packages check (capacity_packages > 0),
constraint ck_biz_pallet_asset_status check (asset_status in ('0', '1'))
) engine=innodb comment = '托盘资产主数据表';
-- 用户与仓库关联表
create table if not exists biz_user_warehouse (
user_id bigint(20) not null comment '用户ID',
warehouse_id bigint(20) not null comment '仓库ID',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
primary key (user_id, warehouse_id),
constraint fk_biz_user_warehouse_user foreign key (user_id) references sys_user (user_id),
constraint fk_biz_user_warehouse_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id)
) engine=innodb comment = '用户与仓库关联表';
-- 用户与客户现场关联表
create table if not exists biz_user_site (
user_id bigint(20) not null comment '用户ID',
site_id bigint(20) not null comment '现场ID',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
primary key (user_id, site_id),
constraint fk_biz_user_site_user foreign key (user_id) references sys_user (user_id),
constraint fk_biz_user_site_site foreign key (site_id) references biz_customer_site (site_id)
) engine=innodb comment = '用户与客户现场关联表';
-- 首次入库单
create table if not exists biz_inbound_order (
inbound_id bigint(20) not null auto_increment comment '入库单ID',
inbound_no varchar(64) not null comment '入库单号',
warehouse_id bigint(20) not null comment '仓库ID',
status varchar(32) not null default 'DRAFT' comment '单据状态',
confirm_idempotency_key varchar(64) comment '确认幂等键',
confirm_request_hash varchar(64) comment '确认请求摘要',
confirmed_by bigint(20) comment '确认人ID',
confirmed_at datetime comment '确认时间',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (inbound_id),
constraint uq_biz_inbound_order_no unique (inbound_no),
constraint uq_biz_inbound_order_warehouse_confirm_idempotency unique (warehouse_id, confirm_idempotency_key),
constraint fk_biz_inbound_order_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_inbound_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
constraint ck_biz_inbound_order_status check (status in ('DRAFT', 'CONFIRMED'))
) engine=innodb comment = '首次入库单';
-- 首次入库单托盘明细
create table if not exists biz_inbound_item (
inbound_item_id bigint(20) not null auto_increment comment '入库明细ID',
inbound_id bigint(20) not null comment '入库单ID',
pallet_id bigint(20) not null comment '托盘ID',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
primary key (inbound_item_id),
constraint uq_biz_inbound_item_order_pallet unique (inbound_id, pallet_id),
constraint fk_biz_inbound_item_order foreign key (inbound_id) references biz_inbound_order (inbound_id),
constraint fk_biz_inbound_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id)
) engine=innodb comment = '首次入库单托盘明细';
-- 托盘装填记录
create table if not exists biz_filling_record (
filling_id bigint(20) not null auto_increment comment '装填记录ID',
filling_no varchar(64) not null comment '装填单号',
pallet_id bigint(20) not null comment '托盘ID',
warehouse_id bigint(20) not null comment '仓库ID',
strain_id bigint(20) not null comment '菌种ID',
strain_code_snapshot varchar(64) not null comment '菌种编码快照',
strain_name_snapshot varchar(100) not null comment '菌种名称快照',
batch_no varchar(64) not null comment '生产批次',
package_spec varchar(64) not null comment '包装规格',
initial_packages int not null comment '初始包数',
active_slot varchar(16) comment '活动装填槽',
closed_at datetime comment '装填周期关闭时间',
idempotency_key varchar(64) not null comment '幂等键',
request_hash varchar(64) not null comment '请求摘要',
operator_id bigint(20) not null comment '操作人ID',
operated_at datetime not null comment '操作时间',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (filling_id),
constraint uq_biz_filling_record_no unique (filling_no),
constraint uq_biz_filling_record_warehouse_idempotency unique (warehouse_id, idempotency_key),
constraint uq_biz_filling_record_pallet_active_slot unique (pallet_id, active_slot),
constraint fk_biz_filling_record_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_filling_record_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_filling_record_strain foreign key (strain_id) references biz_strain (strain_id),
constraint fk_biz_filling_record_operator foreign key (operator_id) references sys_user (user_id),
constraint ck_biz_filling_record_initial_packages check (initial_packages > 0),
constraint ck_biz_filling_record_active_slot check (active_slot is null or active_slot = 'ACTIVE')
) engine=innodb comment = '托盘装填记录';
-- 整托发货单
create table if not exists biz_shipment_order (
shipment_id bigint(20) not null auto_increment comment '发货单ID',
shipment_no varchar(64) not null comment '发货单号',
source_warehouse_id bigint(20) not null comment '来源仓库ID',
target_site_id bigint(20) not null comment '目标现场ID',
status varchar(32) not null default 'DRAFT' comment '单据状态',
confirm_idempotency_key varchar(64) comment '确认幂等键',
confirm_request_hash varchar(64) comment '确认请求摘要',
confirmed_by bigint(20) comment '确认人ID',
confirmed_at datetime comment '确认时间',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (shipment_id),
constraint uq_biz_shipment_order_no unique (shipment_no),
constraint uq_biz_shipment_order_route_confirm_idempotency unique (source_warehouse_id, target_site_id, confirm_idempotency_key),
constraint fk_biz_shipment_order_warehouse foreign key (source_warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_shipment_order_site foreign key (target_site_id) references biz_customer_site (site_id),
constraint fk_biz_shipment_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
constraint ck_biz_shipment_order_status check (status in ('DRAFT', 'CONFIRMED'))
) engine=innodb comment = '整托发货单';
-- 整托发货明细
create table if not exists biz_shipment_item (
shipment_item_id bigint(20) not null auto_increment comment '发货明细ID',
shipment_id bigint(20) not null comment '发货单ID',
pallet_id bigint(20) not null comment '托盘ID',
active_filling_id bigint(20) comment '确认时活动装填记录ID',
package_qty int comment '确认时包数快照',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
primary key (shipment_item_id),
constraint uq_biz_shipment_item_order_pallet unique (shipment_id, pallet_id),
constraint fk_biz_shipment_item_order foreign key (shipment_id) references biz_shipment_order (shipment_id),
constraint fk_biz_shipment_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_shipment_item_filling foreign key (active_filling_id) references biz_filling_record (filling_id),
constraint ck_biz_shipment_item_package_qty check (package_qty is null or package_qty > 0)
) engine=innodb comment = '整托发货明细';
-- 客户现场使用事实记录
create table if not exists biz_usage_record (
usage_id bigint(20) not null auto_increment comment '使用记录ID',
usage_no varchar(64) not null comment '使用记录号',
pallet_id bigint(20) not null comment '托盘ID',
active_filling_id bigint(20) not null comment '活动装填记录ID',
site_id bigint(20) not null comment '现场ID',
line_id bigint(20) not null comment '产线ID',
used_packages int not null comment '本次使用包数',
remaining_packages_after int not null comment '使用后剩余包数',
idempotency_key varchar(64) not null comment '幂等键',
request_hash varchar(64) not null comment '请求摘要',
operator_id bigint(20) not null comment '操作人ID',
occurred_at datetime not null comment '发生时间',
primary key (usage_id),
constraint uq_biz_usage_record_no unique (usage_no),
constraint uq_biz_usage_record_site_idempotency unique (site_id, idempotency_key),
constraint fk_biz_usage_record_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_usage_record_filling foreign key (active_filling_id) references biz_filling_record (filling_id),
constraint fk_biz_usage_record_site foreign key (site_id) references biz_customer_site (site_id),
constraint fk_biz_usage_record_line foreign key (line_id) references biz_production_line (line_id),
constraint fk_biz_usage_record_operator foreign key (operator_id) references sys_user (user_id),
constraint ck_biz_usage_record_used_packages check (used_packages > 0),
constraint ck_biz_usage_record_remaining_packages_after check (remaining_packages_after >= 0)
) engine=innodb comment = '客户现场使用事实记录';
-- 托盘退回单
create table if not exists biz_return_order (
return_id bigint(20) not null auto_increment comment '退回单ID',
return_no varchar(64) not null comment '退回单号',
source_site_id bigint(20) not null comment '来源现场ID',
target_warehouse_id bigint(20) not null comment '目标仓库ID',
status varchar(32) not null default 'REQUESTED' comment '退回状态',
request_idempotency_key varchar(64) not null comment '申请幂等键',
request_hash varchar(64) not null comment '申请请求摘要',
confirm_idempotency_key varchar(64) comment '确认幂等键',
confirm_request_hash varchar(64) comment '确认请求摘要',
requested_by bigint(20) not null comment '申请人ID',
requested_at datetime not null comment '申请时间',
confirmed_by bigint(20) comment '确认人ID',
confirmed_at datetime comment '确认时间',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
update_by varchar(64) default '' comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注',
primary key (return_id),
constraint uq_biz_return_order_no unique (return_no),
constraint uq_biz_return_order_route_request_idempotency unique (source_site_id, target_warehouse_id, request_idempotency_key),
constraint uq_biz_return_order_route_confirm_idempotency unique (source_site_id, target_warehouse_id, confirm_idempotency_key),
constraint fk_biz_return_order_site foreign key (source_site_id) references biz_customer_site (site_id),
constraint fk_biz_return_order_warehouse foreign key (target_warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_return_order_requested_by foreign key (requested_by) references sys_user (user_id),
constraint fk_biz_return_order_confirmed_by foreign key (confirmed_by) references sys_user (user_id),
constraint ck_biz_return_order_status check (status in ('REQUESTED', 'CONFIRMED'))
) engine=innodb comment = '托盘退回单';
-- 托盘退回明细
create table if not exists biz_return_item (
return_item_id bigint(20) not null auto_increment comment '退回明细ID',
return_id bigint(20) not null comment '退回单ID',
pallet_id bigint(20) not null comment '托盘ID',
active_filling_id_snapshot bigint(20) comment '申请时活动装填记录快照',
remaining_packages_snapshot int not null comment '申请时剩余包数快照',
create_by varchar(64) default '' comment '创建者',
create_time datetime comment '创建时间',
primary key (return_item_id),
constraint uq_biz_return_item_order_pallet unique (return_id, pallet_id),
constraint fk_biz_return_item_order foreign key (return_id) references biz_return_order (return_id),
constraint fk_biz_return_item_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_return_item_filling foreign key (active_filling_id_snapshot) references biz_filling_record (filling_id),
constraint ck_biz_return_item_remaining_packages_snapshot check (remaining_packages_snapshot >= 0)
) engine=innodb comment = '托盘退回明细';
-- 托盘只追加流转事件;必须先于库存快照创建
create table if not exists biz_pallet_event (
event_id bigint(20) not null auto_increment comment '事件ID',
pallet_id bigint(20) not null comment '托盘ID',
event_seq int not null comment '托盘内事件序号',
event_type varchar(32) not null comment '事件类型',
source_type varchar(32) not null comment '来源类型',
source_id bigint(20) not null comment '来源记录ID',
before_state varchar(32) not null comment '变更前状态',
after_state varchar(32) not null comment '变更后状态',
before_warehouse_id bigint(20) comment '变更前仓库ID',
before_site_id bigint(20) comment '变更前现场ID',
before_line_id bigint(20) comment '变更前产线ID',
after_warehouse_id bigint(20) comment '变更后仓库ID',
after_site_id bigint(20) comment '变更后现场ID',
after_line_id bigint(20) comment '变更后产线ID',
before_remaining_packages int not null comment '变更前剩余包数',
after_remaining_packages int not null comment '变更后剩余包数',
operator_id bigint(20) not null comment '操作人ID',
occurred_at datetime not null comment '发生时间',
idempotency_key varchar(64) not null comment '幂等键',
request_hash varchar(64) not null comment '请求摘要',
primary key (event_id),
constraint uq_biz_pallet_event_pallet_seq unique (pallet_id, event_seq),
constraint uq_biz_pallet_event_pallet_idempotency unique (pallet_id, idempotency_key),
constraint fk_biz_pallet_event_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_pallet_event_before_warehouse foreign key (before_warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_pallet_event_before_site foreign key (before_site_id) references biz_customer_site (site_id),
constraint fk_biz_pallet_event_before_line foreign key (before_line_id) references biz_production_line (line_id),
constraint fk_biz_pallet_event_after_warehouse foreign key (after_warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_pallet_event_after_site foreign key (after_site_id) references biz_customer_site (site_id),
constraint fk_biz_pallet_event_after_line foreign key (after_line_id) references biz_production_line (line_id),
constraint fk_biz_pallet_event_operator foreign key (operator_id) references sys_user (user_id),
constraint ck_biz_pallet_event_event_type check (
event_type in (
'INBOUND_CONFIRMED',
'FILLING_CONFIRMED',
'SHIPMENT_CONFIRMED',
'USAGE_RECORDED',
'RETURN_REQUESTED',
'RETURN_CONFIRMED'
)
)
) engine=innodb comment = '托盘只追加流转事件';
-- 托盘当前库存、位置和流转状态
create table if not exists biz_pallet_inventory (
pallet_id bigint(20) not null comment '托盘ID',
active_filling_id bigint(20) comment '当前活动装填记录ID',
warehouse_id bigint(20) comment '当前仓库ID',
site_id bigint(20) comment '当前现场ID',
current_line_id bigint(20) comment '当前驻场周期绑定产线ID',
flow_state varchar(32) not null default 'UNSTOCKED' comment '托盘流转状态',
remaining_packages int not null default 0 comment '当前剩余包数',
last_event_id bigint(20) comment '最后事件ID',
version int not null default 0 comment '并发版本号',
updated_at datetime not null comment '更新时间',
primary key (pallet_id),
constraint fk_biz_pallet_inventory_pallet foreign key (pallet_id) references biz_pallet (pallet_id),
constraint fk_biz_pallet_inventory_filling foreign key (active_filling_id) references biz_filling_record (filling_id),
constraint fk_biz_pallet_inventory_warehouse foreign key (warehouse_id) references biz_warehouse (warehouse_id),
constraint fk_biz_pallet_inventory_site foreign key (site_id) references biz_customer_site (site_id),
constraint fk_biz_pallet_inventory_line foreign key (current_line_id) references biz_production_line (line_id),
constraint fk_biz_pallet_inventory_event foreign key (last_event_id) references biz_pallet_event (event_id),
constraint ck_biz_pallet_inventory_flow_state check (
flow_state in (
'UNSTOCKED',
'EMPTY_IN_WAREHOUSE',
'FILLED_IN_WAREHOUSE',
'AT_SITE_UNUSED',
'AT_SITE_PARTIAL',
'AT_SITE_EMPTY',
'RETURNING'
)
),
constraint ck_biz_pallet_inventory_remaining_packages check (remaining_packages >= 0),
constraint ck_biz_pallet_inventory_version check (version >= 0),
constraint ck_biz_pallet_inventory_location check (not (warehouse_id is not null and site_id is not null))
) engine=innodb comment = '托盘当前库存、位置和流转状态';
-- ==================== DML:清理旧 seed 并写入托盘业务菜单 ====================
-- 删除前校验固定 ID 仍属于原始 AI/外链 seed;任一 ID 被自定义数据复用时,
-- 临时表唯一键冲突会在所有永久 DML 之前中止补丁,避免误删角色、菜单或字典数据。
drop temporary table if exists pallet_workflow_legacy_seed_guard;
create temporary table pallet_workflow_legacy_seed_guard (
guard_token varchar(64) not null,
primary key (guard_token)
);
insert into pallet_workflow_legacy_seed_guard (guard_token)
select guard_token
from (
select 'legacy-seed-conflict' as guard_token
union all
select if(
not exists (
select 1
from sys_menu
where menu_id in (4, 99, 118, 119, 1061, 1062, 1063, 1064)
and not (
(menu_id = 4
and menu_name <=> 'AI 管理'
and parent_id <=> 0
and path <=> 'ai'
and component <=> null
and perms <=> ''
and menu_type <=> 'M')
or (menu_id = 99
and menu_name <=> '施尔丰仓库'
and parent_id <=> 0
and path <=> 'https://git.yujiangrubber.cn/niuniu/ShiErFeng'
and component <=> null
and perms <=> ''
and menu_type <=> 'M')
or (menu_id = 118
and menu_name <=> '模型管理'
and parent_id <=> 4
and path <=> 'model'
and component <=> 'ai/model/index'
and perms <=> 'ai:model:list'
and menu_type <=> 'C')
or (menu_id = 119
and menu_name <=> 'AI 对话'
and parent_id <=> 4
and path <=> 'chat'
and component <=> 'ai/chat/index'
and perms <=> 'ai:chat:list'
and menu_type <=> 'C')
or (menu_id = 1061
and menu_name <=> '模型查询'
and parent_id <=> 118
and path <=> '#'
and component <=> ''
and perms <=> 'ai:model:query'
and menu_type <=> 'F')
or (menu_id = 1062
and menu_name <=> '模型新增'
and parent_id <=> 118
and path <=> '#'
and component <=> ''
and perms <=> 'ai:model:add'
and menu_type <=> 'F')
or (menu_id = 1063
and menu_name <=> '模型修改'
and parent_id <=> 118
and path <=> '#'
and component <=> ''
and perms <=> 'ai:model:edit'
and menu_type <=> 'F')
or (menu_id = 1064
and menu_name <=> '模型删除'
and parent_id <=> 118
and path <=> '#'
and component <=> ''
and perms <=> 'ai:model:remove'
and menu_type <=> 'F')
)
)
and not exists (
select 1
from sys_dict_data
where dict_code between 33 and 69
and not (dict_type <=> 'ai_provider_type')
)
and not exists (
select 1
from sys_dict_type
where dict_id = 12
and not (dict_type <=> 'ai_provider_type')
),
'legacy-seed-verified',
'legacy-seed-conflict'
) as guard_token
) as legacy_seed_guard_rows;
drop temporary table pallet_workflow_legacy_seed_guard;
-- 先解除所有待清理菜单的历史角色关联。
delete from sys_role_menu
where menu_id in (4, 99, 118, 119, 1061, 1062, 1063, 1064);
-- 再清理原 AI 菜单;外链菜单 99 按要求在字典清理后单独删除。
delete from sys_menu
where menu_id in (4, 118, 119, 1061, 1062, 1063, 1064);
delete from sys_dict_data
where dict_code between 33 and 69
and dict_type = 'ai_provider_type';
-- 同时清理后续可能追加、但仍明确属于 AI provider 字典的扩展项。
delete from sys_dict_data
where dict_type = 'ai_provider_type';
delete from sys_dict_type
where dict_id = 12
and dict_type = 'ai_provider_type';
delete from sys_dict_type
where dict_type = 'ai_provider_type';
delete from sys_menu
where menu_id = 99;
-- 保存当前会话模式,再无空项、无重复地启用 STRICT_ALL_TABLES,确保菜单冲突按错误中止。
set @pallet_workflow_original_sql_mode = @@session.sql_mode;
set session sql_mode = concat_ws(',',
nullif(@pallet_workflow_original_sql_mode, ''),
if(find_in_set('STRICT_ALL_TABLES', @pallet_workflow_original_sql_mode) = 0,
'STRICT_ALL_TABLES',
null));
-- 固定 ID 已存在时,只有全部稳定字段一致才允许幂等空操作。
-- 任一稳定字段冲突都会令 menu_name 为 NULL,触发 menu_name NOT NULL 约束并中止整条语句。
-- 必须人工解决冲突;本补丁不会静默覆盖未知 ID。
insert into sys_menu values
(121, '基础资料维护', 1, '10', 'businessMaster', null, '', '', 1, 0, 'M', '0', '0', '', '#', 'admin', sysdate(), '', null, ''),
(122, '业务管理', 1, '11', 'businessOperation', null, '', '', 1, 0, 'M', '0', '0', '', '#', 'admin', sysdate(), '', null, ''),
(123, '报表查询', 1, '12', 'businessReport', null, '', '', 1, 0, 'M', '0', '0', '', '#', 'admin', sysdate(), '', null, ''),
(502, '菌种资料', 121, '1', 'strain', 'master/strain/index', '', '', 1, 0, 'C', '0', '0', 'master:strain:list', '#', 'admin', sysdate(), '', null, ''),
(503, '客户资料', 121, '2', 'customer', 'master/customer/index', '', '', 1, 0, 'C', '0', '0', 'master:customer:list', '#', 'admin', sysdate(), '', null, ''),
(504, '客户现场', 121, '3', 'site', 'master/site/index', '', '', 1, 0, 'C', '0', '0', 'master:site:list', '#', 'admin', sysdate(), '', null, ''),
(505, '产线资料', 121, '4', 'line', 'master/line/index', '', '', 1, 0, 'C', '0', '0', 'master:line:list', '#', 'admin', sysdate(), '', null, ''),
(506, '仓库资料', 121, '5', 'warehouse', 'master/warehouse/index', '', '', 1, 0, 'C', '0', '0', 'master:warehouse:list', '#', 'admin', sysdate(), '', null, ''),
(507, '托盘资料', 121, '6', 'pallet', 'master/pallet/index', '', '', 1, 0, 'C', '0', '0', 'master:pallet:list', '#', 'admin', sysdate(), '', null, ''),
(508, '仓库入库', 122, '1', 'inbound', 'business/inbound/index', '', '', 1, 0, 'C', '0', '0', 'business:inbound:list', '#', 'admin', sysdate(), '', null, ''),
(509, '工厂装填', 122, '2', 'filling', 'business/filling/index', '', '', 1, 0, 'C', '0', '0', 'business:filling:list', '#', 'admin', sysdate(), '', null, ''),
(510, '发货出库', 122, '3', 'shipment', 'business/shipment/index', '', '', 1, 0, 'C', '0', '0', 'business:shipment:list', '#', 'admin', sysdate(), '', null, ''),
(511, '客户现场使用', 122, '4', 'usage', 'business/usage/index', '', '', 1, 0, 'C', '0', '0', 'business:usage:list', '#', 'admin', sysdate(), '', null, ''),
(512, '退回仓库', 122, '5', 'return', 'business/return/index', '', '', 1, 0, 'C', '0', '0', 'business:return:list', '#', 'admin', sysdate(), '', null, ''),
(513, '托盘库存', 123, '1', 'palletInventory', 'report/palletInventory/index', '', '', 1, 0, 'C', '0', '0', 'report:palletinventory:list', '#', 'admin', sysdate(), '', null, ''),
(514, '装填记录', 123, '2', 'reportFilling', 'report/filling/index', '', '', 1, 0, 'C', '0', '0', 'report:filling:list', '#', 'admin', sysdate(), '', null, ''),
(515, '发货出库', 123, '3', 'reportShipment', 'report/shipment/index', '', '', 1, 0, 'C', '0', '0', 'report:shipment:list', '#', 'admin', sysdate(), '', null, ''),
(516, '产线消耗', 123, '4', 'consumption', 'report/consumption/index', '', '', 1, 0, 'C', '0', '0', 'report:consumption:list', '#', 'admin', sysdate(), '', null, ''),
(517, '退回仓库', 123, '5', 'reportReturn', 'report/return/index', '', '', 1, 0, 'C', '0', '0', 'report:return:list', '#', 'admin', sysdate(), '', null, ''),
(518, '托盘追溯', 123, '6', 'palletTrace', 'report/palletTrace/index', '', '', 1, 0, 'C', '0', '0', 'report:pallettrace:list', '#', 'admin', sysdate(), '', null, ''),
(1065, '菌种查询', 502, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:strain:query', '#', 'admin', sysdate(), '', null, ''),
(1066, '菌种新增', 502, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:strain:add', '#', 'admin', sysdate(), '', null, ''),
(1067, '菌种修改', 502, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:strain:edit', '#', 'admin', sysdate(), '', null, ''),
(1068, '菌种删除', 502, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:strain:remove', '#', 'admin', sysdate(), '', null, ''),
(1069, '客户查询', 503, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:customer:query', '#', 'admin', sysdate(), '', null, ''),
(1070, '客户新增', 503, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:customer:add', '#', 'admin', sysdate(), '', null, ''),
(1071, '客户修改', 503, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:customer:edit', '#', 'admin', sysdate(), '', null, ''),
(1072, '客户删除', 503, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:customer:remove', '#', 'admin', sysdate(), '', null, ''),
(1073, '现场查询', 504, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:site:query', '#', 'admin', sysdate(), '', null, ''),
(1074, '现场新增', 504, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:site:add', '#', 'admin', sysdate(), '', null, ''),
(1075, '现场修改', 504, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:site:edit', '#', 'admin', sysdate(), '', null, ''),
(1076, '现场删除', 504, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:site:remove', '#', 'admin', sysdate(), '', null, ''),
(1077, '分配用户', 504, '5', '', '', '', '', 1, 0, 'F', '0', '0', 'master:site:assign', '#', 'admin', sysdate(), '', null, ''),
(1078, '产线查询', 505, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:line:query', '#', 'admin', sysdate(), '', null, ''),
(1079, '产线新增', 505, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:line:add', '#', 'admin', sysdate(), '', null, ''),
(1080, '产线修改', 505, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:line:edit', '#', 'admin', sysdate(), '', null, ''),
(1081, '产线删除', 505, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:line:remove', '#', 'admin', sysdate(), '', null, ''),
(1082, '仓库查询', 506, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:warehouse:query', '#', 'admin', sysdate(), '', null, ''),
(1083, '仓库新增', 506, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:warehouse:add', '#', 'admin', sysdate(), '', null, ''),
(1084, '仓库修改', 506, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:warehouse:edit', '#', 'admin', sysdate(), '', null, ''),
(1085, '仓库删除', 506, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:warehouse:remove', '#', 'admin', sysdate(), '', null, ''),
(1086, '分配用户', 506, '5', '', '', '', '', 1, 0, 'F', '0', '0', 'master:warehouse:assign', '#', 'admin', sysdate(), '', null, ''),
(1087, '托盘查询', 507, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'master:pallet:query', '#', 'admin', sysdate(), '', null, ''),
(1088, '托盘新增', 507, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'master:pallet:add', '#', 'admin', sysdate(), '', null, ''),
(1089, '托盘修改', 507, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'master:pallet:edit', '#', 'admin', sysdate(), '', null, ''),
(1090, '托盘删除', 507, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'master:pallet:remove', '#', 'admin', sysdate(), '', null, ''),
(1091, '托盘打印', 507, '5', '', '', '', '', 1, 0, 'F', '0', '0', 'master:pallet:print', '#', 'admin', sysdate(), '', null, ''),
(1092, '入库查询', 508, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'business:inbound:query', '#', 'admin', sysdate(), '', null, ''),
(1093, '入库新增', 508, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'business:inbound:add', '#', 'admin', sysdate(), '', null, ''),
(1094, '入库修改', 508, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'business:inbound:edit', '#', 'admin', sysdate(), '', null, ''),
(1095, '入库删除', 508, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'business:inbound:remove', '#', 'admin', sysdate(), '', null, ''),
(1096, '入库确认', 508, '5', '', '', '', '', 1, 0, 'F', '0', '0', 'business:inbound:confirm', '#', 'admin', sysdate(), '', null, ''),
(1097, '装填查询', 509, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'business:filling:query', '#', 'admin', sysdate(), '', null, ''),
(1098, '装填新增', 509, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'business:filling:add', '#', 'admin', sysdate(), '', null, ''),
(1099, '发货查询', 510, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'business:shipment:query', '#', 'admin', sysdate(), '', null, ''),
(1100, '发货新增', 510, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'business:shipment:add', '#', 'admin', sysdate(), '', null, ''),
(1101, '发货修改', 510, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'business:shipment:edit', '#', 'admin', sysdate(), '', null, ''),
(1102, '发货删除', 510, '4', '', '', '', '', 1, 0, 'F', '0', '0', 'business:shipment:remove', '#', 'admin', sysdate(), '', null, ''),
(1103, '发货确认', 510, '5', '', '', '', '', 1, 0, 'F', '0', '0', 'business:shipment:confirm', '#', 'admin', sysdate(), '', null, ''),
(1104, '使用查询', 511, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'business:usage:query', '#', 'admin', sysdate(), '', null, ''),
(1105, '使用新增', 511, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'business:usage:add', '#', 'admin', sysdate(), '', null, ''),
(1106, '退回查询', 512, '1', '', '', '', '', 1, 0, 'F', '0', '0', 'business:return:query', '#', 'admin', sysdate(), '', null, ''),
(1107, '退回申请', 512, '2', '', '', '', '', 1, 0, 'F', '0', '0', 'business:return:request', '#', 'admin', sysdate(), '', null, ''),
(1108, '退回确认', 512, '3', '', '', '', '', 1, 0, 'F', '0', '0', 'business:return:confirm', '#', 'admin', sysdate(), '', null, '')
on duplicate key update
menu_name = if(
menu_name <=> values(menu_name)
and parent_id <=> values(parent_id)
and order_num <=> values(order_num)
and path <=> values(path)
and component <=> values(component)
and query <=> values(query)
and route_name <=> values(route_name)
and is_frame <=> values(is_frame)
and is_cache <=> values(is_cache)
and menu_type <=> values(menu_type)
and visible <=> values(visible)
and status <=> values(status)
and perms <=> values(perms)
and icon <=> values(icon),
menu_name,
null
);
-- seed 成功后立即恢复原会话模式;后续仅执行只读人工核对,无需继续保持严格模式。
set session sql_mode = @pallet_workflow_original_sql_mode;
-- 人工核对业务菜单固定 ID;查询结果必须为 64 行,且各字段应与本补丁 seed 一致。
select menu_id, menu_name, parent_id, order_num, path, component, query, route_name,
is_frame, is_cache, menu_type, visible, status, perms, icon
from sys_menu
where menu_id in (
121, 122, 123,
502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518,
1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075,
1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086,
1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097,
1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108
);
-- 应用完成后仅人工清理 /getRouters、用户信息以及 sys_dict:ai_provider_type 相关缓存;本补丁不执行缓存命令。