DROP TABLE IF EXISTS `pro_assy_kpsn`;
DROP TABLE IF EXISTS `pro_issue_part`;
DROP TABLE IF EXISTS pro_pack_d_data;
DROP TABLE IF EXISTS pro_pack_m_data;
DROP TABLE IF EXISTS pro_piece_count;
DROP TABLE IF EXISTS pro_piece_status;
DROP TABLE IF EXISTS pro_piece_status_log;
DROP TABLE IF EXISTS pro_put_in_storage;
DROP TABLE IF EXISTS pro_report_work;
DROP TABLE IF EXISTS pro_temp_kpsn;
DROP TABLE IF EXISTS pro_wo;
DROP TABLE IF EXISTS pro_wo_sn;

DROP TABLE IF EXISTS `pro_task_dispatch`;
CREATE TABLE `pro_task_dispatch` (
                                     `id` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                     `code` VARCHAR ( 32 ) DEFAULT NULL COMMENT '编号，唯一',
                                     `dispatch_type` varchar(16) not null comment '派工类型 生产任务|装配任务 PRODUCTION|ASSEMBLE',
                                     `task_id` BIGINT ( 20 ) COMMENT '生产任务id',
                                     `plan_id` BIGINT ( 20 ) NOT NULL COMMENT '生产计划id',
                                     `project_id` BIGINT ( 20 ) NOT NULL COMMENT '项目id',
                                     `project_sub_id` BIGINT ( 20 ) NOT NULL COMMENT '子项目id',
                                     `bom_detail_id` BIGINT ( 20 ) COMMENT 'bom明细id',
                                     `dispatch_status` TINYINT ( 1 ) NOT NULL COMMENT '派工状态 已保存|已提交|已终止 1|2|3',
                                     `remark` VARCHAR ( 255 ) DEFAULT NULL COMMENT '备注',
                                     `status` TINYINT ( 1 ) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用',
                                     `creator` VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
                                     `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                     `updater` VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
                                     `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                     `deleted` BIT ( 1 ) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                     `tenant_id` BIGINT ( 20 ) NOT NULL DEFAULT '0' COMMENT '租户编号',
                                     PRIMARY KEY ( `id` ) USING BTREE,
                                     UNIQUE KEY `uk_code` (`code`,`tenant_id`),
                                     KEY `idx_plan` ( `plan_id` ) USING BTREE,
                                     KEY `idx_project` ( `project_id` ) USING BTREE
) ENGINE = InnoDB COMMENT = '派工单表';

DROP TABLE IF EXISTS pro_task_dispatch_detail;
CREATE TABLE `pro_task_dispatch_detail` (
                                            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                            `dispatch_id` bigint(20) NOT NULL COMMENT '派工单id',
                                            `procedure_id` bigint(20) NOT NULL COMMENT '工序id',
                                            `sort` int(11) COMMENT '顺序号',
                                            `owner` bigint(20) NOT NULL COMMENT '负责人',
                                            `device_model` bigint(20) COMMENT '设备型号',
                                            `start_time` datetime not null comment '预计开始日期',
                                            `end_time` datetime not null comment '预计结束日期',
                                            `work_time` decimal(20,2) NOT NULL COMMENT '预计工时',
                                            `amount` int(11) NOT NULL COMMENT '派工数量',
                                            `summary` varchar(255) DEFAULT NULL COMMENT '工序要点',
                                            `procedure_status` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '工序状态 默认|已提交|已完成 0|1|2',
                                            `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用',
                                            `creator` varchar(64) DEFAULT '' COMMENT '创建者',
                                            `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                            `updater` varchar(64) DEFAULT '' COMMENT '更新者',
                                            `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                            `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                            `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号',
                                            PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB COMMENT='派工明细表';

ALTER TABLE base_composition MODIFY COLUMN `density` DECIMAL(20,4) COMMENT '密度';

DROP TABLE IF EXISTS `project_purchase_order_boom`;
CREATE TABLE `project_purchase_order_boom` (
                                               `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                               `purchase_order_id` bigint(20) NOT NULL COMMENT '采购单编号',
                                               `boom_detail_id` bigint(20) DEFAULT NULL COMMENT '加工件boom detail id',
                                               `boom_name` varchar(255)  DEFAULT NULL COMMENT '零件名称',
                                               `boom_spec` varchar(255)  DEFAULT NULL COMMENT '规格型号',
                                               `boom_unit` tinyint(2) DEFAULT NULL COMMENT '系统单位',
                                               `composition` varchar(255) DEFAULT NULL COMMENT '材质',
                                               `boom_amount` decimal(20,2) DEFAULT NULL COMMENT '需求数量',
                                               `purchase_amount` decimal(20,2) DEFAULT NULL COMMENT '采购数量',
                                               `estimated_price` decimal(20,6) DEFAULT NULL COMMENT '暂估价金额',
                                               `actual_price` decimal(20,6) DEFAULT NULL COMMENT '实际价金额',
                                               `arrive_time` datetime DEFAULT NULL COMMENT '预计到期日期',
                                               `require_time` datetime DEFAULT NULL COMMENT '需求到期日期',
                                               `creator` varchar(64)  DEFAULT '' COMMENT '创建者',
                                               `description` varchar(255)  DEFAULT NULL COMMENT '备注',
                                               `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                               `updater` varchar(64)  DEFAULT '' COMMENT '更新者',
                                               `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                               `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                               `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号',
                                               PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='采购订单加工件明细表';

DROP TABLE IF EXISTS `project_material_plan_boom`;
CREATE TABLE `project_material_plan_boom` (
                                              `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                              `project_material_plan_id` bigint(20) NOT NULL COMMENT '物料需求计划id',
                                              `boom_detail_id` bigint(20) NOT NULL COMMENT '工艺boom明细id，零件类型：加工件',
                                              `project_plan_sub_id` bigint(20) NOT NULL COMMENT '订单子项目id',
                                              `boom_amount` decimal(20,2) DEFAULT NULL COMMENT '需求数量',
                                              `boom_arrive_date` datetime DEFAULT NULL COMMENT '需求到货日期',
                                              `description` varchar(255)  DEFAULT NULL COMMENT '备注',
                                              `creator` varchar(64)  DEFAULT '' COMMENT '创建者',
                                              `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                              `updater` varchar(64)  DEFAULT '' COMMENT '更新者',
                                              `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
                                              `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
                                              `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号',
                                              PRIMARY KEY (`id`)
) ENGINE=InnoDB  COMMENT='物料需求计划加工件明细表';

ALTER TABLE base_material DROP INDEX `idx_code`;
ALTER TABLE base_material ADD UNIQUE KEY `idx_code` ( `code`, `tenant_id` ) USING BTREE;

ALTER TABLE `wms_storage` MODIFY COLUMN stock_no varchar(100) NOT NULL COMMENT '入/出库单号';
