-- 采集站 ISAPI 参数（系统字典 CS_PARAM）
-- 表结构：SYSTEM_DICT（字典类型）+ SYSTEM_DICT_DATA（字典项，LABEL=键名，CODE=配置值）
INSERT INTO `SYSTEM_DICT`(`CODE`, `NAME`, `REMARK`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT 'CS_PARAM', '采集站ISAPI参数', '海康采集站ISAPI对接配置', 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `SYSTEM_DICT` WHERE `CODE` = 'CS_PARAM' AND `DELETED` = 0);

INSERT INTO `SYSTEM_DICT_DATA`(`DICT_ID`, `LABEL`, `CODE`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'CS_SEARCH_TRACK_ID', 'auto', '媒体检索trackID，auto/空=自动从record/tracks获取全部', 1, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'CS_PARAM' AND d.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_DICT_DATA` dd
  WHERE dd.`DICT_ID` = d.`ID` AND dd.`LABEL` = 'CS_SEARCH_TRACK_ID' AND dd.`DELETED` = 0
);

INSERT INTO `SYSTEM_DICT_DATA`(`DICT_ID`, `LABEL`, `CODE`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'CS_DOWNLOAD_BATCH_SIZE', '10', '批量下载媒体文件数量', 2, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'CS_PARAM' AND d.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_DICT_DATA` dd
  WHERE dd.`DICT_ID` = d.`ID` AND dd.`LABEL` = 'CS_DOWNLOAD_BATCH_SIZE' AND dd.`DELETED` = 0
);

INSERT INTO `SYSTEM_DICT_DATA`(`DICT_ID`, `LABEL`, `CODE`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'CS_FFMPEG_PATH', 'ffmpeg', 'FFmpeg可执行文件路径，用于采集站视频转码为浏览器可播MP4', 3, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'CS_PARAM' AND d.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_DICT_DATA` dd
  WHERE dd.`DICT_ID` = d.`ID` AND dd.`LABEL` = 'CS_FFMPEG_PATH' AND dd.`DELETED` = 0
);

-- FTP 字典通常已存在，仅追加采集站媒体存储目录
INSERT INTO `SYSTEM_DICT_DATA`(`DICT_ID`, `LABEL`, `CODE`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'COLLECTION_MEDIA', '/collection_media/', '采集站媒体FTP存储目录', 99, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'FTP' AND d.`DELETED` = 0
AND NOT EXISTS (
  SELECT 1 FROM `SYSTEM_DICT_DATA` dd
  WHERE dd.`DICT_ID` = d.`ID` AND dd.`LABEL` = 'COLLECTION_MEDIA' AND dd.`DELETED` = 0
);
