模块化拆分
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,5 +4,5 @@
|
||||
target/
|
||||
|
||||
# 本地项目的私有文件
|
||||
src/main/resources/application-dev.properties
|
||||
blog-deploy/src/main/resources/application-dev.properties
|
||||
src/main/resources/application-prod.properties
|
||||
|
||||
50
blog-article/pom.xml
Normal file
50
blog-article/pom.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-article</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>13</maven.compiler.source>
|
||||
<maven.compiler.target>13</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--MarkDown 2 html -->
|
||||
<dependency>
|
||||
<groupId>com.youbenzi</groupId>
|
||||
<artifactId>MDTool</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.minidev</groupId>
|
||||
<artifactId>json-smart</artifactId>
|
||||
<version>2.4.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,163 +1,163 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.request.ArticleReq;
|
||||
import cn.celess.blog.service.ArticleService;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import cn.celess.blog.util.SitemapGenerateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:18
|
||||
*/
|
||||
@RestController
|
||||
public class ArticleController {
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Autowired
|
||||
SitemapGenerateUtil sitemapGenerateUtil;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
/**
|
||||
* 新建一篇文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/article/create")
|
||||
public Response create(@RequestBody ArticleReq body) {
|
||||
ArticleModel articleModel = articleService.create(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(articleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文章id 删除一篇文章
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/article/del")
|
||||
public Response delete(@RequestParam("articleID") long articleId) {
|
||||
boolean delete = articleService.delete(articleId);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/article/update")
|
||||
public Response update(@RequestBody ArticleReq body) {
|
||||
ArticleModel update = articleService.update(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查找一篇文章
|
||||
* 公开 =>返回数据
|
||||
* 不公开
|
||||
* *** =>作者 返回数据
|
||||
* *** =>其他 抛出错误
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是更新
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/article/articleID/{articleID}")
|
||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||
HttpServletRequest request) {
|
||||
ArticleModel article = articleService.retrieveOneById(articleId, is4update);
|
||||
if (article.getOpen()) {
|
||||
return Response.success(article);
|
||||
} else if (article.getAuthor().getId().equals(redisUserUtil.get().getId())) {
|
||||
return Response.success(article);
|
||||
}
|
||||
return Response.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章状态为开放的的文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles")
|
||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||
return Response.success(articleService.retrievePageForOpen(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/admin/articles")
|
||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类获取文章(文章摘要)
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/category/{name}")
|
||||
public Response findByCategory(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByCategory(name, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名获取文章(文章摘要)
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/tag/{name}")
|
||||
public Response findByTag(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByTag(name, page, count));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/createSitemap")
|
||||
public Response createSitemap() {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return Response.success(null);
|
||||
}
|
||||
}
|
||||
package cn.celess.article.controller;
|
||||
|
||||
import cn.celess.article.util.SitemapGenerateUtil;
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.ArticleReq;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.service.ArticleService;
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:18
|
||||
*/
|
||||
@RestController
|
||||
public class ArticleController {
|
||||
@Autowired
|
||||
ArticleService articleService;
|
||||
@Autowired
|
||||
SitemapGenerateUtil sitemapGenerateUtil;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
/**
|
||||
* 新建一篇文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/article/create")
|
||||
public Response create(@RequestBody ArticleReq body) {
|
||||
ArticleModel articleModel = articleService.create(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(articleModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过文章id 删除一篇文章
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/article/del")
|
||||
public Response delete(@RequestParam("articleID") long articleId) {
|
||||
boolean delete = articleService.delete(articleId);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(delete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
*
|
||||
* @param body 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/article/update")
|
||||
public Response update(@RequestBody ArticleReq body) {
|
||||
ArticleModel update = articleService.update(body);
|
||||
if ("prod".equals(activeModel)) {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
}
|
||||
return Response.success(update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查找一篇文章
|
||||
* 公开 =>返回数据
|
||||
* 不公开
|
||||
* *** =>作者 返回数据
|
||||
* *** =>其他 抛出错误
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是更新
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/article/articleID/{articleID}")
|
||||
public Response retrieveOneById(@PathVariable("articleID") long articleId,
|
||||
@RequestParam(value = "update", defaultValue = "false") boolean is4update,
|
||||
HttpServletRequest request) {
|
||||
ArticleModel article = articleService.retrieveOneById(articleId, is4update);
|
||||
if (article.getOpen()) {
|
||||
return Response.success(article);
|
||||
} else if (article.getAuthor().getId().equals(redisUserUtil.get().getId())) {
|
||||
return Response.success(article);
|
||||
}
|
||||
return Response.response(ResponseEnum.PERMISSION_ERROR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章状态为开放的的文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles")
|
||||
public Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "5") int count) {
|
||||
return Response.success(articleService.retrievePageForOpen(count, page));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取所有文章
|
||||
*
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/admin/articles")
|
||||
public Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count,
|
||||
@RequestParam(name = "deleted", required = false) Boolean deleted) {
|
||||
return Response.success(articleService.adminArticles(count, page, deleted));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过分类获取文章(文章摘要)
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/category/{name}")
|
||||
public Response findByCategory(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByCategory(name, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过标签名获取文章(文章摘要)
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param page 页码
|
||||
* @param count 单页数据量
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/articles/tag/{name}")
|
||||
public Response findByTag(@PathVariable("name") String name,
|
||||
@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "10") int count) {
|
||||
return Response.success(articleService.findByTag(name, page, count));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/createSitemap")
|
||||
public Response createSitemap() {
|
||||
sitemapGenerateUtil.createSitemap();
|
||||
return Response.success(null);
|
||||
}
|
||||
}
|
||||
@@ -1,361 +1,367 @@
|
||||
package cn.celess.blog.service.serviceimpl;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.enmu.RoleEnum;
|
||||
import cn.celess.blog.entity.*;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.request.ArticleReq;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.mapper.*;
|
||||
import cn.celess.blog.service.ArticleService;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.ModalTrans;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import cn.celess.blog.util.RegexUtil;
|
||||
import cn.celess.blog.util.StringFromHtmlUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.youbenzi.mdtool.tool.MDTool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:21
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Autowired
|
||||
TagMapper tagMapper;
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
CommentMapper commentMapper;
|
||||
@Autowired
|
||||
ArticleTagMapper articleTagMapper;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ArticleModel create(ArticleReq reqBody) {
|
||||
if (reqBody == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
//数据判断
|
||||
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
//转载 判断链接
|
||||
if (!reqBody.getType()) {
|
||||
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||
}
|
||||
}
|
||||
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||
}
|
||||
// 查看是否存在已有的分类
|
||||
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 构建 需要写入数据库的对象数据
|
||||
Article article = new Article();
|
||||
BeanUtils.copyProperties(reqBody, article);
|
||||
|
||||
article.setUser(redisUserUtil.get());
|
||||
|
||||
//markdown->html->summary
|
||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||
//获取摘要 摘要长度为255个字符
|
||||
String summary = str.length() > 240 ? str.substring(0, 240) + "......" : str;
|
||||
article.setSummary(summary);
|
||||
|
||||
article.setCategory(category);
|
||||
|
||||
//文章存数据库
|
||||
articleMapper.insert(article);
|
||||
//将标签写入数据库
|
||||
for (String tagName : reqBody.getTags()) {
|
||||
if (tagName.replaceAll(" ", "").length() == 0) {
|
||||
//单个标签只含空格
|
||||
continue;
|
||||
}
|
||||
Tag tag = tagMapper.findTagByName(tagName);
|
||||
if (tag == null) {
|
||||
tag = new Tag();
|
||||
tag.setName(tagName);
|
||||
tagMapper.insert(tag);
|
||||
}
|
||||
ArticleTag articleTag = new ArticleTag(article, tag);
|
||||
articleTagMapper.insert(articleTag);
|
||||
}
|
||||
Article articleFromDb = articleMapper.findArticleById(article.getId());
|
||||
|
||||
ArticleModel articleModel = ModalTrans.article(articleFromDb);
|
||||
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(article.getId()), true));
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(long articleId) {
|
||||
Article articleForDel = articleMapper.findArticleById(articleId);
|
||||
|
||||
if (articleForDel == null) {
|
||||
//文章不存在
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||
}
|
||||
|
||||
//对访问情况进行判断 非admin 权限不可删除文章
|
||||
User user = redisUserUtil.get();
|
||||
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
||||
throw new MyException(ResponseEnum.PERMISSION_ERROR);
|
||||
}
|
||||
//删除指定文章
|
||||
articleMapper.delete(articleId);
|
||||
|
||||
//articleTagMapper.deleteByArticleId(articleId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public ArticleModel update(ArticleReq reqBody) {
|
||||
if (reqBody == null || reqBody.getId() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
// 查找数据
|
||||
Article article = articleMapper.findArticleById(reqBody.getId());
|
||||
|
||||
//数据判断
|
||||
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||
}
|
||||
article.setTitle(reqBody.getTitle());
|
||||
}
|
||||
if (reqBody.getMdContent() != null && !reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||
article.setMdContent(reqBody.getMdContent());
|
||||
}
|
||||
|
||||
//转载 判断链接
|
||||
if (reqBody.getType() != null) {
|
||||
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
|
||||
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||
}
|
||||
article.setType(reqBody.getType());
|
||||
article.setUrl(reqBody.getUrl());
|
||||
}
|
||||
if (reqBody.getCategory() != null && !reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||
if (category == null) {
|
||||
category = new Category();
|
||||
category.setName(reqBody.getCategory());
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
article.setCategory(category);
|
||||
}
|
||||
|
||||
//写入数据库的数据
|
||||
article.setOpen(reqBody.getOpen() == null ? article.getOpen() : reqBody.getOpen());
|
||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||
article.setSummary(str.length() > 240 ? str.substring(0, 240) + "......" : str);
|
||||
articleMapper.update(article);
|
||||
|
||||
|
||||
List<ArticleTag> allByArticleId = articleTagMapper.findAllByArticleId(article.getId());
|
||||
List<ArticleTag> updateList = new ArrayList<>();
|
||||
List<ArticleTag> deleteList = new ArrayList<>();
|
||||
|
||||
// 获取要更新 的标签
|
||||
for (String tag : reqBody.getTags()) {
|
||||
boolean contain = allByArticleId.stream().anyMatch(articleTag -> articleTag.getTag().getName().equals(tag));
|
||||
if (!contain) {
|
||||
ArticleTag articleTag = new ArticleTag();
|
||||
articleTag.setArticle(article);
|
||||
Tag tagByName = tagMapper.findTagByName(tag);
|
||||
if (tagByName == null) {
|
||||
tagByName = new Tag(tag);
|
||||
tagMapper.insert(tagByName);
|
||||
}
|
||||
articleTag.setTag(tagByName);
|
||||
updateList.add(articleTag);
|
||||
}
|
||||
}
|
||||
// 获取要删除的标签
|
||||
allByArticleId.forEach(articleTag -> {
|
||||
boolean contain = false;
|
||||
for (String tag : reqBody.getTags()) {
|
||||
if (articleTag.getTag().getName().equals(tag)) {
|
||||
contain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contain) {
|
||||
deleteList.add(articleTag);
|
||||
}
|
||||
});
|
||||
|
||||
if (updateList.size() != 0) {
|
||||
updateList.forEach(articleTag -> articleTagMapper.insert(articleTag));
|
||||
}
|
||||
|
||||
if (deleteList.size() != 0) {
|
||||
articleTagMapper.deleteMultiById(deleteList);
|
||||
}
|
||||
|
||||
//更新完成移除
|
||||
request.getSession().removeAttribute("article4update");
|
||||
ArticleModel articleModel = ModalTrans.article(articleMapper.findArticleById(article.getId()));
|
||||
setPreAndNextArticle(articleModel);
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
||||
Article article = articleMapper.findArticleById(articleId);
|
||||
if (article == null) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||
}
|
||||
if (!article.getOpen()) {
|
||||
User user = redisUserUtil.getWithOutExc();
|
||||
if (user == null || "user".equals(user.getRole())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
||||
}
|
||||
}
|
||||
ArticleModel articleModel = ModalTrans.article(article);
|
||||
|
||||
if (is4update) {
|
||||
//因更新而获取文章 不需要增加阅读量
|
||||
request.getSession().setAttribute("article4update", article);
|
||||
return articleModel;
|
||||
}
|
||||
setPreAndNextArticle(articleModel);
|
||||
articleMapper.updateReadingNumber(articleId);
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param count 数目
|
||||
* @param page 页面
|
||||
* @return PageInfo
|
||||
*/
|
||||
@Override
|
||||
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> articleList = articleMapper.findAll();
|
||||
|
||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||
|
||||
List<Article> collect;
|
||||
if (deleted != null) {
|
||||
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||
} else {
|
||||
collect = articleList;
|
||||
}
|
||||
List<ArticleModel> articleModels = collect.stream()
|
||||
.peek(article -> article.setMdContent(null))
|
||||
.map(ModalTrans::article)
|
||||
.collect(Collectors.toList());
|
||||
pageData.setList(articleModels);
|
||||
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> articleList = articleMapper.findAllByOpen(true);
|
||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||
|
||||
List<ArticleModel> articleModelList = articleList
|
||||
.stream()
|
||||
.map(article -> setPreAndNextArticle(ModalTrans.article(article, true)))
|
||||
.collect(Collectors.toList());
|
||||
pageData.setList(articleModelList);
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
||||
Category category = categoryMapper.findCategoryByName(name);
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||
|
||||
List<ArticleModel> modelList = open.stream()
|
||||
.map(article -> ModalTrans.article(article, true))
|
||||
.peek(articleModel -> {
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setPreArticle(null);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(open), modelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
||||
Tag tag = tagMapper.findTagByName(name);
|
||||
if (tag == null) {
|
||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||
}
|
||||
PageHelper.startPage(page, count);
|
||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||
List<ArticleModel> modelList = articleByTag
|
||||
.stream()
|
||||
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||
.peek(articleModel -> {
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setPreArticle(null);
|
||||
}).collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(articleByTag), modelList);
|
||||
}
|
||||
|
||||
private ArticleModel setPreAndNextArticle(ArticleModel articleModel) {
|
||||
if (articleModel == null) {
|
||||
return null;
|
||||
}
|
||||
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||
return articleModel;
|
||||
}
|
||||
}
|
||||
package cn.celess.article.serviceimpl;
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.enmu.RoleEnum;
|
||||
import cn.celess.common.entity.*;
|
||||
import cn.celess.common.entity.dto.ArticleReq;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.exception.MyException;
|
||||
import cn.celess.common.mapper.*;
|
||||
import cn.celess.common.service.ArticleService;
|
||||
import cn.celess.common.service.UserService;
|
||||
import cn.celess.common.util.ModalTrans;
|
||||
import cn.celess.common.util.RegexUtil;
|
||||
import cn.celess.common.util.StringFromHtmlUtil;
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.youbenzi.mdtool.tool.MDTool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:21
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ArticleServiceImpl implements ArticleService {
|
||||
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Autowired
|
||||
TagMapper tagMapper;
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
CommentMapper commentMapper;
|
||||
@Autowired
|
||||
ArticleTagMapper articleTagMapper;
|
||||
@Autowired
|
||||
UserService userService;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ArticleModel create(ArticleReq reqBody) {
|
||||
if (reqBody == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
//数据判断
|
||||
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
//转载 判断链接
|
||||
if (!reqBody.getType()) {
|
||||
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||
}
|
||||
}
|
||||
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||
}
|
||||
// 查看是否存在已有的分类
|
||||
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 构建 需要写入数据库的对象数据
|
||||
Article article = new Article();
|
||||
BeanUtils.copyProperties(reqBody, article);
|
||||
|
||||
article.setUser(redisUserUtil.get());
|
||||
|
||||
//markdown->html->summary
|
||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||
//获取摘要 摘要长度为255个字符
|
||||
String summary = str.length() > 240 ? str.substring(0, 240) + "......" : str;
|
||||
article.setSummary(summary);
|
||||
|
||||
article.setCategory(category);
|
||||
|
||||
//文章存数据库
|
||||
articleMapper.insert(article);
|
||||
//将标签写入数据库
|
||||
for (String tagName : reqBody.getTags()) {
|
||||
if (tagName.replaceAll(" ", "").length() == 0) {
|
||||
//单个标签只含空格
|
||||
continue;
|
||||
}
|
||||
Tag tag = tagMapper.findTagByName(tagName);
|
||||
if (tag == null) {
|
||||
tag = new Tag();
|
||||
tag.setName(tagName);
|
||||
tagMapper.insert(tag);
|
||||
}
|
||||
ArticleTag articleTag = new ArticleTag(article, tag);
|
||||
articleTagMapper.insert(articleTag);
|
||||
}
|
||||
Article articleFromDb = articleMapper.findArticleById(article.getId());
|
||||
|
||||
ArticleModel articleModel = ModalTrans.article(articleFromDb);
|
||||
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(article.getId()), true));
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(long articleId) {
|
||||
Article articleForDel = articleMapper.findArticleById(articleId);
|
||||
|
||||
if (articleForDel == null) {
|
||||
//文章不存在
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||
}
|
||||
|
||||
//对访问情况进行判断 非admin 权限不可删除文章
|
||||
User user = redisUserUtil.get();
|
||||
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
||||
throw new MyException(ResponseEnum.PERMISSION_ERROR);
|
||||
}
|
||||
//删除指定文章
|
||||
articleMapper.delete(articleId);
|
||||
|
||||
//articleTagMapper.deleteByArticleId(articleId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public ArticleModel update(ArticleReq reqBody) {
|
||||
if (reqBody == null || reqBody.getId() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
// 查找数据
|
||||
Article article = articleMapper.findArticleById(reqBody.getId());
|
||||
|
||||
//数据判断
|
||||
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||
}
|
||||
article.setTitle(reqBody.getTitle());
|
||||
}
|
||||
if (reqBody.getMdContent() != null && !reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||
article.setMdContent(reqBody.getMdContent());
|
||||
}
|
||||
|
||||
//转载 判断链接
|
||||
if (reqBody.getType() != null) {
|
||||
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
|
||||
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||
}
|
||||
article.setType(reqBody.getType());
|
||||
article.setUrl(reqBody.getUrl());
|
||||
}
|
||||
if (reqBody.getCategory() != null && !reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||
if (category == null) {
|
||||
category = new Category();
|
||||
category.setName(reqBody.getCategory());
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
article.setCategory(category);
|
||||
}
|
||||
|
||||
//写入数据库的数据
|
||||
article.setOpen(reqBody.getOpen() == null ? article.getOpen() : reqBody.getOpen());
|
||||
String str = StringFromHtmlUtil.getString(MDTool.markdown2Html(article.getMdContent()));
|
||||
article.setSummary(str.length() > 240 ? str.substring(0, 240) + "......" : str);
|
||||
articleMapper.update(article);
|
||||
|
||||
|
||||
List<ArticleTag> allByArticleId = articleTagMapper.findAllByArticleId(article.getId());
|
||||
List<ArticleTag> updateList = new ArrayList<>();
|
||||
List<ArticleTag> deleteList = new ArrayList<>();
|
||||
|
||||
// 获取要更新 的标签
|
||||
for (String tag : reqBody.getTags()) {
|
||||
boolean contain = allByArticleId.stream().anyMatch(articleTag -> articleTag.getTag().getName().equals(tag));
|
||||
if (!contain) {
|
||||
ArticleTag articleTag = new ArticleTag();
|
||||
articleTag.setArticle(article);
|
||||
Tag tagByName = tagMapper.findTagByName(tag);
|
||||
if (tagByName == null) {
|
||||
tagByName = new Tag(tag);
|
||||
tagMapper.insert(tagByName);
|
||||
}
|
||||
articleTag.setTag(tagByName);
|
||||
updateList.add(articleTag);
|
||||
}
|
||||
}
|
||||
// 获取要删除的标签
|
||||
allByArticleId.forEach(articleTag -> {
|
||||
boolean contain = false;
|
||||
for (String tag : reqBody.getTags()) {
|
||||
if (articleTag.getTag().getName().equals(tag)) {
|
||||
contain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contain) {
|
||||
deleteList.add(articleTag);
|
||||
}
|
||||
});
|
||||
|
||||
if (updateList.size() != 0) {
|
||||
updateList.forEach(articleTag -> articleTagMapper.insert(articleTag));
|
||||
}
|
||||
|
||||
if (deleteList.size() != 0) {
|
||||
articleTagMapper.deleteMultiById(deleteList);
|
||||
}
|
||||
|
||||
//更新完成移除
|
||||
request.getSession().removeAttribute("article4update");
|
||||
ArticleModel articleModel = ModalTrans.article(articleMapper.findArticleById(article.getId()));
|
||||
setPreAndNextArticle(articleModel);
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = {"article"}, key = "'retrieveOneById'+#articleId")
|
||||
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
||||
Article article = articleMapper.findArticleById(articleId);
|
||||
if (article == null) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||
}
|
||||
if (!article.getOpen()) {
|
||||
User user = redisUserUtil.getWithOutExc();
|
||||
if (user == null || "user".equals(user.getRole())) {
|
||||
throw new MyException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
||||
}
|
||||
}
|
||||
ArticleModel articleModel = ModalTrans.article(article);
|
||||
|
||||
if (is4update) {
|
||||
//因更新而获取文章 不需要增加阅读量
|
||||
request.getSession().setAttribute("article4update", article);
|
||||
return articleModel;
|
||||
}
|
||||
setPreAndNextArticle(articleModel);
|
||||
articleMapper.updateReadingNumber(articleId);
|
||||
return articleModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param count 数目
|
||||
* @param page 页面
|
||||
* @return PageInfo
|
||||
*/
|
||||
@Override
|
||||
public PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> articleList = articleMapper.findAll();
|
||||
|
||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||
|
||||
List<Article> collect;
|
||||
if (deleted != null) {
|
||||
collect = articleList.stream().filter(article -> article.isDeleted() == deleted).collect(Collectors.toList());
|
||||
} else {
|
||||
collect = articleList;
|
||||
}
|
||||
List<ArticleModel> articleModels = collect.stream()
|
||||
.peek(article -> article.setMdContent(null))
|
||||
.map(ModalTrans::article)
|
||||
.collect(Collectors.toList());
|
||||
pageData.setList(articleModels);
|
||||
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = {"article"}, key = "'retrievePageForOpen:'+#page+':'+#count")
|
||||
public PageData<ArticleModel> retrievePageForOpen(int count, int page) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> articleList = articleMapper.findAllByOpen(true);
|
||||
PageData<ArticleModel> pageData = new PageData<>(new PageInfo<>(articleList));
|
||||
|
||||
List<ArticleModel> articleModelList = articleList
|
||||
.stream()
|
||||
.map(article -> setPreAndNextArticle(ModalTrans.article(article, true)))
|
||||
.collect(Collectors.toList());
|
||||
pageData.setList(articleModelList);
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = {"article"}, key = "'findByCategory:'+#name")
|
||||
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
||||
Category category = categoryMapper.findCategoryByName(name);
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
PageHelper.startPage(page, count);
|
||||
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||
|
||||
List<ArticleModel> modelList = open.stream()
|
||||
.map(article -> ModalTrans.article(article, true))
|
||||
.peek(articleModel -> {
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setPreArticle(null);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(open), modelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = {"article"}, key = "'findByTag:'+#name")
|
||||
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
||||
Tag tag = tagMapper.findTagByName(name);
|
||||
if (tag == null) {
|
||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||
}
|
||||
PageHelper.startPage(page, count);
|
||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||
List<ArticleModel> modelList = articleByTag
|
||||
.stream()
|
||||
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||
.peek(articleModel -> {
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setPreArticle(null);
|
||||
}).collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(articleByTag), modelList);
|
||||
}
|
||||
|
||||
|
||||
private ArticleModel setPreAndNextArticle(ArticleModel articleModel) {
|
||||
if (articleModel == null) {
|
||||
return null;
|
||||
}
|
||||
articleModel.setPreArticle(ModalTrans.article(articleMapper.getPreArticle(articleModel.getId()), true));
|
||||
articleModel.setNextArticle(ModalTrans.article(articleMapper.getNextArticle(articleModel.getId()), true));
|
||||
return articleModel;
|
||||
}
|
||||
}
|
||||
@@ -1,111 +1,113 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
import cn.celess.blog.entity.Article;
|
||||
import cn.celess.blog.mapper.ArticleMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/30 17:29
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
public class SitemapGenerateUtil {
|
||||
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Value("${sitemap.path}")
|
||||
private String path;
|
||||
private Map<String, String> urlList;
|
||||
|
||||
private static DocumentBuilder getDocumentBuilder() {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = null;
|
||||
try {
|
||||
db = dbf.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
@Async
|
||||
public void createSitemap() {
|
||||
initList();
|
||||
if ("".equals(path) || "classpath".equals(path)) {
|
||||
path = System.getProperty("user.dir") + "/sitemap.xml";
|
||||
}
|
||||
File file = new File(path);
|
||||
try {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
} else {
|
||||
file.createNewFile();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
DocumentBuilder db = getDocumentBuilder();
|
||||
Document document = db.newDocument();
|
||||
document.setXmlVersion("1.0");
|
||||
document.setXmlStandalone(true);
|
||||
Element urlset = document.createElement("urlset");
|
||||
urlset.setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
|
||||
// 创建url 结点
|
||||
urlList.forEach((s, s2) -> {
|
||||
Element url = document.createElement("url");
|
||||
Element loc = document.createElement("loc");
|
||||
Element lastmod = document.createElement("lastmod");
|
||||
loc.setTextContent(s);
|
||||
lastmod.setTextContent(s2);
|
||||
url.appendChild(loc);
|
||||
url.appendChild(lastmod);
|
||||
urlset.appendChild(url);
|
||||
});
|
||||
document.appendChild(urlset);
|
||||
try {
|
||||
TransformerFactory tff = TransformerFactory.newInstance();
|
||||
Transformer tf = tff.newTransformer();
|
||||
tf.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
tf.transform(new DOMSource(document), new StreamResult(file));
|
||||
} catch (TransformerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initList() {
|
||||
urlList = new HashMap<>();
|
||||
urlList.put("https://www.celess.cn", DateFormatUtil.getForXmlDate(new Date()));
|
||||
urlList.put("https://www.celess.cn/links", DateFormatUtil.getForXmlDate(new Date()));
|
||||
urlList.put("https://www.celess.cn/leaveMsg", DateFormatUtil.getForXmlDate(new Date()));
|
||||
List<Article> articles = articleMapper.findAll().stream().filter(article -> article.getOpen()&&!article.isDeleted()).collect(Collectors.toList());
|
||||
articles.forEach(article -> {
|
||||
urlList.put("https://www.celess.cn/article/" + article.getId(), DateFormatUtil.getForXmlDate(
|
||||
article.getUpdateDate() == null ? article.getPublishDate() : article.getUpdateDate()));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package cn.celess.article.util;
|
||||
|
||||
|
||||
import cn.celess.common.entity.Article;
|
||||
import cn.celess.common.mapper.ArticleMapper;
|
||||
import cn.celess.common.util.DateFormatUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/30 17:29
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
public class SitemapGenerateUtil {
|
||||
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Value("${sitemap.path}")
|
||||
private String path;
|
||||
private Map<String, String> urlList;
|
||||
|
||||
private static DocumentBuilder getDocumentBuilder() {
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = null;
|
||||
try {
|
||||
db = dbf.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
@Async
|
||||
public void createSitemap() {
|
||||
initList();
|
||||
if ("".equals(path) || "classpath".equals(path)) {
|
||||
path = System.getProperty("user.dir") + "/sitemap.xml";
|
||||
}
|
||||
File file = new File(path);
|
||||
try {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
} else {
|
||||
file.createNewFile();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
DocumentBuilder db = getDocumentBuilder();
|
||||
Document document = db.newDocument();
|
||||
document.setXmlVersion("1.0");
|
||||
document.setXmlStandalone(true);
|
||||
Element urlset = document.createElement("urlset");
|
||||
urlset.setAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
|
||||
// 创建url 结点
|
||||
urlList.forEach((s, s2) -> {
|
||||
Element url = document.createElement("url");
|
||||
Element loc = document.createElement("loc");
|
||||
Element lastmod = document.createElement("lastmod");
|
||||
loc.setTextContent(s);
|
||||
lastmod.setTextContent(s2);
|
||||
url.appendChild(loc);
|
||||
url.appendChild(lastmod);
|
||||
urlset.appendChild(url);
|
||||
});
|
||||
document.appendChild(urlset);
|
||||
try {
|
||||
TransformerFactory tff = TransformerFactory.newInstance();
|
||||
Transformer tf = tff.newTransformer();
|
||||
tf.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
tf.transform(new DOMSource(document), new StreamResult(file));
|
||||
} catch (TransformerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initList() {
|
||||
urlList = new HashMap<>();
|
||||
urlList.put("https://www.celess.cn", DateFormatUtil.getForXmlDate(new Date()));
|
||||
urlList.put("https://www.celess.cn/links", DateFormatUtil.getForXmlDate(new Date()));
|
||||
urlList.put("https://www.celess.cn/leaveMsg", DateFormatUtil.getForXmlDate(new Date()));
|
||||
List<Article> articles = articleMapper.findAll().stream().filter(article -> article.getOpen() && !article.isDeleted()).collect(Collectors.toList());
|
||||
articles.forEach(article -> {
|
||||
urlList.put("https://www.celess.cn/article/" + article.getId(), DateFormatUtil.getForXmlDate(
|
||||
article.getUpdateDate() == null ? article.getPublishDate() : article.getUpdateDate()));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
31
blog-categorytag/pom.xml
Normal file
31
blog-categorytag/pom.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-categorytag</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>13</maven.compiler.source>
|
||||
<maven.compiler.target>13</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,63 +1,63 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/category/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.create(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/category/del")
|
||||
public Response deleteOne(@RequestParam("id") long id) {
|
||||
return Response.success(categoryService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 更新后的名字
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/category/update")
|
||||
public Response updateOne(@RequestParam("id") Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.update(id, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的分类
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Response getPage(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "1000") int count) {
|
||||
return Response.success(categoryService.retrievePage(page, count));
|
||||
}
|
||||
}
|
||||
package cn.celess.categorytag.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/admin/category/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.create(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return Response
|
||||
*/
|
||||
@DeleteMapping("/admin/category/del")
|
||||
public Response deleteOne(@RequestParam("id") long id) {
|
||||
return Response.success(categoryService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新一个分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 更新后的名字
|
||||
* @return Response
|
||||
*/
|
||||
@PutMapping("/admin/category/update")
|
||||
public Response updateOne(@RequestParam("id") Long id,
|
||||
@RequestParam("name") String name) {
|
||||
return Response.success(categoryService.update(id, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的分类
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Response getPage(@RequestParam(name = "page", defaultValue = "1") int page,
|
||||
@RequestParam(name = "count", defaultValue = "1000") int count) {
|
||||
return Response.success(categoryService.retrievePage(page, count));
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,59 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.model.TagModel;
|
||||
import cn.celess.blog.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class TagController {
|
||||
@Autowired
|
||||
TagService tagService;
|
||||
|
||||
|
||||
@PostMapping("/admin/tag/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(tagService.create(name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/tag/del")
|
||||
public Response delOne(@RequestParam("id") long id) {
|
||||
return Response.success(tagService.delete(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/admin/tag/update")
|
||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||
return Response.success(tagService.update(id, name));
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||
return Response.success(tagService.retrievePage(page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||
List<TagModel> all = tagService.findAll();
|
||||
for (TagModel t : all) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("name", t.getName());
|
||||
map.put("size", t.getArticles().size());
|
||||
nameAndCount.add(map);
|
||||
}
|
||||
return Response.success(nameAndCount);
|
||||
}
|
||||
|
||||
}
|
||||
package cn.celess.categorytag.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.vo.TagModel;
|
||||
import cn.celess.common.service.TagService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:36
|
||||
*/
|
||||
@RestController
|
||||
public class TagController {
|
||||
@Autowired
|
||||
TagService tagService;
|
||||
|
||||
|
||||
@PostMapping("/admin/tag/create")
|
||||
public Response addOne(@RequestParam("name") String name) {
|
||||
return Response.success(tagService.create(name));
|
||||
}
|
||||
|
||||
@DeleteMapping("/admin/tag/del")
|
||||
public Response delOne(@RequestParam("id") long id) {
|
||||
return Response.success(tagService.delete(id));
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/admin/tag/update")
|
||||
public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) {
|
||||
return Response.success(tagService.update(id, name));
|
||||
}
|
||||
|
||||
@GetMapping("/tags")
|
||||
public Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
|
||||
@RequestParam(required = false, defaultValue = "1", value = "page") int page) {
|
||||
return Response.success(tagService.retrievePage(page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/tags/nac")
|
||||
public Response getTagNameAndCount() {
|
||||
List<Map<String, Object>> nameAndCount = new ArrayList<>();
|
||||
List<TagModel> all = tagService.findAll();
|
||||
for (TagModel t : all) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
map.put("name", t.getName());
|
||||
map.put("size", t.getArticles().size());
|
||||
nameAndCount.add(map);
|
||||
}
|
||||
return Response.success(nameAndCount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +1,92 @@
|
||||
package cn.celess.blog.service.serviceimpl;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Article;
|
||||
import cn.celess.blog.entity.Category;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.model.CategoryModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.mapper.ArticleMapper;
|
||||
import cn.celess.blog.mapper.CategoryMapper;
|
||||
import cn.celess.blog.service.CategoryService;
|
||||
import cn.celess.blog.util.ModalTrans;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:43
|
||||
*/
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Override
|
||||
public CategoryModel create(String name) {
|
||||
if (categoryMapper.existsByName(name)) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_HAS_EXIST);
|
||||
}
|
||||
Category category = new Category();
|
||||
category.setName(name);
|
||||
categoryMapper.insert(category);
|
||||
return ModalTrans.category(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(long id) {
|
||||
Category category = categoryMapper.findCategoryById(id);
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
return categoryMapper.delete(id) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CategoryModel update(Long id, String name) {
|
||||
if (id == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||
}
|
||||
Category category = categoryMapper.findCategoryById(id);
|
||||
category.setName(name);
|
||||
categoryMapper.update(category);
|
||||
return ModalTrans.category(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CategoryModel> retrievePage(int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Category> all = categoryMapper.findAll();
|
||||
// 遍历没一个category
|
||||
List<CategoryModel> modelList = all
|
||||
.stream()
|
||||
.map(ModalTrans::category)
|
||||
.peek(categoryModel -> {
|
||||
// 根据category去查article,并赋值给categoryModel
|
||||
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(categoryModel.getId());
|
||||
List<ArticleModel> articleModelList = allByCategoryId
|
||||
.stream()
|
||||
.map(article -> ModalTrans.article(article, true))
|
||||
.peek(articleModel -> {
|
||||
// 去除不必要的字段
|
||||
articleModel.setPreArticle(null);
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setTags(null);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
categoryModel.setArticles(articleModelList);
|
||||
}).collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(all), modelList);
|
||||
}
|
||||
}
|
||||
package cn.celess.categorytag.serviceimpl;
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.entity.Article;
|
||||
import cn.celess.common.entity.Category;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.entity.vo.CategoryModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.exception.MyException;
|
||||
import cn.celess.common.mapper.ArticleMapper;
|
||||
import cn.celess.common.mapper.CategoryMapper;
|
||||
import cn.celess.common.service.CategoryService;
|
||||
import cn.celess.common.util.ModalTrans;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:43
|
||||
*/
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
|
||||
@Override
|
||||
public CategoryModel create(String name) {
|
||||
if (categoryMapper.existsByName(name)) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_HAS_EXIST);
|
||||
}
|
||||
Category category = new Category();
|
||||
category.setName(name);
|
||||
categoryMapper.insert(category);
|
||||
return ModalTrans.category(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(long id) {
|
||||
Category category = categoryMapper.findCategoryById(id);
|
||||
if (category == null) {
|
||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||
}
|
||||
return categoryMapper.delete(id) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CategoryModel update(Long id, String name) {
|
||||
if (id == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||
}
|
||||
Category category = categoryMapper.findCategoryById(id);
|
||||
category.setName(name);
|
||||
categoryMapper.update(category);
|
||||
return ModalTrans.category(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CategoryModel> retrievePage(int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Category> all = categoryMapper.findAll();
|
||||
// 遍历没一个category
|
||||
List<CategoryModel> modelList = all
|
||||
.stream()
|
||||
.map(ModalTrans::category)
|
||||
.peek(categoryModel -> {
|
||||
// 根据category去查article,并赋值给categoryModel
|
||||
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(categoryModel.getId());
|
||||
List<ArticleModel> articleModelList = allByCategoryId
|
||||
.stream()
|
||||
.map(article -> ModalTrans.article(article, true))
|
||||
.peek(articleModel -> {
|
||||
// 去除不必要的字段
|
||||
articleModel.setPreArticle(null);
|
||||
articleModel.setNextArticle(null);
|
||||
articleModel.setTags(null);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
categoryModel.setArticles(articleModelList);
|
||||
}).collect(Collectors.toList());
|
||||
return new PageData<>(new PageInfo<>(all), modelList);
|
||||
}
|
||||
}
|
||||
@@ -1,103 +1,103 @@
|
||||
package cn.celess.blog.service.serviceimpl;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.ArticleTag;
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.TagModel;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.mapper.ArticleMapper;
|
||||
import cn.celess.blog.mapper.ArticleTagMapper;
|
||||
import cn.celess.blog.mapper.TagMapper;
|
||||
import cn.celess.blog.service.TagService;
|
||||
import cn.celess.blog.util.ModalTrans;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:29
|
||||
*/
|
||||
@Service
|
||||
public class TagServiceImpl implements TagService {
|
||||
@Autowired
|
||||
TagMapper tagMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Autowired
|
||||
ArticleTagMapper articleTagMapper;
|
||||
|
||||
@Override
|
||||
public TagModel create(String name) {
|
||||
boolean b = tagMapper.existsByName(name);
|
||||
if (b) {
|
||||
throw new MyException(ResponseEnum.TAG_HAS_EXIST);
|
||||
}
|
||||
Tag tag = new Tag();
|
||||
tag.setName(name);
|
||||
tagMapper.insert(tag);
|
||||
return ModalTrans.tag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(long tagId) {
|
||||
Tag tag = tagMapper.findTagById(tagId);
|
||||
if (tag == null) {
|
||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||
}
|
||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
||||
// 删除文章
|
||||
articleByTag.forEach(articleTag -> articleMapper.delete(articleTag.getArticle().getId()));
|
||||
return tagMapper.delete(tagId) == 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TagModel update(Long id, String name) {
|
||||
if (id == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
||||
}
|
||||
Tag tag = tagMapper.findTagById(id);
|
||||
tag.setName(name);
|
||||
tagMapper.update(tag);
|
||||
return ModalTrans.tag(tag);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<TagModel> retrievePage(int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Tag> tagList = tagMapper.findAll();
|
||||
List<TagModel> modelList = new ArrayList<>();
|
||||
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
||||
return new PageData<>(new PageInfo<>(tagList), modelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TagModel> findAll() {
|
||||
return tagMapper.findAll().stream()
|
||||
.map(ModalTrans::tag)
|
||||
.peek(tagModel -> {
|
||||
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(tagModel.getId());
|
||||
tagModel.setArticles(
|
||||
articleByTagAndOpen
|
||||
.stream()
|
||||
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
package cn.celess.categorytag.serviceimpl;
|
||||
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.entity.ArticleTag;
|
||||
import cn.celess.common.entity.Tag;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.entity.vo.TagModel;
|
||||
import cn.celess.common.exception.MyException;
|
||||
import cn.celess.common.mapper.ArticleMapper;
|
||||
import cn.celess.common.mapper.ArticleTagMapper;
|
||||
import cn.celess.common.mapper.TagMapper;
|
||||
import cn.celess.common.service.TagService;
|
||||
import cn.celess.common.util.ModalTrans;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:29
|
||||
*/
|
||||
@Service
|
||||
public class TagServiceImpl implements TagService {
|
||||
@Autowired
|
||||
TagMapper tagMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Autowired
|
||||
ArticleTagMapper articleTagMapper;
|
||||
|
||||
@Override
|
||||
public TagModel create(String name) {
|
||||
boolean b = tagMapper.existsByName(name);
|
||||
if (b) {
|
||||
throw new MyException(ResponseEnum.TAG_HAS_EXIST);
|
||||
}
|
||||
Tag tag = new Tag();
|
||||
tag.setName(name);
|
||||
tagMapper.insert(tag);
|
||||
return ModalTrans.tag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(long tagId) {
|
||||
Tag tag = tagMapper.findTagById(tagId);
|
||||
if (tag == null) {
|
||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
||||
}
|
||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
||||
// 删除文章
|
||||
articleByTag.forEach(articleTag -> articleMapper.delete(articleTag.getArticle().getId()));
|
||||
return tagMapper.delete(tagId) == 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TagModel update(Long id, String name) {
|
||||
if (id == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
||||
}
|
||||
Tag tag = tagMapper.findTagById(id);
|
||||
tag.setName(name);
|
||||
tagMapper.update(tag);
|
||||
return ModalTrans.tag(tag);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<TagModel> retrievePage(int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Tag> tagList = tagMapper.findAll();
|
||||
List<TagModel> modelList = new ArrayList<>();
|
||||
tagList.forEach(tag -> modelList.add(ModalTrans.tag(tag)));
|
||||
return new PageData<>(new PageInfo<>(tagList), modelList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TagModel> findAll() {
|
||||
return tagMapper.findAll().stream()
|
||||
.map(ModalTrans::tag)
|
||||
.peek(tagModel -> {
|
||||
List<ArticleTag> articleByTagAndOpen = articleTagMapper.findArticleByTagAndOpen(tagModel.getId());
|
||||
tagModel.setArticles(
|
||||
articleByTagAndOpen
|
||||
.stream()
|
||||
.map(articleTag -> ModalTrans.article(articleTag.getArticle(), true))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
38
blog-comment/pom.xml
Normal file
38
blog-comment/pom.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-comment</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>13</maven.compiler.source>
|
||||
<maven.compiler.target>13</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,119 +1,119 @@
|
||||
package cn.celess.blog.controller;
|
||||
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.entity.request.CommentReq;
|
||||
import cn.celess.blog.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class CommentController {
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增一条评论数据
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/user/comment/create")
|
||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/comment/del")
|
||||
public Response delete(@RequestParam("id") long id) {
|
||||
return Response.success(commentService.delete(id));
|
||||
}
|
||||
|
||||
@PutMapping("/user/comment/update")
|
||||
public Response update(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.update(reqBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的评论
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 页码
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comments/{pagePath}/{pid}")
|
||||
public Response commentsOfArticle(@PathVariable("pagePath") String pagePath, @PathVariable(value = "pid") long pid,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPageAndPid(path, pid, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count count
|
||||
* @param page page
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comment/pagePath/{pagePath}")
|
||||
public Response retrievePage(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePage(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/user/comment/pagePath/{pagePath}")
|
||||
public Response userComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByAuthor(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPage(path, page, count));
|
||||
}
|
||||
}
|
||||
package cn.celess.comment.controller;
|
||||
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.entity.dto.CommentReq;
|
||||
import cn.celess.common.service.CommentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 20:37
|
||||
*/
|
||||
@RestController
|
||||
public class CommentController {
|
||||
@Autowired
|
||||
CommentService commentService;
|
||||
|
||||
/**
|
||||
* 新增一条评论数据
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return Response
|
||||
*/
|
||||
@PostMapping("/user/comment/create")
|
||||
public Response addOne(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.create(reqBody));
|
||||
}
|
||||
|
||||
@DeleteMapping("/user/comment/del")
|
||||
public Response delete(@RequestParam("id") long id) {
|
||||
return Response.success(commentService.delete(id));
|
||||
}
|
||||
|
||||
@PutMapping("/user/comment/update")
|
||||
public Response update(@RequestBody CommentReq reqBody) {
|
||||
return Response.success(commentService.update(reqBody));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的评论
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 页码
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comments/{pagePath}/{pid}")
|
||||
public Response commentsOfArticle(@PathVariable("pagePath") String pagePath, @PathVariable(value = "pid") long pid,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPageAndPid(path, pid, page, count));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count count
|
||||
* @param page page
|
||||
* @return Response
|
||||
*/
|
||||
@GetMapping("/comment/pagePath/{pagePath}")
|
||||
public Response retrievePage(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePage(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/user/comment/pagePath/{pagePath}")
|
||||
public Response userComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByAuthor(path, page, count));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/comment/pagePath/{pagePath}")
|
||||
public Response adminComment(@PathVariable("pagePath") String pagePath,
|
||||
@RequestParam(value = "count", required = false, defaultValue = "10") int count,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
|
||||
String path = "";
|
||||
if (pagePath.contains("article+")) {
|
||||
path = "article/" + pagePath.split("\\+", 2)[1];
|
||||
} else {
|
||||
path = pagePath;
|
||||
}
|
||||
if ("*".equals(pagePath)) {
|
||||
path = null;
|
||||
}
|
||||
return Response.success(commentService.retrievePageByPage(path, page, count));
|
||||
}
|
||||
}
|
||||
@@ -1,153 +1,152 @@
|
||||
package cn.celess.blog.service.serviceimpl;
|
||||
|
||||
import cn.celess.blog.enmu.CommentStatusEnum;
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Comment;
|
||||
import cn.celess.blog.entity.User;
|
||||
import cn.celess.blog.entity.model.CommentModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.request.CommentReq;
|
||||
import cn.celess.blog.exception.MyException;
|
||||
import cn.celess.blog.mapper.ArticleMapper;
|
||||
import cn.celess.blog.mapper.CommentMapper;
|
||||
import cn.celess.blog.mapper.UserMapper;
|
||||
import cn.celess.blog.service.CommentService;
|
||||
import cn.celess.blog.util.ModalTrans;
|
||||
import cn.celess.blog.util.RedisUserUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 17:05
|
||||
*/
|
||||
@Service
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
@Autowired
|
||||
CommentMapper commentMapper;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
@Override
|
||||
public CommentModel create(CommentReq reqBody) {
|
||||
if (reqBody == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
User user = redisUserUtil.get();
|
||||
Comment pComment = null;
|
||||
if (reqBody.getPid() != -1) {
|
||||
pComment = commentMapper.findCommentById(reqBody.getPid());
|
||||
}
|
||||
//不是一级评论
|
||||
if (reqBody.getPid() != -1 && pComment == null) {
|
||||
//父评论不存在
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
Comment comment = new Comment();
|
||||
comment.setFromUser(user);
|
||||
User userTo = new User();
|
||||
userTo.setId(null);
|
||||
if (reqBody.getToUserId() != -1) {
|
||||
userTo = userMapper.findById(reqBody.getToUserId());
|
||||
comment.setToUser(userTo);
|
||||
}
|
||||
comment.setToUser(userTo);
|
||||
userMapper.findById(reqBody.getToUserId());
|
||||
BeanUtils.copyProperties(reqBody, comment);
|
||||
commentMapper.insert(comment);
|
||||
return ModalTrans.comment(commentMapper.findCommentById(comment.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(long id) {
|
||||
Comment b = commentMapper.findCommentById(id);
|
||||
if (b == null) {
|
||||
throw new MyException(ResponseEnum.COMMENT_NOT_EXIST);
|
||||
}
|
||||
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
||||
throw new MyException(ResponseEnum.DATA_IS_DELETED);
|
||||
}
|
||||
commentMapper.delete(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentModel update(CommentReq reqBody) {
|
||||
if (reqBody.getId() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||
}
|
||||
Comment comment = commentMapper.findCommentById(reqBody.getId());
|
||||
if (!comment.getContent().equals(reqBody.getContent())) {
|
||||
commentMapper.updateContent(reqBody.getContent(), reqBody.getId());
|
||||
comment.setContent(reqBody.getContent());
|
||||
}
|
||||
return ModalTrans.comment(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePage(String pagePath, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePathAndPidAndNormal(pagePath, -1);
|
||||
return pageTrans(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommentModel> retrievePageByPid(long pid) {
|
||||
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
||||
return allByPagePath
|
||||
.stream()
|
||||
.filter(comment -> comment.getStatus() != CommentStatusEnum.DELETED.getCode())
|
||||
.map(ModalTrans::comment)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count) {
|
||||
User user = redisUserUtil.get();
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePathAndFromUser(pagePath, user.getId());
|
||||
return pageTrans(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||
return pageTrans(list, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||
return pageTrans(list, true);
|
||||
}
|
||||
|
||||
private PageData<CommentModel> pageTrans(List<Comment> commentList) {
|
||||
return pageTrans(commentList, false);
|
||||
}
|
||||
|
||||
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
||||
PageInfo<Comment> p = PageInfo.of(commentList);
|
||||
List<CommentModel> modelList = commentList
|
||||
.stream()
|
||||
.map(ModalTrans::comment)
|
||||
.peek(commentModel -> commentModel.setRespComment(this.retrievePageByPid(commentModel.getId())))
|
||||
.collect(Collectors.toList());
|
||||
return new PageData<>(p, modelList);
|
||||
}
|
||||
}
|
||||
package cn.celess.comment.serviceimpl;
|
||||
|
||||
import cn.celess.common.enmu.CommentStatusEnum;
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.entity.Comment;
|
||||
import cn.celess.common.entity.User;
|
||||
import cn.celess.common.entity.dto.CommentReq;
|
||||
import cn.celess.common.entity.vo.CommentModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.exception.MyException;
|
||||
import cn.celess.common.mapper.ArticleMapper;
|
||||
import cn.celess.common.mapper.CommentMapper;
|
||||
import cn.celess.common.mapper.UserMapper;
|
||||
import cn.celess.common.service.CommentService;
|
||||
import cn.celess.common.util.ModalTrans;
|
||||
import cn.celess.user.util.RedisUserUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 17:05
|
||||
*/
|
||||
@Service
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
@Autowired
|
||||
CommentMapper commentMapper;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
@Autowired
|
||||
ArticleMapper articleMapper;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Autowired
|
||||
RedisUserUtil redisUserUtil;
|
||||
|
||||
@Override
|
||||
public CommentModel create(CommentReq reqBody) {
|
||||
if (reqBody == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
User user = redisUserUtil.get();
|
||||
Comment pComment = null;
|
||||
if (reqBody.getPid() != -1) {
|
||||
pComment = commentMapper.findCommentById(reqBody.getPid());
|
||||
}
|
||||
//不是一级评论
|
||||
if (reqBody.getPid() != -1 && pComment == null) {
|
||||
//父评论不存在
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
||||
}
|
||||
Comment comment = new Comment();
|
||||
comment.setFromUser(user);
|
||||
User userTo = new User();
|
||||
userTo.setId(null);
|
||||
if (reqBody.getToUserId() != -1) {
|
||||
userTo = userMapper.findById(reqBody.getToUserId());
|
||||
comment.setToUser(userTo);
|
||||
}
|
||||
comment.setToUser(userTo);
|
||||
userMapper.findById(reqBody.getToUserId());
|
||||
BeanUtils.copyProperties(reqBody, comment);
|
||||
commentMapper.insert(comment);
|
||||
return ModalTrans.comment(commentMapper.findCommentById(comment.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(long id) {
|
||||
Comment b = commentMapper.findCommentById(id);
|
||||
if (b == null) {
|
||||
throw new MyException(ResponseEnum.COMMENT_NOT_EXIST);
|
||||
}
|
||||
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
||||
throw new MyException(ResponseEnum.DATA_IS_DELETED);
|
||||
}
|
||||
commentMapper.delete(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentModel update(CommentReq reqBody) {
|
||||
if (reqBody.getId() == null) {
|
||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||
}
|
||||
Comment comment = commentMapper.findCommentById(reqBody.getId());
|
||||
if (!comment.getContent().equals(reqBody.getContent())) {
|
||||
commentMapper.updateContent(reqBody.getContent(), reqBody.getId());
|
||||
comment.setContent(reqBody.getContent());
|
||||
}
|
||||
return ModalTrans.comment(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePage(String pagePath, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePathAndPidAndNormal(pagePath, -1);
|
||||
return pageTrans(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommentModel> retrievePageByPid(long pid) {
|
||||
List<Comment> allByPagePath = commentMapper.findAllByPid(pid);
|
||||
return allByPagePath
|
||||
.stream()
|
||||
.filter(comment -> comment.getStatus() != CommentStatusEnum.DELETED.getCode())
|
||||
.map(ModalTrans::comment)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count) {
|
||||
User user = redisUserUtil.get();
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePathAndFromUser(pagePath, user.getId());
|
||||
return pageTrans(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||
return pageTrans(list, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
|
||||
return pageTrans(list, true);
|
||||
}
|
||||
|
||||
private PageData<CommentModel> pageTrans(List<Comment> commentList) {
|
||||
return pageTrans(commentList, false);
|
||||
}
|
||||
|
||||
private PageData<CommentModel> pageTrans(List<Comment> commentList, boolean noResponseList) {
|
||||
PageInfo<Comment> p = PageInfo.of(commentList);
|
||||
List<CommentModel> modelList = commentList
|
||||
.stream()
|
||||
.map(ModalTrans::comment)
|
||||
.peek(commentModel -> commentModel.setRespComment(this.retrievePageByPid(commentModel.getId())))
|
||||
.collect(Collectors.toList());
|
||||
return new PageData<>(p, modelList);
|
||||
}
|
||||
}
|
||||
91
blog-common/pom.xml
Normal file
91
blog-common/pom.xml
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-common</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--druid-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.2.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- pageHelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--Email-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
</dependency>
|
||||
<!-- TODO: remove this -->
|
||||
<dependency>
|
||||
<groupId>com.qiniu</groupId>
|
||||
<artifactId>qiniu-java-sdk</artifactId>
|
||||
<version>[7.2.0, 7.2.99]</version>
|
||||
</dependency>
|
||||
|
||||
<!-- redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
<version>2.45.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- protostuff序列化依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-core</artifactId>
|
||||
<version>1.1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dyuproject.protostuff</groupId>
|
||||
<artifactId>protostuff-runtime</artifactId>
|
||||
<version>1.1.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.celess.common.config;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.celess.common.mapper")
|
||||
public class MybatisConfig {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.blog.enmu;
|
||||
package cn.celess.common.enmu;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
package cn.celess.blog.enmu;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:37
|
||||
*/
|
||||
public enum ResponseEnum {
|
||||
// Response enum
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
FAILURE(-1, "失败"),
|
||||
ERROR(-2, "错误"),
|
||||
|
||||
DATA_IS_DELETED(1000, "数据已被删除"),
|
||||
|
||||
//文章类
|
||||
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
||||
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
||||
ARTICLE_NOT_PUBLIC(2030, "文章暂未公开"),
|
||||
ARTICLE_NOT_BELONG_YOU(2040, "无权限操作别人的文章"),
|
||||
|
||||
//用户类
|
||||
HAVE_NOT_LOG_IN(3010, "还未登录"),
|
||||
PERMISSION_ERROR(3020, "没有此权限"),
|
||||
USER_NOT_EXIST(3030, "用户不存在"),
|
||||
USERNAME_HAS_EXIST(3040, "用户名已存在"),
|
||||
USERNAME_TOO_SHORT(3050, "用户名太短"),
|
||||
PASSWORD_TOO_SHORT_OR_LONG(3060, "密码长度过长或者过短"),
|
||||
LOGIN_FAILURE(3100, "登录失败,用户名/密码不正确"),
|
||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||
PWD_SAME(3601, "新密码与原密码相同"),
|
||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||
LOGOUT(3710, "账户已注销"),
|
||||
CAN_NOT_USE(3711, "账户不可用"),
|
||||
PWD_WRONG(3800, "密码不正确"),
|
||||
|
||||
JWT_EXPIRED(3810, "Token过期"),
|
||||
JWT_MALFORMED(3820, "Token格式不对"),
|
||||
JWT_SIGNATURE(3830, "Token签名错误"),
|
||||
JWT_NOT_SUPPORT(3840, "不支持的Token"),
|
||||
|
||||
//标签
|
||||
TAG_NOT_EXIST(4010, "标签不存在"),
|
||||
TAG_HAS_EXIST(4020, "标签已存在"),
|
||||
|
||||
//分类
|
||||
CATEGORY_NOT_EXIST(5010, "分类不存在"),
|
||||
CATEGORY_HAS_EXIST(5020, "分类已存在"),
|
||||
|
||||
//评论/留言
|
||||
COMMENT_NOT_EXIST(6010, "评论/留言不存在"),
|
||||
COMMENT_HAS_EXIST(6020, "评论/留言已存在,请不要重复提交"),
|
||||
|
||||
//webUdpateInfo amd PartnerSite
|
||||
DATA_NOT_EXIST(7010, "数据不存在"),
|
||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
||||
|
||||
//其他
|
||||
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||
DATA_EXPIRED(7300, "数据过期"),
|
||||
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||
NO_FILE(7500, "未选择文件,请重新选择"),
|
||||
|
||||
|
||||
//提交更新之前,没有获取数据/,
|
||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||
IMG_CODE_TIMEOUT(8100, "验证码已失效"),
|
||||
IMG_CODE_DIDNOTVERIFY(8200, "请先验证验证码"),
|
||||
VERIFY_ERROR(8300, "验证失败"),
|
||||
PARAMETERS_ERROR(8500, "参数错误"),
|
||||
PARAMETERS_URL_ERROR(8510, "链接格式错误"),
|
||||
PARAMETERS_EMAIL_ERROR(8520, "邮箱格式错误"),
|
||||
PARAMETERS_PHONE_ERROR(8530, "手机格式错误"),
|
||||
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
||||
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
||||
VERIFY_OUT(8400, "已经验证过了");
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
ResponseEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.enmu;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:37
|
||||
*/
|
||||
public enum ResponseEnum {
|
||||
// Response enum
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
FAILURE(-1, "失败"),
|
||||
ERROR(-2, "错误"),
|
||||
|
||||
DATA_IS_DELETED(1000, "数据已被删除"),
|
||||
|
||||
//文章类
|
||||
ARTICLE_NOT_EXIST(2010, "文章不存在"),
|
||||
ARTICLE_HAS_EXIST(2020, "文章已存在"),
|
||||
ARTICLE_NOT_PUBLIC(2030, "文章暂未公开"),
|
||||
ARTICLE_NOT_BELONG_YOU(2040, "无权限操作别人的文章"),
|
||||
|
||||
//用户类
|
||||
HAVE_NOT_LOG_IN(3010, "还未登录"),
|
||||
PERMISSION_ERROR(3020, "没有此权限"),
|
||||
USER_NOT_EXIST(3030, "用户不存在"),
|
||||
USERNAME_HAS_EXIST(3040, "用户名已存在"),
|
||||
USERNAME_TOO_SHORT(3050, "用户名太短"),
|
||||
PASSWORD_TOO_SHORT_OR_LONG(3060, "密码长度过长或者过短"),
|
||||
LOGIN_FAILURE(3100, "登录失败,用户名/密码不正确"),
|
||||
USEREMAIL_NULL(3310, "未设置邮箱"),
|
||||
USEREMAIL_NOT_VERIFY(3320, "邮箱未验证"),
|
||||
LOGIN_LATER(3500, "错误次数已达5次,请稍后再试"),
|
||||
PWD_SAME(3601, "新密码与原密码相同"),
|
||||
PWD_NOT_SAME(3602, "新密码与原密码不相同"),
|
||||
LOGIN_EXPIRED(3700, "登陆过期"),
|
||||
LOGOUT(3710, "账户已注销"),
|
||||
CAN_NOT_USE(3711, "账户不可用"),
|
||||
PWD_WRONG(3800, "密码不正确"),
|
||||
|
||||
JWT_EXPIRED(3810, "Token过期"),
|
||||
JWT_MALFORMED(3820, "Token格式不对"),
|
||||
JWT_SIGNATURE(3830, "Token签名错误"),
|
||||
JWT_NOT_SUPPORT(3840, "不支持的Token"),
|
||||
|
||||
//标签
|
||||
TAG_NOT_EXIST(4010, "标签不存在"),
|
||||
TAG_HAS_EXIST(4020, "标签已存在"),
|
||||
|
||||
//分类
|
||||
CATEGORY_NOT_EXIST(5010, "分类不存在"),
|
||||
CATEGORY_HAS_EXIST(5020, "分类已存在"),
|
||||
|
||||
//评论/留言
|
||||
COMMENT_NOT_EXIST(6010, "评论/留言不存在"),
|
||||
COMMENT_HAS_EXIST(6020, "评论/留言已存在,请不要重复提交"),
|
||||
|
||||
//webUdpateInfo amd PartnerSite
|
||||
DATA_NOT_EXIST(7010, "数据不存在"),
|
||||
DATA_HAS_EXIST(7020, "数据已存在"),
|
||||
|
||||
//其他
|
||||
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
|
||||
DATA_EXPIRED(7300, "数据过期"),
|
||||
CANNOT_GET_DATA(7400, "暂无法获取到数据"),
|
||||
NO_FILE(7500, "未选择文件,请重新选择"),
|
||||
|
||||
|
||||
//提交更新之前,没有获取数据/,
|
||||
DID_NOT_GET_THE_DATA(8020, "非法访问"),
|
||||
IMG_CODE_TIMEOUT(8100, "验证码已失效"),
|
||||
IMG_CODE_DIDNOTVERIFY(8200, "请先验证验证码"),
|
||||
VERIFY_ERROR(8300, "验证失败"),
|
||||
PARAMETERS_ERROR(8500, "参数错误"),
|
||||
PARAMETERS_URL_ERROR(8510, "链接格式错误"),
|
||||
PARAMETERS_EMAIL_ERROR(8520, "邮箱格式错误"),
|
||||
PARAMETERS_PHONE_ERROR(8530, "手机格式错误"),
|
||||
PARAMETERS_QQ_ERROR(8540, "QQ格式错误"),
|
||||
PARAMETERS_PWD_ERROR(8550, "密码格式错误"),
|
||||
VERIFY_OUT(8400, "已经验证过了");
|
||||
private final int code;
|
||||
private final String msg;
|
||||
|
||||
|
||||
ResponseEnum(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.blog.enmu;
|
||||
package cn.celess.common.enmu;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.celess.blog.enmu;
|
||||
package cn.celess.common.enmu;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
@@ -1,63 +1,64 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Article {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean type;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url = null;
|
||||
|
||||
private Date publishDate;
|
||||
|
||||
private Date updateDate = null;
|
||||
|
||||
private Long readingNumber;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private Category category;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
private User user;
|
||||
|
||||
private boolean deleted = false;
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:51
|
||||
*/
|
||||
@Data
|
||||
public class Article implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean type;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url = null;
|
||||
|
||||
private Date publishDate;
|
||||
|
||||
private Date updateDate = null;
|
||||
|
||||
private Long readingNumber;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private Category category;
|
||||
|
||||
private List<Tag> tags;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
private User user;
|
||||
|
||||
private boolean deleted = false;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package cn.celess.blog.entity;
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2020-05-24 14:52
|
||||
@@ -12,7 +14,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ArticleTag {
|
||||
public class ArticleTag implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private Article article;
|
||||
@@ -1,13 +1,15 @@
|
||||
package cn.celess.blog.entity;
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:18
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class Category extends TagCategory {
|
||||
public class Category extends TagCategory implements Serializable {
|
||||
public Category(String name) {
|
||||
super.setName(name);
|
||||
}
|
||||
@@ -1,34 +1,35 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Comment {
|
||||
|
||||
private Long id;
|
||||
|
||||
private int status;
|
||||
|
||||
private String pagePath;
|
||||
|
||||
private String content;
|
||||
|
||||
private Date date;
|
||||
|
||||
private User fromUser;
|
||||
|
||||
private User toUser;
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
// private boolean delete;
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class Comment implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private int status;
|
||||
|
||||
private String pagePath;
|
||||
|
||||
private String content;
|
||||
|
||||
private Date date;
|
||||
|
||||
private User fromUser;
|
||||
|
||||
private User toUser;
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
// private boolean delete;
|
||||
}
|
||||
@@ -1,40 +1,42 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 友链
|
||||
*
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:33
|
||||
*/
|
||||
@Data
|
||||
public class PartnerSite {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private Boolean open;
|
||||
|
||||
private String iconPath;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Boolean delete = false;
|
||||
|
||||
private String email;
|
||||
|
||||
private Boolean notification = true;
|
||||
|
||||
public PartnerSite() {
|
||||
}
|
||||
|
||||
public PartnerSite(String name, String url, Boolean open) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 友链
|
||||
*
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:33
|
||||
*/
|
||||
@Data
|
||||
public class PartnerSite implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private Boolean open;
|
||||
|
||||
private String iconPath;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Boolean delete = false;
|
||||
|
||||
private String email;
|
||||
|
||||
private Boolean notification = true;
|
||||
|
||||
public PartnerSite() {
|
||||
}
|
||||
|
||||
public PartnerSite(String name, String url, Boolean open) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.open = open;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,65 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:24
|
||||
*/
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
private int code;
|
||||
private String msg;
|
||||
private T result;
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public Response(int code, String msg, T result) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功相应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> success(T result) {
|
||||
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败的响应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static Response<String> failure(String result) {
|
||||
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他的响应
|
||||
*
|
||||
* @param r 枚举常量
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> response(ResponseEnum r, T result) {
|
||||
return new Response<T>(r.getCode(), r.getMsg(), result);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ObjectMapper().writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:24
|
||||
*/
|
||||
@Data
|
||||
public class Response<T> implements Serializable {
|
||||
private int code;
|
||||
private String msg;
|
||||
private T result;
|
||||
|
||||
public Response() {
|
||||
}
|
||||
|
||||
public Response(int code, String msg, T result) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功相应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> success(T result) {
|
||||
return new Response<T>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败的响应
|
||||
*
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static Response<String> failure(String result) {
|
||||
return new Response<String>(ResponseEnum.FAILURE.getCode(), ResponseEnum.FAILURE.getMsg(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 其他的响应
|
||||
*
|
||||
* @param r 枚举常量
|
||||
* @param result 结果
|
||||
* @return Response
|
||||
*/
|
||||
public static <T> Response<T> response(ResponseEnum r, T result) {
|
||||
return new Response<T>(r.getCode(), r.getMsg(), result);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ObjectMapper().writeValueAsString(this);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package cn.celess.blog.entity;
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:19
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class Tag extends TagCategory {
|
||||
public class Tag extends TagCategory implements Serializable {
|
||||
|
||||
public Tag(String name) {
|
||||
super.setName(name);
|
||||
@@ -1,14 +1,16 @@
|
||||
package cn.celess.blog.entity;
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2020-05-24 14:03
|
||||
* @Desc:
|
||||
*/
|
||||
@Data
|
||||
public class TagCategory {
|
||||
public class TagCategory implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
@@ -1,53 +1,54 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:52
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class User {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String pwd;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus = false;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatarImgUrl;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Date recentlyLandedDate;
|
||||
|
||||
private String role = "user";
|
||||
|
||||
private int status;
|
||||
|
||||
public User(String email, String pwd) {
|
||||
this.email = email;
|
||||
this.pwd = pwd;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 14:52
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class User implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String pwd;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus = false;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatarImgUrl;
|
||||
|
||||
private String desc;
|
||||
|
||||
private Date recentlyLandedDate;
|
||||
|
||||
private String role = "user";
|
||||
|
||||
private int status;
|
||||
|
||||
public User(String email, String pwd) {
|
||||
this.email = email;
|
||||
this.pwd = pwd;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:14
|
||||
*/
|
||||
@Data
|
||||
public class Visitor {
|
||||
|
||||
private long id;
|
||||
private String ip;
|
||||
private Date date;
|
||||
private String ua;
|
||||
private boolean delete;
|
||||
|
||||
public Visitor(String ip, Date date, String ua) {
|
||||
this.ip = ip;
|
||||
this.date = date;
|
||||
this.ua = ua;
|
||||
}
|
||||
|
||||
public Visitor() {
|
||||
}
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:14
|
||||
*/
|
||||
@Data
|
||||
public class Visitor implements Serializable {
|
||||
|
||||
private long id;
|
||||
private String ip;
|
||||
private Date date;
|
||||
private String ua;
|
||||
private boolean delete;
|
||||
|
||||
public Visitor(String ip, Date date, String ua) {
|
||||
this.ip = ip;
|
||||
this.date = date;
|
||||
this.ua = ua;
|
||||
}
|
||||
|
||||
public Visitor() {
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,29 @@
|
||||
package cn.celess.blog.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:29
|
||||
*/
|
||||
@Data
|
||||
public class WebUpdate {
|
||||
|
||||
private long id;
|
||||
|
||||
private String updateInfo;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
private boolean delete;
|
||||
|
||||
public WebUpdate() {
|
||||
}
|
||||
|
||||
public WebUpdate(String updateInfo) {
|
||||
this.updateInfo = updateInfo;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:29
|
||||
*/
|
||||
@Data
|
||||
public class WebUpdate implements Serializable {
|
||||
|
||||
private long id;
|
||||
|
||||
private String updateInfo;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
private boolean delete;
|
||||
|
||||
public WebUpdate() {
|
||||
}
|
||||
|
||||
public WebUpdate(String updateInfo) {
|
||||
this.updateInfo = updateInfo;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/01 22:46
|
||||
*/
|
||||
@Data
|
||||
public class ArticleReq {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String mdContent;
|
||||
private String[] tags;
|
||||
private Boolean type;
|
||||
private String url;
|
||||
private String category;
|
||||
private Boolean open = true;
|
||||
}
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/01 22:46
|
||||
*/
|
||||
@Data
|
||||
public class ArticleReq implements Serializable {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String mdContent;
|
||||
private String[] tags;
|
||||
private Boolean type;
|
||||
private String url;
|
||||
private String category;
|
||||
private Boolean open = true;
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/02 10:35
|
||||
*/
|
||||
@Data
|
||||
public class CommentReq {
|
||||
private Long id;
|
||||
private String content;
|
||||
private long pid = -1;
|
||||
private String pagePath;
|
||||
private long toUserId = -1;
|
||||
}
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/02 10:35
|
||||
*/
|
||||
@Data
|
||||
public class CommentReq implements Serializable {
|
||||
private Long id;
|
||||
private String content;
|
||||
private long pid = -1;
|
||||
private String pagePath;
|
||||
private long toUserId = -1;
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2020/07/31 20:50
|
||||
*/
|
||||
@Data
|
||||
public class LinkApplyReq {
|
||||
public class LinkApplyReq implements Serializable {
|
||||
private String name;
|
||||
private String email;
|
||||
private String url;
|
||||
@@ -1,17 +1,19 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/02 11:40
|
||||
*/
|
||||
@Data
|
||||
public class LinkReq {
|
||||
private long id;
|
||||
private String name;
|
||||
private String url;
|
||||
private String iconPath;
|
||||
private String desc;
|
||||
private boolean open;
|
||||
}
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/02 11:40
|
||||
*/
|
||||
@Data
|
||||
public class LinkReq implements Serializable {
|
||||
private long id;
|
||||
private String name;
|
||||
private String url;
|
||||
private String iconPath;
|
||||
private String desc;
|
||||
private boolean open;
|
||||
}
|
||||
@@ -1,23 +1,25 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/01 22:47
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoginReq {
|
||||
private String email;
|
||||
private String password;
|
||||
/**
|
||||
* isRememberMe默认为false
|
||||
*/
|
||||
private Boolean isRememberMe = false;
|
||||
|
||||
}
|
||||
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/06/01 22:47
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoginReq implements Serializable {
|
||||
private String email;
|
||||
private String password;
|
||||
/**
|
||||
* isRememberMe默认为false
|
||||
*/
|
||||
private Boolean isRememberMe = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package cn.celess.blog.entity.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/09/06 13:33
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
public class UserReq {
|
||||
private Long id;
|
||||
|
||||
private String email;
|
||||
|
||||
private String pwd;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String role;
|
||||
|
||||
}
|
||||
package cn.celess.common.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/09/06 13:33
|
||||
* @Description:
|
||||
*/
|
||||
@Data
|
||||
public class UserReq implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String email;
|
||||
|
||||
private String pwd;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String role;
|
||||
|
||||
}
|
||||
@@ -1,87 +1,88 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/23 12:02
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ArticleModel {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean original;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
private String publishDateFormat;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateDateFormat;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private List<Tag> tags;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private UserModel author;
|
||||
|
||||
private ArticleModel preArticle;
|
||||
|
||||
private ArticleModel nextArticle;
|
||||
|
||||
/**
|
||||
* 阅读数
|
||||
*/
|
||||
private Long readingNumber;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private boolean deleted;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import cn.celess.common.entity.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/23 12:02
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class ArticleModel implements Serializable {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 摘要
|
||||
*/
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* Markdown正文
|
||||
*/
|
||||
private String mdContent;
|
||||
|
||||
/**
|
||||
* 文章类型 true(1)为原创 false(0)为转载
|
||||
*/
|
||||
private Boolean original;
|
||||
|
||||
/**
|
||||
* 若为转载 则为转载文章的url
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 发布时间
|
||||
*/
|
||||
private String publishDateFormat;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateDateFormat;
|
||||
|
||||
/**
|
||||
* 分类
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private List<Tag> tags;
|
||||
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
private UserModel author;
|
||||
|
||||
private ArticleModel preArticle;
|
||||
|
||||
private ArticleModel nextArticle;
|
||||
|
||||
/**
|
||||
* 阅读数
|
||||
*/
|
||||
private Long readingNumber;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Integer dislikeCount;
|
||||
|
||||
/**
|
||||
* 文章的状态 true:公开 false:不公开
|
||||
*/
|
||||
private Boolean open;
|
||||
|
||||
private boolean deleted;
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CategoryModel {
|
||||
public class CategoryModel implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
@@ -1,44 +1,45 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 21:50
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class CommentModel {
|
||||
private long id;
|
||||
|
||||
private UserModel fromUser;
|
||||
|
||||
private UserModel toUser;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 文章标题
|
||||
*/
|
||||
private String pagePath;
|
||||
|
||||
/**
|
||||
* 发布日期
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
private List<CommentModel> respComment;
|
||||
|
||||
private int status;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 21:50
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public class CommentModel implements Serializable {
|
||||
private long id;
|
||||
|
||||
private UserModel fromUser;
|
||||
|
||||
private UserModel toUser;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 文章标题
|
||||
*/
|
||||
private String pagePath;
|
||||
|
||||
/**
|
||||
* 发布日期
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* 评论的父ID
|
||||
*/
|
||||
private Long pid;
|
||||
|
||||
private List<CommentModel> respComment;
|
||||
|
||||
private int status;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -15,7 +16,7 @@ import java.util.List;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PageData<T> {
|
||||
public class PageData<T> implements Serializable {
|
||||
|
||||
private List<T> list;
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/21 22:43
|
||||
*/
|
||||
public class QiniuResponse {
|
||||
public String key;
|
||||
public String hash;
|
||||
public String bucket;
|
||||
public long fsize;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/21 22:43
|
||||
*/
|
||||
public class QiniuResponse implements Serializable {
|
||||
public String key;
|
||||
public String hash;
|
||||
public String bucket;
|
||||
public long fsize;
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TagModel {
|
||||
public class TagModel implements Serializable {
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
@@ -1,43 +1,45 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 23:13
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserModel {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus = false;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatarImgUrl;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String recentlyLandedDate;
|
||||
|
||||
private String role = "user";
|
||||
|
||||
private String token;
|
||||
|
||||
private UserAccountStatusEnum status;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import cn.celess.common.enmu.UserAccountStatusEnum;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 23:13
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserModel implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String displayName;
|
||||
|
||||
private Boolean emailStatus = false;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatarImgUrl;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String recentlyLandedDate;
|
||||
|
||||
private String role = "user";
|
||||
|
||||
private String token;
|
||||
|
||||
private UserAccountStatusEnum status;
|
||||
}
|
||||
@@ -1,24 +1,26 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/05 16:05
|
||||
*/
|
||||
@Data
|
||||
public class VisitorModel {
|
||||
private long id;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String date;
|
||||
|
||||
private String browserName;
|
||||
|
||||
private String browserVersion;
|
||||
|
||||
private String OSName;
|
||||
|
||||
private String location;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/05 16:05
|
||||
*/
|
||||
@Data
|
||||
public class VisitorModel implements Serializable {
|
||||
private long id;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String date;
|
||||
|
||||
private String browserName;
|
||||
|
||||
private String browserVersion;
|
||||
|
||||
private String OSName;
|
||||
|
||||
private String location;
|
||||
}
|
||||
@@ -1,26 +1,28 @@
|
||||
package cn.celess.blog.entity.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:32
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WebUpdateModel {
|
||||
private long id;
|
||||
|
||||
private String info;
|
||||
|
||||
private String time;
|
||||
|
||||
public WebUpdateModel(long id, String info, String time) {
|
||||
this.id = id;
|
||||
this.info = info;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
private boolean deleted;
|
||||
}
|
||||
package cn.celess.common.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:32
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WebUpdateModel implements Serializable {
|
||||
private long id;
|
||||
|
||||
private String info;
|
||||
|
||||
private String time;
|
||||
|
||||
public WebUpdateModel(long id, String info, String time) {
|
||||
this.id = id;
|
||||
this.info = info;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
private boolean deleted;
|
||||
}
|
||||
@@ -1,100 +1,101 @@
|
||||
package cn.celess.blog.exception;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.MailService;
|
||||
import cn.celess.blog.util.DateFormatUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:02
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
public class ExceptionHandle {
|
||||
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
||||
@Autowired
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Response handle(Exception e) {
|
||||
//自定义错误
|
||||
if (e instanceof MyException) {
|
||||
MyException exception = (MyException) e;
|
||||
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
||||
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
||||
}
|
||||
//请求路径不支持该方法
|
||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
|
||||
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null);
|
||||
}
|
||||
//数据输入类型不匹配
|
||||
if (e instanceof MethodArgumentTypeMismatchException) {
|
||||
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null);
|
||||
}
|
||||
//数据验证失败
|
||||
if (e instanceof BindException) {
|
||||
logger.debug("数据验证失败,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null);
|
||||
}
|
||||
//数据输入不完整
|
||||
if (e instanceof MissingServletRequestParameterException) {
|
||||
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null);
|
||||
}
|
||||
|
||||
// 发送错误信息到邮箱
|
||||
if ("prod".equals(activeModel)) {
|
||||
logger.debug("有一个未捕获的bug,已发送到邮箱");
|
||||
sendMessage(e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送错误信息
|
||||
*
|
||||
* @param e 错误
|
||||
*/
|
||||
private void sendMessage(Exception e) {
|
||||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
|
||||
simpleMailMessage.setTo("a@celess.cn");
|
||||
simpleMailMessage.setSubject("服务器出现了错误");
|
||||
StringBuilder msg = new StringBuilder();
|
||||
String queryString = request.getQueryString();
|
||||
msg.append("requirePath:\n").append(request.getRequestURL().toString());
|
||||
if (queryString != null) {
|
||||
msg.append("?").append(queryString);
|
||||
}
|
||||
msg.append("\n\n\n");
|
||||
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
||||
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
||||
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
||||
msg.append("ip:\n").append(request.getRemoteAddr()).append("\n\n\n");
|
||||
simpleMailMessage.setText(msg.toString());
|
||||
mailService.AsyncSend(simpleMailMessage);
|
||||
}
|
||||
|
||||
}
|
||||
package cn.celess.common.exception;
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import cn.celess.common.entity.Response;
|
||||
import cn.celess.common.service.MailService;
|
||||
import cn.celess.common.util.DateFormatUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.MissingServletRequestParameterException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:02
|
||||
*/
|
||||
|
||||
@ControllerAdvice
|
||||
public class ExceptionHandle {
|
||||
public static final Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);
|
||||
@Resource
|
||||
MailService mailService;
|
||||
@Autowired
|
||||
HttpServletRequest request;
|
||||
@Value("${spring.profiles.active}")
|
||||
private String activeModel;
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Response handle(Exception e) {
|
||||
//自定义错误
|
||||
if (e instanceof MyException) {
|
||||
MyException exception = (MyException) e;
|
||||
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
||||
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
||||
}
|
||||
//请求路径不支持该方法
|
||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||
logger.debug("遇到请求路径与请求方法不匹配的请求,[msg={},path:{},method:{}]", e.getMessage(), request.getRequestURL(), request.getMethod());
|
||||
return new Response(ResponseEnum.ERROR.getCode(), e.getMessage(), null);
|
||||
}
|
||||
//数据输入类型不匹配
|
||||
if (e instanceof MethodArgumentTypeMismatchException) {
|
||||
logger.debug("输入类型不匹配,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改后再访问", null);
|
||||
}
|
||||
//数据验证失败
|
||||
if (e instanceof BindException) {
|
||||
logger.debug("数据验证失败,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入有问题,请修改", null);
|
||||
}
|
||||
//数据输入不完整
|
||||
if (e instanceof MissingServletRequestParameterException) {
|
||||
logger.debug("数据输入不完整,[msg={}]", e.getMessage());
|
||||
return new Response(ResponseEnum.PARAMETERS_ERROR.getCode(), "数据输入不完整,请检查", null);
|
||||
}
|
||||
|
||||
// 发送错误信息到邮箱
|
||||
if ("prod".equals(activeModel)) {
|
||||
logger.debug("有一个未捕获的bug,已发送到邮箱");
|
||||
sendMessage(e);
|
||||
}
|
||||
e.printStackTrace();
|
||||
return new Response(ResponseEnum.ERROR.getCode(), "服务器出现错误,已记录", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送错误信息
|
||||
*
|
||||
* @param e 错误
|
||||
*/
|
||||
private void sendMessage(Exception e) {
|
||||
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
|
||||
simpleMailMessage.setTo("a@celess.cn");
|
||||
simpleMailMessage.setSubject("服务器出现了错误");
|
||||
StringBuilder msg = new StringBuilder();
|
||||
String queryString = request.getQueryString();
|
||||
msg.append("requirePath:\n").append(request.getRequestURL().toString());
|
||||
if (queryString != null) {
|
||||
msg.append("?").append(queryString);
|
||||
}
|
||||
msg.append("\n\n\n");
|
||||
msg.append("msg:\n").append(e.getMessage()).append("\n\n\n");
|
||||
msg.append("date:\n").append(DateFormatUtil.getNow()).append("\n\n\n");
|
||||
msg.append("from:\n").append(request.getHeader("User-Agent")).append("\n\n\n");
|
||||
msg.append("ip:\n").append(request.getRemoteAddr()).append("\n\n\n");
|
||||
simpleMailMessage.setText(msg.toString());
|
||||
mailService.AsyncSend(simpleMailMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +1,41 @@
|
||||
package cn.celess.blog.exception;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 16:56
|
||||
*/
|
||||
@Data
|
||||
public class MyException extends RuntimeException {
|
||||
private int code;
|
||||
private Object result;
|
||||
|
||||
public MyException(int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, Object result) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, String msg) {
|
||||
super(msg + e.getMsg());
|
||||
this.code = e.getCode();
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, String msg, Object result) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.exception;
|
||||
|
||||
import cn.celess.common.enmu.ResponseEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 16:56
|
||||
*/
|
||||
@Data
|
||||
public class MyException extends RuntimeException {
|
||||
private int code;
|
||||
private Object result;
|
||||
|
||||
public MyException(int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, Object result) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, String msg) {
|
||||
super(msg + e.getMsg());
|
||||
this.code = e.getCode();
|
||||
}
|
||||
|
||||
public MyException(ResponseEnum e, String msg, Object result) {
|
||||
super(e.getMsg());
|
||||
this.code = e.getCode();
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +1,55 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.Article;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/27 20:43
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ArticleMapper {
|
||||
|
||||
int insert(Article a);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(Article a);
|
||||
|
||||
Article getLastestArticle();
|
||||
|
||||
Article findArticleById(long id);
|
||||
|
||||
boolean existsByTitle(String title);
|
||||
|
||||
boolean isDeletedById(long id);
|
||||
|
||||
List<Article> findAllByAuthorId(long authorId);
|
||||
|
||||
List<Article> findAllByOpen(boolean isOpen);
|
||||
|
||||
String getTitleById(long id);
|
||||
|
||||
List<Article> findAllByCategoryId(long id);
|
||||
|
||||
List<Article> findAllByCategoryIdAndOpen(long id);
|
||||
|
||||
List<Article> findAll();
|
||||
|
||||
Article getPreArticle(Long id);
|
||||
|
||||
Article getNextArticle(Long id);
|
||||
|
||||
int updateReadingNumber(long id);
|
||||
|
||||
long count();
|
||||
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.Article;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/27 20:43
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ArticleMapper {
|
||||
|
||||
int insert(Article a);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(Article a);
|
||||
|
||||
Article getLastestArticle();
|
||||
|
||||
Article findArticleById(long id);
|
||||
|
||||
boolean existsByTitle(String title);
|
||||
|
||||
boolean isDeletedById(long id);
|
||||
|
||||
List<Article> findAllByAuthorId(long authorId);
|
||||
|
||||
List<Article> findAllByOpen(boolean isOpen);
|
||||
|
||||
String getTitleById(long id);
|
||||
|
||||
List<Article> findAllByCategoryId(long id);
|
||||
|
||||
List<Article> findAllByCategoryIdAndOpen(long id);
|
||||
|
||||
List<Article> findAll();
|
||||
|
||||
@Cacheable(value = {"articleDao"}, key = "'getPreArticle:'+#id")
|
||||
Article getPreArticle(Long id);
|
||||
|
||||
@Cacheable(value = {"articleDao"}, key = "'getNextArticle:'+#id")
|
||||
Article getNextArticle(Long id);
|
||||
|
||||
int updateReadingNumber(long id);
|
||||
|
||||
long count();
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.celess.blog.mapper;
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.blog.entity.ArticleTag;
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import cn.celess.common.entity.ArticleTag;
|
||||
import cn.celess.common.entity.Tag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/30 12:56
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface CategoryMapper {
|
||||
int insert(Category c);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(Category c);
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
Category findCategoryByName(String name);
|
||||
|
||||
Category findCategoryById(long id);
|
||||
|
||||
List<Category> findAll();
|
||||
|
||||
List<String> getAllName();
|
||||
|
||||
String getNameById(long id);
|
||||
|
||||
Long getIdByName(String name);
|
||||
|
||||
Category getLastestCategory();
|
||||
|
||||
long count();
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/30 12:56
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface CategoryMapper {
|
||||
int insert(Category c);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(Category c);
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
Category findCategoryByName(String name);
|
||||
|
||||
Category findCategoryById(long id);
|
||||
|
||||
List<Category> findAll();
|
||||
|
||||
List<String> getAllName();
|
||||
|
||||
String getNameById(long id);
|
||||
|
||||
Long getIdByName(String name);
|
||||
|
||||
Category getLastestCategory();
|
||||
|
||||
long count();
|
||||
}
|
||||
@@ -1,44 +1,44 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.Comment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/30 16:19
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface CommentMapper {
|
||||
int insert(Comment c);
|
||||
|
||||
int updateContent(String content, long id);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int deleteByPagePath(String pagePath);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
Comment findCommentById(long id);
|
||||
|
||||
Comment getLastestComment();
|
||||
|
||||
List<Comment> findAllByFromUser(long id);
|
||||
|
||||
List<Comment> findAllByPid(long pid);
|
||||
|
||||
List<Comment> findAllByPagePath(String pagePath);
|
||||
|
||||
List<Comment> findAllByPagePathAndFromUser(String pagePath, long userId);
|
||||
|
||||
List<Comment> findAllByPagePathAndPidAndNormal(String pagePath, long pid);
|
||||
|
||||
long countByPagePath(String pagePath);
|
||||
|
||||
long count();
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.Comment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/30 16:19
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface CommentMapper {
|
||||
int insert(Comment c);
|
||||
|
||||
int updateContent(String content, long id);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int deleteByPagePath(String pagePath);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
Comment findCommentById(long id);
|
||||
|
||||
Comment getLastestComment();
|
||||
|
||||
List<Comment> findAllByFromUser(long id);
|
||||
|
||||
List<Comment> findAllByPid(long pid);
|
||||
|
||||
List<Comment> findAllByPagePath(String pagePath);
|
||||
|
||||
List<Comment> findAllByPagePathAndFromUser(String pagePath, long userId);
|
||||
|
||||
List<Comment> findAllByPagePathAndPidAndNormal(String pagePath, long pid);
|
||||
|
||||
long countByPagePath(String pagePath);
|
||||
|
||||
long count();
|
||||
}
|
||||
@@ -1,41 +1,41 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.PartnerSite;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:22
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface PartnerMapper {
|
||||
int insert(PartnerSite site);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(PartnerSite site);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByUrl(String url);
|
||||
|
||||
PartnerSite findById(long id);
|
||||
|
||||
PartnerSite findByName(String name);
|
||||
|
||||
PartnerSite findByUrl(String url);
|
||||
|
||||
PartnerSite getLastest();
|
||||
|
||||
List<PartnerSite> findAll();
|
||||
|
||||
List<PartnerSite> findAll(Boolean deleted);
|
||||
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.PartnerSite;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:22
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface PartnerMapper {
|
||||
int insert(PartnerSite site);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(PartnerSite site);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
boolean existsByName(String name);
|
||||
|
||||
boolean existsByUrl(String url);
|
||||
|
||||
PartnerSite findById(long id);
|
||||
|
||||
PartnerSite findByName(String name);
|
||||
|
||||
PartnerSite findByUrl(String url);
|
||||
|
||||
PartnerSite getLastest();
|
||||
|
||||
List<PartnerSite> findAll();
|
||||
|
||||
List<PartnerSite> findAll(Boolean deleted);
|
||||
|
||||
}
|
||||
@@ -1,34 +1,34 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.Tag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/29 22:00
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface TagMapper {
|
||||
int insert(Tag tag);
|
||||
|
||||
int update(Tag tag);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
Tag findTagById(long id);
|
||||
|
||||
Tag findTagByName(String name);
|
||||
|
||||
Boolean existsByName(String name);
|
||||
|
||||
Tag getLastestTag();
|
||||
|
||||
List<Tag> findAll();
|
||||
|
||||
long count();
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.Tag;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/06/29 22:00
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface TagMapper {
|
||||
int insert(Tag tag);
|
||||
|
||||
int update(Tag tag);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
Tag findTagById(long id);
|
||||
|
||||
Tag findTagByName(String name);
|
||||
|
||||
Boolean existsByName(String name);
|
||||
|
||||
Tag getLastestTag();
|
||||
|
||||
List<Tag> findAll();
|
||||
|
||||
long count();
|
||||
}
|
||||
@@ -1,61 +1,61 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:23
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface UserMapper {
|
||||
|
||||
int addUser(User user);
|
||||
|
||||
int updateInfo(String desc, String displayName, long id);
|
||||
|
||||
int updateAvatarImgUrl(String avatarImgUrl, long id);
|
||||
|
||||
int updateLoginTime(String email);
|
||||
|
||||
int updateEmailStatus(String email, boolean status);
|
||||
|
||||
int updatePwd(String email, String pwd);
|
||||
|
||||
String getPwd(String email);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
User findByEmail(String email);
|
||||
|
||||
User findById(long id);
|
||||
|
||||
String getAvatarImgUrlById(long id);
|
||||
|
||||
String getEmail(long id);
|
||||
|
||||
String getDisPlayName(long id);
|
||||
|
||||
String getRoleByEmail(String email);
|
||||
|
||||
String getRoleById(long id);
|
||||
|
||||
long count();
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int lock(long id);
|
||||
|
||||
int setUserRole(Long id, String role);
|
||||
|
||||
List<User> findAll(Integer status);
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
int update(User user);
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:23
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface UserMapper {
|
||||
|
||||
int addUser(User user);
|
||||
|
||||
int updateInfo(String desc, String displayName, long id);
|
||||
|
||||
int updateAvatarImgUrl(String avatarImgUrl, long id);
|
||||
|
||||
int updateLoginTime(String email);
|
||||
|
||||
int updateEmailStatus(String email, boolean status);
|
||||
|
||||
int updatePwd(String email, String pwd);
|
||||
|
||||
String getPwd(String email);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
User findByEmail(String email);
|
||||
|
||||
User findById(long id);
|
||||
|
||||
String getAvatarImgUrlById(long id);
|
||||
|
||||
String getEmail(long id);
|
||||
|
||||
String getDisPlayName(long id);
|
||||
|
||||
String getRoleByEmail(String email);
|
||||
|
||||
String getRoleById(long id);
|
||||
|
||||
long count();
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int lock(long id);
|
||||
|
||||
int setUserRole(Long id, String role);
|
||||
|
||||
List<User> findAll(Integer status);
|
||||
|
||||
List<User> findAll();
|
||||
|
||||
int update(User user);
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.Visitor;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:23
|
||||
* @Description:
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface VisitorMapper {
|
||||
int insert(Visitor visitor);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
List<Visitor> findAll();
|
||||
|
||||
List<Visitor> findAllNotDeleted();
|
||||
|
||||
long count();
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.Visitor;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:23
|
||||
* @Description:
|
||||
*/
|
||||
@Repository
|
||||
@Mapper
|
||||
public interface VisitorMapper {
|
||||
int insert(Visitor visitor);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
List<Visitor> findAll();
|
||||
|
||||
List<Visitor> findAllNotDeleted();
|
||||
|
||||
long count();
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
package cn.celess.blog.mapper;
|
||||
|
||||
import cn.celess.blog.entity.WebUpdate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:24
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface WebUpdateInfoMapper {
|
||||
int insert(WebUpdate webUpdate);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(long id, String info);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
WebUpdate findById(long id);
|
||||
|
||||
List<WebUpdate> findAll();
|
||||
|
||||
List<WebUpdate> findAllNotDeleted();
|
||||
|
||||
WebUpdate getLastestOne();
|
||||
}
|
||||
package cn.celess.common.mapper;
|
||||
|
||||
import cn.celess.common.entity.WebUpdate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/07/03 00:24
|
||||
* @Description:
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface WebUpdateInfoMapper {
|
||||
int insert(WebUpdate webUpdate);
|
||||
|
||||
int delete(long id);
|
||||
|
||||
int update(long id, String info);
|
||||
|
||||
boolean existsById(long id);
|
||||
|
||||
WebUpdate findById(long id);
|
||||
|
||||
List<WebUpdate> findAll();
|
||||
|
||||
List<WebUpdate> findAllNotDeleted();
|
||||
|
||||
WebUpdate getLastestOne();
|
||||
}
|
||||
@@ -1,85 +1,85 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.ArticleModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.request.ArticleReq;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:20
|
||||
*/
|
||||
@Service
|
||||
public interface ArticleService {
|
||||
/**
|
||||
* 新增一篇文章
|
||||
*
|
||||
* @param reqBody 请求文章的数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel create(ArticleReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除一篇文章
|
||||
*
|
||||
* @param articleID 文章id
|
||||
* @return 删除状态 true:删除成功 false:失败
|
||||
*/
|
||||
boolean delete(long articleID);
|
||||
|
||||
/**
|
||||
* 更新一篇文章
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel update(ArticleReq reqBody);
|
||||
|
||||
/**
|
||||
* 获取一篇文章的数据
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是因文章更新而请求数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel retrieveOneById(long articleId, boolean is4update);
|
||||
|
||||
/**
|
||||
* 管理员 获取分页数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted);
|
||||
|
||||
/**
|
||||
* 获取文章状态为开放的文章
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> retrievePageForOpen(int count, int page);
|
||||
|
||||
/**
|
||||
* 根据分类名获取文章数据
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> findByCategory(String name, int page, int count);
|
||||
|
||||
/**
|
||||
* 根据标签名获取文章数据
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> findByTag(String name, int page, int count);
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.dto.ArticleReq;
|
||||
import cn.celess.common.entity.vo.ArticleModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 15:20
|
||||
*/
|
||||
@Service
|
||||
public interface ArticleService {
|
||||
/**
|
||||
* 新增一篇文章
|
||||
*
|
||||
* @param reqBody 请求文章的数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel create(ArticleReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除一篇文章
|
||||
*
|
||||
* @param articleID 文章id
|
||||
* @return 删除状态 true:删除成功 false:失败
|
||||
*/
|
||||
boolean delete(long articleID);
|
||||
|
||||
/**
|
||||
* 更新一篇文章
|
||||
*
|
||||
* @param reqBody 请求数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel update(ArticleReq reqBody);
|
||||
|
||||
/**
|
||||
* 获取一篇文章的数据
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @param is4update 是否是因文章更新而请求数据
|
||||
* @return 文章数据
|
||||
*/
|
||||
ArticleModel retrieveOneById(long articleId, boolean is4update);
|
||||
|
||||
/**
|
||||
* 管理员 获取分页数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> adminArticles(int count, int page, Boolean deleted);
|
||||
|
||||
/**
|
||||
* 获取文章状态为开放的文章
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> retrievePageForOpen(int count, int page);
|
||||
|
||||
/**
|
||||
* 根据分类名获取文章数据
|
||||
*
|
||||
* @param name 分类名
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> findByCategory(String name, int page, int count);
|
||||
|
||||
/**
|
||||
* 根据标签名获取文章数据
|
||||
*
|
||||
* @param name 标签名
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<ArticleModel> findByTag(String name, int page, int count);
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.CategoryModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:42
|
||||
*/
|
||||
@Service
|
||||
public interface CategoryService {
|
||||
/**
|
||||
* 增加一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return 所增加的分类数据
|
||||
*/
|
||||
CategoryModel create(String name);
|
||||
|
||||
/**
|
||||
* 通过id删除分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long id);
|
||||
|
||||
/**
|
||||
* 编辑分类的名字
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 分类名字
|
||||
* @return 更新后的分类的数据
|
||||
*/
|
||||
CategoryModel update(Long id, String name);
|
||||
|
||||
/**
|
||||
* 获取全部的分类数据
|
||||
*
|
||||
* @return 全部的分类数据
|
||||
*/
|
||||
PageData<CategoryModel> retrievePage(int page, int count);
|
||||
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.vo.CategoryModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:42
|
||||
*/
|
||||
@Service
|
||||
public interface CategoryService {
|
||||
/**
|
||||
* 增加一个分类
|
||||
*
|
||||
* @param name 分类名
|
||||
* @return 所增加的分类数据
|
||||
*/
|
||||
CategoryModel create(String name);
|
||||
|
||||
/**
|
||||
* 通过id删除分类
|
||||
*
|
||||
* @param id 分类id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long id);
|
||||
|
||||
/**
|
||||
* 编辑分类的名字
|
||||
*
|
||||
* @param id 分类id
|
||||
* @param name 分类名字
|
||||
* @return 更新后的分类的数据
|
||||
*/
|
||||
CategoryModel update(Long id, String name);
|
||||
|
||||
/**
|
||||
* 获取全部的分类数据
|
||||
*
|
||||
* @return 全部的分类数据
|
||||
*/
|
||||
PageData<CategoryModel> retrievePage(int page, int count);
|
||||
|
||||
}
|
||||
@@ -1,91 +1,92 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.CommentModel;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.request.CommentReq;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:58
|
||||
*/
|
||||
@Service
|
||||
public interface CommentService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param reqBody 请求数据体
|
||||
* @return 增加的comment数据
|
||||
*/
|
||||
CommentModel create(CommentReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id comment的id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param reqBody comment请求体
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
CommentModel update(CommentReq reqBody);
|
||||
|
||||
/**
|
||||
* 分页获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePage(String pagePath, int page, int count);
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pid 父id
|
||||
* @return 分页数据
|
||||
*/
|
||||
List<CommentModel> retrievePageByPid(long pid);
|
||||
|
||||
|
||||
/**
|
||||
* 根据评论者获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count);
|
||||
|
||||
|
||||
/**
|
||||
* 根据数据的type和pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param pid 父id
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count);
|
||||
|
||||
/**
|
||||
* 根据type获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count);
|
||||
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
|
||||
import cn.celess.common.entity.dto.CommentReq;
|
||||
import cn.celess.common.entity.vo.CommentModel;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/29 16:58
|
||||
*/
|
||||
@Service
|
||||
public interface CommentService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param reqBody 请求数据体
|
||||
* @return 增加的comment数据
|
||||
*/
|
||||
CommentModel create(CommentReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id comment的id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param reqBody comment请求体
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
CommentModel update(CommentReq reqBody);
|
||||
|
||||
/**
|
||||
* 分页获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePage(String pagePath, int page, int count);
|
||||
|
||||
/**
|
||||
* 通过pid获取数据
|
||||
*
|
||||
* @param pid 父id
|
||||
* @return 分页数据
|
||||
*/
|
||||
List<CommentModel> retrievePageByPid(long pid);
|
||||
|
||||
|
||||
/**
|
||||
* 根据评论者获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByAuthor(String pagePath, int page, int count);
|
||||
|
||||
|
||||
/**
|
||||
* 根据数据的type和pid获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param pid 父id
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count);
|
||||
|
||||
/**
|
||||
* 根据type获取数据
|
||||
*
|
||||
* @param pagePath pagePath
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<CommentModel> retrievePageByPage(String pagePath, int page, int count);
|
||||
|
||||
}
|
||||
@@ -1,59 +1,59 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:04
|
||||
*/
|
||||
@Service
|
||||
public interface CountService {
|
||||
/**
|
||||
* 获取评论的数据量
|
||||
*
|
||||
* @return 评论的数据量
|
||||
*/
|
||||
long getCommentCount();
|
||||
|
||||
/**
|
||||
* 获取文章的篇数
|
||||
*
|
||||
* @return 文章的篇数
|
||||
*/
|
||||
long getArticleCount();
|
||||
|
||||
/**
|
||||
* 获取分类数量
|
||||
*
|
||||
* @return 分类数量
|
||||
*/
|
||||
long getCategoriesCount();
|
||||
|
||||
/**
|
||||
* 获取标签数量
|
||||
*
|
||||
* @return 标签数量
|
||||
*/
|
||||
long getTagsCount();
|
||||
|
||||
/**
|
||||
* 获取用户量
|
||||
*
|
||||
* @return 用户量
|
||||
*/
|
||||
long getUserCount();
|
||||
|
||||
/**
|
||||
* 获取总访问量
|
||||
*
|
||||
* @return 总访问量
|
||||
*/
|
||||
long getVisitorCount();
|
||||
|
||||
/**
|
||||
* 获取日访问量
|
||||
*
|
||||
* @return 日访问量
|
||||
*/
|
||||
long getDayVisitCount();
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 22:04
|
||||
*/
|
||||
@Service
|
||||
public interface CountService {
|
||||
/**
|
||||
* 获取评论的数据量
|
||||
*
|
||||
* @return 评论的数据量
|
||||
*/
|
||||
long getCommentCount();
|
||||
|
||||
/**
|
||||
* 获取文章的篇数
|
||||
*
|
||||
* @return 文章的篇数
|
||||
*/
|
||||
long getArticleCount();
|
||||
|
||||
/**
|
||||
* 获取分类数量
|
||||
*
|
||||
* @return 分类数量
|
||||
*/
|
||||
long getCategoriesCount();
|
||||
|
||||
/**
|
||||
* 获取标签数量
|
||||
*
|
||||
* @return 标签数量
|
||||
*/
|
||||
long getTagsCount();
|
||||
|
||||
/**
|
||||
* 获取用户量
|
||||
*
|
||||
* @return 用户量
|
||||
*/
|
||||
long getUserCount();
|
||||
|
||||
/**
|
||||
* 获取总访问量
|
||||
*
|
||||
* @return 总访问量
|
||||
*/
|
||||
long getVisitorCount();
|
||||
|
||||
/**
|
||||
* 获取日访问量
|
||||
*
|
||||
* @return 日访问量
|
||||
*/
|
||||
long getDayVisitCount();
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 14:25
|
||||
*/
|
||||
@Service
|
||||
public interface MailService {
|
||||
/**
|
||||
* 异步发生邮件
|
||||
*
|
||||
* @param message SimpleMailMessage对象
|
||||
* @return //
|
||||
*/
|
||||
Boolean AsyncSend(SimpleMailMessage message);
|
||||
|
||||
/**
|
||||
* 同步发送邮件
|
||||
*
|
||||
* @param message SimpleMailMessage对象
|
||||
* @return 发送状态
|
||||
*/
|
||||
Boolean send(SimpleMailMessage message);
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/22 14:25
|
||||
*/
|
||||
@Service
|
||||
public interface MailService {
|
||||
/**
|
||||
* 异步发生邮件
|
||||
*
|
||||
* @param message SimpleMailMessage对象
|
||||
* @return //
|
||||
*/
|
||||
Boolean AsyncSend(SimpleMailMessage message);
|
||||
|
||||
/**
|
||||
* 同步发送邮件
|
||||
*
|
||||
* @param message SimpleMailMessage对象
|
||||
* @return 发送状态
|
||||
*/
|
||||
Boolean send(SimpleMailMessage message);
|
||||
}
|
||||
@@ -1,72 +1,72 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.PartnerSite;
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.request.LinkApplyReq;
|
||||
import cn.celess.blog.entity.request.LinkReq;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:42
|
||||
*/
|
||||
@Service
|
||||
public interface PartnerSiteService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param reqBody 数据请求体
|
||||
* @return 新增数据
|
||||
*/
|
||||
PartnerSite create(LinkReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @return 删除状态
|
||||
*/
|
||||
Boolean del(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param reqBody 数据请求体
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
PartnerSite update(LinkReq reqBody);
|
||||
|
||||
/**
|
||||
* 分页获取数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted);
|
||||
|
||||
/**
|
||||
* 获取全部数据
|
||||
*
|
||||
* @return 全部友链数据
|
||||
*/
|
||||
List<PartnerSite> findAll();
|
||||
|
||||
/**
|
||||
* 申请友链
|
||||
*
|
||||
* @param linkApplyReq linkApplyReq
|
||||
* @return linkApplyReq
|
||||
*/
|
||||
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||
|
||||
/**
|
||||
* 重写申请友链
|
||||
*
|
||||
* @param key key
|
||||
* @return msg
|
||||
*/
|
||||
String reapply(String key);
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.PartnerSite;
|
||||
import cn.celess.common.entity.dto.LinkApplyReq;
|
||||
import cn.celess.common.entity.dto.LinkReq;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:42
|
||||
*/
|
||||
@Service
|
||||
public interface PartnerSiteService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param reqBody 数据请求体
|
||||
* @return 新增数据
|
||||
*/
|
||||
PartnerSite create(LinkReq reqBody);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @return 删除状态
|
||||
*/
|
||||
Boolean del(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param reqBody 数据请求体
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
PartnerSite update(LinkReq reqBody);
|
||||
|
||||
/**
|
||||
* 分页获取数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<PartnerSite> partnerSitePages(int page, int count, Boolean deleted);
|
||||
|
||||
/**
|
||||
* 获取全部数据
|
||||
*
|
||||
* @return 全部友链数据
|
||||
*/
|
||||
List<PartnerSite> findAll();
|
||||
|
||||
/**
|
||||
* 申请友链
|
||||
*
|
||||
* @param linkApplyReq linkApplyReq
|
||||
* @return linkApplyReq
|
||||
*/
|
||||
PartnerSite apply(LinkApplyReq linkApplyReq);
|
||||
|
||||
/**
|
||||
* 重写申请友链
|
||||
*
|
||||
* @param key key
|
||||
* @return msg
|
||||
*/
|
||||
String reapply(String key);
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.QiniuResponse;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
public interface QiniuService {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param is InputStream流
|
||||
* @param fileName 文件名
|
||||
* @return 响应数据
|
||||
*/
|
||||
QiniuResponse uploadFile(InputStream is, String fileName);
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @return 文件列表
|
||||
*/
|
||||
FileInfo[] getFileList();
|
||||
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.vo.QiniuResponse;
|
||||
import com.qiniu.storage.model.FileInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/25 18:15
|
||||
*/
|
||||
@Service
|
||||
public interface QiniuService {
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param is InputStream流
|
||||
* @param fileName 文件名
|
||||
* @return 响应数据
|
||||
*/
|
||||
QiniuResponse uploadFile(InputStream is, String fileName);
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @return 文件列表
|
||||
*/
|
||||
FileInfo[] getFileList();
|
||||
|
||||
}
|
||||
@@ -1,56 +1,56 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.TagModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:23
|
||||
*/
|
||||
@Service
|
||||
public interface TagService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param name 标签名
|
||||
* @return 新增后的数据
|
||||
*/
|
||||
TagModel create(String name);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param tagId 标签id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long tagId);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param id 标签id
|
||||
* @param name 改名的name值
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
TagModel update(Long id, String name);
|
||||
|
||||
/**
|
||||
* 分页获取标签数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<TagModel> retrievePage(int page, int count);
|
||||
|
||||
/**
|
||||
* 获取全部标签数据
|
||||
*
|
||||
* @return 标签数据列表
|
||||
*/
|
||||
List<TagModel> findAll();
|
||||
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.entity.vo.TagModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 22:23
|
||||
*/
|
||||
@Service
|
||||
public interface TagService {
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param name 标签名
|
||||
* @return 新增后的数据
|
||||
*/
|
||||
TagModel create(String name);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param tagId 标签id
|
||||
* @return 删除状态
|
||||
*/
|
||||
boolean delete(long tagId);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param id 标签id
|
||||
* @param name 改名的name值
|
||||
* @return 更新后的数据
|
||||
*/
|
||||
TagModel update(Long id, String name);
|
||||
|
||||
/**
|
||||
* 分页获取标签数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<TagModel> retrievePage(int page, int count);
|
||||
|
||||
/**
|
||||
* 获取全部标签数据
|
||||
*
|
||||
* @return 标签数据列表
|
||||
*/
|
||||
List<TagModel> findAll();
|
||||
|
||||
}
|
||||
@@ -1,159 +1,159 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.UserModel;
|
||||
import cn.celess.blog.entity.request.LoginReq;
|
||||
import cn.celess.blog.entity.request.UserReq;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 18:40
|
||||
*/
|
||||
@Service
|
||||
public interface UserService {
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @param password 密码
|
||||
* @return 注册状态
|
||||
*/
|
||||
Boolean registration(String email, String password);
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param loginReq 请求数据
|
||||
* @return 用户数据
|
||||
*/
|
||||
UserModel login(LoginReq loginReq);
|
||||
|
||||
/**
|
||||
* 注销登录
|
||||
*
|
||||
* @return **
|
||||
*/
|
||||
Object logout();
|
||||
|
||||
/**
|
||||
* 更新用户数据
|
||||
*
|
||||
* @param desc 用户描述
|
||||
* @param displayName 显示昵称
|
||||
* @return 用户数据
|
||||
*/
|
||||
UserModel update(String desc, String displayName);
|
||||
|
||||
/**
|
||||
* 更新头像
|
||||
*
|
||||
* @param is 头像文件的输入流
|
||||
* @param mime 文件的mime
|
||||
* @return 响应数据
|
||||
*/
|
||||
Object updateUserAavatarImg(InputStream is, String mime);
|
||||
|
||||
/**
|
||||
* 获取session中存储的用户资料
|
||||
*
|
||||
* @return 用户资料
|
||||
*/
|
||||
UserModel getUserInfoBySession();
|
||||
|
||||
/**
|
||||
* 获取用户的角色
|
||||
*
|
||||
* @param email 用户的邮箱
|
||||
* @return role
|
||||
*/
|
||||
String getUserRoleByEmail(String email);
|
||||
|
||||
/**
|
||||
* 获取邮箱是否注册过
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 注册状态
|
||||
*/
|
||||
boolean isExistOfEmail(String email);
|
||||
|
||||
/**
|
||||
* 发送重置密码邮件
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 发送状态
|
||||
*/
|
||||
Object sendResetPwdEmail(String email);
|
||||
|
||||
/**
|
||||
* 发送验证邮箱邮件
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 发送状态
|
||||
*/
|
||||
Object sendVerifyEmail(String email);
|
||||
|
||||
/**
|
||||
* 验证邮箱
|
||||
*
|
||||
* @param verifyId 验证码
|
||||
* @param email 邮箱
|
||||
* @return 验证状态
|
||||
*/
|
||||
Object verifyEmail(String verifyId, String email);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param verifyId 验证码
|
||||
* @param email 邮箱
|
||||
* @param pwd 新密码
|
||||
* @return 修改状态
|
||||
*/
|
||||
Object reSetPwd(String verifyId, String email, String pwd);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id 用户id的数组
|
||||
* @return 对应id 的删除状态
|
||||
*/
|
||||
Object deleteUser(Integer[] id);
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<UserModel> getUserList(Integer page, Integer count, Integer status);
|
||||
|
||||
/**
|
||||
* 更改用户信息
|
||||
*
|
||||
* @param user 用户数据
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserModel adminUpdate(UserReq user);
|
||||
|
||||
/**
|
||||
* 获取电子邮件的存在状态
|
||||
*
|
||||
* @param email email
|
||||
* @return true:存在 false:不存在
|
||||
*/
|
||||
boolean getStatusOfEmail(String email);
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
*
|
||||
* @param pwd pwd
|
||||
* @param newPwd newPwd
|
||||
* @param confirmPwd confirmPwd
|
||||
* @return UserModel
|
||||
*/
|
||||
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.dto.LoginReq;
|
||||
import cn.celess.common.entity.dto.UserReq;
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.entity.vo.UserModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 18:40
|
||||
*/
|
||||
@Service
|
||||
public interface UserService {
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
* @param email 邮箱
|
||||
* @param password 密码
|
||||
* @return 注册状态
|
||||
*/
|
||||
Boolean registration(String email, String password);
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @param loginReq 请求数据
|
||||
* @return 用户数据
|
||||
*/
|
||||
UserModel login(LoginReq loginReq);
|
||||
|
||||
/**
|
||||
* 注销登录
|
||||
*
|
||||
* @return **
|
||||
*/
|
||||
Object logout();
|
||||
|
||||
/**
|
||||
* 更新用户数据
|
||||
*
|
||||
* @param desc 用户描述
|
||||
* @param displayName 显示昵称
|
||||
* @return 用户数据
|
||||
*/
|
||||
UserModel update(String desc, String displayName);
|
||||
|
||||
/**
|
||||
* 更新头像
|
||||
*
|
||||
* @param is 头像文件的输入流
|
||||
* @param mime 文件的mime
|
||||
* @return 响应数据
|
||||
*/
|
||||
Object updateUserAavatarImg(InputStream is, String mime);
|
||||
|
||||
/**
|
||||
* 获取session中存储的用户资料
|
||||
*
|
||||
* @return 用户资料
|
||||
*/
|
||||
UserModel getUserInfoBySession();
|
||||
|
||||
/**
|
||||
* 获取用户的角色
|
||||
*
|
||||
* @param email 用户的邮箱
|
||||
* @return role
|
||||
*/
|
||||
String getUserRoleByEmail(String email);
|
||||
|
||||
/**
|
||||
* 获取邮箱是否注册过
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 注册状态
|
||||
*/
|
||||
boolean isExistOfEmail(String email);
|
||||
|
||||
/**
|
||||
* 发送重置密码邮件
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 发送状态
|
||||
*/
|
||||
Object sendResetPwdEmail(String email);
|
||||
|
||||
/**
|
||||
* 发送验证邮箱邮件
|
||||
*
|
||||
* @param email 用户邮箱
|
||||
* @return 发送状态
|
||||
*/
|
||||
Object sendVerifyEmail(String email);
|
||||
|
||||
/**
|
||||
* 验证邮箱
|
||||
*
|
||||
* @param verifyId 验证码
|
||||
* @param email 邮箱
|
||||
* @return 验证状态
|
||||
*/
|
||||
Object verifyEmail(String verifyId, String email);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param verifyId 验证码
|
||||
* @param email 邮箱
|
||||
* @param pwd 新密码
|
||||
* @return 修改状态
|
||||
*/
|
||||
Object reSetPwd(String verifyId, String email, String pwd);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id 用户id的数组
|
||||
* @return 对应id 的删除状态
|
||||
*/
|
||||
Object deleteUser(Integer[] id);
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<UserModel> getUserList(Integer page, Integer count, Integer status);
|
||||
|
||||
/**
|
||||
* 更改用户信息
|
||||
*
|
||||
* @param user 用户数据
|
||||
* @return 用户信息
|
||||
*/
|
||||
UserModel adminUpdate(UserReq user);
|
||||
|
||||
/**
|
||||
* 获取电子邮件的存在状态
|
||||
*
|
||||
* @param email email
|
||||
* @return true:存在 false:不存在
|
||||
*/
|
||||
boolean getStatusOfEmail(String email);
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
*
|
||||
* @param pwd pwd
|
||||
* @param newPwd newPwd
|
||||
* @param confirmPwd confirmPwd
|
||||
* @return UserModel
|
||||
*/
|
||||
UserModel setPwd(String pwd, String newPwd, String confirmPwd);
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.VisitorModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 23:03
|
||||
*/
|
||||
@Service
|
||||
public interface VisitorService {
|
||||
/**
|
||||
* 分页获取访客数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @param showLocation 是否显示位置信息 开启改选项数据响应超慢
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation);
|
||||
|
||||
/**
|
||||
* 新增访客
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return 返回状态 null: 访客信息已记录、爬虫
|
||||
*/
|
||||
VisitorModel addVisitor(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 获取位置信息
|
||||
*
|
||||
* @param ip ip地址
|
||||
* @return 位置信息
|
||||
*/
|
||||
String location(String ip);
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.entity.vo.VisitorModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/02 23:03
|
||||
*/
|
||||
@Service
|
||||
public interface VisitorService {
|
||||
/**
|
||||
* 分页获取访客数据
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @param showLocation 是否显示位置信息 开启改选项数据响应超慢
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<VisitorModel> visitorPage(int page, int count, boolean showLocation);
|
||||
|
||||
/**
|
||||
* 新增访客
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return 返回状态 null: 访客信息已记录、爬虫
|
||||
*/
|
||||
VisitorModel addVisitor(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 获取位置信息
|
||||
*
|
||||
* @param ip ip地址
|
||||
* @return 位置信息
|
||||
*/
|
||||
String location(String ip);
|
||||
}
|
||||
@@ -1,63 +1,64 @@
|
||||
package cn.celess.blog.service;
|
||||
|
||||
import cn.celess.blog.entity.model.PageData;
|
||||
import cn.celess.blog.entity.model.WebUpdateModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:42
|
||||
*/
|
||||
@Service
|
||||
public interface WebUpdateInfoService {
|
||||
/**
|
||||
* 新增记录
|
||||
*
|
||||
* @param info 更新内容
|
||||
* @return 创建状态
|
||||
*/
|
||||
WebUpdateModel create(String info);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @return 删除状态
|
||||
*/
|
||||
Boolean del(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @param info 新内容
|
||||
* @return 数据
|
||||
*/
|
||||
WebUpdateModel update(long id, String info);
|
||||
|
||||
/**
|
||||
* 分页获取更新记录
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<WebUpdateModel> pages(int count, int page);
|
||||
|
||||
/**
|
||||
* 获取全部的更新记录
|
||||
*
|
||||
* @return 更新记录
|
||||
*/
|
||||
List<WebUpdateModel> findAll();
|
||||
|
||||
/**
|
||||
* 获取最后更新时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getLastestUpdateTime();
|
||||
}
|
||||
package cn.celess.common.service;
|
||||
|
||||
|
||||
import cn.celess.common.entity.vo.PageData;
|
||||
import cn.celess.common.entity.vo.WebUpdateModel;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:42
|
||||
*/
|
||||
@Service
|
||||
public interface WebUpdateInfoService {
|
||||
/**
|
||||
* 新增记录
|
||||
*
|
||||
* @param info 更新内容
|
||||
* @return 创建状态
|
||||
*/
|
||||
WebUpdateModel create(String info);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @return 删除状态
|
||||
*/
|
||||
Boolean del(long id);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
*
|
||||
* @param id 数据id
|
||||
* @param info 新内容
|
||||
* @return 数据
|
||||
*/
|
||||
WebUpdateModel update(long id, String info);
|
||||
|
||||
/**
|
||||
* 分页获取更新记录
|
||||
*
|
||||
* @param count 单页数据量
|
||||
* @param page 数据页
|
||||
* @return 分页数据
|
||||
*/
|
||||
PageData<WebUpdateModel> pages(int count, int page);
|
||||
|
||||
/**
|
||||
* 获取全部的更新记录
|
||||
*
|
||||
* @return 更新记录
|
||||
*/
|
||||
List<WebUpdateModel> findAll();
|
||||
|
||||
/**
|
||||
* 获取最后更新时间
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getLastestUpdateTime();
|
||||
}
|
||||
@@ -1,42 +1,42 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:22
|
||||
*/
|
||||
public class DateFormatUtil {
|
||||
public static String get(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String getForXmlDate(Date date) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
String dateString = sdf.format(date);
|
||||
try {
|
||||
gc.setTime(sdf.parse(dateString));
|
||||
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
|
||||
return date2.toString();
|
||||
} catch (DatatypeConfigurationException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getNow() {
|
||||
return get(new Date());
|
||||
}
|
||||
}
|
||||
package cn.celess.common.util;
|
||||
|
||||
import javax.xml.datatype.DatatypeConfigurationException;
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:22
|
||||
*/
|
||||
public class DateFormatUtil {
|
||||
public static String get(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return sdf.format(date);
|
||||
}
|
||||
|
||||
public static String getForXmlDate(Date date) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
|
||||
GregorianCalendar gc = new GregorianCalendar();
|
||||
String dateString = sdf.format(date);
|
||||
try {
|
||||
gc.setTime(sdf.parse(dateString));
|
||||
XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
|
||||
return date2.toString();
|
||||
} catch (DatatypeConfigurationException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getNow() {
|
||||
return get(new Date());
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package cn.celess.blog.util;
|
||||
package cn.celess.common.util;
|
||||
|
||||
|
||||
import com.gargoylesoftware.htmlunit.BrowserVersion;
|
||||
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
|
||||
import com.gargoylesoftware.htmlunit.Page;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
@@ -17,15 +15,20 @@ import java.util.Objects;
|
||||
* @Desc:
|
||||
*/
|
||||
public class HttpUtil {
|
||||
private static final OkHttpClient CLIENT = new OkHttpClient();
|
||||
|
||||
public static String get(String urlStr) {
|
||||
Request request = new Request.Builder()
|
||||
.url(urlStr)
|
||||
.get()
|
||||
.build();
|
||||
try (Response response = CLIENT.newCall(request).execute()) {
|
||||
return Objects.requireNonNull(response.body()).string();
|
||||
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||
webClient.getOptions().setCssEnabled(false);
|
||||
webClient.getOptions().setJavaScriptEnabled(false);
|
||||
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
|
||||
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||
webClient.getOptions().setDownloadImages(false);
|
||||
webClient.getOptions().setActiveXNative(false);
|
||||
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
|
||||
Page clientPage = webClient.getPage(urlStr);
|
||||
if (clientPage.isHtmlPage()) {
|
||||
return clientPage.toString();
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
@@ -33,7 +36,7 @@ public class HttpUtil {
|
||||
|
||||
|
||||
public static String getAfterRendering(String url) {
|
||||
try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) {
|
||||
try (final WebClient webClient = new WebClient(BrowserVersion.BEST_SUPPORTED)) {
|
||||
webClient.getOptions().setCssEnabled(false);
|
||||
webClient.getOptions().setJavaScriptEnabled(true);
|
||||
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
|
||||
@@ -1,14 +1,14 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 18:56
|
||||
*/
|
||||
public class MD5Util {
|
||||
public static String getMD5(String str) {
|
||||
String md5 = DigestUtils.md5DigestAsHex(str.getBytes());
|
||||
return md5;
|
||||
}
|
||||
}
|
||||
package cn.celess.common.util;
|
||||
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/30 18:56
|
||||
*/
|
||||
public class MD5Util {
|
||||
public static String getMD5(String str) {
|
||||
String md5 = DigestUtils.md5DigestAsHex(str.getBytes());
|
||||
return md5;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package cn.celess.blog.util;
|
||||
package cn.celess.common.util;
|
||||
|
||||
import cn.celess.blog.enmu.UserAccountStatusEnum;
|
||||
import cn.celess.blog.entity.*;
|
||||
import cn.celess.blog.entity.model.*;
|
||||
|
||||
import cn.celess.common.enmu.UserAccountStatusEnum;
|
||||
import cn.celess.common.entity.*;
|
||||
import cn.celess.common.entity.vo.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/**
|
||||
@@ -1,126 +1,126 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
|
||||
import com.dyuproject.protostuff.LinkedBuffer;
|
||||
import com.dyuproject.protostuff.ProtostuffIOUtil;
|
||||
import com.dyuproject.protostuff.Schema;
|
||||
import com.dyuproject.protostuff.runtime.RuntimeSchema;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ProtoStuffSerializerUtil
|
||||
*
|
||||
* @author Sirius
|
||||
* @date 2019-1-8
|
||||
*/
|
||||
public class ProtoStuffSerializerUtil {
|
||||
/**
|
||||
* 序列化对象
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static <T> byte[] serialize(T obj) {
|
||||
if (obj == null) {
|
||||
throw new RuntimeException("序列化对象(" + obj + ")!");
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(obj.getClass());
|
||||
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
|
||||
byte[] protostuff = null;
|
||||
try {
|
||||
protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
|
||||
} finally {
|
||||
buffer.clear();
|
||||
}
|
||||
return protostuff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化对象
|
||||
*
|
||||
* @param paramArrayOfByte
|
||||
* @param targetClass
|
||||
* @return
|
||||
*/
|
||||
public static <T> T deserialize(byte[] paramArrayOfByte, Class<T> targetClass) {
|
||||
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
|
||||
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
|
||||
}
|
||||
T instance = null;
|
||||
try {
|
||||
instance = targetClass.newInstance();
|
||||
} catch (InstantiationException e1) {
|
||||
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e1);
|
||||
} catch (IllegalAccessException e2) {
|
||||
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e2);
|
||||
}
|
||||
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
|
||||
ProtostuffIOUtil.mergeFrom(paramArrayOfByte, instance, schema);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化列表
|
||||
*
|
||||
* @param objList
|
||||
* @return
|
||||
*/
|
||||
public static <T> byte[] serializeList(List<T> objList) {
|
||||
if (objList == null || objList.isEmpty()) {
|
||||
throw new RuntimeException("序列化对象列表(" + objList + ")参数异常!");
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(objList.get(0).getClass());
|
||||
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
|
||||
byte[] protostuff = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
ProtostuffIOUtil.writeListTo(bos, objList, schema, buffer);
|
||||
protostuff = bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("序列化对象列表(" + objList + ")发生异常!", e);
|
||||
} finally {
|
||||
buffer.clear();
|
||||
try {
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return protostuff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化列表
|
||||
*
|
||||
* @param paramArrayOfByte
|
||||
* @param targetClass
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> deserializeList(byte[] paramArrayOfByte, Class<T> targetClass) {
|
||||
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
|
||||
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
|
||||
}
|
||||
|
||||
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
|
||||
List<T> result = null;
|
||||
try {
|
||||
result = ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(paramArrayOfByte), schema);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("反序列化对象列表发生异常!", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
package cn.celess.common.util;
|
||||
|
||||
|
||||
import com.dyuproject.protostuff.LinkedBuffer;
|
||||
import com.dyuproject.protostuff.ProtostuffIOUtil;
|
||||
import com.dyuproject.protostuff.Schema;
|
||||
import com.dyuproject.protostuff.runtime.RuntimeSchema;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ProtoStuffSerializerUtil
|
||||
*
|
||||
* @author Sirius
|
||||
* @date 2019-1-8
|
||||
*/
|
||||
public class ProtoStuffSerializerUtil {
|
||||
/**
|
||||
* 序列化对象
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static <T> byte[] serialize(T obj) {
|
||||
if (obj == null) {
|
||||
throw new RuntimeException("序列化对象(" + obj + ")!");
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(obj.getClass());
|
||||
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
|
||||
byte[] protostuff = null;
|
||||
try {
|
||||
protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
|
||||
} finally {
|
||||
buffer.clear();
|
||||
}
|
||||
return protostuff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化对象
|
||||
*
|
||||
* @param paramArrayOfByte
|
||||
* @param targetClass
|
||||
* @return
|
||||
*/
|
||||
public static <T> T deserialize(byte[] paramArrayOfByte, Class<T> targetClass) {
|
||||
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
|
||||
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
|
||||
}
|
||||
T instance = null;
|
||||
try {
|
||||
instance = targetClass.newInstance();
|
||||
} catch (InstantiationException e1) {
|
||||
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e1);
|
||||
} catch (IllegalAccessException e2) {
|
||||
throw new RuntimeException("反序列化过程中依据类型创建对象失败!", e2);
|
||||
}
|
||||
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
|
||||
ProtostuffIOUtil.mergeFrom(paramArrayOfByte, instance, schema);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 序列化列表
|
||||
*
|
||||
* @param objList
|
||||
* @return
|
||||
*/
|
||||
public static <T> byte[] serializeList(List<T> objList) {
|
||||
if (objList == null || objList.isEmpty()) {
|
||||
throw new RuntimeException("序列化对象列表(" + objList + ")参数异常!");
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(objList.get(0).getClass());
|
||||
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
|
||||
byte[] protostuff = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
ProtostuffIOUtil.writeListTo(bos, objList, schema, buffer);
|
||||
protostuff = bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("序列化对象列表(" + objList + ")发生异常!", e);
|
||||
} finally {
|
||||
buffer.clear();
|
||||
try {
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return protostuff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化列表
|
||||
*
|
||||
* @param paramArrayOfByte
|
||||
* @param targetClass
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> deserializeList(byte[] paramArrayOfByte, Class<T> targetClass) {
|
||||
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
|
||||
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
|
||||
}
|
||||
|
||||
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
|
||||
List<T> result = null;
|
||||
try {
|
||||
result = ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(paramArrayOfByte), schema);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("反序列化对象列表发生异常!", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,80 +1,80 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:04
|
||||
*/
|
||||
public class RegexUtil {
|
||||
/**
|
||||
* 网址匹配
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean urlMatch(String url) {
|
||||
if (url == null || url.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则 (http(s)://www.celess/xxxx,www.celess.cn/xxx)
|
||||
String pattern = "^(http://|https://|)([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
|
||||
return match(url, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean emailMatch(String email) {
|
||||
if (email == null || email.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
||||
return match(email, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号匹配
|
||||
*
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public static boolean phoneMatch(String phone) {
|
||||
if (phone == null || phone.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^([1][3,4,5,6,7,8,9])\\d{9}$";
|
||||
return match(phone, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码正则
|
||||
* 最短6位,最长16位 {6,16}
|
||||
* 可以包含小写大母 [a-z] 和大写字母 [A-Z]
|
||||
* 可以包含数字 [0-9]
|
||||
* 可以包含下划线 [ _ ] 和减号 [ - ]
|
||||
*
|
||||
* @param pwd
|
||||
* @return
|
||||
*/
|
||||
public static boolean pwdMatch(String pwd) {
|
||||
if (pwd == null || pwd.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^[\\w_-]{6,16}$";
|
||||
return match(pwd, pattern);
|
||||
}
|
||||
|
||||
private static boolean match(String str, String pattern) {
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
Matcher m = r.matcher(str);
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
package cn.celess.common.util;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/05/12 11:04
|
||||
*/
|
||||
public class RegexUtil {
|
||||
/**
|
||||
* 网址匹配
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean urlMatch(String url) {
|
||||
if (url == null || url.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则 (http(s)://www.celess/xxxx,www.celess.cn/xxx)
|
||||
String pattern = "^(http://|https://|)([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
|
||||
return match(url, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱验证
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean emailMatch(String email) {
|
||||
if (email == null || email.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
||||
return match(email, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号匹配
|
||||
*
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
public static boolean phoneMatch(String phone) {
|
||||
if (phone == null || phone.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^([1][3,4,5,6,7,8,9])\\d{9}$";
|
||||
return match(phone, pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码正则
|
||||
* 最短6位,最长16位 {6,16}
|
||||
* 可以包含小写大母 [a-z] 和大写字母 [A-Z]
|
||||
* 可以包含数字 [0-9]
|
||||
* 可以包含下划线 [ _ ] 和减号 [ - ]
|
||||
*
|
||||
* @param pwd
|
||||
* @return
|
||||
*/
|
||||
public static boolean pwdMatch(String pwd) {
|
||||
if (pwd == null || pwd.replaceAll(" ", "").isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//正则
|
||||
String pattern = "^[\\w_-]{6,16}$";
|
||||
return match(pwd, pattern);
|
||||
}
|
||||
|
||||
private static boolean match(String str, String pattern) {
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
Matcher m = r.matcher(str);
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:44
|
||||
* @Description:
|
||||
*/
|
||||
public class RequestUtil {
|
||||
public static String getCompleteUrlAndMethod(HttpServletRequest request) {
|
||||
// like this : /articles?page=1&count=5:GET
|
||||
return request.getRequestURI() +
|
||||
(request.getQueryString() == null ? "" : "?" + request.getQueryString()) +
|
||||
":" + request.getMethod();
|
||||
}
|
||||
}
|
||||
package cn.celess.common.util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Author: 小海
|
||||
* @Date: 2019/10/18 15:44
|
||||
* @Description:
|
||||
*/
|
||||
public class RequestUtil {
|
||||
public static String getCompleteUrlAndMethod(HttpServletRequest request) {
|
||||
// like this : /articles?page=1&count=5:GET
|
||||
return request.getRequestURI() +
|
||||
(request.getQueryString() == null ? "" : "?" + request.getQueryString()) +
|
||||
":" + request.getMethod();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:21
|
||||
*/
|
||||
public class StringFromHtmlUtil {
|
||||
public static String getString(String html) {
|
||||
//从html中提取纯文本
|
||||
//剔出<html>的标签
|
||||
String txtcontent = html.replaceAll("</?[^>]+>", "");
|
||||
//去除字符串中的空格,回车,换行符,制表符
|
||||
txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
|
||||
return txtcontent;
|
||||
}
|
||||
}
|
||||
|
||||
package cn.celess.common.util;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/03/28 17:21
|
||||
*/
|
||||
public class StringFromHtmlUtil {
|
||||
public static String getString(String html) {
|
||||
//从html中提取纯文本
|
||||
//剔出<html>的标签
|
||||
String txtcontent = html.replaceAll("</?[^>]+>", "");
|
||||
//去除字符串中的空格,回车,换行符,制表符
|
||||
txtcontent = txtcontent.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
|
||||
return txtcontent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +1,90 @@
|
||||
package cn.celess.blog.util;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/11 15:42
|
||||
*/
|
||||
|
||||
public class VeriCodeUtil {
|
||||
// 验证码字符集
|
||||
private static final char[] chars = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
|
||||
// 字符数量
|
||||
private static final int SIZE = 4;
|
||||
// 干扰线数量
|
||||
private static final int LINES = 5;
|
||||
// 宽度
|
||||
private static final int WIDTH = 80;
|
||||
// 高度
|
||||
private static final int HEIGHT = 40;
|
||||
// 字体大小
|
||||
private static final int FONT_SIZE = 30;
|
||||
|
||||
/**
|
||||
* 生成随机验证码及图片
|
||||
* Object[0]:验证码字符串;
|
||||
* Object[1]:验证码图片。
|
||||
*/
|
||||
public static Object[] createImage() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
// 1.创建空白图片
|
||||
BufferedImage image = new BufferedImage(
|
||||
WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
// 2.获取图片画笔
|
||||
Graphics graphic = image.getGraphics();
|
||||
// 3.设置画笔颜色
|
||||
graphic.setColor(Color.LIGHT_GRAY);
|
||||
// 4.绘制矩形背景
|
||||
graphic.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
// 5.画随机字符
|
||||
Random ran = new Random();
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
// 取随机字符索引
|
||||
int n = ran.nextInt(chars.length);
|
||||
// 设置随机颜色
|
||||
graphic.setColor(getRandomColor());
|
||||
// 设置字体大小
|
||||
graphic.setFont(new Font(
|
||||
null, Font.BOLD + Font.ITALIC, FONT_SIZE));
|
||||
// 画字符
|
||||
graphic.drawString(
|
||||
chars[n] + "", i * WIDTH / SIZE, HEIGHT * 2 / 3);
|
||||
// 记录字符
|
||||
sb.append(chars[n]);
|
||||
}
|
||||
// 6.画干扰线
|
||||
for (int i = 0; i < LINES; i++) {
|
||||
// 设置随机颜色
|
||||
graphic.setColor(getRandomColor());
|
||||
// 随机画线
|
||||
graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT),
|
||||
ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
|
||||
}
|
||||
// 7.返回验证码和图片
|
||||
return new Object[]{sb.toString(), image};
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机取色
|
||||
*/
|
||||
public static Color getRandomColor() {
|
||||
Random ran = new Random();
|
||||
Color color = new Color(ran.nextInt(256),
|
||||
ran.nextInt(256), ran.nextInt(256));
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
package cn.celess.common.util;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author : xiaohai
|
||||
* @date : 2019/04/11 15:42
|
||||
*/
|
||||
|
||||
public class VeriCodeUtil {
|
||||
// 验证码字符集
|
||||
private static final char[] chars = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
|
||||
// 字符数量
|
||||
private static final int SIZE = 4;
|
||||
// 干扰线数量
|
||||
private static final int LINES = 5;
|
||||
// 宽度
|
||||
private static final int WIDTH = 80;
|
||||
// 高度
|
||||
private static final int HEIGHT = 40;
|
||||
// 字体大小
|
||||
private static final int FONT_SIZE = 30;
|
||||
|
||||
/**
|
||||
* 生成随机验证码及图片
|
||||
* Object[0]:验证码字符串;
|
||||
* Object[1]:验证码图片。
|
||||
*/
|
||||
public static Object[] createImage() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
// 1.创建空白图片
|
||||
BufferedImage image = new BufferedImage(
|
||||
WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
||||
// 2.获取图片画笔
|
||||
Graphics graphic = image.getGraphics();
|
||||
// 3.设置画笔颜色
|
||||
graphic.setColor(Color.LIGHT_GRAY);
|
||||
// 4.绘制矩形背景
|
||||
graphic.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
// 5.画随机字符
|
||||
Random ran = new Random();
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
// 取随机字符索引
|
||||
int n = ran.nextInt(chars.length);
|
||||
// 设置随机颜色
|
||||
graphic.setColor(getRandomColor());
|
||||
// 设置字体大小
|
||||
graphic.setFont(new Font(
|
||||
null, Font.BOLD + Font.ITALIC, FONT_SIZE));
|
||||
// 画字符
|
||||
graphic.drawString(
|
||||
chars[n] + "", i * WIDTH / SIZE, HEIGHT * 2 / 3);
|
||||
// 记录字符
|
||||
sb.append(chars[n]);
|
||||
}
|
||||
// 6.画干扰线
|
||||
for (int i = 0; i < LINES; i++) {
|
||||
// 设置随机颜色
|
||||
graphic.setColor(getRandomColor());
|
||||
// 随机画线
|
||||
graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT),
|
||||
ran.nextInt(WIDTH), ran.nextInt(HEIGHT));
|
||||
}
|
||||
// 7.返回验证码和图片
|
||||
return new Object[]{sb.toString(), image};
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机取色
|
||||
*/
|
||||
public static Color getRandomColor() {
|
||||
Random ran = new Random();
|
||||
Color color = new Color(ran.nextInt(256),
|
||||
ran.nextInt(256), ran.nextInt(256));
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.celess.blog.mapper.ArticleTagMapper">
|
||||
<mapper namespace="cn.celess.common.mapper.ArticleTagMapper">
|
||||
|
||||
<resultMap id="articleTagResultMap" type="cn.celess.blog.entity.ArticleTag">
|
||||
<resultMap id="articleTagResultMap" type="cn.celess.common.entity.ArticleTag">
|
||||
<id column="at_id" property="id"/>
|
||||
<result column="a_id" property="article.id"/>
|
||||
<result column="t_id" property="tag.id"/>
|
||||
<association property="article" column="a_id" resultMap="cn.celess.blog.mapper.ArticleMapper.articleResultMap"
|
||||
javaType="cn.celess.blog.entity.Article">
|
||||
<association property="article" column="a_id" resultMap="cn.celess.common.mapper.ArticleMapper.articleResultMap"
|
||||
javaType="cn.celess.common.entity.Article">
|
||||
</association>
|
||||
<association property="tag" column="t_id" resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap"
|
||||
javaType="cn.celess.blog.entity.TagCategory">
|
||||
<association property="tag" column="t_id" resultMap="cn.celess.common.mapper.CategoryMapper.categoryResultMap"
|
||||
javaType="cn.celess.common.entity.TagCategory">
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
and article_tag.t_id = tag_category.t_id
|
||||
</select>
|
||||
|
||||
<select id="findTagByArticleId" resultMap="cn.celess.blog.mapper.TagMapper.tagResultMap">
|
||||
<select id="findTagByArticleId" resultMap="cn.celess.common.mapper.TagMapper.tagResultMap">
|
||||
select tag_category.*
|
||||
from article_tag,
|
||||
tag_category
|
||||
@@ -1,93 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.CategoryMapper">
|
||||
<resultMap id="categoryResultMap" type="cn.celess.blog.entity.Category">
|
||||
<id column="t_id" property="id"/>
|
||||
<result column="t_name" property="name"/>
|
||||
<result column="is_category" property="category"/>
|
||||
<result column="is_delete" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
values (#{name}, true);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete= true
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</update>
|
||||
|
||||
<select id="findCategoryByName" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = true
|
||||
</select>
|
||||
|
||||
<select id="findCategoryById" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = true
|
||||
</select>
|
||||
|
||||
<select id="getAllName" resultType="java.lang.String">
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true
|
||||
</select>
|
||||
|
||||
<select id="getNameById" resultType="java.lang.String">
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and t_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getIdByName" resultType="java.lang.Long">
|
||||
select t_id
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and t_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = true)
|
||||
</select>
|
||||
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="getLastestCategory" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = true
|
||||
order by t_id desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and is_delete = false;
|
||||
</select>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.CategoryMapper">
|
||||
<resultMap id="categoryResultMap" type="cn.celess.common.entity.Category">
|
||||
<id column="t_id" property="id"/>
|
||||
<result column="t_name" property="name"/>
|
||||
<result column="is_category" property="category"/>
|
||||
<result column="is_delete" property="deleted"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
values (#{name}, true);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete= true
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</update>
|
||||
|
||||
<select id="findCategoryByName" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = true
|
||||
</select>
|
||||
|
||||
<select id="findCategoryById" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = true
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = true
|
||||
</select>
|
||||
|
||||
<select id="getAllName" resultType="java.lang.String">
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true
|
||||
</select>
|
||||
|
||||
<select id="getNameById" resultType="java.lang.String">
|
||||
select t_name
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and t_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getIdByName" resultType="java.lang.Long">
|
||||
select t_id
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and t_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = true)
|
||||
</select>
|
||||
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="getLastestCategory" resultMap="categoryResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = true
|
||||
order by t_id desc
|
||||
limit 1;
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from tag_category
|
||||
where is_category = true
|
||||
and is_delete = false;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,131 +1,131 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.CommentMapper">
|
||||
<resultMap id="commentResultMap" type="cn.celess.blog.entity.Comment">
|
||||
<id column="co_id" property="id"/>
|
||||
<result column="co_page_path" property="pagePath"/>
|
||||
<result column="co_status" property="status"/>
|
||||
<result column="co_content" property="content"/>
|
||||
<result column="co_date" property="date"/>
|
||||
<result column="co_pid" property="pid"/>
|
||||
<result column="co_from_author_id" property="fromUser.id"/>
|
||||
<result column="co_to_author_id" property="toUser.id"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="commentViewResultMap" type="cn.celess.blog.entity.Comment">
|
||||
<id column="commentId" property="id"/>
|
||||
<result column="pagePath" property="pagePath"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="content" property="content"/>
|
||||
<result column="date" property="date"/>
|
||||
<result column="pid" property="pid"/>
|
||||
<result column="fromAuthorId" property="fromUser.id"/>
|
||||
<result column="toAuthorId" property="toUser.id"/>
|
||||
<association property="fromUser" column="fromAuthorId" javaType="cn.celess.blog.entity.User">
|
||||
<id column="fromAuthorId" property="id"/>
|
||||
<result column="fromAuthorEmail" property="email"/>
|
||||
<result column="fromAuthorDisplayName" property="displayName"/>
|
||||
<result column="fromAuthorAvatar" property="avatarImgUrl"/>
|
||||
</association>
|
||||
<association property="toUser" column="toAuthorId" javaType="cn.celess.blog.entity.User">
|
||||
<id column="toAuthorId" property="id"/>
|
||||
<result column="toAuthorEmail" property="email"/>
|
||||
<result column="toAuthorDisplayName" property="displayName"/>
|
||||
<result column="toAuthorAvatar" property="avatarImgUrl"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into comment (co_page_path, co_content, co_date, co_pid, co_from_author_id, co_to_author_id, co_status)
|
||||
VALUES (#{pagePath}, #{content}, now(), #{pid}, #{fromUser.id}, #{toUser.id}, 0)
|
||||
</insert>
|
||||
|
||||
<update id="updateContent">
|
||||
update comment
|
||||
set co_content=#{content}
|
||||
where co_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update comment
|
||||
set co_status = 3
|
||||
where co_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="deleteByPagePath">
|
||||
update comment
|
||||
set co_status = 3
|
||||
where co_page_path = #{path}
|
||||
</update>
|
||||
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="findCommentById" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where commentId = #{sqid}
|
||||
</select>
|
||||
|
||||
<select id="findAllByFromUser" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where fromAuthorId = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPid" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where pid = #{pid}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePath" resultMap="commentViewResultMap" parameterType="string">
|
||||
select *
|
||||
from commentView
|
||||
<if test="toString() != null ">
|
||||
where pagePath = #{pagePath}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePathAndFromUser" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where
|
||||
<if test="pagePath != null ">
|
||||
pagePath = #{pagePath} and
|
||||
</if>
|
||||
fromAuthorId = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePathAndPidAndNormal" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where
|
||||
<if test="pagePath != null ">
|
||||
pagePath = #{pagePath} and
|
||||
</if>
|
||||
pid = #{pid} and status = 0
|
||||
</select>
|
||||
|
||||
<select id="countByPagePath" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from commentView
|
||||
where pagePath = #{pagePath}
|
||||
</select>
|
||||
|
||||
<select id="getLastestComment" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
order by commentId desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="long">
|
||||
select count(*)
|
||||
from comment
|
||||
where co_status = 0;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.CommentMapper">
|
||||
<resultMap id="commentResultMap" type="cn.celess.common.entity.Comment">
|
||||
<id column="co_id" property="id"/>
|
||||
<result column="co_page_path" property="pagePath"/>
|
||||
<result column="co_status" property="status"/>
|
||||
<result column="co_content" property="content"/>
|
||||
<result column="co_date" property="date"/>
|
||||
<result column="co_pid" property="pid"/>
|
||||
<result column="co_from_author_id" property="fromUser.id"/>
|
||||
<result column="co_to_author_id" property="toUser.id"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="commentViewResultMap" type="cn.celess.common.entity.Comment">
|
||||
<id column="commentId" property="id"/>
|
||||
<result column="pagePath" property="pagePath"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="content" property="content"/>
|
||||
<result column="date" property="date"/>
|
||||
<result column="pid" property="pid"/>
|
||||
<result column="fromAuthorId" property="fromUser.id"/>
|
||||
<result column="toAuthorId" property="toUser.id"/>
|
||||
<association property="fromUser" column="fromAuthorId" javaType="cn.celess.common.entity.User">
|
||||
<id column="fromAuthorId" property="id"/>
|
||||
<result column="fromAuthorEmail" property="email"/>
|
||||
<result column="fromAuthorDisplayName" property="displayName"/>
|
||||
<result column="fromAuthorAvatar" property="avatarImgUrl"/>
|
||||
</association>
|
||||
<association property="toUser" column="toAuthorId" javaType="cn.celess.common.entity.User">
|
||||
<id column="toAuthorId" property="id"/>
|
||||
<result column="toAuthorEmail" property="email"/>
|
||||
<result column="toAuthorDisplayName" property="displayName"/>
|
||||
<result column="toAuthorAvatar" property="avatarImgUrl"/>
|
||||
</association>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into comment (co_page_path, co_content, co_date, co_pid, co_from_author_id, co_to_author_id, co_status)
|
||||
VALUES (#{pagePath}, #{content}, now(), #{pid}, #{fromUser.id}, #{toUser.id}, 0)
|
||||
</insert>
|
||||
|
||||
<update id="updateContent">
|
||||
update comment
|
||||
set co_content=#{content}
|
||||
where co_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update comment
|
||||
set co_status = 3
|
||||
where co_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="deleteByPagePath">
|
||||
update comment
|
||||
set co_status = 3
|
||||
where co_page_path = #{path}
|
||||
</update>
|
||||
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
SELECT EXISTS(SELECT * FROM comment WHERE co_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="findCommentById" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where commentId = #{sqid}
|
||||
</select>
|
||||
|
||||
<select id="findAllByFromUser" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where fromAuthorId = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPid" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where pid = #{pid}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePath" resultMap="commentViewResultMap" parameterType="string">
|
||||
select *
|
||||
from commentView
|
||||
<if test="toString() != null ">
|
||||
where pagePath = #{pagePath}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePathAndFromUser" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where
|
||||
<if test="pagePath != null ">
|
||||
pagePath = #{pagePath} and
|
||||
</if>
|
||||
fromAuthorId = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="findAllByPagePathAndPidAndNormal" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
where
|
||||
<if test="pagePath != null ">
|
||||
pagePath = #{pagePath} and
|
||||
</if>
|
||||
pid = #{pid} and status = 0
|
||||
</select>
|
||||
|
||||
<select id="countByPagePath" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from commentView
|
||||
where pagePath = #{pagePath}
|
||||
</select>
|
||||
|
||||
<select id="getLastestComment" resultMap="commentViewResultMap">
|
||||
select *
|
||||
from commentView
|
||||
order by commentId desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="long">
|
||||
select count(*)
|
||||
from comment
|
||||
where co_status = 0;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,87 +1,87 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.PartnerMapper">
|
||||
<resultMap id="partnerSiteResultMap" type="cn.celess.blog.entity.PartnerSite">
|
||||
<id column="l_id" property="id"/>
|
||||
<result column="l_name" property="name"/>
|
||||
<result column="l_url" property="url"/>
|
||||
<result column="l_is_open" property="open"/>
|
||||
<result column="l_icon_path" property="iconPath"/>
|
||||
<result column="l_desc" property="desc"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
<result column="l_email" property="email"/>
|
||||
<result column="l_notification" property="notification"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
|
||||
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
|
||||
update links
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="open!=null">l_is_open=#{open},</if>
|
||||
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
|
||||
<if test="desc!=null">l_desc=#{desc},</if>
|
||||
<if test="url!=null">l_url=#{url},</if>
|
||||
<if test="name!=null">l_name=#{name},</if>
|
||||
<if test="notification!=null">l_notification=#{notification},</if>
|
||||
<if test="email!=null">l_email=#{email}</if>
|
||||
</trim>
|
||||
where l_id=#{id}
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update links
|
||||
set is_delete = true
|
||||
where l_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="existsById" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_name = #{name})
|
||||
|
||||
</select>
|
||||
|
||||
<select id="existsByUrl" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_url = #{url})
|
||||
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findByName" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="findByUrl" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_url = #{url}
|
||||
</select>
|
||||
<select id="getLastest" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
order by l_id desc
|
||||
limit 1
|
||||
</select>
|
||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
<if test="_parameter != null">
|
||||
where is_delete=#{deleted}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.PartnerMapper">
|
||||
<resultMap id="partnerSiteResultMap" type="cn.celess.common.entity.PartnerSite">
|
||||
<id column="l_id" property="id"/>
|
||||
<result column="l_name" property="name"/>
|
||||
<result column="l_url" property="url"/>
|
||||
<result column="l_is_open" property="open"/>
|
||||
<result column="l_icon_path" property="iconPath"/>
|
||||
<result column="l_desc" property="desc"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
<result column="l_email" property="email"/>
|
||||
<result column="l_notification" property="notification"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="cn.celess.common.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
|
||||
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="cn.celess.common.entity.PartnerSite">
|
||||
update links
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<if test="open!=null">l_is_open=#{open},</if>
|
||||
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
|
||||
<if test="desc!=null">l_desc=#{desc},</if>
|
||||
<if test="url!=null">l_url=#{url},</if>
|
||||
<if test="name!=null">l_name=#{name},</if>
|
||||
<if test="notification!=null">l_notification=#{notification},</if>
|
||||
<if test="email!=null">l_email=#{email}</if>
|
||||
</trim>
|
||||
where l_id=#{id}
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update links
|
||||
set is_delete = true
|
||||
where l_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="existsById" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_name = #{name})
|
||||
|
||||
</select>
|
||||
|
||||
<select id="existsByUrl" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM links WHERE l_url = #{url})
|
||||
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findByName" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_name = #{name}
|
||||
</select>
|
||||
|
||||
<select id="findByUrl" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
where l_url = #{url}
|
||||
</select>
|
||||
<select id="getLastest" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
order by l_id desc
|
||||
limit 1
|
||||
</select>
|
||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from links
|
||||
<if test="_parameter != null">
|
||||
where is_delete=#{deleted}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,137 +1,137 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.UserMapper">
|
||||
<resultMap id="userResultMap" type="cn.celess.blog.entity.User">
|
||||
<id column="u_id" property="id"/>
|
||||
<result column="u_email" property="email"/>
|
||||
<result column="u_pwd" property="pwd"/>
|
||||
<result column="u_email_status" property="emailStatus"/>
|
||||
<result column="u_avatar" property="avatarImgUrl"/>
|
||||
<result column="u_desc" property="desc"/>
|
||||
<result column="u_recently_landed_time" property="recentlyLandedDate"/>
|
||||
<result column="u_display_name" property="displayName"/>
|
||||
<result column="u_role" property="role"/>
|
||||
<result column="status" property="status"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="addUser" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into user(u_email, u_pwd)
|
||||
values (#{email}, #{pwd})
|
||||
</insert>
|
||||
|
||||
<update id="updateInfo">
|
||||
update user set
|
||||
<if test="desc!=null">u_desc=#{desc},</if>
|
||||
<if test="displayName!=null">u_display_name=#{displayName}</if>
|
||||
where u_id=#{id}
|
||||
</update>
|
||||
<update id="updateLoginTime">
|
||||
update user
|
||||
set u_recently_landed_time=now()
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="updateAvatarImgUrl">
|
||||
update user
|
||||
set u_avatar=#{avatarImgUrl}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="updateEmailStatus">
|
||||
update user
|
||||
set u_email_status=#{status}
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="updatePwd">
|
||||
update user
|
||||
set u_pwd=#{pwd}
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="setUserRole">
|
||||
update user
|
||||
set u_role=#{role}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="update">
|
||||
update user
|
||||
set u_email = #{email},
|
||||
u_pwd = #{pwd},
|
||||
u_email_status = #{emailStatus},
|
||||
u_desc = #{desc},
|
||||
u_display_name = #{displayName},
|
||||
u_avatar = #{avatarImgUrl},
|
||||
u_role = #{role}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="delete">
|
||||
update user
|
||||
set status= 2
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="lock">
|
||||
update user
|
||||
set status= 1
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="existsByEmail" resultType="java.lang.Boolean">
|
||||
select exists(select * from user where u_email = #{email})
|
||||
</select>
|
||||
|
||||
<select id="findByEmail" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
where u_email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getAvatarImgUrlById" resultType="string">
|
||||
select u_avatar
|
||||
from user
|
||||
where u_id = #{id};
|
||||
</select>
|
||||
|
||||
<select id="getEmail" resultType="java.lang.String">
|
||||
select u_email
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getDisPlayName" resultType="java.lang.String">
|
||||
select u_display_name
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getPwd" resultType="java.lang.String">
|
||||
select u_pwd
|
||||
from user
|
||||
where u_email = #{email}
|
||||
</select>
|
||||
<select id="getRoleByEmail" resultType="java.lang.String">
|
||||
select u_role
|
||||
from user
|
||||
where u_email = #{emai}
|
||||
</select>
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from user
|
||||
where status =0;
|
||||
</select>
|
||||
<select id="getRoleById" resultType="java.lang.String">
|
||||
select u_role
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
<select id="findAll" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
<if test="_parameter != null">
|
||||
where status=#{status}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.UserMapper">
|
||||
<resultMap id="userResultMap" type="cn.celess.common.entity.User">
|
||||
<id column="u_id" property="id"/>
|
||||
<result column="u_email" property="email"/>
|
||||
<result column="u_pwd" property="pwd"/>
|
||||
<result column="u_email_status" property="emailStatus"/>
|
||||
<result column="u_avatar" property="avatarImgUrl"/>
|
||||
<result column="u_desc" property="desc"/>
|
||||
<result column="u_recently_landed_time" property="recentlyLandedDate"/>
|
||||
<result column="u_display_name" property="displayName"/>
|
||||
<result column="u_role" property="role"/>
|
||||
<result column="status" property="status"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="addUser" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into user(u_email, u_pwd)
|
||||
values (#{email}, #{pwd})
|
||||
</insert>
|
||||
|
||||
<update id="updateInfo">
|
||||
update user set
|
||||
<if test="desc!=null">u_desc=#{desc},</if>
|
||||
<if test="displayName!=null">u_display_name=#{displayName}</if>
|
||||
where u_id=#{id}
|
||||
</update>
|
||||
<update id="updateLoginTime">
|
||||
update user
|
||||
set u_recently_landed_time=now()
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="updateAvatarImgUrl">
|
||||
update user
|
||||
set u_avatar=#{avatarImgUrl}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="updateEmailStatus">
|
||||
update user
|
||||
set u_email_status=#{status}
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="updatePwd">
|
||||
update user
|
||||
set u_pwd=#{pwd}
|
||||
where u_email = #{email}
|
||||
</update>
|
||||
<update id="setUserRole">
|
||||
update user
|
||||
set u_role=#{role}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="update">
|
||||
update user
|
||||
set u_email = #{email},
|
||||
u_pwd = #{pwd},
|
||||
u_email_status = #{emailStatus},
|
||||
u_desc = #{desc},
|
||||
u_display_name = #{displayName},
|
||||
u_avatar = #{avatarImgUrl},
|
||||
u_role = #{role}
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
<update id="delete">
|
||||
update user
|
||||
set status= 2
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="lock">
|
||||
update user
|
||||
set status= 1
|
||||
where u_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="existsByEmail" resultType="java.lang.Boolean">
|
||||
select exists(select * from user where u_email = #{email})
|
||||
</select>
|
||||
|
||||
<select id="findByEmail" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
where u_email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getAvatarImgUrlById" resultType="string">
|
||||
select u_avatar
|
||||
from user
|
||||
where u_id = #{id};
|
||||
</select>
|
||||
|
||||
<select id="getEmail" resultType="java.lang.String">
|
||||
select u_email
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getDisPlayName" resultType="java.lang.String">
|
||||
select u_display_name
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getPwd" resultType="java.lang.String">
|
||||
select u_pwd
|
||||
from user
|
||||
where u_email = #{email}
|
||||
</select>
|
||||
<select id="getRoleByEmail" resultType="java.lang.String">
|
||||
select u_role
|
||||
from user
|
||||
where u_email = #{emai}
|
||||
</select>
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from user
|
||||
where status =0;
|
||||
</select>
|
||||
<select id="getRoleById" resultType="java.lang.String">
|
||||
select u_role
|
||||
from user
|
||||
where u_id = #{id}
|
||||
</select>
|
||||
<select id="findAll" resultMap="userResultMap">
|
||||
select *
|
||||
from user
|
||||
<if test="_parameter != null">
|
||||
where status=#{status}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -1,39 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.VisitorMapper">
|
||||
<resultMap id="partnerSiteResultMap" type="cn.celess.blog.entity.Visitor">
|
||||
<id column="v_id" property="id"/>
|
||||
<result column="v_date" property="date"/>
|
||||
<result column="v_user_agent" property="ua"/>
|
||||
<result column="v_ip" property="ip"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into visitor (v_date, v_ip, v_user_agent)
|
||||
values (#{date}, #{ip}, #{ua})
|
||||
</insert>
|
||||
<update id="delete">
|
||||
update visitor
|
||||
set is_delete = true
|
||||
where v_id = #{id}
|
||||
</update>
|
||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from visitor
|
||||
order by v_id desc
|
||||
</select>
|
||||
|
||||
<select id="findAllNotDeleted" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from visitor
|
||||
where is_delete = false
|
||||
order by v_id desc
|
||||
</select>
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from visitor
|
||||
</select>
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.VisitorMapper">
|
||||
<resultMap id="partnerSiteResultMap" type="cn.celess.common.entity.Visitor">
|
||||
<id column="v_id" property="id"/>
|
||||
<result column="v_date" property="date"/>
|
||||
<result column="v_user_agent" property="ua"/>
|
||||
<result column="v_ip" property="ip"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into visitor (v_date, v_ip, v_user_agent)
|
||||
values (#{date}, #{ip}, #{ua})
|
||||
</insert>
|
||||
<update id="delete">
|
||||
update visitor
|
||||
set is_delete = true
|
||||
where v_id = #{id}
|
||||
</update>
|
||||
<select id="findAll" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from visitor
|
||||
order by v_id desc
|
||||
</select>
|
||||
|
||||
<select id="findAllNotDeleted" resultMap="partnerSiteResultMap">
|
||||
select *
|
||||
from visitor
|
||||
where is_delete = false
|
||||
order by v_id desc
|
||||
</select>
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(*)
|
||||
from visitor
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,57 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.WebUpdateInfoMapper">
|
||||
<resultMap id="webUpdateResultMap" type="cn.celess.blog.entity.WebUpdate">
|
||||
<id column="wu_id" property="id"/>
|
||||
<result column="wu_info" property="updateInfo"/>
|
||||
<result column="wu_time" property="updateTime"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="cn.celess.blog.entity.WebUpdate" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into web_update(wu_info, wu_time, is_delete)
|
||||
values (#{updateInfo}, now(), false)
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update web_update
|
||||
set wu_info=#{info}
|
||||
where wu_id = #{id};
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update web_update
|
||||
set is_delete = true
|
||||
where wu_id = #{id}
|
||||
</update>
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
select EXISTS(select * from web_update where wu_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
where wu_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
order by wu_id desc
|
||||
</select>
|
||||
|
||||
<select id="findAllNotDeleted" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
where is_delete = false
|
||||
</select>
|
||||
|
||||
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
order by wu_id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.WebUpdateInfoMapper">
|
||||
<resultMap id="webUpdateResultMap" type="cn.celess.common.entity.WebUpdate">
|
||||
<id column="wu_id" property="id"/>
|
||||
<result column="wu_info" property="updateInfo"/>
|
||||
<result column="wu_time" property="updateTime"/>
|
||||
<result column="is_delete" property="delete"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="cn.celess.common.entity.WebUpdate" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into web_update(wu_info, wu_time, is_delete)
|
||||
values (#{updateInfo}, now(), false)
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update web_update
|
||||
set wu_info=#{info}
|
||||
where wu_id = #{id};
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update web_update
|
||||
set is_delete = true
|
||||
where wu_id = #{id}
|
||||
</update>
|
||||
<select id="existsById" resultType="java.lang.Boolean">
|
||||
select EXISTS(select * from web_update where wu_id = #{id})
|
||||
</select>
|
||||
|
||||
<select id="findById" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
where wu_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
order by wu_id desc
|
||||
</select>
|
||||
|
||||
<select id="findAllNotDeleted" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
where is_delete = false
|
||||
</select>
|
||||
|
||||
<select id="getLastestOne" resultMap="webUpdateResultMap">
|
||||
select *
|
||||
from web_update
|
||||
order by wu_id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.ArticleMapper">
|
||||
<resultMap id="articleResultMap" type="cn.celess.blog.entity.Article">
|
||||
<mapper namespace="cn.celess.common.mapper.ArticleMapper">
|
||||
<resultMap id="articleResultMap" type="cn.celess.common.entity.Article">
|
||||
<id column="a_id" property="id"/>
|
||||
<result column="a_title" property="title"/>
|
||||
<result column="a_summary" property="summary"/>
|
||||
@@ -16,18 +16,18 @@
|
||||
<result column="a_publish_date" property="publishDate"/>
|
||||
<result column="a_update_date" property="updateDate"/>
|
||||
<result column="is_delete" property="deleted"/>
|
||||
<association property="category" column="a_category_id" javaType="cn.celess.blog.entity.TagCategory"
|
||||
resultMap="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
<association property="category" column="a_category_id" javaType="cn.celess.common.entity.TagCategory"
|
||||
resultMap="cn.celess.common.mapper.CategoryMapper.categoryResultMap">
|
||||
</association>
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.Tag"
|
||||
select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
|
||||
<collection property="tags" ofType="cn.celess.common.entity.Tag"
|
||||
select="cn.celess.common.mapper.ArticleTagMapper.findTagByArticleId" column="a_id">
|
||||
<id column="tagId" property="id"/>
|
||||
<result column="tagName" property="name"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<resultMap id="articleViewResultMap" type="cn.celess.blog.entity.Article">
|
||||
<resultMap id="articleViewResultMap" type="cn.celess.common.entity.Article">
|
||||
<id column="articleId" property="id"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="summary" property="summary"/>
|
||||
@@ -41,25 +41,25 @@
|
||||
<result column="publishDate" property="publishDate"/>
|
||||
<result column="updateDate" property="updateDate"/>
|
||||
<result column="isDelete" property="deleted"/>
|
||||
<association property="category" column="categoryId" javaType="cn.celess.blog.entity.Category">
|
||||
<association property="category" column="categoryId" javaType="cn.celess.common.entity.Category">
|
||||
<id column="categoryId" property="id"/>
|
||||
<result column="categoryName" property="name"/>
|
||||
</association>
|
||||
<association property="user" column="authorId" javaType="cn.celess.blog.entity.User">
|
||||
<association property="user" column="authorId" javaType="cn.celess.common.entity.User">
|
||||
<id column="authorId" property="id"/>
|
||||
<result column="userEmail" property="email"/>
|
||||
<result column="userAvatar" property="avatarImgUrl"/>
|
||||
<result column="userDisplayName" property="displayName"/>
|
||||
</association>
|
||||
<collection property="tags" ofType="cn.celess.blog.entity.Tag"
|
||||
select="cn.celess.blog.mapper.ArticleTagMapper.findTagByArticleId" column="{articleId=articleId}">
|
||||
<collection property="tags" ofType="cn.celess.common.entity.Tag"
|
||||
select="cn.celess.common.mapper.ArticleTagMapper.findTagByArticleId" column="{articleId=articleId}">
|
||||
<id column="tagId" property="id"/>
|
||||
<result column="tagName" property="name"/>
|
||||
</collection>
|
||||
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.blog.entity.Article">
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.celess.common.entity.Article">
|
||||
insert into article (a_author_id, a_category_id, a_md_content, a_is_original,
|
||||
a_summary, a_title, a_url)
|
||||
values (#{user.id}, #{category.id}, #{mdContent}, #{type}, #{summary}, #{title}, #{url})
|
||||
@@ -89,7 +89,7 @@
|
||||
where a_id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.blog.entity.Article">
|
||||
<select id="getLastestArticle" resultMap="articleViewResultMap" resultType="cn.celess.common.entity.Article">
|
||||
select *
|
||||
from articleView
|
||||
order by articleId desc
|
||||
@@ -1,66 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.blog.mapper.TagMapper">
|
||||
|
||||
<resultMap id="tagResultMap" type="cn.celess.blog.entity.Tag"
|
||||
extends="cn.celess.blog.mapper.CategoryMapper.categoryResultMap">
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
VALUES (#{name}, false);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete = true
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<select id="findTagById" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="findTagByName" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = false)
|
||||
</select>
|
||||
|
||||
<select id="getLastestTag" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = false
|
||||
order by t_id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = false
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="long">
|
||||
select count(*)
|
||||
from tag_category
|
||||
where is_category = false
|
||||
and is_delete = false;
|
||||
</select>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.celess.common.mapper.TagMapper">
|
||||
|
||||
<resultMap id="tagResultMap" type="cn.celess.common.entity.Tag"
|
||||
extends="cn.celess.common.mapper.CategoryMapper.categoryResultMap">
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into tag_category (t_name, is_category)
|
||||
VALUES (#{name}, false);
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update tag_category
|
||||
set t_name=#{name}
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<update id="delete">
|
||||
update tag_category
|
||||
set is_delete = true
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</update>
|
||||
|
||||
<select id="findTagById" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_id = #{id}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="findTagByName" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where t_name = #{name}
|
||||
and is_category = false;
|
||||
</select>
|
||||
|
||||
<select id="existsByName" resultType="boolean">
|
||||
SELECT EXISTS(SELECT * FROM tag_category WHERE t_name = #{name} and is_category = false)
|
||||
</select>
|
||||
|
||||
<select id="getLastestTag" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = false
|
||||
order by t_id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="findAll" resultMap="tagResultMap">
|
||||
select *
|
||||
from tag_category
|
||||
where is_category = false
|
||||
</select>
|
||||
|
||||
<select id="count" resultType="long">
|
||||
select count(*)
|
||||
from tag_category
|
||||
where is_category = false
|
||||
and is_delete = false;
|
||||
</select>
|
||||
</mapper>
|
||||
114
blog-deploy/pom.xml
Normal file
114
blog-deploy/pom.xml
Normal file
@@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>blog</artifactId>
|
||||
<groupId>cn.celess</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blog-deploy</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>13</maven.compiler.source>
|
||||
<maven.compiler.target>13</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.6</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-common</artifactId>
|
||||
<version>${blog-common.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-article</artifactId>
|
||||
<version>${blog-article.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-categorytag</artifactId>
|
||||
<version>${blog-categorytag.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-comment</artifactId>
|
||||
<version>${blog-comment.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-extension</artifactId>
|
||||
<version>${blog-extension.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-partnersite</artifactId>
|
||||
<version>${blog-partnersite.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-siteinfo</artifactId>
|
||||
<version>${blog-siteinfo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-user</artifactId>
|
||||
<version>${blog-user.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.celess</groupId>
|
||||
<artifactId>blog-visitor</artifactId>
|
||||
<version>${blog-visitor.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,20 +1,18 @@
|
||||
package cn.celess.blog;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
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
|
||||
@MapperScan("cn.celess.blog.mapper")
|
||||
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("启动完成!");
|
||||
}
|
||||
}
|
||||
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("启动完成!");
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
package cn.celess.blog.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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,41 @@
|
||||
package cn.celess.blog.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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,39 @@
|
||||
package cn.celess.blog.configuration;
|
||||
|
||||
import cn.celess.blog.configuration.filter.AuthenticationFilter;
|
||||
import cn.celess.blog.configuration.filter.MultipleSubmitFilter;
|
||||
import cn.celess.blog.configuration.filter.VisitorRecord;
|
||||
import cn.celess.blog.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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +1,67 @@
|
||||
package cn.celess.blog.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;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,46 @@
|
||||
package cn.celess.blog.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.blog"))
|
||||
.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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +1,94 @@
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.service.UserService;
|
||||
import cn.celess.blog.util.JwtUtil;
|
||||
import cn.celess.blog.util.RedisUtil;
|
||||
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.equals(rootPath.toLowerCase()) && !ADMIN_PREFIX.equals(rootPath.toLowerCase())) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,44 @@
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.enmu.ResponseEnum;
|
||||
import cn.celess.blog.entity.Response;
|
||||
import cn.celess.blog.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.toString());
|
||||
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));
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,38 @@
|
||||
package cn.celess.blog.configuration.filter;
|
||||
|
||||
import cn.celess.blog.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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
package cn.celess.blog.configuration.listener;
|
||||
|
||||
import cn.celess.blog.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());
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -1,90 +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.blog.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
|
||||
# 连接超时时间(毫秒)
|
||||
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
|
||||
68
blog-deploy/src/main/resources/application-prod.properties
Normal file
68
blog-deploy/src/main/resources/application-prod.properties
Normal 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
|
||||
@@ -8,23 +8,17 @@ qiniu.bucket=
|
||||
sitemap.path=
|
||||
# 生成JWT时候的密钥
|
||||
jwt.secret=sdaniod213k123123ipoeqowekqwe
|
||||
|
||||
##spring.jpa.show-sql=false
|
||||
##spring.jpa.hibernate.ddl-auto=update
|
||||
|
||||
mybatis.type-handlers-package=cn.celess.blog.mapper.typehandler
|
||||
logging.level.cn.celess.blog.mapper=debug
|
||||
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
|
||||
@@ -41,7 +35,7 @@ spring.datasource.data=classpath:sql/data.sql
|
||||
|
||||
################## mybatis ##################
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
mybatis.type-aliases-package=cn.celess.blog.entity
|
||||
mybatis.type-aliases-package=cn.celess.common.entity
|
||||
|
||||
|
||||
pagehelper.helper-dialect=mysql
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user