-- 空木箱规格、实例状态和仓位锁初始化
CREATE TABLE IF NOT EXISTS wms_boxtype (
    id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键',
    material_code VARCHAR(50) NOT NULL COMMENT '木箱规格编码',
    material_name VARCHAR(100) NOT NULL COMMENT '木箱规格名称',
    lash_num VARCHAR(10) NOT NULL COMMENT '捆扎次数',
    box_length VARCHAR(20) NOT NULL COMMENT '长度',
    box_width VARCHAR(20) NOT NULL COMMENT '宽度',
    box_height VARCHAR(20) NOT NULL COMMENT '高度',
    PRIMARY KEY (id),
    UNIQUE KEY uk_wms_boxtype_material_code (material_code)
) COMMENT '木箱规格';

ALTER TABLE wmw_boxinfo
    ADD COLUMN status VARCHAR(1) NOT NULL DEFAULT '1' COMMENT '状态：0待入库、1在库、2已出库',
    ADD COLUMN out_time VARCHAR(25) NULL COMMENT '出库时间',
    ADD INDEX idx_wmw_boxinfo_fifo (material_code, status, insert_time);

INSERT INTO system_dict_data
    (id, sort, label, value, dict_type, status, color_type, css_class, remark, creator, create_time, updater, update_time, deleted)
SELECT 2080566516439883785, 8, '木箱入库锁', '8', 'wms_lock_type', 0, 'success', '', '', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_dict_data WHERE dict_type = 'wms_lock_type' AND value = '8' AND deleted = b'0');

INSERT INTO system_dict_data
    (id, sort, label, value, dict_type, status, color_type, css_class, remark, creator, create_time, updater, update_time, deleted)
SELECT 2080566516439883786, 9, '木箱出库锁', '9', 'wms_lock_type', 0, 'warning', '', '', '1', NOW(), '1', NOW(), b'0'
WHERE NOT EXISTS (SELECT 1 FROM system_dict_data WHERE dict_type = 'wms_lock_type' AND value = '9' AND deleted = b'0');

INSERT INTO base_code_rule
    (rule_name, rule_code, segment_config, code_separator, letter_case, total_length,
     seq_strategy, status, remark, creator, updater, deleted)
SELECT '木箱编码', 'BOX_CODE',
       JSON_ARRAY(
           JSON_OBJECT('type', 'PREFIX', 'value', 'BOX'),
           JSON_OBJECT('type', 'DATE', 'format', 'yyyyMMdd'),
           JSON_OBJECT('type', 'SEQUENCE', 'resetBy', 'DAY', 'startAt', 1,
                       'maxValue', 9999, 'paddingLen', 4, 'paddingChar', '0')
       ), '-', 1, 0, 'segment', 0, '空木箱编码', '1', '1', 0
WHERE NOT EXISTS (SELECT 1 FROM base_code_rule WHERE rule_code = 'BOX_CODE' AND deleted = 0);
