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';
