DROP TABLE IF EXISTS `tz_ai_sample`;
CREATE TABLE `tz_ai_sample`
(
    `id`               bigint       NOT NULL AUTO_INCREMENT COMMENT '主键',
    `sample_file_id`   bigint       NOT NULL COMMENT '样本文件id',
    `sample_name`      varchar(64)  NULL     DEFAULT '' COMMENT '样本名称',
    `sample_time`      varchar(16)  NULL     DEFAULT '' COMMENT '样本时长',
    `sample_mine_type` varchar(16)  NULL     DEFAULT '' COMMENT '样本格式',
    `sample_size`      varchar(16)  NULL     DEFAULT '' COMMENT '样本大小',
    `remark`           varchar(255) NULL     DEFAULT '' COMMENT '样本注释',
    `creator`          varchar(64)  NULL     DEFAULT '' COMMENT '创建者',
    `create_time`      datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`          varchar(64)  NULL     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`) USING BTREE,
    INDEX `idx_create_time` (`create_time` ASC) USING BTREE
) ENGINE = InnoDB COMMENT = '样本库';


DROP TABLE IF EXISTS `tz_ai_sample_tag_relate`;
CREATE TABLE `tz_ai_sample_tag_relate`
(
    `id`            bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
    `sample_id`     bigint NOT NULL COMMENT '样本id',
    `sample_tag_id` bigint NOT NULL COMMENT '样本标签id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB COMMENT = '样本-标签关联表';



DROP TABLE IF EXISTS `tz_ai_sample_tag`;
CREATE TABLE `tz_ai_sample_tag`
(
    `id`          bigint      NOT NULL AUTO_INCREMENT COMMENT '主键',
    `tag_name`    varchar(64) NULL     DEFAULT '' COMMENT '标签名称',
    `creator`     varchar(64) NULL     DEFAULT '' COMMENT '创建者',
    `create_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) NULL     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`) USING BTREE,
    INDEX `idx_create_time` (`create_time` ASC) USING BTREE
) ENGINE = InnoDB COMMENT = '样本标签库';

DROP TABLE IF EXISTS `tz_ai_sample_tag_group`;
CREATE TABLE `tz_ai_sample_tag_group`
(
    `id`          bigint      NOT NULL AUTO_INCREMENT COMMENT '主键',
    `group_name`  varchar(64) NULL     DEFAULT '' COMMENT '分组名称',
    `creator`     varchar(64) NULL     DEFAULT '' COMMENT '创建者',
    `create_time` datetime    NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) NULL     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`) USING BTREE,
    INDEX `idx_create_time` (`create_time` ASC) USING BTREE
) ENGINE = InnoDB COMMENT = '样本标签分组库';



DROP TABLE IF EXISTS `tz_ai_sample_tag_group_relate`;
CREATE TABLE `tz_ai_sample_tag_group_relate`
(
    `id`                  bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
    `sample_tag_id`       bigint NOT NULL COMMENT '样本标签id',
    `sample_tag_group_id` bigint NOT NULL COMMENT '样本标签分组id',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB COMMENT = '样本标签-分组关联表';


DROP TABLE IF EXISTS `tz_ai_dialog`;
CREATE TABLE `tz_ai_dialog`
(
    `id`            bigint   NOT NULL AUTO_INCREMENT COMMENT '主键',
    `title`         varchar(128)      DEFAULT '' COMMENT '对话标题',
    `user_id`       bigint   NOT NULL COMMENT '用户id',
    `dialog_status` int               DEFAULT NULL COMMENT '对话状态（1active, 2archived, 3deleted）',
    `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`) USING BTREE
) ENGINE = InnoDB COMMENT ='ai-对话表';

DROP TABLE IF EXISTS `tz_ai_dialog_message`;
CREATE TABLE `tz_ai_dialog_message`
(
    `id`               bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
    `dialog_id`        bigint NOT NULL COMMENT '对话id',
    `content_text`     text COMMENT '内容',
    `content_type`     int          DEFAULT NULL COMMENT '文本类型（1text，2file）',
    `message_order`    int          DEFAULT NULL COMMENT '对话中的顺序',
    `message_status`   int          DEFAULT NULL COMMENT '消息状态 1正常 0删除',
    `pet_id`           bigint       DEFAULT NULL COMMENT '宠物id',
    `pet_name`         varchar(255) DEFAULT NULL COMMENT '宠物名称',
    `pet_avatar`       varchar(255) DEFAULT NULL COMMENT '宠物头像',
    `pet_type`         varchar(64)  DEFAULT NULL COMMENT '宠物类型',
    `create_time`      datetime     DEFAULT NULL COMMENT '创建时间',
    `trans_result`     text COMMENT '回答结果',
    `content_duration` bigint       DEFAULT NULL COMMENT '文件时长',
    `trans_status`     int          DEFAULT NULL COMMENT '翻译状态（1成功 0失败）',
    `source_result`    text COMMENT '原始结果',
    `file_name`        varchar(255) DEFAULT NULL COMMENT '文件名称',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB COMMENT ='ai-对话消息表';


DROP TABLE IF EXISTS `tz_ai_model`;
CREATE TABLE `tz_ai_model`
(
    `id`                   bigint       NOT NULL AUTO_INCREMENT COMMENT '主键',
    `model_name`           varchar(128) NOT NULL COMMENT '模型名称',
    `version`              varchar(32)  NOT NULL COMMENT '版本号',
    `load_percentage`      decimal(5,4) NULL     DEFAULT 0.0000 COMMENT '负载百分比',
    `status`               tinyint      NOT NULL DEFAULT 0 COMMENT '状态（0-禁用 1-启用 2-测试中 3-已废弃）',
    `description`          varchar(500) NULL     DEFAULT '' COMMENT '版本描述',
    `creator`              varchar(64)  NULL     DEFAULT '' COMMENT '创建者',
    `create_time`          datetime     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`              varchar(64)  NULL     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`) USING BTREE,
    INDEX `idx_model_name` (`model_name` ASC) USING BTREE,
    INDEX `idx_version` (`version` ASC) USING BTREE,
    INDEX `idx_status` (`status` ASC) USING BTREE,
    INDEX `idx_create_time` (`create_time` ASC) USING BTREE
) ENGINE = InnoDB COMMENT = 'AI模型版本管理表';


