-- 2026-06-16
-- Tencent ASR (mod_tx_asr) full SQL.
-- Based on current database inspection:
-- 1. sys_config 已存在 config_asr_provider_tx
-- 2. cc_asr_languages 已存在 provider=tx 数据
-- 3. fs_variables 已存在部分共享字段，但缺少若干 tx_asr 专属参数
-- 4. sys_menu 中缺少 tx_asr 配置菜单，需要补齐

START TRANSACTION;

-- 1) ASR provider 配置项
INSERT INTO `sys_config` (`config_name`, `config_key`, `config_value`, `config_type`, `create_by`, `create_time`, `remark`)
SELECT '腾讯ASR', 'config_asr_provider_tx', 'tx', 'Y', 'admin', NOW(), 'ASR厂商-mod_tx_asr'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `sys_config` WHERE `config_key` = 'config_asr_provider_tx'
);

UPDATE `sys_config`
SET `config_name` = '腾讯ASR',
    `config_value` = 'tx',
    `config_type` = 'Y',
    `remark` = 'ASR厂商-mod_tx_asr'
WHERE `config_key` = 'config_asr_provider_tx';

-- 2) 腾讯 ASR 配置菜单
UPDATE `sys_menu`
SET `menu_name` = '腾讯ASR配置',
    `menu_code` = 'txAsrBridgeConf',
    `parent_id` = 3018,
    `order_num` = 8,
    `url` = '/cc/fsconf/txasrbridgeconf',
    `target` = 'menuItem',
    `menu_type` = 'C',
    `visible` = '0',
    `is_refresh` = '1',
    `perms` = 'cc:txasrbridgeconf:view',
    `icon` = '#',
    `update_by` = 'admin',
    `update_time` = NOW(),
    `remark` = 'mod_tx_asr 参数配置菜单'
WHERE `perms` = 'cc:txasrbridgeconf:view'
   OR `url` = '/cc/fsconf/txasrbridgeconf'
   OR `menu_name` = '腾讯ASR配置';

INSERT INTO `sys_menu` (`menu_name`, `menu_code`, `parent_id`, `order_num`, `url`, `target`, `menu_type`, `visible`, `is_refresh`, `perms`, `icon`, `create_by`, `create_time`, `remark`)
SELECT '腾讯ASR配置', 'txAsrBridgeConf', 3018, 8, '/cc/fsconf/txasrbridgeconf', 'menuItem', 'C', '0', '1', 'cc:txasrbridgeconf:view', '#', 'admin', NOW(), 'mod_tx_asr 参数配置菜单'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1
    FROM `sys_menu`
    WHERE `perms` = 'cc:txasrbridgeconf:view'
       OR `url` = '/cc/fsconf/txasrbridgeconf'
);

SET @tx_asr_menu_id := (
    SELECT `menu_id`
    FROM `sys_menu`
    WHERE `perms` = 'cc:txasrbridgeconf:view'
       OR `url` = '/cc/fsconf/txasrbridgeconf'
    ORDER BY `menu_id` DESC
    LIMIT 1
);

INSERT INTO `sys_role_menu` (`role_id`, `menu_id`)
SELECT 2, @tx_asr_menu_id
FROM DUAL
WHERE @tx_asr_menu_id IS NOT NULL
  AND NOT EXISTS (
      SELECT 1
      FROM `sys_role_menu`
      WHERE `role_id` = 2
        AND `menu_id` = @tx_asr_menu_id
  );

-- 3) fs_variables：共享字段缺了就补，已存在则保留
INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'appid', '腾讯 ASR AppID'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'appid'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'secret-id', '腾讯 ASR SecretId'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'secret-id'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'secret-key', '腾讯 ASR SecretKey'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'secret-key'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'websocket-host', 'WebSocket Host'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'websocket-host'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'engine-model-type', '引擎模型'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'engine-model-type'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'voice-format', '音频编码格式'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'voice-format'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'need-vad', '启用 VAD'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'need-vad'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'filter-dirty', '脏词过滤'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'filter-dirty'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'filter-modal', '语气词过滤'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'filter-modal'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'filter-punc', '标点过滤'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'filter-punc'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'filter-empty-result', '过滤空识别结果'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'filter-empty-result'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'convert-num-mode', '数字转换模式'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'convert-num-mode'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'word-info', '词级时间戳'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'word-info'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'vad-silence-time', '句尾静音时长(毫秒)'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'vad-silence-time'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'max-speak-time', '强制断句时长(毫秒)'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'max-speak-time'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'hotword-id', '热词表 ID'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'hotword-id'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'hotword-list', '临时热词表'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'hotword-list'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'customization-id', '自学习模型 ID'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'customization-id'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'noise-threshold', '噪音阈值'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'noise-threshold'
);

INSERT INTO `fs_variables` (`cat`, `var_field_name`, `var_field_alias`)
SELECT 5, 'signature-expire-seconds', '签名有效期(秒)'
FROM DUAL
WHERE NOT EXISTS (
    SELECT 1 FROM `fs_variables` WHERE `cat` = 5 AND `var_field_name` = 'signature-expire-seconds'
);

-- 4) 腾讯 realtime ASR 模型/语言
DELETE FROM `cc_asr_languages`
WHERE `asr_provider` = 'tx';

INSERT INTO `cc_asr_languages` (`asr_provider`, `models`, `language_code`, `language_name`) VALUES
('tx', '8k_zh', 'zh-CN', '中文(8k)'),
('tx', '16k_zh', 'zh-CN', '中文(16k)'),
('tx', '8k_en', 'en-US', '英文(8k)'),
('tx', '16k_en', 'en-US', '英文(16k)'),
('tx', '16k_yue', 'zh-HK', '粤语');

-- 5) 双向ASR默认引擎描述补齐
UPDATE `cc_params`
SET `param_name` = '双向asr语音识别，使用哪个asr引擎(chinatelecom/funasr/aliyun/ali/tx/tx1)'
WHERE `param_code` = 'fs_call_asr_engine';

COMMIT;
