-- 智能电表第三方平台参数（SYSTEM_DICT / SYSTEM_DICT_DATA）
-- 字典类型：ELECTRICAL_PARAM
-- 字典数据：label=参数键，code=参数值

INSERT INTO `SYSTEM_DICT` (`CODE`, `NAME`, `REMARK`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT 'ELECTRICAL_PARAM', '电表三方平台参数', '智能电表第三方 API：auth_code、nonce、notify_url、api_url、api_url2', 1, CURRENT_TIMESTAMP, NULL, NULL, 0
WHERE NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT` WHERE `CODE` = 'ELECTRICAL_PARAM' AND `DELETED` = 0
);

INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, '1f29d378fc6792d5d2b735877993ffb7', 'auth_code', '三方授权码', 1, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'ELECTRICAL_PARAM' AND d.`DELETED` = 0
  AND NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT_DATA` x WHERE x.`DICT_ID` = d.`ID` AND x.`LABEL` = 'auth_code' AND x.`DELETED` = 0
  );

INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'lvyOY7fcun719WkxF8ToVYatStgt', 'nonce', '签名随机串', 2, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'ELECTRICAL_PARAM' AND d.`DELETED` = 0
  AND NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT_DATA` x WHERE x.`DICT_ID` = d.`ID` AND x.`LABEL` = 'nonce' AND x.`DELETED` = 0
  );

INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'http://115.221.15.8:8055/electronic/electricalNotify', 'notify_url', '异步回调完整 URL', 3, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'ELECTRICAL_PARAM' AND d.`DELETED` = 0
  AND NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT_DATA` x WHERE x.`DICT_ID` = d.`ID` AND x.`LABEL` = 'notify_url' AND x.`DELETED` = 0
  );

INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'http://api1.tqdianbiao.com', 'api_url', 'Api v1 根地址', 4, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'ELECTRICAL_PARAM' AND d.`DELETED` = 0
  AND NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT_DATA` x WHERE x.`DICT_ID` = d.`ID` AND x.`LABEL` = 'api_url' AND x.`DELETED` = 0
  );

INSERT INTO `SYSTEM_DICT_DATA` (`DICT_ID`, `CODE`, `LABEL`, `REMARK`, `SORT`, `DISABLED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`)
SELECT d.`ID`, 'http://api2.tqdianbiao.com', 'api_url2', 'Api v2 根地址', 5, 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0
FROM `SYSTEM_DICT` d
WHERE d.`CODE` = 'ELECTRICAL_PARAM' AND d.`DELETED` = 0
  AND NOT EXISTS (
    SELECT 1 FROM `SYSTEM_DICT_DATA` x WHERE x.`DICT_ID` = d.`ID` AND x.`LABEL` = 'api_url2' AND x.`DELETED` = 0
  );
