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

@@ -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()));
}
}