
-- ----------------------------
-- Table structure for eqp_auxiliary_material
-- ----------------------------
DROP TABLE IF EXISTS `eqp_auxiliary_material`;
CREATE TABLE `eqp_auxiliary_material`  (
  `auxiliary_id` bigint NOT NULL AUTO_INCREMENT COMMENT '辅料ID',
  `auxiliary_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '辅料名称',
  `material_category` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '物料品类',
  `auxiliary_model` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '辅料型号',
  `unit` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '计量单位',
  `equipment_id` bigint NULL DEFAULT NULL COMMENT '关联设备ID（可为空，通用辅料）',
  `quantity` int NULL DEFAULT 0 COMMENT '当前库存数量',
  `unit_price` decimal(18, 6) NULL DEFAULT 0 COMMENT '当前移动加权平均单价',
  `total_amount` decimal(18, 2) NULL DEFAULT 0 COMMENT '当前库存总金额（可冗余，= quantity * unit_price）',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建者',
  `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '更新者',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '删除标志（0=存在 2=删除）',
  `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '备注',
  PRIMARY KEY (`auxiliary_id`) USING BTREE,
  INDEX `fk_auxiliary_equipment`(`equipment_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2007691600657760258 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '辅料表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for eqp_auxiliary_material_change
-- ----------------------------
DROP TABLE IF EXISTS `eqp_auxiliary_material_change`;
CREATE TABLE `eqp_auxiliary_material_change`  (
  `change_id` bigint NOT NULL AUTO_INCREMENT COMMENT '变动记录ID',
  `auxiliary_id` bigint NOT NULL COMMENT '关联辅料ID',
  `change_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '变动类型（增加/减少）',
  `change_quantity` int NOT NULL COMMENT '变动数量',
  `in_unit_price` decimal(18, 6) NULL DEFAULT NULL COMMENT '入库单价（仅增加时有意义）',
  `unit_price_snapshot` decimal(18, 6) NULL DEFAULT NULL COMMENT '单价快照（减少时必填，增加时可记录入库后单价）',
  `amount` decimal(18, 2) NULL DEFAULT NULL COMMENT '本次变动金额（有符号；建议减少时为负数：-unit_price_snapshot*change_quantity）',
  `reason` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '变动原因',
  `change_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '变动时间',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建者',
  `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '更新者',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '删除标志（0=存在 2=删除）',
  `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '备注',
  PRIMARY KEY (`change_id`) USING BTREE,
  INDEX `fk_change_auxiliary`(`auxiliary_id` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2007692247788535810 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '辅料变动记录表' ROW_FORMAT = DYNAMIC;




CREATE TABLE `eqp_spare_part` (
  `part_id` bigint NOT NULL AUTO_INCREMENT COMMENT '备件ID',
  `part_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '备件名称',
  `material_category` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '物料品类',
  `model` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '备件型号',
  `unit` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '计量单位',
  `equipment_id` bigint DEFAULT NULL COMMENT '关联设备ID（可为空，通用备件）',
  `quantity` int DEFAULT '0' COMMENT '当前库存数量',
  `unit_price` decimal(18, 6) NULL DEFAULT 0 COMMENT '当前移动加权平均单价',
  `total_amount` decimal(18, 2) NULL DEFAULT 0 COMMENT '当前库存总金额（可冗余，= quantity * unit_price）',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '创建者',
  `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '更新者',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '删除标志（0=存在 2=删除）',
  `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '备注',
  PRIMARY KEY (`part_id`) USING BTREE,
  KEY `fk_part_equipment` (`equipment_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1979376133262389251 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='备品备件表';



CREATE TABLE `eqp_spare_parts_change` (
  `change_id` bigint NOT NULL AUTO_INCREMENT COMMENT '变动记录ID',
  `part_id` bigint NOT NULL COMMENT '关联备件ID',
  `change_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '变动类型（增加/减少）',
  `change_quantity` int NOT NULL COMMENT '变动数量',
  `in_unit_price` decimal(18, 6) NULL DEFAULT NULL COMMENT '入库单价',
  `unit_price_snapshot` decimal(18, 6) NULL DEFAULT NULL COMMENT '单价快照（减少时必填，增加时可记录入库后单价）',
  `amount` decimal(18, 2) NULL DEFAULT NULL COMMENT '本次变动金额（有符号；建议减少时为负数：-unit_price_snapshot*change_quantity）',
  `reason` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '变动原因',
  `change_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '变动时间',
  `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '创建者',
  `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '更新者',
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '删除标志（0=存在 2=删除）',
  `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '备注',
  PRIMARY KEY (`change_id`) USING BTREE,
  KEY `fk_change_part` (`part_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1980201774324969474 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='备品备件变动记录表';

create table wms_material_coil
(
    coil_id               bigint auto_increment comment '主键ID'
        primary key,
    enter_coil_no         varchar(50)                          not null comment '入场钢卷号（年份后两位+月份+当月第几个，如25100001、25102422）',
    current_coil_no       varchar(50)                          not null comment '当前钢卷号（入场钢卷号和当前钢卷号可能不同）',
    supplier_coil_no      varchar(50)                          null comment '厂家原料卷号',
    data_type             tinyint(1) default 1                 not null comment '数据类型（0=历史，1=现存）',
    warehouse_id          bigint                               null comment '所在库区ID',
    next_warehouse_id     bigint                               null comment '下一库区ID',
    actual_warehouse_id   bigint                               null comment '所在实际库区ID（关联wms_actual_warehouse表）',
    qrcode_record_id      bigint                               null comment '关联二维码ID（wms_generate_record.record_id）',
    team                  varchar(50)                          null comment '班组',
    has_merge_split       tinyint(1) default 0                 not null comment '是否合卷/分卷（0=否，1=分卷，2=合卷）',
    parent_coil_nos       varchar(500)                         null comment '父卷号（合卷或分卷时用，逗号分隔）',
    item_id               bigint                               not null comment '物品ID（指向原材料或产品主键）',
    item_type             varchar(20)                          not null comment '物品类型（raw_material/product）',
    material_type         varchar(20)                          null comment '材料类型(废品，成品，原料)',
    quality_status        varchar(20)                          null comment '质量状态（C+,C,C-,D+,D,D-为次品，ABC*为良品）',
    status                tinyint(1) default 0                 null comment '状态（0=在库，1=已出库）',
    remark                varchar(255)                         null comment '备注',
    export_time           datetime                             null comment '发货时间',
    del_flag              tinyint(1) default 0                 not null comment '删除标志（0=正常，1=已删除）',
    create_time           datetime   default CURRENT_TIMESTAMP not null comment '创建时间',
    create_by             varchar(50)                          null comment '创建人',
    update_time           datetime   default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
    update_by             varchar(50)                          null comment '更新人',
    gross_weight          decimal(10, 3)                       null comment '毛重',
    net_weight            decimal(10, 3)                       null comment '毛重',
    length                decimal(10, 3)                       null comment '钢卷长度（单位：米）',
    trimming_requirement  varchar(100)                         null comment '切边要求',
    packing_status        varchar(20)                          null comment '打包状态（0=未打包，1=已打包）',
    packaging_requirement varchar(255)                         null comment '包装要求',
    sale_id               bigint                               null comment '销售id',
    constraint fk_coil_next_warehouse
        foreign key (next_warehouse_id) references wms_warehouse (warehouse_id),
    constraint fk_coil_qrcode
        foreign key (qrcode_record_id) references wms_generate_record (record_id)
)
    comment '钢卷物料表';

create index idx_coil_current_no
    on wms_material_coil (current_coil_no);

create index idx_coil_type
    on wms_material_coil (data_type);

create index idx_coil_warehouse
    on wms_material_coil (warehouse_id);

create index idx_mc_coil_id
    on wms_material_coil (coil_id);

create index idx_mc_core
    on wms_material_coil (del_flag, data_type, status, material_type, actual_warehouse_id, item_type, item_id);

create index idx_mc_data_type
    on wms_material_coil (data_type);

create index idx_mc_del_awh
    on wms_material_coil (del_flag, actual_warehouse_id);

create index idx_mc_del_create
    on wms_material_coil (del_flag, create_time);

create index idx_mc_del_item
    on wms_material_coil (del_flag, item_type, item_id);

create index idx_mc_del_status_sale
    on wms_material_coil (del_flag, status, sale_id);

create index idx_mc_del_update
    on wms_material_coil (del_flag, update_time);

create index idx_mc_del_wh
    on wms_material_coil (del_flag, warehouse_id);

create index idx_mc_enter_coil_no
    on wms_material_coil (enter_coil_no);

create index idx_mc_fixed_group
    on wms_material_coil (del_flag, data_type, status, item_type, actual_warehouse_id, item_id);

create index idx_mc_has_merge_split
    on wms_material_coil (has_merge_split);

create index idx_mc_team
    on wms_material_coil (team);




create table wms_coil_pending_action
(
    action_id       bigint auto_increment comment '主键ID'
        primary key,
    coil_id         bigint                                not null comment '关联的钢卷ID',
    current_coil_no varchar(50)                           not null comment '当前钢卷号',
    action_type     int                                   not null comment '操作类型（1=分卷，2=合卷，3=更新）',
    action_status   tinyint(1)  default 0                 not null comment '操作状态（0=待处理，1=处理中，2=已完成，3=已取消）',
    scan_time       datetime                              null comment '扫码时间',
    scan_device     varchar(100)                          null comment '扫码设备（移动端设备信息）',
    priority        tinyint(1)  default 0                 null comment '优先级（0=普通，1=重要，2=紧急）',
    source_type     varchar(20) default 'scan'            not null comment '来源类型（scan=扫码，manual=手动创建）',
    warehouse_id    bigint                                null comment '所在库区ID',
    operator_id     bigint                                null comment '操作人ID',
    operator_name   varchar(50)                           null comment '操作人姓名',
    process_time    datetime                              null comment '处理时间',
    complete_time   datetime                              null comment '完成时间',
    remark          varchar(500)                          null comment '备注',
    del_flag        tinyint(1)  default 0                 not null comment '删除标志（0=正常，1=已删除）',
    create_time     datetime    default CURRENT_TIMESTAMP not null comment '创建时间',
    create_by       varchar(50)                           null comment '创建人',
    update_time     datetime    default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
    update_by       varchar(50)                           null comment '更新人'
)
    comment '钢卷待操作表';

create index idx_action_status
    on wms_coil_pending_action (action_status);

create index idx_action_type
    on wms_coil_pending_action (action_type);

create index idx_coil_id
    on wms_coil_pending_action (coil_id);

create index idx_scan_time
    on wms_coil_pending_action (scan_time);

create index idx_warehouse_id
    on wms_coil_pending_action (warehouse_id);
