ALTER TABLE base_procedure ADD COLUMN salary_type VARCHAR ( 16 ) COMMENT '工资类型 HourWage|PieceRateWage|NoAccounting 计时工资/计件工资/不核算' AFTER `procedure_type`;
ALTER TABLE base_procedure ADD COLUMN standard_labour_price DECIMAL ( 20, 2 ) COMMENT '额定工价' AFTER `procedure_type`;
ALTER TABLE base_procedure ADD COLUMN piecework_basis CHAR ( 2 ) COMMENT '计件依据 01：合格数量02：报工数量' AFTER `procedure_type`;

ALTER TABLE project_sale_order ADD COLUMN `external_code` VARCHAR ( 64 ) COMMENT '销售订单号 来源用友 唯一' AFTER `code`;

ALTER TABLE system_dept ADD COLUMN `code` VARCHAR ( 16 ) COMMENT '部门编码' AFTER `name`;

ALTER TABLE project_sale_order_sub ADD COLUMN `material_id` BIGINT ( 20 ) NOT NULL COMMENT '物料id' AFTER project_order_id;
alter table project_sale_order_sub DROP INDEX uk_project_name;
alter table project_sale_order_sub ADD UNIQUE KEY `uk_project_material`(`project_order_id`, `material_id`);
alter table project_sale_order_sub MODIFY COLUMN `name` varchar(128) COMMENT '子项目名称，唯一';

DROP TABLE IF EXISTS `project_sale_order`;
CREATE TABLE `project_sale_order` (
                                      `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                      `code` varchar(64) NOT NULL COMMENT '项目编号，唯一',
                                      `external_code` varchar(64) DEFAULT NULL COMMENT '销售订单号 来源用友 唯一',
                                      `order_status` int(11) NOT NULL DEFAULT '0' COMMENT '单据状态 已保存/已送审/已审核/已启动/已打回/已终止',
                                      `order_time` datetime NOT NULL COMMENT '单据日期',
                                      `delivery_status` tinyint(1) COMMENT '发货状态 未发货/部分发货/全部发货',
                                      `business_man` bigint(20) COMMENT '业务员',
                                      `business_dept_id` bigint(20) NOT NULL COMMENT '提出部门id',
                                      `customer_id` bigint(20) NOT NULL COMMENT '客户id',
                                      `contract_no` varchar(128) DEFAULT NULL COMMENT '合同编号',
                                      `project_name` varchar(255) COMMENT '项目名称',
                                      `business_line` char(1) NOT NULL COMMENT '业务线',
                                      `blueprint_no` varchar(32) DEFAULT NULL COMMENT '图号',
                                      `has_price` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否有价格',
                                      `price` decimal(20,6) DEFAULT NULL COMMENT '价格 保留四位小数',
                                      `currency` char(1) DEFAULT NULL COMMENT '币种',
                                      `project_start_time` datetime NOT NULL COMMENT '项目开始时间',
                                      `project_end_time` datetime NOT NULL COMMENT '项目结束时间',
                                      `is_urgency` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否紧急',
                                      `property` tinyint(1) COMMENT '性质 新制|维修',
                                      `reference_technology` varchar(255) DEFAULT NULL COMMENT '可引用的原有技术',
                                      `has_alter` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已变更',
                                      `last_alter_time` datetime DEFAULT NULL COMMENT '上一次变更时间',
                                      `quality_requirement` varchar(255) DEFAULT NULL COMMENT '检验要求',
                                      `remark` varchar(255) DEFAULT NULL COMMENT '备注',
                                      `has_contract` tinyint(1) NOT NULL DEFAULT '0' COMMENT '有无合同',
                                      `has_technology_protocol` tinyint(1) NOT NULL DEFAULT '0' COMMENT '有无技术协议',
                                      `has_blueprint` tinyint(1) NOT NULL DEFAULT '0' COMMENT '有无图纸/数模',
                                      `blueprint_remark` varchar(255) DEFAULT NULL COMMENT '图纸/数模 说明',
                                      `is_snapshot` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否快照',
                                      `snapshot_order_time` datetime DEFAULT NULL COMMENT '快照原始单据日期',
                                      `snapshot_id` bigint(20) DEFAULT NULL COMMENT '快照原始id',
                                      `snapshot_code` varchar(64) 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`) USING BTREE
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC COMMENT='项目销售订单表';

ALTER TABLE base_workshop MODIFY COLUMN `dept_id` BIGINT ( 20 ) COMMENT '部门id';
ALTER TABLE base_workshop MODIFY COLUMN `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态,1表示正常，2表示禁用，默认是1';
ALTER TABLE base_customer MODIFY COLUMN `status` TINYINT ( 1 ) NOT NULL DEFAULT '1' COMMENT '状态,1 表示正常，2 表示禁用';
ALTER TABLE base_procedure MODIFY COLUMN `procedure_type` CHAR ( 1 ) COMMENT '工序类型';
ALTER TABLE base_material MODIFY COLUMN `material_type` VARCHAR ( 32 ) NOT NULL COMMENT '物料类型';
ALTER TABLE project_sale_order ADD COLUMN order_source TINYINT ( 1 ) NOT NULL DEFAULT '1' COMMENT '单据来源 1 默认手动新增 2 接口同步' AFTER `code`;

ALTER TABLE project_sale_order MODIFY COLUMN `business_dept_id` bigint(20) COMMENT '提出部门id';
ALTER TABLE project_sale_order MODIFY COLUMN `business_line` char(1) COMMENT '业务线';
ALTER TABLE project_sale_order MODIFY COLUMN `project_start_time` datetime COMMENT '项目开始时间';
ALTER TABLE project_sale_order MODIFY COLUMN `project_end_time` datetime COMMENT '项目结束时间';

ALTER TABLE project_sale_order_sub MODIFY COLUMN `composition_id` BIGINT ( 20 ) COMMENT '材质';
ALTER TABLE infra_file ADD COLUMN `business_file_remark` VARCHAR(255) COMMENT '业务文件说明' AFTER `business_file_type`;

drop table if exists project_plan_task;
drop table if exists project_plan_task_bom;


drop table if exists `project_plan_workshop`;
CREATE TABLE `project_plan_workshop` (
                                         `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                         `project_plan_id` bigint(20) NOT NULL COMMENT '计划id',
                                         `project_id` bigint(20) NOT NULL COMMENT '项目id',
                                         `workshop_id` bigint(20) NOT NULL COMMENT '车间id',
                                         `start_time` datetime COMMENT '预计开始时间',
                                         `end_time` datetime 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`) USING BTREE,
                                         UNIQUE KEY `uk_project_workshop` (`project_plan_id`, `workshop_id`,`tenant_id`) USING BTREE
) ENGINE=InnoDB COMMENT='生产计划车间计划';

ALTER TABLE pro_task_dispatch ADD COLUMN `workshop_id` BIGINT ( 20 ) NOT NULL COMMENT '车间id' AFTER `project_sub_id`;

drop table if exists pro_process_bom;
drop table if exists pro_process_bom_detail;

alter table project_sale_order_sub drop column unit;
ALTER TABLE project_plan_sub DROP COLUMN project_sub_code;

ALTER TABLE pro_task_dispatch MODIFY COLUMN `dispatch_type` VARCHAR ( 16 ) COMMENT '派工类型 生产任务|装配任务 PRODUCTION|ASSEMBLE';

ALTER TABLE `project_sale_order` ADD COLUMN `external_id` VARCHAR ( 32 ) NULL COMMENT '销售订单id 来源用友 唯一' AFTER `order_source`;

ALTER TABLE base_equip_manufacture ADD COLUMN `workshop_id` BIGINT ( 20 ) NOT NULL COMMENT '车间id' AFTER `model`;


drop table if exists `base_equip_maintenance_record`;
CREATE TABLE `base_equip_maintenance_record` (
                                                 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                                 `code` varchar(64) NOT NULL COMMENT '编码，唯一',
                                                 `type` char(1) NOT NULL COMMENT '名称 维修|保养',
                                                 `equip_id` bigint(20) NOT NULL COMMENT '设备id',
                                                 `submit_time` datetime COMMENT '上报日期',
                                                 `description` varchar(255) DEFAULT NULL COMMENT '描述',
                                                 `owner` bigint(20) NOT NULL COMMENT '维保人',
                                                 `progress` char(1) NOT NULL COMMENT '维保进度 未开始/进行中/已完成',
                                                 `time_consumed` decimal(20,2) COMMENT '耗时 单位小时',
                                                 `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`) USING BTREE
) ENGINE=InnoDB COMMENT='设备维保记录表';

ALTER TABLE `project_sale_order_sub` ADD COLUMN production_detail_id VARCHAR ( 32 ) COMMENT '生产加工单明细id' AFTER project_order_id;
ALTER TABLE `project_sale_order_sub` ADD COLUMN production_id VARCHAR ( 32 ) COMMENT '生产加工单id' AFTER project_order_id;

ALTER TABLE pro_unqualified_notification DROP COLUMN `bom_detail_id`;
ALTER TABLE pro_unqualified_notification ADD COLUMN `workshop_id` BIGINT ( 20 ) NOT NULL COMMENT '车间id' AFTER `project_sub_id`;

ALTER TABLE pro_task_report MODIFY COLUMN `dispatch_detail_id` BIGINT ( 20 ) COMMENT '派工单任务明细id';

ALTER TABLE pro_task_report ADD COLUMN `dispatch_id` BIGINT ( 20 ) COMMENT '派工单id' AFTER `id`;
ALTER TABLE pro_task_report ADD COLUMN `procedure_id` bigint(20) COMMENT '工序id' AFTER `dispatch_detail_id`;
ALTER TABLE pro_task_report ADD COLUMN `type` VARCHAR(16) NOT NULL DEFAULT 'PRODUCTION' COMMENT '报工任务类型 生产|包装 PRODUCTION|ASSEMBLE' AFTER `dispatch_detail_id`;
ALTER TABLE pro_task_report ADD COLUMN `assemble_code` VARCHAR(32) COMMENT '包装码' AFTER `dispatch_detail_id`;

DROP TABLE IF EXISTS `sc_equipment`;
CREATE TABLE `sc_equipment`  (
                                 `Id` int(11) NOT NULL COMMENT '设备id',
                                 `Nmae` varchar(64) CHARACTER SET utf8mb4  NULL DEFAULT NULL COMMENT '设备名称',
                                 `OEE` decimal(24, 2) NULL DEFAULT NULL COMMENT 'OEE',
                                 `UtilizationRate` decimal(24, 2) NULL DEFAULT NULL COMMENT '设备利用率',
                                 `QualificationRate` decimal(24, 2) NULL DEFAULT NULL COMMENT '产品合格率',
                                 `ShutdownTime` decimal(24, 2) NULL DEFAULT NULL COMMENT '当日停机次数',
                                 `Num` decimal(24, 2) NULL DEFAULT NULL COMMENT '当日合格数量',
                                 `Statuss` int(11) NULL DEFAULT NULL COMMENT '设备状态',
                                 PRIMARY KEY (`Id`) USING BTREE
) ENGINE = InnoDB comment='数采设备表';

alter table wms_storage_mat add column `procedure_id` bigint(20) COMMENT '工序id' AFTER `lot_no`;

ALTER TABLE sc_equipment ADD COLUMN `deleted` BIT ( 1 ) NOT NULL DEFAULT b '0' COMMENT '是否删除';
ALTER TABLE sc_equipment ADD COLUMN `creator` varchar(64) DEFAULT '' COMMENT '创建者';
ALTER TABLE sc_equipment ADD COLUMN `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';
ALTER TABLE sc_equipment ADD COLUMN `updater` varchar(64) DEFAULT '' COMMENT '更新者';
ALTER TABLE sc_equipment ADD COLUMN `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wms_wh MODIFY COLUMN `wh_status` TINYINT (1) NOT NULL DEFAULT '1' COMMENT '状态,1 表示正常，2 表示禁用';
ALTER TABLE project_sale_order_sub ADD COLUMN `warehouse_id` BIGINT ( 20 ) COMMENT '仓库id' AFTER `material_id`;

ALTER TABLE `project_sale_order` ADD COLUMN `warehouse_id` BIGINT ( 20 ) DEFAULT NULL COMMENT '仓库id' AFTER `order_status`;

ALTER TABLE base_material ADD COLUMN inventory_property INT ( 11 ) DEFAULT '0' COMMENT '物料属性' AFTER `description`;



drop table if exists `base_system_parameters`;
CREATE TABLE `base_system_parameters` (
                                          `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                          `creator` varchar(64) COLLATE DEFAULT '' COMMENT '创建者',
                                          `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
                                          `updater` varchar(64) COLLATE 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 '租户编号',
                                          `code` varchar(255) COLLATE DEFAULT NULL COMMENT '参数编码',
                                          `name` varchar(255) COLLATE DEFAULT NULL COMMENT '参数名称',
                                          `scope` varchar(255) COLLATE DEFAULT NULL COMMENT '值范围',
                                          `current_value` varchar(255) COLLATE DEFAULT NULL COMMENT '当前值',
                                          `description` varchar(255) COLLATE DEFAULT NULL COMMENT '备注',
                                          PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='系统参数设置表';

drop table if exists `base_process`;
CREATE TABLE `base_process` (
                                `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                `code` varchar(64) DEFAULT NULL COMMENT '工艺路线编号',
                                `name` varchar(64) NOT NULL COMMENT '工艺路线名称,唯一',
                                `status` tinyint(1) NOT NULL 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`)
) ENGINE=InnoDB COMMENT='工艺路线表';

drop table if exists `base_process_detail`;
CREATE TABLE `base_process_detail` (
                                       `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                       `process_id` bigint(20) DEFAULT NULL COMMENT '工艺路线id',
                                       `procedure_id` bigint(20) DEFAULT NULL COMMENT '工序id',
                                       `procedure_sort` int(11) DEFAULT NULL COMMENT '工序顺序号',
                                       `procedure_equip_id` bigint(20) DEFAULT NULL COMMENT '生产设备id',
                                       `type` int(11) DEFAULT NULL COMMENT '明细类型：1为工序，2为产品',
                                       `material_id` bigint(20) DEFAULT NULL COMMENT '产品id（物料）',
                                       `creator` varchar(64) COLLATE 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 add COLUMN `process_id` BIGINT null comment '工艺路线id';
alter table base_material add COLUMN `safe_amount` BIGINT null comment '安全库存量';

drop table if exists `base_process_setting`;
CREATE TABLE `base_process_setting` (
                                        `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                        `material_id` bigint(20) DEFAULT NULL COMMENT '物料id',
                                        `process_id` bigint(20) DEFAULT NULL COMMENT '工艺路线id',
                                        `procedure_id` bigint(20) DEFAULT NULL COMMENT '工序id',
                                        `user_id` bigint(20) DEFAULT NULL COMMENT '用户id',
                                        `salary_type` varchar(20) DEFAULT NULL COMMENT '工资类型',
                                        `price` decimal(10,4) DEFAULT NULL COMMENT '工价',
                                        `work_time` decimal(10,4) 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 pro_task_dispatch_detail add column `owner_ids` VARCHAR(128) null comment '多个负责人' after `owner`;
alter table pro_task_dispatch_detail modify column `owner` bigint(20) null comment '负责人' ;
alter table pro_task_report add COLUMN `has_synch` tinyint(1) default null comment '是否已同步用友';

drop table if exists `pro_task_dispatch_detail_owner`;
CREATE TABLE `pro_task_dispatch_detail_owner` (
                                                  `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) DEFAULT NULL COMMENT '顺序号',
                                                  `owner` bigint(20) DEFAULT NULL COMMENT '负责人',
                                                  `device_model` bigint(20) DEFAULT NULL 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 '租户编号',
                                                  `owner_ids` varchar(128)  DEFAULT NULL COMMENT '多个负责人',
                                                  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB COMMENT='派工明细表';

alter table pro_task_dispatch_detail add COLUMN `detail_owner_id` bigint(20) default null comment '派工明细拆分前对应id' after id;

update pro_task_dispatch_detail as a set detail_owner_id =(select id from pro_task_dispatch_detail_owner where owner_ids is not null and dispatch_id=a.dispatch_id and procedure_id=a.procedure_id and owner_ids=a.owner_ids limit 1);

alter table base_material add COLUMN `available_quantity` decimal(20,6) DEFAULT NULL COMMENT '库存数量';

drop table if exists `base_salary_setting`;
CREATE TABLE `base_salary_setting` (
                                       `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                       `user_id` bigint(20) DEFAULT NULL COMMENT '员工id',
                                       `salary_type` varchar(64) DEFAULT NULL COMMENT '工资类型字典',
                                       `procedureType` varchar(512)  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`)
) ENGINE=InnoDB COMMENT='员工工资设置';

drop table if exists `base_salary_user`;
CREATE TABLE `base_salary_user` (
                                    `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                    `user_id` bigint(20) DEFAULT NULL COMMENT '员工id',
                                    `salary_type` varchar(64) DEFAULT NULL COMMENT '工资类型字典',
                                    `price` decimal(10,2) DEFAULT NULL COMMENT '工价',
                                    `procedureType` varchar(512)  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 '租户编号',
                                    `dept_id` bigint(20) DEFAULT NULL COMMENT '部门id',
                                    PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='员工工资设置主表';


ALTER TABLE `system_operate_log` MODIFY COLUMN `user_agent` VARCHAR(1024) DEFAULT NULL COMMENT '浏览器 UA';

ALTER TABLE `project_sale_order_sub` ADD COLUMN `order_amount` int(11) DEFAULT NULL COMMENT '订单数量';

ALTER TABLE `project_plan` ADD COLUMN `has_edit` int(2) DEFAULT 2 COMMENT '编辑状态：1已编辑/2未编辑';

//=====================================================
drop table if exists `pro_task_dispatch_detail_ratio`;
CREATE TABLE `pro_task_dispatch_detail_ratio` (
                                                  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                                  `detail_owner_id` bigint(20) DEFAULT NULL COMMENT '派工明细拆分前对应id',
                                                  `owner` bigint(20) DEFAULT NULL COMMENT '负责人',
                                                  `ratio` decimal(10,2) 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 `pro_unqualified_notification` ADD COLUMN `product_amount` int(11) DEFAULT NULL COMMENT '生产总数';
ALTER TABLE `pro_unqualified_notification` ADD COLUMN `check_amount` int(11) DEFAULT NULL COMMENT '检验数量';
ALTER TABLE `pro_unqualified_notification` ADD COLUMN `solution_content` varchar(512) DEFAULT NULL COMMENT '解决方案';
ALTER TABLE `pro_unqualified_notification` ADD COLUMN `punishment_opinion` varchar(512) DEFAULT NULL COMMENT '处罚意见';


drop table if exists `project_sale_order_packing_clause`;
CREATE TABLE `project_sale_order_packing_clause` (
                                                     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                                     `project_order_id` bigint(20) NOT NULL COMMENT '项目订单id',
                                                     `rule_name` 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='生产订单包装规则表';

drop table if exists `project_sale_order_packing_clause_detail`;
CREATE TABLE `project_sale_order_packing_clause_detail` (
                                                            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                                            `project_order_id` bigint(20) DEFAULT NULL COMMENT '项目订单id',
                                                            `clause_id` bigint(20) NOT NULL COMMENT '项目订单包装规则id',
                                                            `material_id` bigint(20) NOT NULL COMMENT '产品id',
                                                            `amount` int(10) DEFAULT NULL COMMENT '每箱配比',
                                                            `sort` int(10) 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='生产订单包装规则明细表';

drop table if exists `base_salary_month`;
CREATE TABLE `base_salary_month` (
                                     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                     `user_id` bigint(20) DEFAULT NULL COMMENT '员工id',
                                     `month` varchar(10)  DEFAULT NULL COMMENT '所属年月',
                                     `attendance_days` int(11) DEFAULT NULL COMMENT '实际出勤天数',
                                     `basic_salary` decimal(10,2) DEFAULT NULL COMMENT '基本工资',
                                     `job_allowance` decimal(10,2) DEFAULT NULL COMMENT '职务津贴',
                                     `five_one_fund` decimal(10,2) DEFAULT NULL COMMENT '五险一金补贴',
                                     `non_compete_subsidy` decimal(10,2) DEFAULT NULL COMMENT '敬业限制补贴',
                                     `weekend_work` varchar(255)  DEFAULT NULL COMMENT '3天周末加班',
                                     `weekend_worktime` datetime DEFAULT NULL COMMENT '加班小时',
                                     `weekend_work_amount` decimal(10,2) DEFAULT NULL COMMENT '加班金额',
                                     `absence_time` int(10) DEFAULT NULL COMMENT '事假小时',
                                     `absence_amount` decimal(10,2) DEFAULT NULL COMMENT '事假金额',
                                     `full_attendance_salary` decimal(10,2) DEFAULT NULL COMMENT '全勤工资',
                                     `service_experience_award` decimal(10,2) DEFAULT NULL COMMENT '工龄奖补助',
                                     `other_award` decimal(10,2) DEFAULT NULL COMMENT '夜班/其他补助',
                                     `gross_pay` decimal(10,2) DEFAULT NULL COMMENT '应发工资',
                                     `retire_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣退休金',
                                     `medical_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣医疗金',
                                     `unemployment_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣失业金',
                                     `tax_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣个税',
                                     `water_electricity_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣水电费',
                                     `food_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣餐费',
                                     `lodging_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣住宿费',
                                     `loan_deduction` decimal(10,2) DEFAULT NULL COMMENT '扣借款/其他',
                                     `reissue` decimal(10,2) DEFAULT NULL COMMENT '补发',
                                     `net_salary` decimal(10,2) 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='所属年月工资明细表';

drop table if exists `tplus_lastest_stock`;
CREATE TABLE `tplus_lastest_stock` (
                                       `id` bigint(20) NOT NULL AUTO_INCREMENT 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 '租户编号',
                                       `WarehouseID` varchar(50)  DEFAULT NULL COMMENT '仓库id',
                                       `WarehouseName` varchar(50)  DEFAULT NULL COMMENT '仓库名称',
                                       `WarehouseCode` varchar(50)  DEFAULT NULL COMMENT '仓库编码',
                                       `InventoryID` varchar(50)  DEFAULT NULL COMMENT '物料ID',
                                       `InventoryCode` varchar(50)  DEFAULT NULL COMMENT '物料编码',
                                       `InventoryName` varchar(50)  DEFAULT NULL COMMENT '物料名称',
                                       `InventoryClassCode` varchar(50)  DEFAULT NULL COMMENT '物料类型',
                                       `InventoryClassName` varchar(50)  DEFAULT NULL COMMENT '物料类型名称',
                                       `AvailableQuantity` varchar(50)  DEFAULT NULL COMMENT '可用量',
                                       `ExistingQuantity` varchar(50)  DEFAULT NULL COMMENT '现存量',
                                       PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='用友Tplus最新库存表';


drop table if exists `tplus_lastest_bom`;
CREATE TABLE `tplus_lastest_bom` (
                                     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                     `parent_id` bigint(20) DEFAULT NULL COMMENT '父级id',
                                     `top_code` varchar(255)  DEFAULT NULL COMMENT '一级产品编码',
                                     `sort` int(11) DEFAULT NULL COMMENT '序号',
                                     `layer` int(11) DEFAULT NULL COMMENT '层级',
                                     `layer_sort` int(11) DEFAULT NULL COMMENT '层次',
                                     `project_sub_code` varchar(255)  DEFAULT NULL COMMENT '物料编码',
                                     `project_sub_name` varchar(255)  DEFAULT NULL COMMENT '物料名称',
                                     `material_type` varchar(255)  DEFAULT NULL COMMENT '物料类型',
                                     `spec` varchar(255)  DEFAULT NULL COMMENT '规格/型号',
                                     `is_virtual` int(11) DEFAULT NULL COMMENT '是否虚拟物料',
                                     `bom_version` varchar(255)  DEFAULT NULL COMMENT '版本号',
                                     `stock_quantity` decimal(10,2) DEFAULT NULL COMMENT '库存数量',
                                     `unit` varchar(255)  DEFAULT NULL COMMENT '库存单位',
                                     `material_id` bigint(20) DEFAULT NULL COMMENT '物料id',
                                     `produce_quantity` decimal(10,2) DEFAULT NULL COMMENT '生产数量',
                                     `required_quantity` decimal(10,2) 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='用友Tplus最新BOM表';


alter table wms_storage add column `project_order_code` varchar(64) default null comment '生产订单id';
alter table wms_storage add column `material_mode` int(2) default null comment '领料模式';

alter table project_sale_order add `package_status` int(2) default 2 comment '包装状态';

alter table wms_storage_mat add column `pre_amount` decimal(10,2) DEFAULT NULL COMMENT '预估消耗值';
alter table wms_storage_mat add column `stock_quantity` decimal(10,2) DEFAULT NULL COMMENT '库存';


drop table if exists `tplus_storage_out`;
CREATE TABLE `tplus_storage_out` (
                                     `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                     `stock_id` bigint(20) DEFAULT NULL COMMENT '出库id',
                                     `storage_ok_qty` decimal(10,2) DEFAULT NULL COMMENT '领料数量',
                                     `product_code` varchar(255)  DEFAULT NULL COMMENT '产品编码',
                                     `project_sub_code` varchar(255)  DEFAULT NULL COMMENT '物料编码',
                                     `procedure_id` bigint(20) DEFAULT NULL COMMENT '工序id',
                                     `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 '租户编号',
                                     `is_send` int(2) DEFAULT NULL COMMENT '是否推送',
                                     `project_order_id` bigint(20) DEFAULT NULL COMMENT '生产订单id',
                                     `project_order_code` varchar(255)  DEFAULT NULL COMMENT '生产订单编号',
                                     `dept_name` varchar(255)  DEFAULT NULL COMMENT '生产订单部门名称',
                                     `stock_create_date` datetime DEFAULT NULL COMMENT '单据日期',
                                     `wh_no` varchar(255)  DEFAULT NULL COMMENT '出库仓库编码',
                                     `wh_name` varchar(255)  DEFAULT NULL COMMENT '出库仓库名称',
                                     `product_name` varchar(255)  DEFAULT NULL COMMENT '产品名称',
                                     `project_sub_name` varchar(255)  DEFAULT NULL COMMENT '物料名称',
                                     `procedure_code` varchar(255)  DEFAULT NULL COMMENT '工序编码',
                                     `procedure_name` varchar(255)  DEFAULT NULL COMMENT '工序名称',
                                     `fix_ratio` decimal(10,2) DEFAULT NULL COMMENT '定额',
                                     `unit` varchar(255)  DEFAULT NULL COMMENT '领料单位',
                                     `wh_id` bigint(20) DEFAULT NULL COMMENT '仓库id',
                                     `mat_id` bigint(20) DEFAULT NULL COMMENT '物料id',
                                     PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='用友生产领料表';

alter table pro_task_report add column `material_id` bigint(20) DEFAULT NULL COMMENT '产品id';

alter table tplus_lastest_bom add column `procedure_code` varchar(255) DEFAULT NULL COMMENT '工序编码';
alter table tplus_lastest_bom add column `procedure_name` varchar(255) DEFAULT NULL COMMENT '工序名称';

//====================================================================================================
drop table if exists `base_cn_en`;
CREATE TABLE `base_cn_en` (
                              `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
                              `cn` varchar(255)  DEFAULT NULL COMMENT '中文',
                              `en` 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='中英文对照表';