# distrident **Repository Path**: DistributedTrident/distrident ## Basic Information - **Project Name**: distrident - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-07-26 - **Last Updated**: 2020-12-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # distrident ## SpringCloud ### 新建工程 1.New project 2.聚合总父工程名字 ### 端口协议 测试端口: 10xxx 正式端口: 11xxx ### 服务器ip 服务器1: 47.102.210.6 服务器2: 120.79.224.142 ### Nacos [Nacos README](Nacos/Nacos.md) ### 服务调用 OpenFeign Feign是Spring Cloud组件中的一个轻量级restful的HTTP服务客户端 Feign内置了Ribbon,用来做客户端负载均衡,去调用服务注册中心的服务。 Feign的使用方式是:使用Feign的注解定义接口,调用这个接口,就可以调用服务注册中心的服务 OpenFeign是Spring Cloud 在Feign的基础上支持了Spring MVC的注解 [OpenFeign](/OpenFeign/OpenFeign.md) [Ribbon](/Ribbon/Ribbon.md) ### 网关 gateway [gateway](/Gateway/gateway.md) ### 流量控制 服务降级 sentinel [Sentinel_README](Sentinel/Sentinel.md) ## 中间件 ### Sharding 轻量级Java框架,在Java的JDBC层提供的额外服务。 它使用客户端直连数据库,以jar包形式提供服务,无需额外部署和依赖,可理解为增强版的JDBC驱动,完全兼容JDBC和各种ORM框架。 ```xml org.apache.shardingsphere sharding-jdbc-core ${latest.release.version} ``` 可以实现数据分片,读写分离,数据脱敏等功能。 本项目使用了读写分离。 ```yaml spring: application: name: sharding-jdbc shardingsphere: datasource: names: distrident0, distrident distrident0: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://47.102.210.6:3306/distrident0?useUnicode=true&serverTimezone=UTC&characterEncoding=UTF-8 username: root password: * distrident: type: com.zaxxer.hikari.HikariDataSource driver-class-name: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://120.79.224.142:3306/distrident?useUnicode=true&characterEncoding=UTF-8 username: root password: * masterslave: # 均衡设置,ROUND_ROBIN(轮询),RANDOM(随机) load-balance-algorithm-type: round_robin # 最终数据源名称 name: dataSource master-data-source-name: distrident0 # 从库数据源名称列表,多个逗号分隔 slave-data-source-names: distrident props: sql: # 开启SQL显示 show: true check: table: metadata: # 启动时检查分表元数据一致性 enabled: true ``` #### 读写分离 ### MybatisPlus #### 依赖 ```xml com.baomidou mybatis-plus-boot-starter 3.0.7.1 com.baomidou mybatis-plus-generator org.projectlombok lombok true mysql mysql-connector-java ``` #### 配置 具体datasource配置参照sharding jdbc的配置,使用的是相同的配置。 ```yaml mybatis-plus: mapper-locations: classpath:/mapper/*.xml type-aliases-package: com.ditri.* type-aliases-super-type: com.ditri.common.entity.BasicEntity # 自定义枚举类型包 # type-enums-package: # TypeHandler 通常用于自定义类型转换。 # type-handlers-package: check-config-location: false # 是否检查MyBatis XML 文件的存在,默认不检查 # 执行器, 可选batch, reuse, simple executor-type: batch # 原生mybatis设置 configuration: # 数据库命名转驼峰 如:xx_yy 转 xxYy map-underscore-to-camel-case: true # 自动映射 full, partial, none auto-mapping-behavior: partial # 自动映射位置column处理 none, warning, failing auto-mapping-unknown-column-behavior: warning # 二级缓存 cache-enabled: true # 当数据为空时调用setter方法,使返回结果不会丢失 call-setters-on-nulls: true global-config: # 打印mybatis-plus LOGO banner: true db-config: # 数据库自增id,依赖数据库 还有uuid, 雪花算法 id-type: auto ``` #### 自动生成代码 EasyCode 插件,修改一些参数。 ## 数据库 - 版本:MYSQL 5.7 ### 数据字典 | COLUMN_NAME | COLUMN_TYPE | COLUMN_COMMENT | | :---------------------: | :------------: | :----------------------------------------: | | blog_id | bigint(20) | 博客唯一id | | class_id | bigint(20) | 分类唯一id | | comment_id | bigint(20) | 评论唯一id | | pid | bigint(20) | 评论的上级评论id | | stars | bigint(20) | 点赞 | | click_times | bigint(20) | 点击次数 | | tag_id | bigint(20) | 标签唯一id | | group_id | bigint(20) | 群众唯一id | | special_id | bigint(20) | 专栏唯一id | | topic_id | bigint(20) | 专题唯一id | | topic_participation | bigint(20) | 话题热度 | | gmt_create | datetime | 数据创建时间 | | gmt_modified | datetime | 数据变更时间 | | blog_content | longtext | 文章内容 | | comment_content | text | 评论内容 | | blog_type | tinyint(4) | 1原创, 2转载 | | state | tinyint(4) | 1 公开,2 草稿,3 私密, 4 密码, 5 已删除 | | sex | tinyint(4) | 性别 | | student_certification | tinyint(4) | 1为统一注册学生用户 | | phone | varchar(11) | 手机号 | | password | varchar(128) | 密码 | | signature | varchar(128) | 个性签名 | | topic_describe | varchar(140) | 话题描述 | | mail | varchar(140) | 邮箱 | | birthday | varchar(20) | 生日 | | last_login | varchar(20) | 最近一次登录时间 | | img_url | varchar(255) | 头像 | | class_name | varchar(32) | 分类名称 | | tag_name | varchar(32) | 标签名称 | | topic_name | varchar(32) | 话题名称 | | username | varchar(32) | 用户名 | | user_id | varchar(64) | 用户唯一id | | result | varchar(64) | 留空备用 | | blog_describe | varchar(64) | 摘要 | | group_name | varchar(64) | 组名 | | group_describe | varchar(64) | 群组描述 | | follow_user_id | varchar(64) | 关注id | | follower_user_id | varchar(64) | 被关注id | | special_describe | varchar(64) | 摘要 | | school_name | varchar(64) | 学校名称 | | school_number | varchar(64) | 统一注册时提交的学号 | ### 数据表 #### user_info 用户信息表 id(PRIMARYKEY), user_id(UNIQUE), username, password, signature 个人签名, phone, mail, birthday, sex, student_certification 学生认证账号, school_name 学校, school_number 学号 gmt_create, gmt_modified last_login 最近登录时间,img_url头像 ```mysql create table user_info( id bigint not null auto_increment primary key , user_id varchar(64) not null unique , username varchar(32) not null, password varchar(128) not null, signature varchar(128) comment '个性签名', phone varchar(11), mail varchar(140), birthday varchar(20), sex tinyint, school_name varchar(64) comment '学校名称', student_certification tinyint default 0 comment '1为统一注册学生用户', school_number varchar(64) comment '统一注册时提交的学号', img_url varchar(255) comment '头像', last_login varchar(20) comment '最近一次登录时间', state tinyint default 1 comment '账号状态,0为注销,1为激活', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### black_user_list 黑名单 id, user_id, gmt_create, gmt_modified, result(留空备用) ```mysql create table black_user_list( id bigint not null auto_increment primary key , user_id varchar(64) not null unique , result varchar(64), gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### relationship_user_list 用户关系表 id(PRIMARYKEY), follow_user_id, follower_user_id, gmt_create, gmt_modified ```mysql create table relationship_user_list( id bigint not null auto_increment primary key , follow_user_id varchar(64) not null , follower_user_id varchar(64) not null , gmt_create datetime , gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### blog_route 博文路由 id(PRIMARYKEY), blog_id(UNIQUE), user_id, gmt_create, gmt_modified ```mysql create table blog_route( id bigint not null auto_increment primary key, blog_id bigint not null UNIQUE, user_id varchar(64) not null, state tinyint not null default 1 comment '1 公开,2 草稿,3 私密, 4 密码, 5 已删除', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### blog_info 博文信息 id(PRIMARYKEY), blog_id(UNIQUE),blog_describe 描述,blog_tag 标签,blog_class 分类,blog_content 博文内容, click_times 点击次数, stars 收藏, gmt_create, gmt_modified ```mysql create table blog_info( id bigint not null auto_increment primary key, blog_id bigint not null UNIQUE, blog_describe varchar(64) comment '摘要', blog_type tinyint default 1 comment '1原创, 2转载', blog_content longtext comment '文章内容', click_times bigint default 0 comment '点击次数', stars bigint comment '收藏', state tinyint not null default 1 comment '1 公开,2 草稿,3 私密, 4 密码, 5 已删除', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### special_route 专题路由 id, special_id, blog_id, gmt_create, gmt_modified ```mysql create table special_route( id bigint not null auto_increment primary key, special_id bigint not null, blog_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### special_info 专题内容 id, special_id, special_describe, special_tag, special_class, stars, gmt_create, gmt_modified ```mysql create table special_info( id bigint not null auto_increment primary key, special_id bigint not null UNIQUE , special_describe varchar(64) comment '摘要', click_times bigint default 0 comment '点击次数', stars bigint comment '收藏', state tinyint not null default 1 comment '1 公开,2 草稿,3 私密, 4 密码, 5 已删除', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### tag_info 标签 id, tag_id, tag_name, click_times, gmt_create, gmt_modified ```mysql create table tag_info( id bigint not null auto_increment primary key, tag_id bigint not null UNIQUE , tag_name varchar(32) not null, click_times bigint default 0, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### blog_tag_route 博客标签路由 id, blog_id, tag_id, gmt_create, gmt_modified ```mysql create table blog_tag_route( id bigint not null auto_increment primary key, blog_id bigint not null, tag_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### special_tag_route 专题标签路由 id, special_id, tag_id, gmt_create, gmt_modified ```mysql create table special_tag_route( id bigint not null auto_increment primary key, special_id bigint not null, tag_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### class_info 分类 ```mysql create table class_info( id bigint not null auto_increment primary key, class_id bigint not null UNIQUE , class_name varchar(32) not null, click_times bigint default 0, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### blog_class_route 博客分类路由 id, blog_id, class_id, gmt_create, gmt_modified ```mysql create table blog_class_route( id bigint not null auto_increment primary key, blog_id bigint not null, class_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### special_class_route 专题分类路由 id, special_id, class_id, gmt_create, gmt_modified ```mysql create table special_class_route( id bigint not null auto_increment primary key, special_id bigint not null, class_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### user_star_blog_route 收藏博客 id, user_id, blog_id, gmt_create, gmt_modified ```mysql create table user_star_blog_route( id bigint not null auto_increment primary key, user_id varchar(64) not null , blog_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### user_star_special_route 收藏专栏 id, user_id, special_id, gmt_create, gmt_modified ```mysql create table user_special_blog_route( id bigint not null auto_increment primary key, user_id varchar(64) not null , special_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### user_star_comment 点赞评论 id, user_id, comment_id, create ```mysql create table user_start_comment( id bigint not null auto_increment primary key, user_id varchar(64) not null , comment_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### blog_comment 评论 id(PRIMARYKEY), comment_id(UNIQUE), pid, blog_id, user_id, comment_content, stars 赞同, gmt_create, gmt_modified ```mysql create table blog_comment( id bigint not null auto_increment primary key, comment_id bigint not null UNIQUE , blog_id bigint not null , pid bigint default null, user_id varchar(64), comment_content text not null , stars bigint comment '点赞', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### topic 社区话题 id(PRIMARYKEY), topic_id(UNIQUE), topic_name, topic_describe, user_id 创建人, topic_class 话题分类, topic_participation 话题参与度, gmt_create, gmt_modified ```mysql create table topic( id bigint not null auto_increment primary key, topic_id bigint not null unique, topic_describe varchar(140) comment '话题描述', topic_name varchar(32) not null , user_id varchar(64) not null , topic_participation bigint not null default 0 comment '话题热度', gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### topic_class_route 话题分类路由 id, topic_id, class_id, gmt_create, gmt_modified ```mysql create table topic_class_route( id bigint not null auto_increment primary key, topic_id bigint not null, class_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### topic_tag_route 话题标签路由 id, topic_id, tag_id, gmt_create, gmt_modified ```mysql create table topic_tag_route( id bigint not null auto_increment primary key, topic_id bigint not null, tag_id bigint not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### group_info 群组 id(PRIMARYKEY), group_id(UNIQUE), group_name, group_describe, gmt_create, gmt_modified ```mysql create table group_info( id bigint not null auto_increment primary key, group_id bigint not null unique, group_name varchar(64), group_describe varchar(64), gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` #### user_group_route id(PRIMARYKEY), group_id, user_id, gmt_create, gmt_modified ```sql create table user_group_route( id bigint not null auto_increment primary key, group_id bigint not null, user_id varchar(64) not null, gmt_create datetime, gmt_modified datetime ) ENGINE=InnoDB DEFAULT CHARSET = utf8; ``` ### 主从设置 双方都新建一个admin用户, 密码也统一,赋予同步数据库的权限 #### 主服务器 47.102.210.6 my.cnf配置 ``` [mysqld] server-id=1 log-bin=mysql-bin.log binlog-do-db=distrident0 ``` 查看master status, 获取pos, 和file 方便从机配置后面使用 ```mysql show master status; ``` #### 从服务器 120.79.224.142 my.cof配置 ``` [mysqld] server-id=2 # 库名不一致转换 replicate-rewrite-db = distrident0 -> distrident ``` ```mysql change master to master_host = '47.102.210.6', master_user = 'admin', master_password = '123456', master_log_pos = 2734, master_log_file = 'mysql-bin.000001'; ``` ## 结构 ### 博客 相关包前缀 com.ditri.blog + com.ditri.blog + dao + entity + controller + service + impl ### 话题广场 com.ditri.topic + com.ditri.blog + dao + entity + controller + service + impl ### 公用方法 commonService ### 公共类 common #### VO, PO, DTO, DO + VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来。 + DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的设计模式,原来的目的是为了EJB的分布式应用提供粗粒度的数据实体,以减少分布式调用的次数,从而提高分布式调用的性能和降低网络负载,但在这里,我泛指用于展示层与服务层之间的数据传输对象。 + DO(Domain Object):领域对象,就是从现实世界中抽象出来的有形或无形的业务实体。 + PO(Persistent Object):持久化对象,它跟持久层(通常是关系型数据库)的数据结构形成一一对应的映射关系,如果持久层是关系型数据库,那么,数据表中的每个字段(或若干个)就对应PO的一个(或若干个)属性。