This commit is contained in:
禾几海
2020-05-27 13:28:48 +08:00
parent 21adedea84
commit 260ae53c8d
9 changed files with 151 additions and 74 deletions

View File

@@ -5,20 +5,20 @@ USE t_blog;
CREATE TABLE `article`
(
`a_id` bigint(20) primary key auto_increment,
`a_title` varchar(255) not null unique comment '文章标题',
`a_summary` varchar(255) not null comment '文章摘要',
`a_md_content` longtext not null comment '文章Markdown内容',
`a_url` tinytext default null comment '转载文章的原文链接',
`a_author_id` int not null comment '作者id',
`a_is_original` boolean default true comment '文章是否原创',
`a_reading_number` int default 0 comment '文章阅读数',
`a_like` int default 0 comment '文章点赞数',
`a_dislike` int default 0 comment '文章不喜欢数',
`a_category_id` int not null comment '文章分类id',
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
`a_update_date` datetime default null comment '文章的更新时间',
`a_is_open` boolean default true comment '文章是否可见',
`is_delete` boolean not null default false comment '该数据是否被删除'
`a_title` varchar(255) COLLATE utf8mb4_unicode_ci not null unique comment '文章标题',
`a_summary` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '文章摘要',
`a_md_content` longtext COLLATE utf8mb4_unicode_ci not null comment '文章Markdown内容',
`a_url` tinytext default null comment '转载文章的原文链接',
`a_author_id` int not null comment '作者id',
`a_is_original` boolean default true comment '文章是否原创',
`a_reading_number` int default 0 comment '文章阅读数',
`a_like` int default 0 comment '文章点赞数',
`a_dislike` int default 0 comment '文章不喜欢数',
`a_category_id` int not null comment '文章分类id',
`a_publish_date` datetime default CURRENT_TIMESTAMP comment '文章发布时间',
`a_update_date` datetime default null comment '文章的更新时间',
`a_is_open` boolean default true comment '文章是否可见',
`is_delete` boolean not null default false comment '该数据是否被删除'
) DEFAULT CHARSET = utf8mb4
COLLATE utf8mb4_general_ci,comment '文章表';
@@ -35,33 +35,32 @@ CREATE TABLE `tag_category`
`t_id` bigint(20) primary key auto_increment,
`t_name` varchar(255) not null,
`is_category` boolean not null default true,
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '标签和分类表';
CREATE TABLE `comment`
(
`co_id` bigint(20) primary key auto_increment,
`co_page_path` varchar(255) not null comment '评论/留言的页面',
`co_content` text not null comment '评论/留言内容',
`co_date` datetime not null comment '评论/留言的日期',
`co_status` tinyint not null default 0 comment '评论的状态',
`co_pid` bigint not null default -1 comment '评论/留言的父id',
`co_from_author_id` int not null comment '留言者id',
`co_to_author_id` int default null comment '父评论的作者id',
`is_delete` boolean not null default false comment '该数据是否被删除'
`co_page_path` varchar(255) not null comment '评论/留言的页面',
`co_content` text COLLATE utf8mb4_unicode_ci not null comment '评论/留言内容',
`co_date` datetime not null comment '评论/留言的日期',
`co_status` tinyint not null default 0 comment '评论的状态',
`co_pid` bigint not null default -1 comment '评论/留言的父id',
`co_from_author_id` int not null comment '留言者id',
`co_to_author_id` int default null comment '父评论的作者id',
`is_delete` boolean not null default false comment '该数据是否被删除'
) DEFAULT CHARSET = utf8mb4
COLLATE utf8mb4_general_ci,comment '评论/留言表';
CREATE TABLE `links`
(
`l_id` bigint(20) primary key auto_increment,
`l_name` varchar(255) not null comment '友站名称',
`l_is_open` boolean default true comment '是否公开',
`l_url` varchar(255) not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除'
`l_name` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友站名称',
`l_is_open` boolean default true comment '是否公开',
`l_url` varchar(255) not null comment '首页地址',
`l_icon_path` varchar(255) not null comment '友链的icon地址',
`l_desc` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '友链的说明描述',
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '友站表';
CREATE TABLE `visitor`
@@ -76,9 +75,9 @@ CREATE TABLE `visitor`
CREATE TABLE `web_update`
(
`wu_id` int primary key auto_increment,
`wu_info` varchar(255) not null comment '更新内容',
`wu_time` datetime not null comment '更新时间',
`is_delete` boolean not null default false comment '该数据是否被删除'
`wu_info` varchar(255) COLLATE utf8mb4_unicode_ci not null comment '更新内容',
`wu_time` datetime not null comment '更新时间',
`is_delete` boolean not null default false comment '该数据是否被删除'
) comment '更新内容表';
CREATE TABLE `user`
@@ -86,13 +85,13 @@ CREATE TABLE `user`
`u_id` int not null primary key auto_increment,
`u_email` varchar(50) not null,
`u_pwd` varchar(40) not null comment '密码',
`u_email_status` boolean default false comment '邮箱验证状态',
`u_avatar` varchar(255) default null comment '用户头像',
`u_desc` tinytext default null comment '用户的描述',
`u_recently_landed_time` datetime default null comment '最近的登录时间',
`u_display_name` varchar(30) default null comment '展示的昵称',
`u_role` varchar(40) not null default 'user' comment '权限组',
`status` tinyint(1) not null default 0 comment '账户状态',
`u_email_status` boolean default false comment '邮箱验证状态',
`u_avatar` varchar(255) default null comment '用户头像',
`u_desc` tinytext COLLATE utf8mb4_unicode_ci default null comment '用户的描述',
`u_recently_landed_time` datetime default null comment '最近的登录时间',
`u_display_name` varchar(30) COLLATE utf8mb4_unicode_ci default null comment '展示的昵称',
`u_role` varchar(40) not null default 'user' comment '权限组',
`status` tinyint(1) not null default 0 comment '账户状态',
unique key `uni_user_id` (`u_id`),
unique key `uni_user_email` (`u_email`)
) comment '用户表';

View File

@@ -45,12 +45,20 @@ public class CommentController {
* @param page 页码
* @return Response
*/
@GetMapping("/comments")
public Response commentsOfArticle(@RequestParam("pagePath") String pagePath,
@RequestParam(value = "pid", required = false, defaultValue = "-1") long pid,
@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) {
return Response.success(commentService.retrievePageByPageAndPid(pagePath, pid, page, count));
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));
}
/**
@@ -61,18 +69,51 @@ public class CommentController {
* @param page page
* @return Response
*/
// FIXME:: 左斜线转义的异常
@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) {
return Response.success(commentService.retrievePage(pagePath, page, count));
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) {
return Response.success(commentService.retrievePageByAuthor(pagePath, page, count));
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));
}
}

View File

@@ -161,7 +161,7 @@ public class ArticleServiceImpl implements ArticleService {
//数据判断
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
if (articleMapper.existsByTitle(reqBody.getTitle())) {
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
}
article.setTitle(reqBody.getTitle());
@@ -176,7 +176,7 @@ public class ArticleServiceImpl implements ArticleService {
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
}
if (!RegexUtil.urlMatch(reqBody.getUrl())) {
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
}
article.setType(reqBody.getType());
@@ -278,7 +278,7 @@ public class ArticleServiceImpl implements ArticleService {
*/
@Override
public PageData<ArticleModel> adminArticles(int count, int page) {
PageHelper.startPage(page, count);
PageHelper.startPage(page, count, "articleId desc");
List<Article> articleList = articleMapper.findAll();
PageData<ArticleModel> pageData = new PageData<ArticleModel>(new PageInfo<Article>(articleList));
List<ArticleModel> articleModelList = new ArrayList<>();

View File

@@ -1,7 +1,9 @@
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;
@@ -67,7 +69,21 @@ public class CategoryServiceImpl implements CategoryService {
PageHelper.startPage(page, count);
List<Category> all = categoryMapper.findAll();
List<CategoryModel> modelList = new ArrayList<>();
all.forEach(e -> modelList.add(ModalTrans.category(e)));
all.forEach(e -> {
CategoryModel model = ModalTrans.category(e);
List<Article> allByCategoryId = articleMapper.findAllByCategoryId(e.getId());
List<ArticleModel> articleModelList = new ArrayList<>();
allByCategoryId.forEach(article -> {
ArticleModel articleModel = ModalTrans.article(article, true);
articleModel.setPreArticle(null);
articleModel.setNextArticle(null);
articleModel.setTags(null);
articleModelList.add(articleModel);
});
model.setArticles(articleModelList);
modelList.add(model);
});
return new PageData<CategoryModel>(new PageInfo<Category>(all), modelList);
}
}

View File

@@ -99,7 +99,7 @@ public class CommentServiceImpl implements CommentService {
@Override
public PageData<CommentModel> retrievePage(String pagePath, int page, int count) {
PageHelper.startPage(page, count);
List<Comment> list = commentMapper.findAllByPagePath(pagePath);
List<Comment> list = commentMapper.findAllByPagePathAndPid(pagePath, -1);
return pageTrans(list);
}
@@ -122,23 +122,29 @@ public class CommentServiceImpl implements CommentService {
@Override
public PageData<CommentModel> retrievePageByPageAndPid(String pagePath, long pid, int page, int count) {
PageHelper.startPage(page, count);
List<Comment> list = commentMapper.findAllByPagePathAndPid(pagePath, pid);
return pageTrans(list);
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.findAllByPagePathAndPid(pagePath, -1);
return pageTrans(list);
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 = new ArrayList<>();
commentList.forEach(l -> {
CommentModel model = ModalTrans.comment(l);
model.setRespComment(this.retrievePageByPid(model.getId()));
if (!noResponseList) {
model.setRespComment(this.retrievePageByPid(model.getId()));
}
modelList.add(model);
});
return new PageData<CommentModel>(p, modelList);

View File

@@ -140,7 +140,7 @@ public class UserServiceImpl implements UserService {
redisUtil.setEx(loginReq.getEmail() + "-passwordWrongTime", count + "", 2, TimeUnit.HOURS);
throw new MyException(ResponseEnum.LOGIN_FAILURE);
}
UserModel trans = ModalTrans.user(user);
UserModel trans = ModalTrans.userFullInfo(user);
trans.setToken(token);
return trans;
@@ -167,7 +167,7 @@ public class UserServiceImpl implements UserService {
userMapper.updateInfo(desc, displayName, user.getId());
redisUserUtil.set(user);
return ModalTrans.user(user);
return ModalTrans.userFullInfo(user);
}
@Override
@@ -192,7 +192,7 @@ public class UserServiceImpl implements UserService {
@Override
public UserModel getUserInfoBySession() {
User user = redisUserUtil.get();
return ModalTrans.user(user);
return ModalTrans.userFullInfo(user);
}
@Override
@@ -346,7 +346,7 @@ public class UserServiceImpl implements UserService {
PageHelper.startPage(page, count);
List<User> all = userMapper.findAll();
List<UserModel> modelList = new ArrayList<>();
all.forEach(user -> modelList.add(ModalTrans.user(user)));
all.forEach(user -> modelList.add(ModalTrans.userFullInfo(user)));
return new PageData<UserModel>(PageInfo.of(all), modelList);
}
@@ -397,7 +397,7 @@ public class UserServiceImpl implements UserService {
redisUserUtil.set(user);
}
logger.info("修改了用户 [id={}] 的用户的资料", userReq.getId());
return ModalTrans.user(user);
return ModalTrans.userFullInfo(user);
}
@Override
@@ -416,6 +416,6 @@ public class UserServiceImpl implements UserService {
throw new MyException(ResponseEnum.PWD_NOT_SAME);
}
userMapper.updatePwd(user.getEmail(), MD5Util.getMD5(newPwd));
return ModalTrans.user(userMapper.findByEmail(user.getEmail()));
return ModalTrans.userFullInfo(userMapper.findByEmail(user.getEmail()));
}
}

View File

@@ -40,8 +40,7 @@ public class ModalTrans {
return article1;
}
public static UserModel user(User user) {
public static UserModel userFullInfo(User user) {
if (user == null || user.getId() == -1) {
return null;
}
@@ -50,13 +49,21 @@ public class ModalTrans {
userModel.setAvatarImgUrl(user.getAvatarImgUrl() == null || user.getAvatarImgUrl().length() == 0 ?
null :
"http://cdn.celess.cn/" + user.getAvatarImgUrl());
userModel.setRole(null);
userModel.setEmailStatus(null);
userModel.setDisplayName(user.getDisplayName() == null ? user.getEmail() : user.getDisplayName());
userModel.setRecentlyLandedDate(DateFormatUtil.get(user.getRecentlyLandedDate()));
return userModel;
}
public static UserModel user(User user) {
UserModel model = userFullInfo(user);
if (model == null) {
return null;
}
model.setRole(null);
model.setEmailStatus(null);
return model;
}
public static CategoryModel category(Category category) {
if (category == null) {
return null;

View File

@@ -86,21 +86,29 @@
<select id="findAllByPagePath" resultMap="commentViewResultMap">
select *
from commentView
where pagePath = #{pagePath}
<if test="pagePath!= null ">
where pagePath = #{pagePath}
</if>
</select>
<select id="findAllByPagePathAndFromUser" resultMap="commentViewResultMap">
select *
from commentView
where pagePath = #{pagePath}
and fromAuthorId = #{userId}
where
<if test="pagePath!= null ">
pagePath = #{pagePath} and
</if>
fromAuthorId = #{userId}
</select>
<select id="findAllByPagePathAndPid" resultMap="commentViewResultMap">
select *
from commentView
where pagePath = #{pagePath}
and pid = #{pid}
where
<if test="pagePath!= null ">
pagePath = #{pagePath} and
</if>
pid = #{pid}
</select>
<select id="countByPagePath" resultType="java.lang.Long">
@@ -108,6 +116,7 @@
from commentView
where pagePath = #{pagePath}
</select>
<select id="getLastestComment" resultMap="commentViewResultMap">
select *
from commentView
@@ -117,7 +126,7 @@
<select id="count" resultType="long">
select count(*)
from article
from comment
where is_delete = false;
</select>

View File

@@ -155,7 +155,6 @@
select *
from articleView
where isDelete = false
order by articleId desc
</select>