# 看注释！！！！！！！！

# 1.执行 2023-11-13 整合leaf模块.sql ，新增的分布式id数据要导入

# 2.给用户服务添加mongodb连接
# 积分、余额的数据放入mongodb。在mall4cloud-user.yml加入以下配置（连接数据注意检查更换），
#   data:
#     mongodb:
#       host: 192.168.193.128
#       port: 27017
#       database: mall4cloud
#       username: mall4cloud
#       password: mall4cloud
#       authentication-database: mall4cloud

# 3.给支付模块增加一个数据库配置
# 在mall4cloud-payment.yml替换以下配置
# 将：
#
#    datasource:
#      names: ds,ds0,ds1,ds2,ds3,ds4,ds5,ds6,ds7
#
# 替换成：
#    datasource:
#      names: ds,ds0,ds1,ds2,ds3,ds4,ds5,ds6,ds7
#      ds:
#        type: com.zaxxer.hikari.HikariDataSource
#        driver-class-name: com.mysql.cj.jdbc.Driver
#        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_payment}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true
#        username: ${MYSQL_USERNAME:root}
#        password: ${MYSQL_PASSWORD:hn02le.34lkdLKD}
#        minimum-idle: 0
#        maximum-pool-size: 20
#        idle-timeout: 25000
#        auto-commit: true
#        connection-test-query: SELECT 1
#
# 将：
#    sharding:
#
# 替换成：
#    sharding:
#      default-data-source-name: ds
#
#
# 或者执行以下两条sql后，重启nacos（二选一）
use mall4cloud_nacos;
update config_info set content = REPLACE(content, 'names: ds0,ds1,ds2,ds3,ds4,ds5,ds6,ds7\n', 'names: ds,ds0,ds1,ds2,ds3,ds4,ds5,ds6,ds7\n      ds:\n        type: com.zaxxer.hikari.HikariDataSource\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        jdbc-url: jdbc:mysql://${MYSQL_HOST:192.168.193.128}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:mall4cloud_payment}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true&useAffectedRows=true\n        username: ${MYSQL_USERNAME:root}\n        password: ${MYSQL_PASSWORD:hn02le.34lkdLKD}\n        minimum-idle: 0\n        maximum-pool-size: 20\n        idle-timeout: 25000\n        auto-commit: true\n        connection-test-query: SELECT 1\n') where data_id = 'mall4cloud-payment.yml';
update config_info set content = REPLACE(content, 'sharding:\n', 'sharding:\n      default-data-source-name: ds\n') where data_id = 'mall4cloud-payment.yml';



# 4.search模块增加一个mongodb配置
# 在mall4cloud-search.yml替换以下配置
# 将：
#
# spring:
#
# 替换成：
# spring:
#   data:
#     mongodb:
#       host: 192.168.193.128
#       port: 27017
#       database: mall4cloud
#       username: mall4cloud
#       password: 'mall4cloud'
#       authentication-database: mall4cloud
#
# 或者执行以下两条sql后，重启nacos（二选一）
use mall4cloud_nacos;
update config_info set content = REPLACE(content, 'spring:\n', 'spring:\n  data:\n    mongodb:\n      host: 192.168.193.128\n      port: 27017\n      database: mall4cloud\n      username: mall4cloud\n      password: mall4cloud\n      authentication-database: mall4cloud\n')  where data_id = 'mall4cloud-search.yml';




# 5.initScoreAndBalanceLogToMongodb这个定时任务只对2023-11-13更新前将积分日志(user_score_log)和余额日志(user_balance_log)存入mysql之后，将数据搬迁到mongodb
# 需要重启用户服务，使该定时任务正常执行*成功*一次后(数据已经完全搬迁到mongodb)就可以置为停止或删除，随后可以将mysql中user_score_log和user_balance_log删除
# 并且可以将UserScoreLogMapper、UserBalanceLogMapper以及相关定时任务代码从代码中删去
USE `mall4cloud_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 (12, '初始化原有数据库记录至mongodb', '2023-11-02 10:07:30', '2023-11-02 10:07:30', 'admin', '', 'CRON',
        '0 0 0 1 1 ? *', 'DO_NOTHING', 'FIRST', 'initScoreAndBalanceLogToMongodb', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN',
        '', 'GLUE代码初始化', '2023-11-02 10:07:30', '', 0, 0, 0);

# 6.优化通联会员注册
USE `mall4cloud_user`;
ALTER TABLE `user_extension`
    ADD COLUMN `allinpay_create` tinyint(1) DEFAULT 0 COMMENT '是否创建通联会员(0:否，1:是)' AFTER `allinpay_actual_balance`;

USE mall4cloud_job;
INSERT INTO `xxl_job`.`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
    (12, '用户创建通联会员', '2023-11-10 14:30:03', '2023-11-10 14:51:03', 'admin', '', 'CRON', '0 0/10 * * * ? *', 'DO_NOTHING', 'FIRST', 'createAllinpayMember', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2023-11-10 14:30:03', '', 1, 0, 1699599600000);




# 7. 上面步骤执行完毕后，重启所有服务

# 8. 重启服务后，导入初始化的定时任务并执行
# 只需要执行一次就可以删除掉，不要重复执行
USE `mall4cloud_job`;
insert into `xxl_job_info` (`id`, `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
('612','11','初始化库存','2023-07-10 09:51:23','2023-11-10 16:38:00','admin','','CRON','0 0 0 1 10 ?','DO_NOTHING','FIRST','intiStock','','SERIAL_EXECUTION','0','0','BEAN','','GLUE代码初始化','2023-07-10 09:51:23','','0','0','0');
