CREATE TABLE sales_ledger_product_process
(
    id               INT PRIMARY KEY AUTO_INCREMENT,
    sales_product_id INT          NOT NULL COMMENT '销售产品ID(关联sales_ledger_product.id)',
    process_name     VARCHAR(100) NOT NULL COMMENT '工艺名称',
    quantity         DECIMAL(12, 3) DEFAULT NULL COMMENT '数量',
    unit_price       DECIMAL(10, 2) DEFAULT NULL COMMENT '单价',
    remark           VARCHAR(255)   DEFAULT NULL,
    create_time      DATETIME       DEFAULT CURRENT_TIMESTAMP
) COMMENT ='销售产品加工明细';


DROP TABLE IF EXISTS `sales_ledger_product_process_bind`;
CREATE TABLE `sales_ledger_product_process_bind`
(
    `id`                              int NOT NULL AUTO_INCREMENT COMMENT '主键',
    `sales_ledger_product_id`         int NULL DEFAULT NULL COMMENT '销售台账产品信息ID',
    `sales_ledger_product_process_id` int NULL DEFAULT NULL COMMENT '销售产品加工明细ID',
    `quantity`                        int NULL DEFAULT NULL COMMENT '加工数量',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  CHARACTER SET = utf8mb3
  COLLATE = utf8mb3_general_ci COMMENT = '销售产品额外加工数量'
  ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

ALTER TABLE sales_ledger_product
    ADD COLUMN actual_piece_area DECIMAL(18, 6) DEFAULT NULL COMMENT '实际单片面积(㎡)',
    ADD COLUMN actual_total_area DECIMAL(18, 6) DEFAULT NULL COMMENT '实际总面积(㎡)',
    ADD COLUMN settle_piece_area DECIMAL(18, 6) DEFAULT NULL COMMENT '结算单片面积(㎡)',
    ADD COLUMN settle_total_area DECIMAL(18, 6) DEFAULT NULL COMMENT '结算总面积(㎡)';

ALTER TABLE sales_ledger_product
    ADD COLUMN process_requirement VARCHAR(500) DEFAULT NULL COMMENT '加工要求';
ALTER TABLE sales_ledger_product
    ADD COLUMN remark VARCHAR(500) DEFAULT NULL COMMENT '备注';

ALTER TABLE sales_ledger_product_process
    CHANGE COLUMN remark code VARCHAR(255) COMMENT '编码';

ALTER TABLE `product-inventory-management-hbtmblc`.`sales_ledger_product`
    MODIFY COLUMN `width` decimal(20, 15) NULL DEFAULT NULL COMMENT '宽(mm)' AFTER `is_checked`,
    MODIFY COLUMN `height` decimal(20, 15) NULL DEFAULT NULL COMMENT '高(mm)' AFTER `width`,
    MODIFY COLUMN `actual_piece_area` decimal(20, 15) NULL DEFAULT NULL COMMENT '实际单片面积(㎡)' AFTER `height`,
    MODIFY COLUMN `actual_total_area` decimal(20, 15) NULL DEFAULT NULL COMMENT '实际总面积(㎡)' AFTER `actual_piece_area`,
    MODIFY COLUMN `settle_piece_area` decimal(20, 15) NULL DEFAULT NULL COMMENT '结算单片面积(㎡)' AFTER `actual_total_area`,
    MODIFY COLUMN `settle_total_area` decimal(20, 15) NULL DEFAULT NULL COMMENT '结算总面积(㎡)' AFTER `settle_piece_area`,
    ADD COLUMN `perimeter` decimal(20, 15) NULL COMMENT '周长' AFTER `settle_total_area`,
    ADD COLUMN `heavy_box` decimal(20, 15) NULL COMMENT '重箱' AFTER `perimeter`;

ALTER TABLE `product-inventory-management-hbtmblc`.`process_route`
    MODIFY COLUMN `product_model_id` bigint NULL DEFAULT 0 COMMENT '产品id' AFTER `id`,
    MODIFY COLUMN `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '描述' AFTER `product_model_id`,
    ADD COLUMN `is_default` tinyint(1) NULL COMMENT '是否默认(0-否,1-是)' AFTER `bom_id`;

ALTER TABLE `product-inventory-management-hbtmblc`.`process_route`
    ADD COLUMN `process_route_name` varchar(255) NULL COMMENT '工艺路线名称' AFTER `product_model_id`;

ALTER TABLE `product-inventory-management-hbtmblc`.`process_route_item`
    MODIFY COLUMN `product_model_id` bigint NULL DEFAULT 0 COMMENT '产品id' AFTER `route_id`,
    MODIFY COLUMN `process_id` bigint NULL DEFAULT 0 COMMENT '工序id' AFTER `product_model_id`,
    ADD COLUMN `process_name` varchar(255) NULL COMMENT '工序名称' AFTER `process_id`;