-- ============================================================================
-- 物料表 (biz_material) 初始化数据
-- 适用数据库: MySQL 8.0+
-- 注意事项: 执行前请确认目标数据库字符集支持 utf8mb4
-- ============================================================================

-- 设置安全执行环境
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- 临时关闭严格模式，避免零日期报错（如果目标数据库有该限制）
SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- ----------------------------
-- 1. 创建物料表 (如已存在则重建)
-- ----------------------------
DROP TABLE IF EXISTS `biz_material`;
CREATE TABLE `biz_material` (
  `material_id`       bigint       NOT NULL AUTO_INCREMENT,
  `tenant_id`         bigint       NOT NULL DEFAULT 1,
  `category_id`       bigint       NULL     DEFAULT 0,
  `material_code`     varchar(50)  CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物料编码',
  `material_name`     varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物料名称',
  `spec`              varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '' COMMENT '规格型号',
  `unit`              varchar(50)  CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '' COMMENT '单位',
  `brand`             varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT NULL COMMENT '厂家/品牌',
  `description`       text         CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '描述',
  `status`            char(1)      CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '0',
  `create_by`         varchar(64)  CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '',
  `create_time`       datetime     NULL     DEFAULT NULL,
  `update_by`         varchar(64)  CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '',
  `update_time`       datetime     NULL     DEFAULT NULL,
  `remark`            varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT NULL,
  `performance_params` text        CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '性能参数(JSON格式)',
  `material`          varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '' COMMENT '材质(铜/铝合金/PVC等)',
  `purpose`           varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '' COMMENT '用途',
  `image_url`         varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL     DEFAULT '' COMMENT '物料图片URL',
  PRIMARY KEY (`material_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '物料' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- 2. 插入物料基础数据
-- ----------------------------
INSERT INTO `biz_material` (
  `material_id`, `tenant_id`, `category_id`, `material_code`, `material_name`,
  `spec`, `unit`, `brand`, `description`, `status`,
  `create_by`, `create_time`, `update_by`, `update_time`,
  `remark`, `performance_params`, `material`, `purpose`, `image_url`
) VALUES
(1,  1,   0, 'M-EL-001', '伺服电机',
 '额定功率750W，额定转矩2.4N·m，额定转速3000rpm', '台', '松下/安川', NULL, '0',
 'admin', '2025-12-01 10:00:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(2,  1,   0, 'M-EL-002', '变频器',
 '三相380V输入，7.5kW，IP20防护', '台', 'ABB/西门子', NULL, '0',
 'admin', '2025-12-01 10:05:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(3,  1,   0, 'M-EL-003', 'PLC控制器',
 'CPU模块，数字量I/O 40点，以太网接口', '套', '西门子S7-1200', NULL, '0',
 'admin', '2025-12-01 10:10:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(4,  1,   0, 'M-EL-004', '工业交换机',
 '8口千兆以太网，导轨安装，宽温型', '台', '赫斯曼/菲尼克斯', NULL, '0',
 'admin', '2025-12-02 09:00:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(5,  1,   0, 'M-ME-001', '精密导轨',
 'THK型，长度1500mm，宽度35mm', '根', 'THK/上银', NULL, '0',
 'admin', '2025-12-02 09:05:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(6,  1,   0, 'M-ME-002', '滚珠丝杠',
 '直径32mm，导程10mm，长度1200mm', '套', 'NSK/银泰', NULL, '0',
 'admin', '2025-12-02 09:10:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(7,  1,   0, 'M-ME-003', '减速机',
 '行星减速比1:10，输出扭矩150N·m，法兰安装', '台', '纽卡特/APEX', NULL, '0',
 'admin', '2025-12-03 10:00:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(8,  1,   0, 'M-EL-005', '触摸屏',
 '7寸TFT，分辨率1024×600，RS485/以太网', '台', '威纶通/昆仑通态', NULL, '0',
 'admin', '2025-12-04 10:00:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(9,  1,   0, 'M-ME-004', '气动电磁阀',
 '5/2通，DC24V，G1/4接口，响应时间≤15ms', '只', 'SMC/费斯托', NULL, '0',
 'admin', '2025-12-05 10:00:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(10, 1,   0, 'M-EL-006', '电源模块',
 '24VDC/10A，输入85-264VAC，效率≥90%', '台', '明纬/西门子', NULL, '0',
 'admin', '2025-12-05 10:05:00', NULL, NULL,
 NULL, NULL, '', '', ''),

(11, 103, NULL, 'M-EL-003-1', 'PLC控制器',
 'I/O 模块：连接传感器、执行器（数字量/模拟量输入输出）', '套', '三菱FX/iQ-R 系列', NULL, '0',
 'admin', '2026-05-29 09:43:31', 'admin', '2026-05-29 09:44:42',
 NULL, '[]', NULL, NULL, NULL);

-- ----------------------------
-- 3. 恢复外键检查
-- ----------------------------
SET FOREIGN_KEY_CHECKS = 1;
