DROP TABLE IF EXISTS `pro_task_report`;
CREATE TABLE `pro_task_report` (
                                   `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                   `dispatch_detail_id` bigint(20) NOT NULL COMMENT '派工单任务明细id',
                                   `owner` bigint(20) NOT NULL COMMENT '负责人',
                                   `amount` int(11) NOT NULL DEFAULT '0' COMMENT '数量',
                                   `start_time` datetime NOT NULL COMMENT '开始时间',
                                   `end_time` datetime NOT NULL COMMENT '结束时间',
                                   `work_time` DECIMAL(20,2) not null comment '报工工时',
                                   `report_time` datetime NOT NULL COMMENT '报工时间',
                                   `has_report` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否已报工 0 默认否 1 是',
                                   `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用',
                                   `creator` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
                                   `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                   `updater` varchar(64) COLLATE utf8mb4_unicode_ci 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,
                                   KEY `idx_dispatch_id` (`dispatch_detail_id`) USING BTREE
) ENGINE=InnoDB COMMENT='任务报工表';

DROP TABLE IF EXISTS `pro_unqualified_notification`;
CREATE TABLE `pro_unqualified_notification` (
                                                `id` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                                `code` VARCHAR ( 32 ) DEFAULT NULL COMMENT '编号，唯一',
                                                `type` CHAR ( 1 ) NOT NULL COMMENT '质检类型',
                                                `notification_status` INT ( 1 ) NOT NULL COMMENT '单据状态 已保存|已送审|已审核 1|2|3',
                                                `project_id` BIGINT ( 20 ) NOT NULL COMMENT '项目订单id',
                                                `project_sub_id` BIGINT ( 20 ) NOT NULL COMMENT '子项目id',
                                                `bom_detail_id` BIGINT ( 20 ) DEFAULT NULL COMMENT 'bom明细id',
                                                `procedure_id` BIGINT ( 20 ) NOT NULL COMMENT '工序id',
                                                `amount` INT ( 11 ) NOT NULL COMMENT '异常数量',
                                                `owner` BIGINT ( 11 ) NOT NULL COMMENT '责任人',
                                                `remark` VARCHAR ( 512 ) NOT NULL COMMENT '情况描述',
                                                `auditor` BIGINT ( 11 ) COMMENT '审核人',
                                                `audit_opinion` CHAR ( 1 ) COMMENT '审核意见',
                                                `audit_time` DATETIME COMMENT '审核时间',
                                                `status` TINYINT ( 1 ) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用',
                                                `creator` VARCHAR ( 64 ) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
                                                `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                                `updater` VARCHAR ( 64 ) COLLATE utf8mb4_unicode_ci 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_project` ( `project_id`, `project_sub_id` ) USING BTREE,
                                                KEY `idx_bom_detail` ( `bom_detail_id` ) USING BTREE,
                                                KEY `idx_procedure` ( `procedure_id` ) USING BTREE
) ENGINE = InnoDB COMMENT = '品质异常通知单审核表';

DROP TABLE IF EXISTS `pro_quality_feedback`;
CREATE TABLE `pro_quality_feedback` (
                                        `id` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                        `project_id` BIGINT ( 20 ) NOT NULL COMMENT '项目订单id',
                                        `project_sub_id` BIGINT ( 20 ) NOT NULL COMMENT '子项目id',
                                        `feedbacker` VARCHAR ( 32 ) COMMENT '反馈人',
                                        `mobile` VARCHAR ( 32 ) COMMENT '联系电话',
                                        `remark` VARCHAR ( 512 ) COMMENT '反馈内容',
                                        `status` TINYINT ( 1 ) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用',
                                        `creator` VARCHAR ( 64 ) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
                                        `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                        `updater` VARCHAR ( 64 ) COLLATE utf8mb4_unicode_ci 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,
                                        KEY `idx_project` ( `project_id`, `project_sub_id` ) USING BTREE
) ENGINE = InnoDB COMMENT = '客户反馈质量表';

DROP TABLE IF EXISTS `project_plan_task`;
CREATE TABLE `project_plan_task` (
                                     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                     `project_id` bigint(20) DEFAULT NULL COMMENT '项目id',
                                     `project_plan_id` bigint(20) NOT NULL COMMENT '生产计划id',
                                     `project_plan_sub_id` bigint(20) DEFAULT NULL COMMENT '生产计划子项目id',
                                     `process_bom_id` bigint(20) DEFAULT NULL COMMENT '工艺bomid',
                                     `task_no` varchar(13)  DEFAULT NULL COMMENT '生产计划编号，唯一',
                                     `bom_version` int(11) DEFAULT NULL COMMENT 'bom版本号',
                                     `description` varchar(255) DEFAULT NULL COMMENT '备注',
                                     `status` tinyint(1) DEFAULT '1' COMMENT '状态,1已保存，2已提交，3已终止 ，默认是1',
                                     `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='生产计划任务表';

DROP TABLE IF EXISTS `project_plan_task_bom`;
CREATE TABLE `project_plan_task_bom` (
                                         `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                         `task_id` bigint(20) NOT NULL COMMENT '生产任务id',
                                         `bom_detail_id` bigint(20) NOT NULL COMMENT 'bom明细id',
                                         `owner` varchar(64)  DEFAULT '' COMMENT '负责人',
                                         `end_time` datetime DEFAULT CURRENT_TIMESTAMP 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='生产计划任务Bom表';

ALTER TABLE pro_process_bom_detail ADD UNIQUE KEY `uk_material`(`bom_id`, `type`, `material_name`,`tenant_id`);

DROP TABLE IF EXISTS `base_equip_manufacture`;
CREATE TABLE `base_equip_manufacture` (
                                          `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                          `code` varchar(64) NOT NULL COMMENT '编码 唯一',
                                          `name` varchar(128) NOT NULL COMMENT '名称',
                                          `type` varchar(64) COMMENT '类型',
                                          `model` varchar(64) COMMENT '型号',
                                          `status` tinyint(1) DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用，默认是1',
                                          `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`),
                                          UNIQUE KEY `idx_code` (`code`, `tenant_id`)
) ENGINE=InnoDB COMMENT='制造设备表';
