2021年12月11日19:15:10
parent
42489a3f89
commit
42b45134aa
|
|
@ -229,7 +229,7 @@ public class ArticleController extends BaseController implements ArticleControll
|
|||
if (sysConfig.getAuthor() == null){
|
||||
sysConfig.setAuthor("转身的背影在心底里沉沦");
|
||||
}
|
||||
|
||||
map.put("sysConfig",sysConfig);
|
||||
map.put("articleModel", articleModel);
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package com.zhangmeng.blog.service;
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.Reply;
|
||||
|
||||
public interface ReplyService extends BaseService<Reply> {
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.zhangmeng.blog.service;
|
||||
|
||||
|
||||
import com.zhangmeng.model.base.baseService.BaseService;
|
||||
import com.zhangmeng.model.entity.Tags;
|
||||
|
||||
public interface TagsService extends BaseService<Tags> {
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.zhangmeng.blog.service.impl;
|
||||
|
||||
|
||||
import com.zhangmeng.blog.service.ReplyService;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.entity.Reply;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ReplyServiceImpl extends AbstractBaseServiceImpl<Reply> implements ReplyService {
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.zhangmeng.blog.service.impl;
|
||||
|
||||
import com.zhangmeng.blog.service.TagsService;
|
||||
import com.zhangmeng.model.base.baseService.impl.AbstractBaseServiceImpl;
|
||||
import com.zhangmeng.model.entity.Tags;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TagsServiceImpl extends AbstractBaseServiceImpl<Tags> implements TagsService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
package com.zhangmeng.blog.tools;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.zhangmeng.blog.feign.SysConfigFeign;
|
||||
import com.zhangmeng.blog.feign.UserFeign;
|
||||
import com.zhangmeng.blog.service.*;
|
||||
import com.zhangmeng.model.dto.article.ArticleModel;
|
||||
import com.zhangmeng.model.dto.article.CategoryModel;
|
||||
import com.zhangmeng.model.dto.comment.CommentModel;
|
||||
import com.zhangmeng.model.dto.query.QueryParams;
|
||||
import com.zhangmeng.model.dto.query.QueryResult;
|
||||
import com.zhangmeng.model.entity.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import tk.mybatis.mapper.entity.Condition;
|
||||
import tk.mybatis.mapper.entity.Example;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author zhangmeng
|
||||
* @date 2021年8月19日12:26:07
|
||||
* @version 1.0
|
||||
* 博客工具类 前端页面查询用
|
||||
*/
|
||||
@Component
|
||||
public class BlogTools {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@Autowired
|
||||
private TagsService tagsService;
|
||||
|
||||
@Autowired
|
||||
private ArticleService articleService;
|
||||
|
||||
@Autowired
|
||||
private CommentService commentService;
|
||||
|
||||
@Autowired
|
||||
private ReplyService replyService;
|
||||
|
||||
@Autowired
|
||||
private SysConfigFeign sysConfigFeign;
|
||||
|
||||
@Autowired
|
||||
private UserFeign userFeign;
|
||||
|
||||
private static String message = "别畏惧路上的孤单,谁也不是你的永远,你又何曾是谁的唯一。没谁陪你一直走,我们只是在浅遇中写因缘天定,在淡忘里看岁月静好。 莫辜负这似水流年,活着就是一种精彩;";
|
||||
|
||||
private static String title = "转身的背影在心底里沉沦";
|
||||
|
||||
/**
|
||||
* 评论
|
||||
*
|
||||
* @param articleId 文章id
|
||||
* @return 评论集合
|
||||
*/
|
||||
public List<CommentModel> commentModelList(Long articleId) {
|
||||
Condition condition = new Condition(Comment.class);
|
||||
Example.Criteria criteria = condition.createCriteria();
|
||||
criteria.andEqualTo("deleteStatus", false);
|
||||
criteria.andEqualTo("article_id", articleId);
|
||||
List<Comment> commentList = this.commentService.findByCondition(condition);
|
||||
List<CommentModel> modelList = new ArrayList<>();
|
||||
if (commentList.size() > 0) {
|
||||
for (Comment comment : commentList) {
|
||||
CommentModel commentModel = new CommentModel();
|
||||
commentModel.setComment(comment);
|
||||
Condition reply_condition = new Condition(Reply.class);
|
||||
Example.Criteria reply_criteria = reply_condition.createCriteria();
|
||||
reply_criteria.andEqualTo("comment_id", comment.getId());
|
||||
List<Reply> replyList = this.replyService.findByCondition(reply_condition);
|
||||
if (replyList.size() > 0) {
|
||||
Reply reply = replyList.get(0);
|
||||
commentModel.setReply(reply);
|
||||
User reply_user = this.userFeign.findByUserId(reply.getUserId());
|
||||
commentModel.setReply_user(reply_user);
|
||||
}
|
||||
modelList.add(commentModel);
|
||||
}
|
||||
}
|
||||
return modelList;
|
||||
}
|
||||
|
||||
//最新博客
|
||||
public List<Article> latest_blog(){
|
||||
Condition article_condition = new Condition(Article.class);
|
||||
Example.Criteria article_criteria = article_condition.createCriteria();
|
||||
article_criteria.andEqualTo("deleteStatus", false);
|
||||
PageInfo<Article> pageInfo = this.articleService.findByCondition(new QueryParams(1, 10, article_condition, "addTime desc"), true);
|
||||
return pageInfo.getList();
|
||||
}
|
||||
|
||||
//最新推荐
|
||||
public List<Article> latest_recommended(){
|
||||
return latest_blog();
|
||||
}
|
||||
|
||||
//博客文章
|
||||
public List<Article> articleList(Integer pageNum,Integer pageSize){
|
||||
Condition article_condition = new Condition(Article.class);
|
||||
Example.Criteria article_criteria = article_condition.createCriteria();
|
||||
article_criteria.andEqualTo("deleteStatus", false);
|
||||
return this.articleService.findByCondition(new QueryParams(pageNum, pageSize, article_condition, "addTime desc"), true).getList();
|
||||
}
|
||||
|
||||
//博客数量统计
|
||||
public Integer blog_count(){
|
||||
return this.articleService.findAll().size();
|
||||
}
|
||||
|
||||
//个人信息
|
||||
public User userInfo(){
|
||||
return this.userFeign.findByUserId(1L);
|
||||
}
|
||||
|
||||
//分类信息
|
||||
public List<CategoryModel> categoryList() {
|
||||
//分类列表
|
||||
Condition category_params = new Condition(Category.class);
|
||||
Example.Criteria category_criteria = category_params.createCriteria();
|
||||
category_criteria.andEqualTo("deleteStatus", false);
|
||||
List<Category> categoryList = this.categoryService.findByCondition(category_params);
|
||||
List<CategoryModel> categoryModels = new ArrayList<>();
|
||||
if (categoryList.size() > 0) {
|
||||
for (Category category : categoryList) {
|
||||
CategoryModel categoryModel = new CategoryModel();
|
||||
BeanUtils.copyProperties(category, categoryModel);
|
||||
categoryModel.setCount(category_cout(category.getId()).longValue());
|
||||
categoryModel.setId(category.getId());
|
||||
categoryModels.add(categoryModel);
|
||||
}
|
||||
}
|
||||
return categoryModels;
|
||||
}
|
||||
|
||||
public Integer category_cout(Long categoryId){
|
||||
Condition article_condition = new Condition(Article.class);
|
||||
Example.Criteria article_criteria = article_condition.createCriteria();
|
||||
article_criteria.andEqualTo("deleteStatus", false);
|
||||
article_criteria.andEqualTo("category_id",categoryId);
|
||||
return this.articleService.selectCountByCondition(article_condition);
|
||||
}
|
||||
|
||||
//分类数量
|
||||
public Integer category_count(){
|
||||
return this.categoryService.findAll().size();
|
||||
}
|
||||
|
||||
//标签信息
|
||||
public List<Tags> tagsList() {
|
||||
return this.tagsService.findAll();
|
||||
}
|
||||
|
||||
public String title() {
|
||||
SysConfig sysConfig = this.sysConfigFeign.getSysConfig();
|
||||
if (sysConfig != null) {
|
||||
String blogTitle = sysConfig.getBlogTitle();
|
||||
if (blogTitle != null && !blogTitle.equals("")) {
|
||||
title = blogTitle;
|
||||
}
|
||||
} else {
|
||||
title = "转身的背影在心底里沉沦";
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 博客标题
|
||||
*/
|
||||
public void title(ArticleModel articleModel) {
|
||||
SysConfig sysConfig = this.sysConfigFeign.getSysConfig();
|
||||
if (sysConfig != null) {
|
||||
String blogTitle = sysConfig.getBlogTitle();
|
||||
if (blogTitle != null && !blogTitle.equals("")) {
|
||||
title = blogTitle;
|
||||
}
|
||||
}
|
||||
articleModel.setBlog_title(title);
|
||||
articleModel.setMessage(message);
|
||||
}
|
||||
|
||||
public <T> QueryResult<T> queryResult(PageInfo pageInfo, List<T> list){
|
||||
if (pageInfo.getPrePage() == 0 ){
|
||||
pageInfo.setPrePage(1);
|
||||
}
|
||||
if (pageInfo.getNextPage() == 0){
|
||||
pageInfo.setNextPage(1);
|
||||
}
|
||||
QueryResult<T> queryResult = new QueryResult<>();
|
||||
queryResult.setList(list);
|
||||
queryResult.setPrevPage(pageInfo.getPrePage());
|
||||
queryResult.setNextPage(pageInfo.getNextPage());
|
||||
queryResult.setPageNum(pageInfo.getPageNum());
|
||||
queryResult.setPageSize(pageInfo.getPageSize());
|
||||
return queryResult;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.zhangmeng.model.dto.article;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class CategoryModel implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Long count;
|
||||
}
|
||||
Loading…
Reference in New Issue