# 本次更新修改了很多东西
# 1. 更新到springboot3,spring cloud 2022, 使用jdk17。vue从vue2更新到vue3。
# 2. 将数据分析的数据全部存入到mongodb，而不是mysql
#
# 3. 使用dubbo代替openfeign
# 3.1 在nacos中的 application.yml的移除所有关于openfeign的配置
# 3.2 在nacos中的 application.yml的增加关于dubbo的配置（dubbo因为要本地调试，所以在开发环境可以加多个dubbo本地的负载均衡配置dubbo.consumer.loadbalance=dev）
# dubbo:
#   application:
#     name: ${spring.cloud.nacos.discovery.namespace}-${spring.application.name}-dubbo-server
#     register-mode: instance
#     service-discovery:
#       migration: FORCE_APPLICATION
#   protocol:
#     name: dubbo
#     serialization: fastjson2
#   provider:
#     token: true
#   registry:
#     # 配置dubbo的注册中心为nacos
#     address: nacos://${spring.cloud.nacos.discovery.server-addr}
#     # group: ${spring.cloud.nacos.discovery.namespace}-dubbo
#     username: ${spring.cloud.nacos.discovery.username}
#     password: ${spring.cloud.nacos.discovery.password}
#     timeout: 50000
#     parameters:
#       namespace: ${spring.cloud.nacos.discovery.namespace}
#   consumer:
#     check: false
#     timeout: 50000
#     #指定服务提供者的namespace
#     provider-namespace: ${spring.cloud.nacos.discovery.namespace}
#
# 4. 删除所有数据库关于库存的记录，统一存在redis，增加一台redis机器，专门用来存商品库存的。一定要有个额外的redis，不然清理缓存之后库存数据再也找不回来了。
# 4.1 在nacos的tmerclub-seckill.yml 加入如下配置（可以为秒杀增加多台redis）
# redis:
#   multi:
#     enable: true
#     password: hn02le.34lkdLKD
#     database: 0
#     redisAddrs:
#       - 192.168.193.128:31377
# 4.2 在nacos的tmerclub-product.yml 加入如下配置 （只能增加一台用于aof的redis）
# redis:
#   aof:
#     enable: true
#     password: hn02le.34lkdLKD
#     database: 0
#     redisAddr: 192.168.193.128:31377
#
# 在服务器增加一台redis-aof的机器，并且配置aof的配置，详细见一键安装的部署文档docker-compose
#
# 5. 移除@ParameterObject 的注解，需要在nacos中的 application.yml的增加关于springdoc的配置。
# springdoc:
#   # 默认是false，需要设置为true
#   default-flat-param-object: true
#
# 6. 支付证书从路径的形式改成读取证书内容的形式
# 6.1.平台端 -> 系统 -> 系统设置 -> 支付配置 -> (微信配置 or 支付宝配置)
# 6.2.将支付宝支付 or 微信v3支付的对应证书的路径，修改为对应证书的内容（鼠标右键 -> 打开方式 -> 记事本打开 -> 将内容复制并填写进对应的输入框）
#
# 7. rocketmq使用rocketmq5.0 在阿里云服务器购买rocketmq5价格巨量降低
#
#
#
# 8.修改knife4j版本到4.3.0，移除nacos当中gateway.yml 的openapi配置
#         - id: openapi
#           uri: lb://tmerclub-gateway
#           predicates:
#             - Path=/v3/api-docs/**
#           filters:
#             - RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/v3/api-docs
#             - AddBasePath
# 增加knife4j配置
# knife4j:
#   gateway:
#     enabled: true
#     strategy: discover
#     discover:
#       version: openapi3
#       enabled: true
# 增加application.yml的springdoc配置
#springdoc:
#  api-docs:
#    path: /v3/api-docs/default
# 9.数据分析的数据放入mongodb。在tmerclub-flow.yml加入以下配置
#   data:
#     mongodb:
#       host: 192.168.193.128
#       port: 27017
#       database: tmerclub
#       username: tmerclub
#       password: tmerclub
#       authentication-database: tmerclub
# 10. 直播使用阿里云直播。未开通小程序直播插件可以在app和h5进行直播。开通小程序直播插件后可以在app、h5以及小程序进行直播。





USE tmerclub_product;

ALTER TABLE `sku` ADD COLUMN `stock_warning_status` tinyint NOT NULL DEFAULT '0' COMMENT '库存预警状态 0:库存充足 1:库存预警';
ALTER TABLE `sku` MODIFY `stock_warning` BIGINT DEFAULT NULL COMMENT '设置库存预警的数量';



USE tmerclub_nacos;
UPDATE config_info
set content = '# 数据源\nspring:\n  profiles:\n    active: dev\n  #避免nacos取网卡出错\n  cloud:\n    inetutils:\n      preferred-networks: 10.1.\n  datasource:\n    driver-class-name: com.mysql.cj.jdbc.Driver\n    type: com.zaxxer.hikari.HikariDataSource\n    hikari:\n      minimum-idle: 0\n      maximum-pool-size: 20\n      idle-timeout: 25000\n      auto-commit: true\n      connection-test-query: SELECT 1\n  data:\n    redis:\n      host: 192.168.193.128\n      password: hn02le.34lkdLKD\n  jackson:\n    date-format: yyyy-MM-dd HH:mm:ss\n    time-zone: GMT+8\n\nspringdoc:\n  # 默认是false，需要设置为true\n  default-flat-param-object: true\n        \n#mybatis的相关配置\nmybatis:\n  #mapper配置文件\n  mapper-locations: classpath:mapper/*Mapper.xml\n  type-aliases-package: com.moyuer.cloud.**.model\n  #开启驼峰命名\n  configuration:\n    map-underscore-to-camel-case: true\n\nseata:\n  config:\n    type: nacos\n    nacos:\n      namespace: 05b1150e-9306-474c-90e1-ed4852c21475\n      dataId: \"seataServer.properties\"\n      server-addr: ${spring.cloud.nacos.discovery.server-addr}\n      password: ${spring.cloud.nacos.discovery.password}\n      username: ${spring.cloud.nacos.discovery.username}\n  registry:\n    type: nacos\n    nacos:\n      server-addr: ${spring.cloud.nacos.discovery.server-addr}\n      password: ${spring.cloud.nacos.discovery.password}\n      username: ${spring.cloud.nacos.discovery.username}\n      namespace: ${seata.config.nacos.namespace}\n\nlogging:\n  level:\n    root: info\n    com:\n      mall4j:\n        cloud: debug\n\n# 分页合理化，当查询到页码大于最后一页的时候，返回最后一页的数据，防止vue在最后一页删除时，数据不对的问题\npagehelper:\n  reasonable: true\n\nbiz:\n  oss:\n    # 文件上传类型 0.阿里云 1.minio\n    type: 1\n    # 资源url，图片域名(阿里云的resources-url是带有bucket的那个url)\n    # resources-url: http://tmerclub.oss-cn-shenzhen.aliyuncs.com\n    # endpoint: https://oss-cn-shenzhen.aliyuncs.com\n    # bucket: tmerclub\n    # access-key-id: key\n    # access-key-secret: secret\n    # resources-url是带有bucket的\n    resources-url: http://192.168.193.128:9000/tmerclub\n    endpoint: http://192.168.193.128:9000\n    bucket: tmerclub\n    access-key-id: admin\n    access-key-secret: admin123456\n\n\ndubbo:\n  application:\n    name: ${spring.cloud.nacos.discovery.namespace}-${spring.application.name}-dubbo-server\n    register-mode: instance\n    service-discovery:\n      migration: FORCE_APPLICATION\n  protocol:\n    name: dubbo\n    serialization: fastjson2\n  registry:\n    # 配置dubbo的注册中心为nacos\n    address: nacos://${spring.cloud.nacos.discovery.server-addr}\n    username: ${spring.cloud.nacos.discovery.username}\n    password: ${spring.cloud.nacos.discovery.password}\n  consumer:\n    check: false\n    loadbalance: dev\n\ntmerclub:\n  job:\n    accessToken: default_token\n    logPath: /data/applogs/xxl-job/jobhandler\n    admin:\n      addresses: http://192.168.193.128:8080/xxl-job-admin\n  expose:\n    permission: true\n\nrocketmq:\n  name-server: 192.168.193.128:9876\n\nsa-token:\n  # token名称 (同时也是cookie名称)\n  token-name: authorization\n  # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)\n  is-concurrent: true\n  # 在多人登录同一账号时，是否共用一个token(不共用，避免登出时导致其他用户也登出)\n  is-share: false\n  # token风格(默认可取值：uuid、simple-uuid、random-32、random-64、random-128、tik)\n  token-style: uuid\n  # 是否输出操作日志\n  is-log: false'
where data_id = "application.yml";


UPDATE config_info
set content = PERLACE(content, 'elastic:\n  # elastic的地址\n  address:', 'spring:\n  elasticsearch:\n    uris:')
where data_id = "tmerclub-search.yml";





USE tmerclub_leaf;

insert into `leaf_alloc` (`biz_tag`, `max_id`, `step`, `update_time`, `description`, `random_step`) values
('tmerclub-flow-user-id','1','100','2023-08-01 10:01:43','tmerclub-flow的用户操作编号','10');



USE tmerclub_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
(11,'处理sku库存的变化','2023-08-16 09:56:14','2023-08-16 09:56:20','admin','','CRON','0/5 * * * * ?','DO_NOTHING','FIRST','handleSkuStockChange','','DISCARD_LATER','0','0','BEAN','','GLUE代码初始化','2023-08-16 09:56:14','',1,1692234575000,1692234580000),
(11,'初始化库存','2023-07-10 09:51:23','2023-07-10 09:52:03','admin','','CRON','0 * * * * ?','DO_NOTHING','FIRST','intiStock','','SERIAL_EXECUTION','0','0','BEAN','','GLUE代码初始化','2023-07-10 09:51:23','','0','0','0');

# 如需配置阿里直播，需要看下tmerclub-doc这个项目下的 基本开发文档-阿里视频直播配置文档，参照文档进行配置
# 清除微信直播的定时任务
DELETE
FROM xxl_job_info
WHERE executor_handler IN
      ('synchronousWxLiveProds', 'offShelfLiveProds', 'synchronousWxLiveRoom', 'synchronousWxLiveUsers');
# 新增阿里直播定时任务
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 (5, '定时改变直播间状态', '2023-07-21 17:08:16', '2023-07-24 10:24:59', 'admin', '', 'CRON', '0 0/30 * * * ? ',
        'DO_NOTHING', 'FIRST', 'changeLiveRoomStatus', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化',
        '2023-07-21 17:08:16', '', 1, 0, 0);

USE tmerclub_marketing;
# 清除没有用的直播相关表格
DROP TABLE IF EXISTS `live_user`;
DROP TABLE IF EXISTS `live_log`;
DROP TABLE IF EXISTS `live_prod_log`;
DROP TABLE IF EXISTS `live_prod_store`;
DROP TABLE IF EXISTS `live_room_back`;

# 更改直播间和直播商品表，请注意，当前直播间信息将会全部删除！
DROP TABLE IF EXISTS `live_room`;
CREATE TABLE `live_room`
(
    `room_id`     BIGINT   NOT NULL AUTO_INCREMENT COMMENT '直播间信息',
    `shop_id`     BIGINT                                                        DEFAULT NULL COMMENT '店铺id',
    `name`        VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci  DEFAULT NULL COMMENT '直播间名称',
    `user_id`     BIGINT   DEFAULT NULL COMMENT '主播用户id',
    `live_status` TINYINT  NOT NULL COMMENT '直播间状态 0.未开始 1.直播中 2.已结束 3.暂停中 -1.违规下架',
    `cover_img`   VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '直播背景图',
    `share_img`   VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '主播分享图',
    `feeds_img`   VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '直播封面图',
    `room_top`    TINYINT                                                       DEFAULT '0' COMMENT '是否置顶 1.是 0.不是',
    `start_time`  DATETIME                                                      DEFAULT NULL COMMENT '直播开始时间',
    `end_time`    DATETIME                                                      DEFAULT NULL COMMENT '直播结束时间',
    `create_time` DATETIME NOT NULL                                             DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `update_time` DATETIME NOT NULL                                             DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `remark`      VARCHAR(500) COLLATE utf8mb4_general_ci                       DEFAULT NULL COMMENT '下线备注',
    PRIMARY KEY (`room_id`)
) ENGINE = INNODB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='直播间';

DROP TABLE IF EXISTS `live_room_prod`;
CREATE TABLE `live_room_prod`
(
    `room_prod_id`   BIGINT NOT NULL AUTO_INCREMENT COMMENT '直播间商品信息',
    `spu_id`         BIGINT NOT NULL COMMENT '商品id',
    `room_id`        BIGINT NOT NULL COMMENT '房间id',
    `explain_status` TINYINT DEFAULT '0' COMMENT '讲解状态 0未讲解 1讲解中',
    PRIMARY KEY (`room_prod_id`)
) ENGINE = INNODB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='直播商品';

USE tmerclub_admin;
# 添加阿里直播配置
INSERT INTO `sys_config` (`param_key`, `param_value`, `remark`)
VALUES ('ALI_LIVE_CONFIG',
        '{\"pushDomain\":\"\",\"pullDomain\":\"\",\"appName\":\"\",\"pushAuthKey\":\"\",\"pullAuthKey\":\"\",\"isHttps\":\"\"}',
        '直播配置');
