package com.tencent.service.impl;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tencent.dao.IArticleCategoryRefDao;
import com.tencent.dao.IArticleDao;
import com.tencent.dao.IArticleTagRefDao;
import com.tencent.entity.*;
import com.tencent.enums.ArticleCommentStatus;
import com.tencent.service.IArticleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.ScoreSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.elasticsearch.common.text.Text;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Service("articleService")
@Slf4j
public class ArticleServiceImpl implements IArticleService {
@Autowired(required = false)
private IArticleDao articleDao;
@Autowired(required = false)
private RestHighLevelClient highLevelClient;
@Autowired(required = false)
private IArticleCategoryRefDao articleCategoryRefDao;
@Autowired(required = false)
private IArticleTagRefDao articleTagRefDao;
@Override
@Transactional(rollbackFor = Exception.class)
public void insertArticle(Article article) {
//添加文章
article.setArticleCreateTime(new Date());
article.setArticleUpdateTime(new Date());
article.setArticleIsComment(ArticleCommentStatus.ALLOW.getValue());
article.setArticleViewCount(0);
article.setArticleLikeCount(0);
article.setArticleCommentCount(0);
article.setArticleOrder(1);
articleDao.insert(article);
//添加分类和文章关联
for(int i=0;i<article.getCategoryList().size();i++){
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(),article.getCategoryList().get(i).getCategoryId());
articleCategoryRefDao.insert(articleCategoryRef);
}
//添加标签和文章关联
for(int i=0;i<article.getTagList().size();i++){
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(),article.getTagList().get(i).getTagId());
articleTagRefDao.insert(articleTagRef);
}
}
@Override
public void deleteArticle(Integer articleId) {
articleDao.deleteById(articleId);
}
@Override
public void deleteArticleBatch(List<Integer> ids) {
articleDao.deleteBatch(ids);
}
@Override
public void updateArticle(Article article) {
articleDao.update(article);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateArticleDetail(Article article) {
article.setArticleUpdateTime(new Date());
articleDao.update(article);
if(article.getTagList()!=null){
//删除标签和文章关联
articleTagRefDao.deleteByArticleId(article.getArticleId());
//添加标签和文章关联
for(int i=0;i<article.getTagList().size();i++){
ArticleTagRef articleTagRef = new ArticleTagRef(article.getArticleId(),article.getTagList().get(i).getTagId());
articleTagRefDao.insert(articleTagRef);
}
}
if(article.getCategoryList()!=null){
//删除分类和文章关联
articleCategoryRefDao.deleteByArticleId(article.getArticleId());
//添加分类和文章关联
for(int i=0;i<article.getCategoryList().size();i++){
ArticleCategoryRef articleCategoryRef = new ArticleCategoryRef(article.getArticleId(),article.getCategoryList().get(i).getCategoryId());
articleCategoryRefDao.insert(articleCategoryRef);
}
}
}
@Override
public Integer getArticleUserId(Integer articleId) {
return articleDao.getArticleUserId(articleId);
}
@Override
public Integer countArticle(Integer status) {
Integer count = 0;
try{
count = articleDao.countArticle(status);
}catch(Exception e){
e.printStackTrace();
log.error("根据状态统计文章数,status:{},cause:{}",status,e);
}
return count;
}
@Override
public Integer updateLikeCount(Integer articleId, Integer likeCount) {
return articleDao.updateLikeCount(articleId, likeCount);
}
@Override
public Integer countArticleComment() {
Integer count = 0;
try{
count = articleDao.countArticleComment();
}catch(Exception e){
e.printStackTrace();
log.error("统计文章评论数失败,cause:{}",e);
}
return count; }
@Override
public Integer countArticleView() {
Integer count = 0;
try{
count = articleDao.countArticleView();
}catch(Exception e){
e.printStackTrace();
log.error("统计文章访问量失败,cause:{}",e);
}
return count;
}
@Override
public Integer countArticleByCategoryId(Integer categoryId) {
Integer count = 0;
try{
count = articleCategoryRefDao.countArticleByCategoryId(categoryId);
}catch (Exception e){
e.printStackTrace();
log.error("根据分类统计文章数量失败,categoryId:{},cause:{}",categoryId,e);
}
return count;
}
@Override
public PageInfo<Article> findArticleByEs(RestHighLevelClient client,HashMap<String, Object> criteria, Integer pageIndex, Integer pageSize) {
String keywords = null;
for(String key : criteria.keySet()){
keywords = criteria.get(key).toString();
System.out.println(criteria.get(key));
break;
}
SearchRequest searchRequest = new SearchRequest();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
//设置搜索结果起始行数下标,默认从0开始。
sourceBuilder.from(0);
//设置搜索结果显示条数
sourceBuilder.size(10);
//设置搜索结果超时时间
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
QueryBuilder queryBuilder = null;
MatchPhraseQueryBuilder mpqBuilder1 = null;
MatchPhraseQueryBuilder mpqBuilder2 = null;
MatchPhraseQueryBuilder mpqBuilder3 = null;
String keyword = keywords;
//如果关键词中包含"+",则默认将其拆分为2部分,+的左半部分用来标识查找范围,+的右半部分是关键词
if(keywords.indexOf("+")>-1){
String[] slist = keywords.split("\\+");
String range = slist[0];
keyword = slist[1];
//
if(range.equals("articleTitle")){
mpqBuilder1 = new MatchPhraseQueryBuilder("article_title",keyword);
queryBuilder = QueryBuilders.boolQuery().must(mpqBuilder1);
}else if(range.equals("articleContent")){
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
## 一.该项目实现了一个简单的博客系统,具体功能包括: 后台:后台管理系统,具体包括:文章管理、分类管理、标签管理、用户管理、活动通知管理等 前台:用户注册登录、搜索文章、评价文章、点赞文章、图片上传、文章分页展示、文章分享等 使用ssm(spring+springmvc+mybaits)+redis+elk作为后台技术,使用layui+jsp+ajax作为前端技术 ### 技术亮点: 1.注册登录时利用ajax对不合适的输入做出提示,并使用MD5+salt对密码进行加密; 2.使用elk替换了原来mysql的模糊查询方式,实现对文章的标题,摘要,全文的搜索功能,并高亮展示; 3.点赞功能由Redis来实现,将点赞数率先存入redis,然后再更新到mysql中; 4.异步处理,利用生产者消费者模式将用户的点赞信息异步通知给用户; 项目预览地址:[腾云博客](http://www.hbquan.top) ## 二.项目前台和后台部分功能预览 ### 1.首页效果展示: ![image](http
资源推荐
资源详情
资源评论
收起资源包目录
适合java web全栈学习的博客项目(ssm+redis+elk+layui+jsp).zip (1127个子文件)
ArticleServiceImpl.class 18KB
ArticleServiceImpl.class 18KB
ArticleController.class 7KB
ArticleController.class 7KB
AdminController.class 6KB
AdminController.class 6KB
HomeIndexController.class 6KB
HomeIndexController.class 6KB
HomePageController.class 6KB
HomePageController.class 6KB
CommentServiceImpl.class 5KB
CommentServiceImpl.class 5KB
Article.class 5KB
Article.class 5KB
HomeArticleController.class 5KB
HomeArticleController.class 5KB
UserController.class 5KB
UserController.class 5KB
RedisAdpeter.class 5KB
RedisAdpeter.class 5KB
CommentController.class 5KB
CommentController.class 5KB
TagServiceImpl.class 5KB
TagServiceImpl.class 5KB
CategoryServiceImpl.class 4KB
CategoryServiceImpl.class 4KB
Options.class 4KB
Options.class 4KB
Comment.class 4KB
Comment.class 4KB
HomeResourceInterceptor.class 4KB
HomeResourceInterceptor.class 4KB
User.class 4KB
User.class 4KB
HomeCategoryController.class 4KB
HomeCategoryController.class 4KB
UploadFileController.class 4KB
UploadFileController.class 4KB
PageController.class 3KB
PageController.class 3KB
TagController.class 3KB
TagController.class 3KB
LinkController.class 3KB
LinkController.class 3KB
Link.class 3KB
Link.class 3KB
EventConsumer.class 3KB
EventConsumer.class 3KB
HomeCommentController.class 3KB
HomeCommentController.class 3KB
CategoryController.class 3KB
CategoryController.class 3KB
Category.class 3KB
Category.class 3KB
NoticeController.class 3KB
NoticeController.class 3KB
HomeTagController.class 3KB
HomeTagController.class 3KB
ArticleParam.class 3KB
ArticleParam.class 3KB
LikeHandler.class 3KB
LikeHandler.class 3KB
LikeController.class 3KB
LikeController.class 3KB
EventModel.class 3KB
EventModel.class 3KB
MenuController.class 3KB
MenuController.class 3KB
Page.class 3KB
Page.class 3KB
IArticleDao.class 3KB
IArticleDao.class 3KB
IArticleService.class 3KB
IArticleService.class 3KB
UserServiceImpl.class 3KB
UserServiceImpl.class 3KB
JsonResult.class 3KB
JsonResult.class 3KB
MyUtils.class 2KB
MyUtils.class 2KB
Response.class 2KB
Response.class 2KB
Notice.class 2KB
Notice.class 2KB
EventConsumer$1.class 2KB
EventConsumer$1.class 2KB
HomeLinkController.class 2KB
HomeLinkController.class 2KB
OptionsController.class 2KB
OptionsController.class 2KB
Menu.class 2KB
Menu.class 2KB
ResultVo.class 2KB
ResultVo.class 2KB
Tag.class 2KB
Tag.class 2KB
IMessageDao.class 2KB
IMessageDao.class 2KB
SecurityInterceptor.class 2KB
SecurityInterceptor.class 2KB
共 1127 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
zy_zeros
- 粉丝: 952
- 资源: 320
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 用于操作 ESC,POS 打印机的 Python 库.zip
- 用于控制“Universal Robots”机器人的 Python 库.zip
- 用于控制 Broadlink RM2,3 (Pro) 遥控器、A1 传感器平台和 SP2,3 智能插头的 Python 模块.zip
- 用于接收和交互来自 Slack 的 RTM API 的事件的框架.zip
- 用于将日志发送到 LogDNA 的 Python 包.zip
- 用于将 Python 计算转换为渲染的乳胶的 Python 库 .zip
- 用于实现推荐系统的 Python 库.zip
- 用于实施无服务器最佳实践并提高开发人员速度的开发人员工具包 .zip
- 用于地理数据的 Python 工具.zip
- 全国大学生FPGA创新设计竞赛作品 泡罩包装药品质量在线检测平台.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功