
-- ----------------------------
-- 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='备品备件变动记录表';

