-- OCR 识别记录表
CREATE TABLE IF NOT EXISTS `ocr_record` (
    `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `scene` VARCHAR(50) NOT NULL COMMENT '识别场景（vehicle_license/driver_license/id_card等）',
    `provider` VARCHAR(50) NOT NULL COMMENT 'OCR 厂商（baidu/tencent/aliyun）',
    `image_url` VARCHAR(500) COMMENT '图片URL',
    `image_size` INT COMMENT '图片大小（字节）',
    `result` TEXT COMMENT '识别结果（JSON格式）',
    `status` TINYINT NOT NULL DEFAULT 0 COMMENT '识别状态（0-成功 1-失败）',
    `error_msg` VARCHAR(500) COMMENT '错误信息',
    `cost_time` INT 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`),
    INDEX `idx_scene` (`scene`),
    INDEX `idx_provider` (`provider`),
    INDEX `idx_create_time` (`create_time`),
    INDEX `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='OCR 识别记录表';

-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    'OCR 识别', '', 1, 100, 0,
    '/ocr', 'eye', NULL, 0, NULL
);

-- 获取刚插入的菜单ID（需要手动替换 @menuId）
SET @menuId = LAST_INSERT_ID();

-- 行驶证识别菜单
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    '行驶证识别', 'ocr:vehicle-license:recognize', 2, 1, @menuId,
    'vehicle-license', 'car', 'ocr/vehicleLicense/index', 0, 'OcrVehicleLicense'
);

-- 识别记录菜单
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
    '识别记录', 'ocr:record:query', 2, 2, @menuId,
    'record', 'list', 'ocr/record/index', 0, 'OcrRecord'
);
