# 工艺路线项目
drop table if exists process_route_item;
create table process_route_item
(
    id               bigint auto_increment primary key,
    route_id         bigint   not null default 0 comment '工艺路线id',
    product_model_id bigint   not null default 0 comment '产品id',
    process_id       bigint   not null default 0 comment '工序id',
    tenant_id        bigint   not null comment '租户id',
    create_time      datetime null comment '录入时间',
    update_time      datetime null comment '更新时间'
);

# 生产工艺路线项目
drop table if exists product_process_route_item;
create table product_process_route_item
(
    id               bigint auto_increment primary key,
    route_id         bigint   not null default 0 comment '工艺路线id',
    product_model_id bigint   not null default 0 comment '销售台账产品id',
    process_id       bigint   not null default 0 comment '工序id',
    tenant_id        bigint   not null comment '租户id',
    create_time      datetime null comment '录入时间',
    update_time      datetime null comment '更新时间'
);

# 生产订单
drop table if exists product_order;
create table product_order
(
    id               bigint auto_increment primary key,
    sales_ledger_id  bigint   not null default 0 comment '销售台账id',
    product_model_id bigint   not null default 0 comment '销售台账产品id',
    route_id         bigint   not null default 0 comment '工艺路线id',
    nps_no          varchar(255) not null default '' comment '生产订单号',
    status            int not null default 0 comment '状态 0 待确认 1 已确认',
    tenant_id        bigint   not null comment '租户id',
    create_time      datetime null comment '录入时间',
    update_time      datetime null comment '更新时间'
);
alter table quality_inspect
    add purchase_ledger_id int null comment '采购订单id';

# 生产工单
drop table if exists product_work_order;
create table product_work_order
(
    id               bigint auto_increment primary key,
    product_process_route_item_id bigint   not null default 0 comment '工艺路线项目id',
    create_time      datetime null comment '录入时间',
    update_time      datetime null comment '更新时间',
    work_order_no    varchar(255) not null default '' comment '工单编号',
    status           int not null default 0 comment '状态  1 待确认  2 待生产 3生产中 4已生产 ',
    tenant_id        bigint   not null comment '租户id'
);

alter table product_process
    add salary_quota numeric(16,3) null comment '工资定额';