cmvr-wms/sql/wms_purchase_operation_log_20261008.sql

30 lines
1.6 KiB
MySQL
Raw Normal View History

-- 采购操作历史。脚本可重复执行。
create table if not exists purchase_operation_log (
id bigint(20) not null auto_increment comment '主键',
purchase_request_id bigint(20) not null comment '采购申请ID',
request_no varchar(64) default null comment '采购申请单号快照',
operation_type varchar(32) not null comment '操作类型',
operation_title varchar(100) not null comment '操作标题',
operation_detail varchar(1000) default null comment '操作说明',
operator_id bigint(20) default null comment '操作人用户ID',
operator_name varchar(64) default null comment '操作人账号快照',
create_time datetime not null comment '操作时间',
primary key (id),
key idx_purchase_operation_request (purchase_request_id, id),
key idx_purchase_operation_type (operation_type)
) engine=innodb default charset=utf8mb4 comment='采购操作历史';
-- 给上线前已有的采购申请补一条起始记录,避免详情时间线为空。
insert into purchase_operation_log(purchase_request_id, request_no, operation_type,
operation_title, operation_detail, operator_id,
operator_name, create_time)
select pr.id, pr.request_no, 'MIGRATION', '历史采购申请',
concat('物料:', pr.material_name, ';数量:', cast(pr.quantity as char),
ifnull(concat(' ', pr.unit), '')),
pr.applicant_id, coalesce(pr.create_by, pr.applicant_name, 'system'),
coalesce(pr.create_time, sysdate())
from purchase_request pr
where not exists (
select 1 from purchase_operation_log pol where pol.purchase_request_id = pr.id
);