ALTER TABLE project_order RENAME project_sale_order;
ALTER TABLE project_sale_order COMMENT '项目销售订单表';

ALTER TABLE project_order_sub RENAME project_sale_order_sub;
ALTER TABLE project_sale_order_sub COMMENT '项目销售订单子项表';

ALTER TABLE base_serial_number DROP INDEX uk_business_segment;
ALTER TABLE base_serial_number ADD UNIQUE INDEX `uk_business_segment` ( `business_type`, `segment`, `tenant_id` ) USING BTREE;

ALTER TABLE project_sale_order DROP INDEX `uk_code`;
ALTER TABLE project_sale_order ADD UNIQUE INDEX `uk_code` ( `code`, `tenant_id` );

DROP TABLE IF EXISTS `project_deliver_order`;
CREATE TABLE `project_deliver_order` (
                                         `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                         `code` varchar(64) NOT NULL COMMENT '编号，唯一',
                                         `sale_order_ids` varchar(255) not null comment '销售订单id列表 多个用英文逗号分割',
                                         `customer_id` BIGINT(20) not null comment '客户id',
                                         `deliver_date` DATETIME not null comment '发货日期',
                                         `deliver_status` char(1) not null COMMENT '发货单状态 已保存/已发货',
                                         `deliver_person` BIGINT(20) not null comment '发货人',
                                         `deliver_person_mobile` varchar(32) not null comment '发货人电话',
                                         `deliver_mode` char(1) not null comment '发货方式',
                                         `receive_person_name` BIGINT(20) not null comment '收货人姓名',
                                         `receive_person_mobile` varchar(32) not null comment '收货人电话',
                                         `transport_driver_name` varchar(16) comment '司机姓名',
                                         `transport_driver_mobile` varchar(32) comment '司机电话',
                                         `transport_bus_number` varchar(32) comment '车牌号',
                                         `transport_weight` varchar(16) comment '重量(T)',
                                         `transport_size` varchar(16) 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='发货订单表';

DROP TABLE IF EXISTS `project_deliver_order_sub`;
CREATE TABLE `project_deliver_order_sub` (
                                             `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增字段，唯一',
                                             `delivery_order_id` bigint(20) NOT NULL COMMENT '订单id',
                                             `category` char(1) not null comment '业务类 发货清单|其他清单 DELIVER_LIST|OTHER_LIST',
                                             `name` varchar(128) NOT NULL COMMENT '名称，唯一',
                                             `blueprint_no` varchar(64) DEFAULT NULL COMMENT '图号',
                                             `amount` int(11) NOT NULL COMMENT '数量',
                                             `unit` char(1) NOT NULL COMMENT '单位',
                                             `weight` varchar(16) comment '重量(T)',
                                             `size` varchar(16) comment '尺寸(米)',
                                             `sub_type` char(1) 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
) ENGINE=InnoDB COMMENT='发货订单子项表';
