模块化拆分

This commit is contained in:
禾几海
2021-09-29 23:09:54 +08:00
parent c8e93c45c7
commit 6d3739517a
157 changed files with 9528 additions and 9014 deletions

View File

@@ -0,0 +1,18 @@
package cn.celess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@EnableAsync
public class BlogApplication {
public static final Logger logger = LoggerFactory.getLogger(BlogApplication.class);
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
logger.info("启动完成!");
}
}

View File

@@ -0,0 +1,45 @@
package cn.celess.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
/**
* @author : xiaohai
* @date : 2019/03/30 19:55
* 跨域
*/
@Configuration
public class CorsConfig {
@Value("${spring.profiles.active}")
private String activeModel;
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.addAllowedOrigin("http://celess.cn");
config.addAllowedOrigin("http://www.celess.cn");
config.addAllowedOrigin("https://celess.cn");
config.addAllowedOrigin("https://www.celess.cn");
// 本地调试时的跨域
if (!"prod".equals(activeModel)) {
config.addAllowedOrigin("http://localhost:4200");
config.addAllowedOrigin("http://127.0.0.1:4200");
}
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
config.addExposedHeader("Authorization");
config.setAllowCredentials(true);
config.setMaxAge(10800L);
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

View File

@@ -0,0 +1,41 @@
package cn.celess.configuration;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author : xiaohai
* @date : 2019/03/28 14:26
*/
@Configuration
public class DruidConfig {
@Value("${spring.datasource.url}")
private String dbUrl;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${spring.datasource.driver-class-name}")
private String driverClassName;
@Bean
public DruidDataSource druidDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driverClassName);
// 数据库基本信息
dataSource.setUrl(dbUrl);
dataSource.setUsername(username);
dataSource.setPassword(password);
// 数据库连接池配置
dataSource.setInitialSize(10);
dataSource.setMinIdle(10);
dataSource.setMaxActive(100);
return dataSource;
}
}

View File

@@ -0,0 +1,39 @@
package cn.celess.configuration;
import cn.celess.configuration.filter.AuthenticationFilter;
import cn.celess.configuration.filter.MultipleSubmitFilter;
import cn.celess.configuration.filter.VisitorRecord;
import cn.celess.configuration.listener.SessionListener;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Author: 小海
* @Date: 2019/10/18 14:19
* @Description:
*/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new MultipleSubmitFilter()).addPathPatterns("/**");
registry.addInterceptor(new VisitorRecord()).addPathPatterns("/**");
registry.addInterceptor(authenticationFilter()).addPathPatterns("/**");
}
@Bean
public AuthenticationFilter authenticationFilter() {
return new AuthenticationFilter();
}
@Bean
public ServletListenerRegistrationBean<SessionListener> servletListenerRegistrationBean() {
// session listener register bean
ServletListenerRegistrationBean<SessionListener> slrBean = new ServletListenerRegistrationBean<SessionListener>();
slrBean.setListener(new SessionListener());
return slrBean;
}
}

View File

@@ -0,0 +1,67 @@
package cn.celess.configuration;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
/**
* @author : xiaohai
* @date : 2019/05/22 17:35
*/
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {
/**
* 缓存的命名前缀
*
* @return KeyGenerator
*/
@Override
@Bean
public KeyGenerator keyGenerator() {
return (target, method, params) -> {
StringBuilder sb = new StringBuilder();
String name = target.getClass().getName();
sb.append(name.substring(name.lastIndexOf(".") + 1));
sb.append(":");
sb.append(method.getName());
for (Object obj : params) {
sb.append("-").append(obj.toString());
}
return sb.toString();
};
}
/**
* 配置redisTemplate
*
* @param redisConnectionFactory redisConnectionFactory
* @return redisTemplate
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(jackson2JsonRedisSerializer);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashKeySerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
}

View File

@@ -0,0 +1,46 @@
package cn.celess.configuration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @author : xiaohai
* @date : 2019/03/28 15:55
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Value("${spring.profiles.active}")
private String environment;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(!"prod".equals(environment))
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("cn.celess"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("小海博客的APi")
.description("小海博客的APi")
.contact(new Contact("小海", "https://www.celess.cn", "a@celess.cn"))
.version("1.0")
.build();
}
}

View File

@@ -0,0 +1,94 @@
package cn.celess.configuration.filter;
import cn.celess.common.enmu.ResponseEnum;
import cn.celess.common.entity.Response;
import cn.celess.common.service.UserService;
import cn.celess.common.util.RedisUtil;
import cn.celess.user.util.JwtUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @Author: 小海
* @Date: 2019/11/16 11:21
* @Description: 鉴权拦截器
*/
public class AuthenticationFilter implements HandlerInterceptor {
private static final Logger logger = LoggerFactory.getLogger(AuthenticationFilter.class);
private static final String USER_PREFIX = "/user";
private static final String ADMIN_PREFIX = "/admin";
private static final String ROLE_ADMIN = "admin";
private static final String ROLE_USER = "user";
@Autowired
JwtUtil jwtUtil;
@Autowired
RedisUtil redisUtil;
@Autowired
UserService userService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String path = request.getRequestURI();
path = path.replaceAll("/+", "/");
int indexOf = path.indexOf("/", 1);
String rootPath = indexOf == -1 ? path : path.substring(0, indexOf);
String jwtStr = request.getHeader("Authorization");
if (jwtStr != null && !jwtStr.isEmpty() && !jwtUtil.isTokenExpired(jwtStr)) {
// 已登录 记录当前email
request.getSession().setAttribute("email", jwtUtil.getUsernameFromToken(jwtStr));
}
// 不需要鉴权的路径
if (!USER_PREFIX.equalsIgnoreCase(rootPath) && !ADMIN_PREFIX.equalsIgnoreCase(rootPath)) {
return true;
}
if (jwtStr == null || jwtStr.isEmpty()) {
return writeResponse(ResponseEnum.HAVE_NOT_LOG_IN, response, request);
}
if (jwtUtil.isTokenExpired(jwtStr)) {
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
}
String email = jwtUtil.getUsernameFromToken(jwtStr);
if (jwtUtil.isTokenExpired(jwtStr)) {
// 登陆过期
return writeResponse(ResponseEnum.LOGIN_EXPIRED, response, request);
}
if (!redisUtil.hasKey(email + "-login")) {
return writeResponse(ResponseEnum.LOGOUT, response, request);
}
String role = userService.getUserRoleByEmail(email);
if (role.equals(ROLE_USER) || role.equals(ROLE_ADMIN)) {
// 更新token
String token = jwtUtil.updateTokenDate(jwtStr);
response.setHeader("Authorization", token);
}
if (role.equals(ROLE_ADMIN)) {
// admin
return true;
}
if (role.equals(ROLE_USER) && !rootPath.equals(ADMIN_PREFIX)) {
// user not admin page
return true;
}
return writeResponse(ResponseEnum.PERMISSION_ERROR, response, request);
}
private boolean writeResponse(ResponseEnum e, HttpServletResponse response, HttpServletRequest request) {
response.setHeader("Content-Type", "application/json;charset=UTF-8");
try {
logger.info("鉴权失败,[code:{},msg:{},path:{}]", e.getCode(), e.getMsg(), request.getRequestURI() + "?" + request.getQueryString());
response.getWriter().println(new ObjectMapper().writeValueAsString(Response.response(e, null)));
} catch (IOException ex) {
ex.printStackTrace();
}
return false;
}
}

View File

@@ -0,0 +1,44 @@
package cn.celess.configuration.filter;
import cn.celess.common.enmu.ResponseEnum;
import cn.celess.common.entity.Response;
import cn.celess.common.util.RequestUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* @Author: 小海
* @Date: 2019/10/18 13:46
* @Description: 多次请求拦截器
*/
public class MultipleSubmitFilter implements HandlerInterceptor {
private static final int WAIT_TIME = 200;// 多次提交中间的间隔
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Long lastSubmitTime = (Long) request.getSession().getAttribute("lastSubmitTime");
String completeUrl = (String) request.getSession().getAttribute("completeUrl&method");
if (lastSubmitTime == null || completeUrl == null) {
return true;
}
if (System.currentTimeMillis() - lastSubmitTime < WAIT_TIME && RequestUtil.getCompleteUrlAndMethod(request).equals(completeUrl)) {
// 请求参数和路径均相同 且请求时间间隔小于 WAIT_TIME
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
Response result = new Response(ResponseEnum.FAILURE.getCode(), "重复请求", null);
response.getWriter().println(result);
return false;
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
HttpSession session = request.getSession();
session.setAttribute("lastSubmitTime", System.currentTimeMillis());
session.setAttribute("completeUrl&method", RequestUtil.getCompleteUrlAndMethod(request));
}
}

View File

@@ -0,0 +1,38 @@
package cn.celess.configuration.filter;
import cn.celess.common.util.RequestUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
/**
* @Author: 小海
* @Date: 2019/10/18 15:38
* @Description: 记录访问情况
*/
@Configuration
public class VisitorRecord implements HandlerInterceptor {
@SuppressWarnings("unchecked")
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) session.getAttribute("visitDetail");
if (visitDetail == null) {
return true;
}
// 获取访问次数
Integer count = visitDetail.get(RequestUtil.getCompleteUrlAndMethod(request));
// 自增
count = count == null ? 1 : ++count;
// 更新
visitDetail.put(RequestUtil.getCompleteUrlAndMethod(request), count);
session.setAttribute("ip", request.getRemoteAddr());
return true;
}
}

View File

@@ -0,0 +1,49 @@
package cn.celess.configuration.listener;
import cn.celess.user.util.RedisUserUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.HashMap;
/**
* @Author: 小海
* @Date: 2019/10/18 15:33
* @Description: 监听session的情况
*/
@Log4j2
@WebListener
public class SessionListener implements HttpSessionListener {
@Autowired
RedisUserUtil redisUserUtil;
@Autowired
HttpServletRequest request;
@Override
public void sessionCreated(HttpSessionEvent se) {
se.getSession().setAttribute("visitDetail", new HashMap<String, Integer>());
// 10s for debug
// se.getSession().setMaxInactiveInterval(10);
// log.info("新增一个Session[{}]", se.getSession().getId());
}
@SuppressWarnings("unchecked")
@Override
public void sessionDestroyed(HttpSessionEvent se) {
HashMap<String, Integer> visitDetail = (HashMap<String, Integer>) se.getSession().getAttribute("visitDetail");
StringBuilder sb = new StringBuilder();
sb.append("ip => ").append(se.getSession().getAttribute("ip"));
if (visitDetail.size() == 0) {
return;
}
sb.append("\t登录情况 => ");
String email = (String) se.getSession().getAttribute("email");
sb.append(email == null ? "游客访问" : email);
visitDetail.forEach((s, integer) -> sb.append("\n").append("Method:[").append(s.split(":")[1]).append("]\tTimes:[").append(integer).append("]\tPath:[").append(s.split(":")[0]).append("]"));
log.info(sb.toString());
}
}

View File

@@ -0,0 +1,90 @@
server.port=8081
# 七牛的密钥配置
qiniu.accessKey=
qiniu.secretKey=
qiniu.bucket=
# sitemap 存放地址
sitemap.path=
# 生成JWT时候的密钥
jwt.secret=
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
# 上传单个文件的大小
spring.servlet.multipart.max-file-size=10MB
# 上传文件的总大小
spring.servlet.multipart.max-request-size=10MB
##null字段不显示
spring.jackson.default-property-inclusion=non_null
################# 数据库 ##################
#请先填写下面的配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.platform=mysql
# never / always / embedded
spring.datasource.initialization-mode=never
spring.datasource.sql-script-encoding=utf-8
spring.datasource.schema=classpath:sql/schema.sql
spring.datasource.data=classpath:sql/data.sql
################## mybatis ##################
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=cn.celess.common.entity
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
################ email ##############
#请先填写下面的配置,不然可能运行不起来
spring.mail.host=
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.default-encoding=UTF-8
spring.mail.port=465
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
#### 用于nginx的代理 获取真实ip
server.use-forward-headers = true
server.tomcat.remote-ip-header = X-Real-IP
server.tomcat.protocol-header = X-Forwarded-Proto
############### redis ##############
# REDIS (RedisProperties)
# Redis数据库索引默认为0
spring.redis.database=0
# Redis服务器地址
spring.redis.host=
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

View File

@@ -0,0 +1,68 @@
server.port=8081
# 七牛的密钥配置
qiniu.accessKey=si3O2_Q7edFtjzmyyzXkoE9G1toxcjDfULhX5zdh
qiniu.secretKey=Pnq8q2Iy1Ez8RQXQR33XmgAYlit7M8C197BZ4lCj
qiniu.bucket=xiaohai
# sitemap 存放地址
sitemap.path=
# 生成JWT时候的密钥
jwt.secret=sdjfi77;47h7uuo4l;4lgiu4;dl5684aasdasdpsidf;sdf
#mybatis.type-handlers-package=cn.celess.common.mapper.typehandler
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
# 上传单个文件的大小
spring.servlet.multipart.max-file-size=10MB
# 上传文件的总大小
spring.servlet.multipart.max-request-size=10MB
spring.jackson.default-property-inclusion=non_null
################# 数据库 ##################
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
# spring.datasource.url=jdbc:mysql://localhost:3306/blog?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.url=jdbc:mysql://localhost:3306/blog?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=zhenghai
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.initialization-mode=never
################## mybatis ##################
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=cn.celess.common.entity
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
#### 用于nginx的代理 获取真实ip
server.use-forward-headers=true
server.tomcat.remote-ip-header=X-Real-IP
server.tomcat.protocol-header=X-Forwarded-Proto
############### email ##############
spring.mail.host=smtp.163.com
spring.mail.username=xiaohai2271@163.com
spring.mail.password=56462271Zh
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.default-encoding=UTF-8
spring.mail.port=465
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
############### redis ##############
# REDIS (RedisProperties)
# Redis数据库索引默认为0
spring.redis.database=0
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码默认为空
spring.redis.password=zhenghai
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

View File

@@ -0,0 +1,90 @@
server.port=8081
# 七牛的密钥配置
qiniu.accessKey=
qiniu.secretKey=
qiniu.bucket=
# sitemap 存放地址
sitemap.path=
# 生成JWT时候的密钥
jwt.secret=sdaniod213k123123ipoeqowekqwe
##spring.jpa.show-sql=false
##spring.jpa.hibernate.ddl-auto=update
mybatis.type-handlers-package=cn.celess.common.mapper.typehandler
logging.level.cn.celess.common.mapper=debug
# 上传单个文件的大小
spring.servlet.multipart.max-file-size=10MB
# 上传文件的总大小
spring.servlet.multipart.max-request-size=10MB
spring.jackson.default-property-inclusion=non_null
################# 数据库 ##################
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#h2
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;mode=mysql;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2
spring.datasource.sql-script-encoding=utf-8
spring.datasource.initialization-mode=ALWAYS
spring.datasource.schema=classpath:sql/schema_h2.sql
spring.datasource.data=classpath:sql/data.sql
################## mybatis ##################
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=cn.celess.common.entity
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
#### 用于nginx的代理 获取真实ip
server.use-forward-headers = true
server.tomcat.remote-ip-header = X-Real-IP
server.tomcat.protocol-header = X-Forwarded-Proto
############### email ##############
spring.mail.host=smtp.163.com
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.default-encoding=UTF-8
spring.mail.port=465
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=false
############### redis ##############
# REDIS (RedisProperties)
# Redis数据库索引默认为0
spring.redis.database=1
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口 解决端口冲突 防止使用本地的redis
spring.redis.port=6380
# Redis服务器连接密码默认为空
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=-1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

View File

@@ -0,0 +1,8 @@
spring.profiles.active=prod
####七牛的配置
####cn.celess.blog.service.serviceimpl.QiniuServiceImpl
logging.level.cn.celess.blog=debug
logging.level.cn.celess.common.mapper=info
spring.cache.type=redis
## 修改openSource 添加-test 文件用于测试 -prod文件用于线上发布

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,188 @@
drop view if exists articleView;
drop view if exists commentView;
drop table if exists article_tag;
drop table if exists comment;
drop table if exists article;
drop table if exists user;
drop table if exists tag_category;
drop table if exists links;
drop table if exists visitor;
drop table if exists web_update;
CREATE TABLE `user`
(
`u_id` int not null primary key auto_increment,
`u_email` varchar(50) not null,
`u_pwd` varchar(40) not null comment '密码',
`u_email_status` boolean default false comment '邮箱验证状态',
`u_avatar` varchar(255) default null comment '用户头像',
`u_desc` tinytext COLLATE utf8mb4_unicode_ci default null comment '用户的描述',
`u_recently_landed_time` datetime default null comment '最近的登录时间',
`u_display_name` varchar(30) COLLATE utf8mb4_unicode_ci default null comment '展示的昵称',
`u_role` varchar(40) not null default 'user' comment '权限组',
`status` tinyint(1) not null default 0 comment '账户状态',
unique key `uni_user_id` (`u_id`),
unique key `uni_user_email` (`u_email`)
) comment '用户表';
CREATE TABLE `tag_category`
(
`t_id` bigint(20) primary key auto_increment,
`t_name` varchar(255) not null,
`is_category` boolean not null default true,
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '标签和分类表';
CREATE TABLE `article`
(
`a_id` bigint(20) primary key auto_increment,
`a_title` varchar(255) COLLATE utf8mb4_unicode_ci not null unique comment '文章标题',
`a_summary` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '文章摘要',
`a_md_content` longtext COLLATE utf8mb4_unicode_ci not null comment '文章Markdown内容',
`a_url` tinytext default null comment '转载文章的原文链接',
`a_author_id` int not null comment '作者id',
`a_is_original` boolean default true comment '文章是否原创',
`a_reading_number` int default 0 comment '文章阅读数',
`a_like` int default 0 comment '文章点赞数',
`a_dislike` int default 0 comment '文章不喜欢数',
`a_category_id` bigint not null comment '文章分类id',
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
`a_update_date` datetime default null comment '文章的更新时间',
`a_is_open` boolean default true comment '文章是否可见',
`is_delete` boolean not null default false comment '该数据是否被删除',
foreign key (a_category_id) references tag_category (t_id),
foreign key (a_author_id) references user (u_id)
) DEFAULT CHARSET = utf8mb4
COLLATE utf8mb4_general_ci,comment '文章表';
CREATE TABLE `article_tag`
(
`at_id` bigint(20) primary key auto_increment,
`a_id` bigint(20) not null comment '文章id',
`t_id` bigint not null comment 'tag/category 的id',
foreign key (a_id) references article (a_id),
foreign key (t_id) references tag_category (t_id)
) comment '文章标签表';
CREATE TABLE `comment`
(
`co_id` bigint(20) primary key auto_increment,
`co_page_path` varchar(255) not null comment '评论/留言的页面',
`co_content` text COLLATE utf8mb4_unicode_ci not null comment '评论/留言内容',
`co_date` datetime not null comment '评论/留言的日期',
`co_status` tinyint not null default 0 comment '评论的状态',
`co_pid` bigint not null default -1 comment '评论/留言的父id',
`co_from_author_id` int not null comment '留言者id',
`co_to_author_id` int default null comment '父评论的作者id',
foreign key (co_from_author_id) references user (u_id),
foreign key (co_to_author_id) references user (u_id)
) DEFAULT CHARSET = utf8mb4
COLLATE utf8mb4_general_ci,comment '评论/留言表';
CREATE TABLE `links`
(
`l_id` bigint(20) primary key auto_increment,
`l_name` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友站名称',
`l_is_open` boolean default true comment '是否公开',
`l_url` varchar(255) unique not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除',
`l_email` varchar(255) comment '网站管理员的邮箱',
`l_notification` boolean default false comment '是否通知了'
) comment '友站表';
CREATE TABLE `visitor`
(
`v_id` bigint(20) primary key auto_increment,
`v_date` datetime not null comment '访问时间',
`v_ip` varchar(255) not null comment '访客ip',
`v_user_agent` text comment '访客ua',
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '访客表';
CREATE TABLE `web_update`
(
`wu_id` int primary key auto_increment,
`wu_info` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '更新内容',
`wu_time` datetime not null comment '更新时间',
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '更新内容表';
CREATE VIEW articleView
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
publishDate, updateDate, isOpen,
categoryId, categoryName, tagId, tagName,
authorId, userEmail, userAvatar, userDisplayName, isDelete)
as
select article.a_id as articleId,
article.a_title as title,
article.a_summary as summary,
article.a_md_content as mdContent,
article.a_url as url,
article.a_is_original as isOriginal,
article.a_reading_number as readingCount,
article.a_like as likeCount,
article.a_dislike as dislikeCount,
article.a_publish_date as publishDate,
article.a_update_date as updateDate,
article.a_is_open as isOpen,
category.t_id as categoryId,
category.t_name as categoryName,
tag.t_id as tagId,
tag.t_name as tagName,
user.u_id as authorId,
user.u_email as userEmail,
user.u_avatar as userAvatar,
user.u_display_name as userDisplayName,
article.is_delete as isDelete
from article,
tag_category as tag,
tag_category as category,
article_tag,
user
where article.a_id = article_tag.a_id
and article_tag.t_id = tag.t_id
and tag.is_category = false
and article.a_category_id = category.t_id
and category.is_category = true
and article.a_author_id = user.u_id;
CREATE VIEW commentView
(commentId, pagePath, content, date, status, pid, toAuthorId, toAuthorEmail, toAuthorDisplayName,
toAuthorAvatar, fromAuthorId, fromAuthorEmail, fromAuthorDisplayName,
fromAuthorAvatar)
as
select cuT.co_id as commentId,
cuT.co_page_path as pagePath,
cuT.co_content as content,
cuT.co_date as date,
cuT.co_status as status,
cuT.co_pid as pid,
cuT.co_to_author_id as toAuthorId,
cuT.toEmail as toAuthorEmail,
cuT.toDisplayName as toAuthorDisplayName,
cuT.toAvatar as toAuthorAvatar,
userFrom.u_id as fromAuthorId,
userFrom.u_email as fromAuthorEmail,
userFrom.u_display_name as fromAuthorDisplayName,
userFrom.u_avatar as fromAuthorAvatar
from (select comment.co_id,
comment.co_page_path,
comment.co_content,
comment.co_date,
comment.co_status,
comment.co_pid,
comment.co_from_author_id,
comment.co_to_author_id,
userTo.u_email as toEmail,
userTo.u_display_name as toDisplayName,
userTo.u_avatar as toAvatar
from comment
left join user userTo on (comment.co_to_author_id = userTo.u_id)
) as cuT,
user as userFrom
where cuT.co_from_author_id = userFrom.u_id;

View File

@@ -0,0 +1,193 @@
drop view if exists articleView;
drop view if exists commentView;
drop table if exists article_tag;
drop table if exists comment;
drop table if exists article;
drop table if exists user;
drop table if exists tag_category;
drop table if exists links;
drop table if exists visitor;
drop table if exists web_update;
-- 用户表
CREATE TABLE `user`
(
`u_id` int not null primary key auto_increment,
`u_email` varchar(50) not null,
`u_pwd` varchar(40) not null comment '密码',
`u_email_status` boolean default false comment '邮箱验证状态',
`u_avatar` varchar(255) default null comment '用户头像',
`u_desc` tinytext default null comment '用户的描述',
`u_recently_landed_time` datetime default null comment '最近的登录时间',
`u_display_name` varchar(30) default null comment '展示的昵称',
`u_role` varchar(40) not null default 'user' comment '权限组',
`status` tinyint(1) not null default 0 comment '账户状态',
unique key `uni_user_id` (`u_id`),
unique key `uni_user_email` (`u_email`)
);
-- 标签和分类表
CREATE TABLE `tag_category`
(
`t_id` bigint(20) primary key auto_increment,
`t_name` varchar(255) not null,
`is_category` boolean not null default true,
`is_delete` boolean not null default false comment '该数据是否被删除'
);
-- 文章表
CREATE TABLE `article`
(
`a_id` bigint(20) primary key auto_increment,
`a_title` varchar(255) not null unique comment '文章标题',
`a_summary` varchar(255) not null comment '文章摘要',
`a_md_content` longtext not null comment '文章Markdown内容',
`a_url` tinytext default null comment '转载文章的原文链接',
`a_author_id` int not null comment '作者id',
`a_is_original` boolean default true comment '文章是否原创',
`a_reading_number` int default 0 comment '文章阅读数',
`a_like` int default 0 comment '文章点赞数',
`a_dislike` int default 0 comment '文章不喜欢数',
`a_category_id` bigint not null comment '文章分类id',
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
`a_update_date` datetime default null comment '文章的更新时间',
`a_is_open` boolean default true comment '文章是否可见',
`is_delete` boolean not null default false comment '该数据是否被删除',
foreign key (a_category_id) references tag_category (t_id),
foreign key (a_author_id) references user (u_id)
);
-- 文章标签表
CREATE TABLE `article_tag`
(
`at_id` bigint(20) primary key auto_increment,
`a_id` bigint(20) not null comment '文章id',
`t_id` bigint not null comment 'tag/category 的id',
foreign key (a_id) references article (a_id),
foreign key (t_id) references tag_category (t_id)
);
-- 评论/留言表
CREATE TABLE `comment`
(
`co_id` bigint(20) primary key auto_increment,
`co_page_path` varchar(255) not null comment '评论/留言的页面',
`co_content` text not null comment '评论/留言内容',
`co_date` datetime not null comment '评论/留言的日期',
`co_status` tinyint not null default 0 comment '评论的状态',
`co_pid` bigint not null default -1 comment '评论/留言的父id',
`co_from_author_id` int not null comment '留言者id',
`co_to_author_id` int default null comment '父评论的作者id',
foreign key (co_from_author_id) references user (u_id),
foreign key (co_to_author_id) references user (u_id)
);
-- 友站表
CREATE TABLE `links`
(
`l_id` bigint(20) primary key auto_increment,
`l_name` varchar(255) not null comment '友站名称',
`l_is_open` boolean default true comment '是否公开',
`l_url` varchar(255) unique not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除',
`l_email` varchar(255) comment '网站管理员的邮箱',
`l_notification` boolean default false comment '是否通知了'
);
-- 访客表
CREATE TABLE `visitor`
(
`v_id` bigint(20) primary key auto_increment,
`v_date` datetime not null comment '访问时间',
`v_ip` varchar(255) not null comment '访客ip',
`v_user_agent` text comment '访客ua',
`is_delete` boolean not null default false comment '该数据是否被删除'
);
-- 更新内容表
CREATE TABLE `web_update`
(
`wu_id` int primary key auto_increment,
`wu_info` varchar(255) not null comment '更新内容',
`wu_time` datetime not null comment '更新时间',
`is_delete` boolean not null default false comment '该数据是否被删除'
);
CREATE VIEW articleView
(articleId, title, summary, mdContent, url, isOriginal, readingCount, likeCount, dislikeCount,
publishDate, updateDate, isOpen,
categoryId, categoryName, tagId, tagName,
authorId, userEmail, userAvatar, userDisplayName, isDelete)
as
select article.a_id as articleId,
article.a_title as title,
article.a_summary as summary,
article.a_md_content as mdContent,
article.a_url as url,
article.a_is_original as isOriginal,
article.a_reading_number as readingCount,
article.a_like as likeCount,
article.a_dislike as dislikeCount,
article.a_publish_date as publishDate,
article.a_update_date as updateDate,
article.a_is_open as isOpen,
category.t_id as categoryId,
category.t_name as categoryName,
tag.t_id as tagId,
tag.t_name as tagName,
user.u_id as authorId,
user.u_email as userEmail,
user.u_avatar as userAvatar,
user.u_display_name as userDisplayName,
article.is_delete as isDelete
from article,
tag_category as tag,
tag_category as category,
article_tag,
user
where article.a_id = article_tag.a_id
and article_tag.t_id = tag.t_id
and tag.is_category = false
and article.a_category_id = category.t_id
and category.is_category = true
and article.a_author_id = user.u_id;
CREATE VIEW commentView
(commentId, pagePath, content, date, status, pid, toAuthorId, toAuthorEmail, toAuthorDisplayName,
toAuthorAvatar, fromAuthorId, fromAuthorEmail, fromAuthorDisplayName,
fromAuthorAvatar)
as
select cuT.co_id as commentId,
cuT.co_page_path as pagePath,
cuT.co_content as content,
cuT.co_date as date,
cuT.co_status as status,
cuT.co_pid as pid,
cuT.co_to_author_id as toAuthorId,
cuT.toEmail as toAuthorEmail,
cuT.toDisplayName as toAuthorDisplayName,
cuT.toAvatar as toAuthorAvatar,
userFrom.u_id as fromAuthorId,
userFrom.u_email as fromAuthorEmail,
userFrom.u_display_name as fromAuthorDisplayName,
userFrom.u_avatar as fromAuthorAvatar
from (select comment.co_id,
comment.co_page_path,
comment.co_content,
comment.co_date,
comment.co_status,
comment.co_pid,
comment.co_from_author_id,
comment.co_to_author_id,
userTo.u_email as toEmail,
userTo.u_display_name as toDisplayName,
userTo.u_avatar as toAvatar
from comment
left join user userTo on (comment.co_to_author_id = userTo.u_id)
) as cuT,
user as userFrom
where cuT.co_from_author_id = userFrom.u_id;