Skip to content

Commit 50e9ff4

Browse files
committed
feat[search]:添加ElasticSearch和RabbitMq,实现搜索功能
1 parent 6f3a5c9 commit 50e9ff4

File tree

24 files changed

+457
-155
lines changed

24 files changed

+457
-155
lines changed

dbblog-backend/dbblog-core/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@
9292
<groupId>org.apache.commons</groupId>
9393
<artifactId>commons-pool2</artifactId>
9494
</dependency>
95+
<dependency>
96+
<groupId>org.springframework.boot</groupId>
97+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.springframework.boot</groupId>
101+
<artifactId>spring-boot-starter-amqp</artifactId>
102+
</dependency>
95103
</dependencies>
96104

97105
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.dblearn.blog.common.constants;
2+
3+
/**
4+
* RabbitMqConstants
5+
*
6+
* @author bobbi
7+
* @date 2019/03/16 22:12
8+
9+
* @description
10+
*/
11+
public class RabbitMqConstants {
12+
public static final String REFRESH_ES_INDEX_QUEUE ="dbblog-queue";
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cn.dblearn.blog.common.mq.annotation;
2+
3+
/**
4+
* RefreshEsMqSender
5+
*
6+
* @author bobbi
7+
* @date 2019/03/16 22:52
8+
9+
* @description
10+
*/
11+
public @interface RefreshEsMqSender {
12+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package cn.dblearn.blog.common.mq.aspect;
2+
3+
import cn.dblearn.blog.common.constants.RabbitMqConstants;
4+
import cn.dblearn.blog.common.util.RabbitMqUtils;
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.aspectj.lang.annotation.Pointcut;
9+
import org.springframework.stereotype.Component;
10+
11+
import javax.annotation.Resource;
12+
13+
/**
14+
* RefreshEsMqAspect
15+
*
16+
* @author bobbi
17+
* @date 2019/03/16 22:53
18+
19+
* @description
20+
*/
21+
@Aspect
22+
@Component
23+
public class RefreshEsMqAspect {
24+
25+
@Resource
26+
private RabbitMqUtils rabbitMqUtils;
27+
28+
@Pointcut("@annotation(cn.dblearn.blog.common.mq.annotation.RefreshEsMqSender)")
29+
public void pointCut() {
30+
31+
}
32+
33+
@Around("pointCut()")
34+
public Object around(ProceedingJoinPoint point) throws Throwable {
35+
//执行方法
36+
Object result = point.proceed();
37+
// 发送刷新信息
38+
rabbitMqUtils.send(RabbitMqConstants.REFRESH_ES_INDEX_QUEUE,"send refresh Es");
39+
return result;
40+
}
41+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cn.dblearn.blog.common.util;
2+
3+
import org.springframework.amqp.core.AmqpTemplate;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.stereotype.Component;
6+
7+
/**
8+
* RabbitMqUtils
9+
*
10+
* @author bobbi
11+
* @date 2019/03/16 22:08
12+
13+
* @description
14+
*/
15+
@Component
16+
public class RabbitMqUtils {
17+
18+
@Autowired
19+
private AmqpTemplate rabbitTemplate;
20+
21+
/**
22+
* 发送到指定Queue
23+
* @param queueName
24+
* @param obj
25+
*/
26+
public void send(String queueName, Object obj){
27+
this.rabbitTemplate.convertAndSend(queueName, obj);
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cn.dblearn.blog.config;
2+
3+
import cn.dblearn.blog.common.constants.RabbitMqConstants;
4+
import org.springframework.amqp.core.Queue;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
9+
/**
10+
* RabbitMQConfig
11+
*
12+
* @author bobbi
13+
* @date 2019/03/16 21:59
14+
15+
* @description
16+
*/
17+
@Configuration
18+
public class RabbitMqConfig {
19+
20+
@Bean
21+
public Queue queue() {
22+
return new Queue(RabbitMqConstants.REFRESH_ES_INDEX_QUEUE);
23+
}
24+
}

dbblog-backend/dbblog-core/src/main/java/cn/dblearn/blog/entity/article/Article.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
import cn.dblearn.blog.common.validator.group.UpdateGroup;
55
import com.baomidou.mybatisplus.annotation.IdType;
66
import com.baomidou.mybatisplus.annotation.TableId;
7-
import com.fasterxml.jackson.annotation.JsonFormat;
87
import io.swagger.annotations.ApiModel;
98
import io.swagger.annotations.ApiModelProperty;
109
import lombok.Data;
10+
import org.springframework.data.annotation.Id;
11+
import org.springframework.data.elasticsearch.annotations.DateFormat;
12+
import org.springframework.data.elasticsearch.annotations.Document;
13+
import org.springframework.data.elasticsearch.annotations.Field;
14+
import org.springframework.data.elasticsearch.annotations.FieldType;
1115

1216
import javax.validation.constraints.NotBlank;
1317
import java.io.Serializable;
14-
import java.time.LocalDateTime;
18+
import java.util.Date;
1519

1620
/**
1721
* <p>
@@ -23,12 +27,14 @@
2327
*/
2428
@Data
2529
@ApiModel(value="BlogArticle对象", description="文章")
30+
@Document(indexName = "dbblog",type = "article")
2631
public class Article implements Serializable {
2732

2833
private static final long serialVersionUID = 1L;
2934

3035
@ApiModelProperty(value = "主键")
3136
@TableId(value = "id", type = IdType.AUTO)
37+
@Id
3238
private Integer id;
3339

3440
@ApiModelProperty(value = "文章标题")
@@ -61,11 +67,12 @@ public class Article implements Serializable {
6167
private Integer coverType;
6268

6369
@ApiModelProperty(value = "创建时间")
64-
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
65-
private LocalDateTime createTime;
70+
@Field(type = FieldType.Date, format = DateFormat.none)
71+
private Date createTime;
6672

6773
@ApiModelProperty(value = "更新时间")
68-
private LocalDateTime updateTime;
74+
@Field(type = FieldType.Date, format = DateFormat.none)
75+
private Date updateTime;
6976

7077
@ApiModelProperty(value = "是否推荐文章")
7178
private Boolean recommend;

dbblog-backend/dbblog-core/src/main/java/cn/dblearn/blog/entity/book/Book.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import lombok.Data;
88

99
import java.io.Serializable;
10-
import java.time.LocalDate;
11-
import java.time.LocalDateTime;
10+
import java.util.Date;
1211

1312
/**
1413
* <p>
@@ -44,7 +43,7 @@ public class Book implements Serializable {
4443

4544
@ApiModelProperty(value = "出版日期")
4645
@JsonFormat(pattern = "yyyy-MM-dd")
47-
private LocalDate publishDate;
46+
private Date publishDate;
4847

4948
@ApiModelProperty(value = "页数")
5049
private int pageNum;
@@ -75,11 +74,11 @@ public class Book implements Serializable {
7574

7675
@ApiModelProperty(value = "创建时间")
7776
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
78-
private LocalDateTime createTime;
77+
private Date createTime;
7978

8079
@ApiModelProperty(value = "更新时间")
8180
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
82-
private LocalDateTime updateTime;
81+
private Date updateTime;
8382

8483
@ApiModelProperty(value = "读书进度")
8584
private Integer progress;

dbblog-backend/dbblog-core/src/main/java/cn/dblearn/blog/entity/book/BookNote.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import io.swagger.annotations.ApiModel;
77
import io.swagger.annotations.ApiModelProperty;
88
import lombok.Data;
9-
import lombok.EqualsAndHashCode;
10-
import lombok.experimental.Accessors;
119

1210
import java.io.Serializable;
13-
import java.time.LocalDateTime;
11+
import java.util.Date;
1412

1513
/**
1614
* <p>
@@ -21,8 +19,6 @@
2119
* @since 2019-02-13
2220
*/
2321
@Data
24-
@EqualsAndHashCode(callSuper = false)
25-
@Accessors(chain = true)
2622
@ApiModel(value = "BookNote对象", description = "笔记")
2723
public class BookNote implements Serializable {
2824

@@ -64,11 +60,11 @@ public class BookNote implements Serializable {
6460

6561
@ApiModelProperty(value = "创建时间")
6662
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
67-
private LocalDateTime createTime;
63+
private Date createTime;
6864

6965
@ApiModelProperty(value = "更新时间")
7066
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
71-
private LocalDateTime updateTime;
67+
private Date updateTime;
7268

7369
@ApiModelProperty(value = "是否推荐笔记")
7470
private Boolean recommend;

dbblog-backend/dbblog-core/src/main/java/cn/dblearn/blog/entity/book/BookSense.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import lombok.experimental.Accessors;
99

1010
import java.io.Serializable;
11-
import java.time.LocalDateTime;
11+
import java.util.Date;
1212

1313
/**
1414
* <p>
@@ -40,11 +40,11 @@ public class BookSense implements Serializable {
4040

4141
@ApiModelProperty(value = "创建时间")
4242
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
43-
private LocalDateTime createTime;
43+
private Date createTime;
4444

4545
@ApiModelProperty(value = "更新时间")
4646
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
47-
private LocalDateTime updateTime;
47+
private Date updateTime;
4848

4949

5050
}

0 commit comments

Comments
 (0)