USE `yami_bbc`;

ALTER TABLE `tz_order`
    ADD COLUMN `jst_order_id` bigint DEFAULT NULL COMMENT '聚水潭内部订单id';

ALTER TABLE  `tz_order_refund`
    ADD COLUMN `jst_refund_id` bigint DEFAULT NULL COMMENT '聚水潭内部售后id';


INSERT INTO `tz_sys_config`(`param_key`, `param_value`, `remark`) VALUES
                            ('JUSHUITAN_CONFIG', '{\"serverUrl\":\"https://openapi.jushuitan.com\",\"appKey\":\"",\"appSecret\":\"",\"openWebUrl\":\"https://openweb.jushuitan.com\",\"signature\":false,\"isOpenJST\":false}', '聚水潭配置');

CREATE TABLE `tz_shop_jst_config` (
                                      `shop_id` bigint NOT NULL COMMENT '商家id',
                                      `access_token` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '访问令牌',
                                      `expires_in` bigint DEFAULT NULL COMMENT 'access_token访问过期时间【单位是秒】，还有多少秒后过期',
                                      `is_open` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否开启聚水潭服务(0-关闭，1-开启)',
                                      `auth_time` datetime DEFAULT NULL COMMENT '授权时间（以此为准，判断还有多久授权过期）',
                                      `shop_no` bigint DEFAULT NULL COMMENT '店铺编号（通过登录聚水潭系统获取）',
                                      PRIMARY KEY (`shop_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


# 补充聚水潭授权菜单及按钮权限
INSERT INTO `tz_shop_menu`(`menu_id`, `parent_id`, `url`, `perms`, `type`, `icon`, `order_num`, `hidden`,`router_name`,`sys_type`) VALUES
('1400','45','','','0','','4','0','','1'),
('1401','1400','sys/jushuitan/authorization/index','','1','','0','0','','1'),
('1402','1400','','jushuitan:auth:getAuthorizationUrl','2','','0','0','','1'),
('1403','1400','','jushuitan:auth:setOpenState','2','','0','0','','1'),
('1404','11','','prod:prod:syncJstProduct','2','','0','0','','1'),
('1405','226','','supplier:supplier:syncSupplierToJst','2','','0','0','','1');


INSERT INTO `tz_shop_menu_lang`(`menu_id`, `lang`, `name`) VALUES
('1400', '0', '聚水潭'),
('1400', '1', 'JuShuiTan'),
('1401', '0', '授权管理'),
('1401', '1', 'Authorization'),
('1402', '0', '获取授权的URL'),
('1402', '1', 'Obtain authorized URL'),
('1403', '0', '更新聚水潭配置信息'),
('1403', '1', 'Update config info of the jushuitan'),
('1404', '0', '批量同步商品到聚水潭'),
('1404', '1', 'Batch synchronize products to Jushuitan'),
('1405', '0', '批量同步供应商到聚水潭'),
('1405', '1', 'Batch synchronization of suppliers to Jushuitan');


USE `xxl_job`;
# 添加聚水潭定时任务
INSERT INTO `xxl_job_info`(`job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`, `trigger_status`, `trigger_last_time`, `trigger_next_time`) VALUES
                          (2, '检查商家聚水潭授权是否已经过期，过期则自动关闭', '2024-10-17 13:42:21', '2024-10-17 13:43:00', 'admin', '', 'CRON', '0 0/1 0 * * ?', 'DO_NOTHING', 'FIRST', 'checkShopJstConfigExpire', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2024-10-17 13:42:21', '', 0, 1729184340000, 1729267200000);
