-- ============================================================
-- our-itam 资产管理数据库初始化脚本
-- UUID v7 主键版本
-- ============================================================

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ============================================================
-- UUID v7 种子数据（预生成，时间有序）
-- ============================================================
SET @uid_admin     = '019e3035-d8be-72ea-9599-7c8d9a68c4ca';
SET @did_companies = '019e3035-d8bf-706e-bd16-522c70829c79'; -- 总公司
SET @did_it        = '019e3035-d8bf-706e-bd17-224931a5bb89'; -- IT部
SET @did_finance   = '019e3035-d8bf-706e-bd18-aa5d97f9e80e'; -- 财务部
SET @rid_admin     = '019e3035-d8bf-706e-bd19-dd4dfc2632cf'; -- 超级管理员
SET @rid_itadmin   = '019e3035-d8bf-706e-bd1a-3a74593c97a4'; -- IT管理员
SET @rid_user      = '019e3035-d8c0-7e72-bd27-e8bd3cf6788e'; -- 普通用户

SET @cid_1  = '019e3035-d8c0-7e72-bd28-fd7262aa0431'; -- IT设备
SET @cid_2  = '019e3035-d8c0-7e72-bd29-ad5352d98cff'; -- 服务器
SET @cid_3  = '019e3035-d8c0-7e72-bd2a-9e07f1f23da5'; -- PC/笔记本
SET @cid_4  = '019e3035-d8c0-7e72-bd2b-555dd8501aba'; -- 网络设备
SET @cid_5  = '019e3035-d8c0-7e72-bd2c-42e63da87ea5'; -- 路由器
SET @cid_6  = '019e3035-d8c1-76cf-9c75-050fad3450e6'; -- 交换机
SET @cid_7  = '019e3035-d8c1-76cf-9c76-11b87304fe61'; -- IT许可
SET @cid_8  = '019e3035-d8c1-76cf-9c77-8a12cb4ec0b9'; -- 软件许可
SET @cid_9  = '019e3035-d8c1-76cf-9c78-77d0601448b5'; -- SaaS许可
SET @cid_10 = '019e3035-d8ce-74ee-9816-98ad2f2d6681'; -- IT配件
SET @cid_11 = '019e3035-d8ce-74ee-9817-64b60562c76c'; -- 电源配件
SET @cid_12 = '019e3035-d8cf-759c-9fa9-a68c1ec47f34'; -- 网络配件
SET @cid_13 = '019e3035-d8cf-759c-9faa-723872d1e191'; -- 办公耗材
SET @cid_14 = '019e3036-e597-7938-be1f-067966358dec'; -- 打印耗材
SET @cid_15 = '019e3036-e598-7269-a9cc-85204d4a5630'; -- IT服务
SET @cid_16 = '019e3036-e598-7269-a9cd-4c55c37f6619'; -- 运维服务

-- ============================================================
-- 系统表
-- ============================================================

-- 部门表
DROP TABLE IF EXISTS `sys_dept`;
CREATE TABLE `sys_dept` (
  `id` char(36) NOT NULL COMMENT '部门ID',
  `parent_id` char(36) DEFAULT NULL COMMENT '父部门ID',
  `dept_name` varchar(30) DEFAULT '' COMMENT '部门名称',
  `order_num` int DEFAULT 0 COMMENT '排序',
  `leader` varchar(20) DEFAULT NULL COMMENT '负责人',
  `phone` varchar(11) DEFAULT NULL COMMENT '电话',
  `email` varchar(50) DEFAULT NULL COMMENT '邮箱',
  `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 2删除)',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='部门表';

-- 用户表
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
  `id` char(36) NOT NULL COMMENT '用户ID',
  `dept_id` char(36) DEFAULT NULL COMMENT '部门ID',
  `user_name` varchar(30) NOT NULL COMMENT '登录账号',
  `nick_name` varchar(30) NOT NULL COMMENT '用户昵称',
  `email` varchar(50) DEFAULT '' COMMENT '邮箱',
  `phonenumber` varchar(11) DEFAULT '' COMMENT '手机号',
  `sex` char(1) DEFAULT '0' COMMENT '性别(0男 1女 2未知)',
  `avatar` varchar(100) DEFAULT '' COMMENT '头像',
  `password` varchar(100) DEFAULT '' COMMENT '密码(BCrypt加密)',
  `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志',
  `login_ip` varchar(128) DEFAULT '' COMMENT '最后登录IP',
  `login_date` datetime DEFAULT NULL COMMENT '最后登录时间',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户表';

-- 角色表
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role` (
  `id` char(36) NOT NULL COMMENT '角色ID',
  `role_name` varchar(30) NOT NULL COMMENT '角色名称',
  `role_key` varchar(100) NOT NULL COMMENT '角色标识',
  `role_sort` int DEFAULT 0 COMMENT '排序',
  `data_scope` char(1) DEFAULT '1' COMMENT '数据范围',
  `status` char(1) NOT NULL DEFAULT '0' COMMENT '状态',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色表';

-- 菜单表
DROP TABLE IF EXISTS `sys_menu`;
CREATE TABLE `sys_menu` (
  `id` char(36) NOT NULL COMMENT '菜单ID',
  `menu_name` varchar(50) NOT NULL COMMENT '菜单名称',
  `parent_id` char(36) DEFAULT '0' COMMENT '父菜单ID',
  `order_num` int DEFAULT 0 COMMENT '排序',
  `path` varchar(200) DEFAULT '' COMMENT '路由地址',
  `component` varchar(255) DEFAULT NULL COMMENT '组件路径',
  `menu_type` char(1) DEFAULT '' COMMENT '类型(M目录 C菜单 F按钮)',
  `visible` char(1) DEFAULT '0' COMMENT '菜单状态(0显示 1隐藏)',
  `status` char(1) DEFAULT '0' COMMENT '菜单状态(0正常 1停用)',
  `perms` varchar(100) DEFAULT NULL COMMENT '权限标识',
  `icon` varchar(100) DEFAULT '#' COMMENT '菜单图标',
  `remark` varchar(500) DEFAULT '' COMMENT '备注',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='菜单表';

-- 用户角色关联表
DROP TABLE IF EXISTS `sys_user_role`;
CREATE TABLE `sys_user_role` (
  `user_id` char(36) NOT NULL COMMENT '用户ID',
  `role_id` char(36) NOT NULL COMMENT '角色ID',
  PRIMARY KEY (`user_id`,`role_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户角色关联';

-- 角色菜单关联表
DROP TABLE IF EXISTS `sys_role_menu`;
CREATE TABLE `sys_role_menu` (
  `role_id` char(36) NOT NULL COMMENT '角色ID',
  `menu_id` char(36) NOT NULL COMMENT '菜单ID',
  PRIMARY KEY (`role_id`,`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色菜单关联';


-- ============================================================
-- 资产核心表
-- ============================================================

-- 分类表
DROP TABLE IF EXISTS `itam_categories`;
CREATE TABLE `itam_categories` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '分类名称',
  `code` varchar(50) NOT NULL COMMENT '分类编码',
  `parent_id` char(36) DEFAULT NULL COMMENT '父级ID',
  `category_type` varchar(50) NOT NULL COMMENT '分类大类(device/license/accessory/consumable/service)',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_code` (`code`),
  KEY `idx_parent` (`parent_id`),
  KEY `idx_type` (`category_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='分类表';

-- 厂商表
DROP TABLE IF EXISTS `itam_manufacturers`;
CREATE TABLE `itam_manufacturers` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '厂商名称',
  `url` varchar(255) DEFAULT NULL COMMENT '官网地址',
  `support_url` varchar(255) DEFAULT NULL COMMENT '支持URL',
  `warranty_url` varchar(255) DEFAULT NULL COMMENT '保修查询URL',
  `support_phone` varchar(50) DEFAULT NULL COMMENT '支持电话',
  `support_email` varchar(50) DEFAULT NULL COMMENT '支持邮箱',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='厂商表';

-- 型号表
DROP TABLE IF EXISTS `itam_models`;
CREATE TABLE `itam_models` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '型号名称',
  `model_number` varchar(255) DEFAULT NULL COMMENT '型号编号',
  `manufacturer_id` char(36) DEFAULT NULL COMMENT '厂商ID',
  `category_id` char(36) DEFAULT NULL COMMENT '分类ID',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_manufacturer` (`manufacturer_id`),
  KEY `idx_category` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='型号表';

-- 位置表
DROP TABLE IF EXISTS `itam_locations`;
CREATE TABLE `itam_locations` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '位置名称',
  `building` varchar(255) DEFAULT NULL COMMENT '建筑物',
  `room` varchar(255) DEFAULT NULL COMMENT '房间号',
  `address` varchar(500) DEFAULT NULL COMMENT '详细地址',
  `city` varchar(100) DEFAULT NULL COMMENT '城市',
  `state` varchar(100) DEFAULT NULL COMMENT '省/州',
  `country` varchar(100) DEFAULT NULL COMMENT '国家',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_building` (`building`),
  KEY `idx_room` (`room`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='位置表';

-- 供应商表
DROP TABLE IF EXISTS `itam_suppliers`;
CREATE TABLE `itam_suppliers` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '供应商名称',
  `contact_name` varchar(255) DEFAULT NULL COMMENT '联系人',
  `phone` varchar(50) DEFAULT NULL COMMENT '联系电话',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='供应商表';

-- 折旧规则表
DROP TABLE IF EXISTS `itam_depreciations`;
CREATE TABLE `itam_depreciations` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '折旧规则名称',
  `status` tinyint DEFAULT 1 COMMENT '1启用 0停用',
  `months` int NOT NULL COMMENT '总折旧月数',
  `floor_type` varchar(20) NOT NULL DEFAULT 'amount' COMMENT '残值类型(amount/percent)',
  `floor_val` decimal(18,2) NOT NULL COMMENT '残值',
  `stages` json DEFAULT NULL COMMENT '分阶段折旧规则',
  `remark` varchar(500) DEFAULT NULL COMMENT '描述',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='折旧规则表';

-- 设备表
DROP TABLE IF EXISTS `itam_device`;
CREATE TABLE `itam_device` (
  `id` char(36) NOT NULL COMMENT '主键',
  `model_id` char(36) NOT NULL COMMENT '关联型号ID',
  `category_id` char(36) DEFAULT NULL COMMENT '分类ID',
  `assets_status` varchar(50) NOT NULL DEFAULT '1' COMMENT '资产状态(1在库/2在用/3维修/4报废)',
  `serial` varchar(255) DEFAULT NULL COMMENT '序列号',
  `device_no` varchar(100) DEFAULT NULL COMMENT '设备编号',
  `name` varchar(255) DEFAULT NULL COMMENT '设备名称',
  `image_url` varchar(500) DEFAULT NULL COMMENT '设备图片',
  `purchase_date` date DEFAULT NULL COMMENT '购买日期',
  `purchase_cost` decimal(18,2) DEFAULT NULL COMMENT '购买成本',
  `warranty_date` date DEFAULT NULL COMMENT '过保日期',
  `assigned_to` char(36) DEFAULT NULL COMMENT '分配给谁(User ID)',
  `location_id` char(36) DEFAULT NULL COMMENT '物理位置ID',
  `supplier_id` char(36) DEFAULT NULL COMMENT '供应商ID',
  `depreciation_id` char(36) DEFAULT NULL COMMENT '折旧规则ID',
  `description` text COMMENT '描述',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_serial` (`serial`),
  KEY `idx_model` (`model_id`),
  KEY `idx_status` (`assets_status`),
  KEY `idx_assigned` (`assigned_to`),
  KEY `idx_location` (`location_id`),
  KEY `idx_supplier` (`supplier_id`),
  KEY `idx_depreciation` (`depreciation_id`),
  KEY `idx_category` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='设备表';

-- 软件授权表
DROP TABLE IF EXISTS `itam_licenses`;
CREATE TABLE `itam_licenses` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '软件名称',
  `license_key` varchar(500) NOT NULL COMMENT '序列号/密钥',
  `total_seats` bigint NOT NULL COMMENT '总授权数',
  `manufacturer_id` char(36) DEFAULT NULL COMMENT '厂商ID',
  `category_id` char(36) DEFAULT NULL COMMENT '分类ID',
  `min_qty` bigint DEFAULT NULL COMMENT '最少数量(库存预警)',
  `licensed_to_name` varchar(255) DEFAULT NULL COMMENT '许可人名字',
  `licensed_to_email` varchar(255) DEFAULT NULL COMMENT '许可人邮箱',
  `supplier_id` char(36) DEFAULT NULL COMMENT '供应商ID',
  `order_number` varchar(255) DEFAULT NULL COMMENT '订单号',
  `purchase_cost` decimal(18,2) DEFAULT NULL COMMENT '采购价格',
  `purchase_date` datetime DEFAULT NULL COMMENT '购买日期',
  `expiration_date` datetime DEFAULT NULL COMMENT '到期日期',
  `termination_date` datetime DEFAULT NULL COMMENT '终止日期',
  `notes` text COMMENT '备注',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_manufacturer` (`manufacturer_id`),
  KEY `idx_expiration` (`expiration_date`),
  KEY `idx_category` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='软件授权表';

-- 配件表
DROP TABLE IF EXISTS `itam_accessories`;
CREATE TABLE `itam_accessories` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '配件名称',
  `asset_number` varchar(255) DEFAULT NULL COMMENT '资产编号',
  `category_id` char(36) NOT NULL COMMENT '分类ID',
  `supplier_id` char(36) DEFAULT NULL COMMENT '供应商ID',
  `manufacturer_id` char(36) DEFAULT NULL COMMENT '厂商ID',
  `specifications` varchar(255) DEFAULT NULL COMMENT '规格',
  `location_id` char(36) DEFAULT NULL COMMENT '存放位置ID',
  `depreciation_id` char(36) DEFAULT NULL COMMENT '折旧规则ID',
  `quantity` int NOT NULL COMMENT '数量',
  `min_quantity` int DEFAULT NULL COMMENT '最小库存预警',
  `purchase_date` date DEFAULT NULL COMMENT '购买日期',
  `warranty_expiration_date` date DEFAULT NULL COMMENT '过保日期',
  `purchase_cost` decimal(18,2) DEFAULT NULL COMMENT '购买成本',
  `order_number` varchar(255) DEFAULT NULL COMMENT '订单号',
  `serial_number` varchar(255) DEFAULT NULL COMMENT '序列号',
  `description` text COMMENT '描述',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_category` (`category_id`),
  KEY `idx_supplier` (`supplier_id`),
  KEY `idx_manufacturer` (`manufacturer_id`),
  KEY `idx_location` (`location_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='配件表';

-- 耗材表
DROP TABLE IF EXISTS `itam_consumables`;
CREATE TABLE `itam_consumables` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '耗材名称',
  `category_id` char(36) NOT NULL COMMENT '分类ID',
  `manufacturer_id` char(36) DEFAULT NULL COMMENT '厂商ID',
  `item_no` varchar(255) DEFAULT NULL COMMENT '物品编号/型号',
  `order_number` varchar(255) DEFAULT NULL COMMENT '采购单号',
  `purchase_date` date DEFAULT NULL COMMENT '购买日期',
  `purchase_cost` decimal(18,2) DEFAULT NULL COMMENT '购买成本',
  `quantity` int NOT NULL COMMENT '当前库存数量',
  `min_quantity` int DEFAULT NULL COMMENT '最小库存预警',
  `location_id` char(36) DEFAULT NULL COMMENT '存放位置ID',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_name` (`name`),
  KEY `idx_category` (`category_id`),
  KEY `idx_manufacturer` (`manufacturer_id`),
  KEY `idx_location` (`location_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='耗材表';

-- 耗材出入库明细表
DROP TABLE IF EXISTS `itam_consumable_transactions`;
CREATE TABLE `itam_consumable_transactions` (
  `id` char(36) NOT NULL COMMENT '主键',
  `consumable_id` char(36) NOT NULL COMMENT '耗材ID',
  `operator_id` char(36) NOT NULL COMMENT '操作人ID',
  `action_type` varchar(50) NOT NULL COMMENT '变动类型(STOCK_IN入库/STOCK_OUT出库/ADJUST调整)',
  `quantity` int NOT NULL COMMENT '变动数量',
  `remaining_quantity` int NOT NULL COMMENT '变动后结存',
  `target_type` varchar(50) DEFAULT NULL COMMENT '关联对象类型',
  `target_id` char(36) DEFAULT NULL COMMENT '关联对象ID',
  `note` text COMMENT '备注',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_consumable` (`consumable_id`),
  KEY `idx_operator` (`operator_id`),
  KEY `idx_target` (`target_type`,`target_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='耗材出入库明细表';

-- 资产分配/领用表
DROP TABLE IF EXISTS `itam_allocations`;
CREATE TABLE `itam_allocations` (
  `id` char(36) NOT NULL COMMENT '主键',
  `item_type` varchar(50) NOT NULL COMMENT '资源类型(device/license/accessory)',
  `item_id` char(36) NOT NULL COMMENT '资源ID',
  `owner_type` varchar(50) NOT NULL COMMENT '归属者类型(user/location)',
  `owner_id` char(36) NOT NULL COMMENT '归属者ID',
  `quantity` int NOT NULL DEFAULT 1 COMMENT '数量',
  `status` varchar(50) NOT NULL DEFAULT 'active' COMMENT '状态(reserved预约/active占用/returned已归还)',
  `assign_date` datetime NOT NULL COMMENT '分配时间',
  `expected_return_date` datetime DEFAULT NULL COMMENT '预计归还时间',
  `return_date` datetime DEFAULT NULL COMMENT '实际归还时间',
  `note` varchar(255) DEFAULT NULL COMMENT '备注',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_item` (`item_type`,`item_id`),
  KEY `idx_owner` (`owner_type`,`owner_id`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='资产分配/领用表';

-- 故障报修表
DROP TABLE IF EXISTS `itam_failures`;
CREATE TABLE `itam_failures` (
  `id` char(36) NOT NULL COMMENT '主键',
  `target_type` varchar(50) NOT NULL COMMENT '关联类型(device/accessory)',
  `target_id` char(36) NOT NULL COMMENT '关联目标ID',
  `failure_name` varchar(255) NOT NULL COMMENT '故障名称',
  `failure_description` text COMMENT '故障描述',
  `failure_date` datetime NOT NULL COMMENT '故障发生时间',
  `status` varchar(50) NOT NULL DEFAULT 'open' COMMENT '状态(open待处理/in_progress处理中/resolved已修复/closed已关闭)',
  `reported_by` char(36) DEFAULT NULL COMMENT '报告人ID',
  `resolved_by` char(36) DEFAULT NULL COMMENT '修复人ID',
  `resolved_date` datetime DEFAULT NULL COMMENT '修复日期',
  `notes` text COMMENT '备注',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_target` (`target_type`,`target_id`),
  KEY `idx_status` (`status`),
  KEY `idx_reported` (`reported_by`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='故障报修表';

-- 盘点任务表
DROP TABLE IF EXISTS `itam_stocktakes`;
CREATE TABLE `itam_stocktakes` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '盘点任务名称',
  `location_id` char(36) DEFAULT NULL COMMENT '盘点位置范围ID',
  `category_id` char(36) DEFAULT NULL COMMENT '盘点分类范围ID',
  `status` varchar(50) NOT NULL DEFAULT 'planning' COMMENT '状态(planning/executing/completed)',
  `manager_id` char(36) NOT NULL COMMENT '负责人ID',
  `start_date` datetime DEFAULT NULL COMMENT '计划开始日期',
  `end_date` datetime DEFAULT NULL COMMENT '计划/实际结束日期',
  `note` text COMMENT '备注',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_manager` (`manager_id`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='盘点任务表';

-- 盘点明细表
DROP TABLE IF EXISTS `itam_stocktake_items`;
CREATE TABLE `itam_stocktake_items` (
  `id` char(36) NOT NULL COMMENT '主键',
  `stocktake_id` char(36) NOT NULL COMMENT '盘点任务ID',
  `item_type` varchar(50) NOT NULL COMMENT '资产类型(device/license/accessory)',
  `item_id` char(36) NOT NULL COMMENT '资产ID',
  `system_quantity` int NOT NULL DEFAULT 0 COMMENT '系统数量',
  `actual_quantity` int DEFAULT NULL COMMENT '实际盘点数量',
  `status` varchar(50) NOT NULL DEFAULT 'pending' COMMENT '状态(pending/checking/matched/mismatch/error)',
  `note` text COMMENT '备注',
  `checked_by` char(36) DEFAULT NULL COMMENT '盘点人ID',
  `checked_time` datetime DEFAULT NULL COMMENT '盘点时间',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_stocktake` (`stocktake_id`),
  KEY `idx_item` (`item_type`,`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='盘点明细表';

-- 资产申请表
DROP TABLE IF EXISTS `itam_asset_requests`;
CREATE TABLE `itam_asset_requests` (
  `id` char(36) NOT NULL COMMENT '主键',
  `request_no` varchar(64) DEFAULT NULL COMMENT '申请单号',
  `user_id` char(36) NOT NULL COMMENT '申请人ID',
  `item_type` varchar(32) NOT NULL COMMENT '资产类型(device/license/accessory)',
  `category_id` char(36) DEFAULT NULL COMMENT '申请分类ID',
  `item_id` char(36) DEFAULT NULL COMMENT '资产ID',
  `quantity` int NOT NULL DEFAULT 1 COMMENT '数量',
  `reason` varchar(500) DEFAULT NULL COMMENT '申请原因',
  `status` varchar(32) DEFAULT 'pending' COMMENT '状态(pending/approved/rejected/canceled)',
  `approver_id` char(36) DEFAULT NULL COMMENT '审批人ID',
  `approval_time` datetime DEFAULT NULL COMMENT '审批时间',
  `approval_note` varchar(500) DEFAULT NULL COMMENT '审批意见',
  `is_long_term` tinyint(1) DEFAULT 1 COMMENT '是否长期使用',
  `expected_return_time` datetime DEFAULT NULL COMMENT '预计归还时间',
  `deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_request_no` (`request_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='资产申请表';

-- 服务管理表
DROP TABLE IF EXISTS `itam_offering`;
CREATE TABLE `itam_offering` (
  `id` char(36) NOT NULL COMMENT '主键',
  `name` varchar(255) NOT NULL COMMENT '服务名称',
  `supplier_id` char(36) DEFAULT NULL COMMENT '供应商ID',
  `service_number` varchar(255) DEFAULT NULL COMMENT '服务单号/合同号',
  `start_date` datetime DEFAULT NULL COMMENT '开始日期',
  `end_date` datetime DEFAULT NULL COMMENT '结束日期',
  `cost` decimal(18,2) DEFAULT NULL COMMENT '费用',
  `notes` text COMMENT '备注',
  `offering_status` varchar(50) DEFAULT 'active' COMMENT '服务状态(active/expired/cancelled)',
  `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '逻辑删除',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  `update_by` char(36) DEFAULT NULL COMMENT '更新者ID',
  PRIMARY KEY (`id`),
  KEY `idx_supplier` (`supplier_id`),
  KEY `idx_status` (`offering_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='服务管理表';

-- 文件表
DROP TABLE IF EXISTS `sys_file`;
CREATE TABLE `sys_file` (
  `id` char(36) NOT NULL COMMENT '主键',
  `file_name` varchar(255) NOT NULL COMMENT '文件名',
  `original_name` varchar(255) DEFAULT NULL COMMENT '原始文件名',
  `file_path` varchar(500) NOT NULL COMMENT '文件路径',
  `file_size` bigint DEFAULT NULL COMMENT '文件大小(字节)',
  `file_type` varchar(50) DEFAULT NULL COMMENT '文件类型',
  `biz_id` char(36) DEFAULT NULL COMMENT '业务ID',
  `biz_type` varchar(50) DEFAULT NULL COMMENT '业务类型',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `create_by` char(36) DEFAULT NULL COMMENT '创建者ID',
  PRIMARY KEY (`id`),
  KEY `idx_biz` (`biz_type`,`biz_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='文件表';


-- magic-api 备份表
DROP TABLE IF EXISTS `magic_backup_record_v2`;
CREATE TABLE `magic_backup_record_v2` (
  `id` varchar(32) NOT NULL COMMENT '原对象ID',
  `create_date` bigint NOT NULL COMMENT '备份时间',
  `tag` varchar(32) DEFAULT NULL COMMENT '标签',
  `type` varchar(32) DEFAULT NULL COMMENT '类型',
  `name` varchar(64) DEFAULT NULL COMMENT '原名称',
  `content` longblob COMMENT '备份内容',
  `create_by` varchar(64) DEFAULT NULL COMMENT '操作人',
  PRIMARY KEY (`id`, `create_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='magic-api备份记录表';

-- ============================================================
-- 初始数据（UUID v7）
-- ============================================================

-- 初始管理员 (密码: admin123)
INSERT INTO `sys_user` (`id`, `user_name`, `nick_name`, `password`, `status`) VALUES
(@uid_admin, 'admin', '超级管理员', '$2a$10$N.zmdr9k7uOCQb376NoUnuTJ8iAt6Z5EHsM8lE9lBOsl7iKTVKIUi', '0');

-- 初始部门
INSERT INTO `sys_dept` (`id`, `dept_name`, `parent_id`, `order_num`, `status`) VALUES
(@did_companies, '总公司', NULL,                                0, '0'),
(@did_it,        'IT部',   @did_companies,                      1, '0'),
(@did_finance,   '财务部', @did_companies,                      2, '0');

-- 初始角色
INSERT INTO `sys_role` (`id`, `role_name`, `role_key`, `role_sort`, `status`) VALUES
(@rid_admin,   '超级管理员', 'admin',    1, '0'),
(@rid_itadmin, 'IT管理员',   'it_admin', 2, '0'),
(@rid_user,    '普通用户',   'user',     3, '0');

-- 用户角色关联
INSERT INTO `sys_user_role` (`user_id`, `role_id`) VALUES (@uid_admin, @rid_admin);

-- ============================================================
-- 菜单种子数据
-- ============================================================
SET @m_system      = '019e3091-0001-7000-8000-000000000001';
SET @m_user        = '019e3091-0002-7000-8000-000000000001';
SET @m_user_add    = '019e3091-0003-7000-8000-000000000001';
SET @m_user_edit   = '019e3091-0004-7000-8000-000000000001';
SET @m_user_del    = '019e3091-0005-7000-8000-000000000001';
SET @m_user_role   = '019e3091-0006-7000-8000-000000000001';
SET @m_role        = '019e3091-0010-7000-8000-000000000001';
SET @m_role_add    = '019e3091-0011-7000-8000-000000000001';
SET @m_role_edit   = '019e3091-0012-7000-8000-000000000001';
SET @m_role_del    = '019e3091-0013-7000-8000-000000000001';
SET @m_dept        = '019e3091-0020-7000-8000-000000000001';
SET @m_dept_add    = '019e3091-0021-7000-8000-000000000001';
SET @m_dept_edit   = '019e3091-0022-7000-8000-000000000001';
SET @m_dept_del    = '019e3091-0023-7000-8000-000000000001';
SET @m_menu        = '019e3091-0030-7000-8000-000000000001';
SET @m_menu_add    = '019e3091-0031-7000-8000-000000000001';
SET @m_menu_edit   = '019e3091-0032-7000-8000-000000000001';
SET @m_menu_del    = '019e3091-0033-7000-8000-000000000001';
SET @m_perm        = '019e3091-0040-7000-8000-000000000001';
SET @m_asset       = '019e3091-0100-7000-8000-000000000001';
SET @m_device      = '019e3091-0101-7000-8000-000000000001';
SET @m_license     = '019e3091-0102-7000-8000-000000000001';
SET @m_accessory   = '019e3091-0103-7000-8000-000000000001';
SET @m_consumable  = '019e3091-0104-7000-8000-000000000001';
SET @m_depreciation= '019e3091-0105-7000-8000-000000000001';
SET @m_offering    = '019e3091-0106-7000-8000-000000000001';
SET @m_base        = '019e3091-0200-7000-8000-000000000001';
SET @m_category    = '019e3091-0201-7000-8000-000000000001';
SET @m_location    = '019e3091-0202-7000-8000-000000000001';
SET @m_manufacturer= '019e3091-0203-7000-8000-000000000001';
SET @m_model       = '019e3091-0204-7000-8000-000000000001';
SET @m_supplier    = '019e3091-0205-7000-8000-000000000001';
SET @m_biz         = '019e3091-0300-7000-8000-000000000001';
SET @m_failure     = '019e3091-0301-7000-8000-000000000001';
SET @m_stocktake   = '019e3091-0302-7000-8000-000000000001';
SET @m_transaction = '019e3091-0303-7000-8000-000000000001';
SET @m_allocation  = '019e3091-0304-7000-8000-000000000001';
SET @m_request     = '019e3091-0305-7000-8000-000000000001';

INSERT INTO sys_menu (id, menu_name, parent_id, order_num, path, component, menu_type, visible, status, perms, icon, create_time, update_time) VALUES
(@m_system,   '系统管理', NULL,         1, '/system',          '',       'M', '0', '0', NULL,                     'SettingOutlined',    now(), now()),
(@m_user,     '用户管理', @m_system,    1, '/system/user',     '',       'C', '0', '0', 'system:user:list',       'UserOutlined',       now(), now()),
(@m_user_add, '新增用户', @m_user,      1, '',                  '',       'F', '0', '0', 'system:user:add',        '',                   now(), now()),
(@m_user_edit,'编辑用户', @m_user,      2, '',                  '',       'F', '0', '0', 'system:user:edit',       '',                   now(), now()),
(@m_user_del, '删除用户', @m_user,      3, '',                  '',       'F', '0', '0', 'system:user:delete',     '',                   now(), now()),
(@m_user_role,'分配角色', @m_user,      4, '',                  '',       'F', '0', '0', 'system:user:assign_role','',                   now(), now()),

(@m_role,     '角色管理', @m_system,    2, '/system/role',     '',       'C', '0', '0', 'system:role:list',       'TeamOutlined',       now(), now()),
(@m_role_add, '新增角色', @m_role,      1, '',                  '',       'F', '0', '0', 'system:role:add',        '',                   now(), now()),
(@m_role_edit,'编辑角色', @m_role,      2, '',                  '',       'F', '0', '0', 'system:role:edit',       '',                   now(), now()),
(@m_role_del, '删除角色', @m_role,      3, '',                  '',       'F', '0', '0', 'system:role:delete',     '',                   now(), now()),

(@m_dept,     '组织架构', @m_system,    3, '/system/dept',     '',       'C', '0', '0', 'system:dept:list',       'ApartmentOutlined',  now(), now()),
(@m_dept_add, '新增部门', @m_dept,      1, '',                  '',       'F', '0', '0', 'system:dept:add',        '',                   now(), now()),
(@m_dept_edit,'编辑部门', @m_dept,      2, '',                  '',       'F', '0', '0', 'system:dept:edit',       '',                   now(), now()),
(@m_dept_del, '删除部门', @m_dept,      3, '',                  '',       'F', '0', '0', 'system:dept:delete',     '',                   now(), now()),

(@m_menu,     '菜单管理', @m_system,    4, '/system/menu',     '',       'C', '0', '0', 'system:menu:list',       'MenuOutlined',       now(), now()),
(@m_menu_add, '新增菜单', @m_menu,      1, '',                  '',       'F', '0', '0', 'system:menu:add',        '',                   now(), now()),
(@m_menu_edit,'编辑菜单', @m_menu,      2, '',                  '',       'F', '0', '0', 'system:menu:edit',       '',                   now(), now()),
(@m_menu_del, '删除菜单', @m_menu,      3, '',                  '',       'F', '0', '0', 'system:menu:delete',     '',                   now(), now()),

(@m_perm,     '权限管理', @m_system,    5, '/system/permission','',       'C', '0', '0', 'system:permission:manage','SafetyCertificateOutlined', now(), now()),

(@m_asset,        '资产管理', NULL,              2, '/asset',               '',       'M', '0', '0', NULL,                     'HddOutlined',        now(), now()),
(@m_device,       '设备管理', @m_asset,           1, '/asset/device',        '',       'C', '0', '0', 'asset:device:list',       'DesktopOutlined',    now(), now()),
(@m_license,      '软件许可', @m_asset,           2, '/asset/license',       '',       'C', '0', '0', 'asset:license:list',      'SafetyOutlined',     now(), now()),
(@m_accessory,    '配件管理', @m_asset,           3, '/asset/accessory',     '',       'C', '0', '0', 'asset:accessory:list',    'ToolOutlined',       now(), now()),
(@m_consumable,   '耗材管理', @m_asset,           4, '/asset/consumable',    '',       'C', '0', '0', 'asset:consumable:list',   'ExperimentOutlined', now(), now()),
(@m_depreciation, '维保管理', @m_asset,           5, '/asset/depreciation',  '',       'C', '0', '0', 'asset:depreciation:list', 'ClockCircleOutlined', now(), now()),
(@m_offering,     '服务提供', @m_asset,           6, '/asset/offering',      '',       'C', '0', '0', 'asset:offering:list',     'CloudServerOutlined',now(), now()),

(@m_base,         '基础数据', NULL,              3, '/base',                '',       'M', '0', '0', NULL,                     'DatabaseOutlined',   now(), now()),
(@m_category,     '资产分类', @m_base,           1, '/base/category',       '',       'C', '0', '0', 'base:category:list',      'TagOutlined',        now(), now()),
(@m_location,     '存放位置', @m_base,           2, '/base/location',       '',       'C', '0', '0', 'base:location:list',      'EnvironmentOutlined',now(), now()),
(@m_manufacturer, '制造商',   @m_base,           3, '/base/manufacturer',   '',       'C', '0', '0', 'base:manufacturer:list',  'BuildOutlined',      now(), now()),
(@m_model,        '型号',     @m_base,           4, '/base/model',          '',       'C', '0', '0', 'base:model:list',         'BarcodeOutlined',    now(), now()),
(@m_supplier,     '供应商',   @m_base,           5, '/base/supplier',       '',       'C', '0', '0', 'base:supplier:list',      'ShopOutlined',       now(), now()),

(@m_biz,          '业务管理', NULL,              4, '/biz',                 '',       'M', '0', '0', NULL,                     'ProfileOutlined',    now(), now()),
(@m_failure,      '故障管理', @m_biz,            1, '/biz/failure',         '',       'C', '0', '0', 'biz:failure:list',        'WarningOutlined',    now(), now()),
(@m_stocktake,    '盘点管理', @m_biz,            2, '/biz/stocktake',       '',       'C', '0', '0', 'biz:stocktake:list',      'CheckSquareOutlined',now(), now()),
(@m_transaction,  '出入库记录',@m_biz,           3, '/biz/transaction',     '',       'C', '0', '0', 'biz:transaction:list',    'SwapOutlined',       now(), now()),
(@m_allocation,   '资产分配', @m_biz,            4, '/biz/allocation',      '',       'C', '0', '0', 'biz:allocation:list',     'SendOutlined',       now(), now()),
(@m_request,      '资产申请', @m_biz,            5, '/biz/request',         '',       'C', '0', '0', 'biz:request:list',        'FileAddOutlined',    now(), now());

INSERT INTO sys_role_menu (role_id, menu_id)
SELECT @rid_admin, id FROM sys_menu;

-- 初始分类数据
INSERT INTO `itam_categories` (`id`, `name`, `code`, `parent_id`, `category_type`) VALUES
(@cid_1,  'IT设备',     'IT_DEVICE',        NULL,      'device'),
(@cid_2,  '服务器',     'SERVER',           @cid_1,    'device'),
(@cid_3,  'PC/笔记本',  'PC_LAPTOP',        @cid_1,    'device'),
(@cid_4,  '网络设备',   'NETWORK_DEVICE',   NULL,      'device'),
(@cid_5,  '路由器',     'ROUTER',           @cid_4,    'device'),
(@cid_6,  '交换机',     'SWITCH',           @cid_4,    'device'),
(@cid_7,  'IT许可',     'IT_LICENSE',       NULL,      'license'),
(@cid_8,  '软件许可',   'SOFTWARE_LICENSE', @cid_7,    'license'),
(@cid_9,  'SaaS许可',   'SAAS_LICENSE',     @cid_7,    'license'),
(@cid_10, 'IT配件',     'IT_ACCESSORY',     NULL,      'accessory'),
(@cid_11, '电源配件',   'POWER_ACCESSORY',  @cid_10,   'accessory'),
(@cid_12, '网络配件',   'NETWORK_ACCESSORY',@cid_10,   'accessory'),
(@cid_13, '办公耗材',   'OFFICE_CONSUMABLE',NULL,      'consumable'),
(@cid_14, '打印耗材',   'PRINT_CONSUMABLE', NULL,      'consumable'),
(@cid_15, 'IT服务',     'IT_SERVICE',       NULL,      'service'),
(@cid_16, '运维服务',   'OPS_SERVICE',      @cid_15,   'service');

SET FOREIGN_KEY_CHECKS = 1;
