-- 供应商信息表
CREATE TABLE IF NOT EXISTS `asset_supplier` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `supplier_code` VARCHAR(50) NOT NULL COMMENT '供应商编码',
    `coop_status` VARCHAR(20) NOT NULL COMMENT '合作状态',
    `supplier_name` VARCHAR(100) NOT NULL COMMENT '供应商名称',
    `type` VARCHAR(50) NOT NULL COMMENT '供应商类型',
    `province` VARCHAR(50) COMMENT '省份',
    `city` VARCHAR(50) COMMENT '城市',
    `address` VARCHAR(255) COMMENT '详细地址',
    `region` VARCHAR(20) COMMENT '区域',
    `contact` VARCHAR(50) COMMENT '联系人',
    `contact_mobile` VARCHAR(20) COMMENT '联系手机',
    `contact_phone` VARCHAR(50) COMMENT '联系电话',
    `email` VARCHAR(100) COMMENT '邮箱',
    `credit_code_or_id` VARCHAR(100) COMMENT '统一社会信用代码/身份证号',
    `remark` VARCHAR(500) COMMENT '备注',

    -- 开票信息
    `tax_id` VARCHAR(100) COMMENT '税号',
    `invoice_address` VARCHAR(255) COMMENT '开票地址',
    `invoice_phone` VARCHAR(50) COMMENT '开票电话',
    `account` VARCHAR(100) COMMENT '账号',
    `opening_bank` VARCHAR(200) COMMENT '开户行',
    `mailing_address` VARCHAR(255) COMMENT '邮寄地址',

    -- 审计字段
    `creator` VARCHAR(64) DEFAULT '' COMMENT '创建者',
    `create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater` VARCHAR(64) DEFAULT '' COMMENT '更新者',
    `update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted` BIT(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id` BIGINT NOT NULL DEFAULT 0 COMMENT '租户编号',

    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_supplier_code` (`supplier_code`, `deleted`),
    INDEX `idx_supplier_name` (`supplier_name`),
    INDEX `idx_coop_status` (`coop_status`),
    INDEX `idx_type` (`type`),
    INDEX `idx_region` (`region`),
    INDEX `idx_city` (`city`),
    INDEX `idx_create_time` (`create_time`),
    INDEX `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='供应商信息表';

-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    '供应商管理', '', 2, 4, 5055,
    'supplier', 'user', 'asset/supplier/index', 0, 'Supplier'
);

-- 获取刚插入的菜单ID
SET @menuId = LAST_INSERT_ID();

-- 供应商管理按钮权限
INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status)
VALUES
    ('供应商查询', 'asset:supplier:query', 3, 1, @menuId, '', '', '', 0),
    ('供应商创建', 'asset:supplier:create', 3, 2, @menuId, '', '', '', 0),
    ('供应商更新', 'asset:supplier:update', 3, 3, @menuId, '', '', '', 0),
    ('供应商删除', 'asset:supplier:delete', 3, 4, @menuId, '', '', '', 0),
    ('供应商导出', 'asset:supplier:export', 3, 5, @menuId, '', '', '', 0);
