Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
9ee60c18
Commit
9ee60c18
authored
Jul 19, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of 47.100.44.39:tp-backend/tanpu-community into dev
parents
b13e20e7
27a98eb2
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
442 additions
and
47 deletions
+442
-47
ESThemeQo.java
...main/java/com/tanpu/community/api/beans/qo/ESThemeQo.java
+42
-0
ThemeQo.java
...c/main/java/com/tanpu/community/api/beans/qo/ThemeQo.java
+23
-23
ThemeFullSearchReq.java
...pu/community/api/beans/req/search/ThemeFullSearchReq.java
+9
-0
TopicDTO.java
.../main/java/com/tanpu/community/api/beans/vo/TopicDTO.java
+1
-1
pom.xml
community-service/pom.xml
+12
-0
CommunityApplication.java
...c/main/java/com/tanpu/community/CommunityApplication.java
+2
-0
RedisCache.java
...e/src/main/java/com/tanpu/community/cache/RedisCache.java
+14
-8
ESConfig.java
...ce/src/main/java/com/tanpu/community/config/ESConfig.java
+41
-0
SearchController.java
...java/com/tanpu/community/controller/SearchController.java
+34
-1
ThemeMapper.java
...com/tanpu/community/dao/mapper/community/ThemeMapper.java
+4
-0
FileManager.java
...rc/main/java/com/tanpu/community/manager/FileManager.java
+1
-1
HomePageManager.java
...ain/java/com/tanpu/community/manager/HomePageManager.java
+1
-0
SearchManager.java
.../main/java/com/tanpu/community/manager/SearchManager.java
+0
-2
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+18
-0
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+2
-2
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+0
-1
ESHelper.java
.../main/java/com/tanpu/community/service/base/ESHelper.java
+157
-0
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+50
-1
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+6
-6
application-dev.yml
community-service/src/main/resources/application-dev.yml
+1
-1
pom.xml
pom.xml
+24
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ESThemeQo.java
0 → 100644
View file @
9ee60c18
package
com
.
tanpu
.
community
.
api
.
beans
.
qo
;
import
com.tanpu.community.api.beans.vo.ImagesDTO
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
ESThemeQo
{
@ApiModelProperty
(
value
=
"主题ID"
)
public
String
themeId
;
@ApiModelProperty
(
value
=
"标题"
)
public
String
title
;
@ApiModelProperty
(
value
=
"类型 1:讨论无标题 2:长文有标题 3:转发 4:评论"
)
public
Integer
themeType
;
@ApiModelProperty
(
value
=
"内容"
)
public
String
content
;
@ApiModelProperty
(
value
=
"话题名称"
)
public
String
topicTitle
;
@ApiModelProperty
(
value
=
"昵称"
)
public
String
nickName
;
@ApiModelProperty
(
value
=
"作者认证"
)
public
String
authLabel
;
@ApiModelProperty
(
value
=
"转发的主题"
)
public
FormerThemeQo
formerTheme
;
@ApiModelProperty
(
value
=
"评论Id(我的评论列表使用)"
)
public
String
commentId
;
public
Long
createTime
;
public
Long
updateTime
;
}
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeQo.java
View file @
9ee60c18
...
@@ -18,44 +18,44 @@ import java.util.List;
...
@@ -18,44 +18,44 @@ import java.util.List;
@ApiModel
(
"主题信息流对象"
)
@ApiModel
(
"主题信息流对象"
)
public
class
ThemeQo
implements
Serializable
{
public
class
ThemeQo
implements
Serializable
{
p
rivate
static
final
long
serialVersionUID
=
-
8585648478551597699L
;
p
ublic
static
final
long
serialVersionUID
=
-
8585648478551597699L
;
@ApiModelProperty
(
value
=
"主题ID"
)
@ApiModelProperty
(
value
=
"主题ID"
)
p
rivate
String
themeId
;
p
ublic
String
themeId
;
@ApiModelProperty
(
value
=
"被转发的主题"
)
@ApiModelProperty
(
value
=
"被转发的主题"
)
p
rivate
String
formerThemeId
;
p
ublic
String
formerThemeId
;
@ApiModelProperty
(
value
=
"标题"
)
@ApiModelProperty
(
value
=
"标题"
)
p
rivate
String
title
;
p
ublic
String
title
;
@ApiModelProperty
(
value
=
"类型 1:讨论无标题 2:长文有标题 3:转发 4:评论"
)
@ApiModelProperty
(
value
=
"类型 1:讨论无标题 2:长文有标题 3:转发 4:评论"
)
p
rivate
Integer
themeType
;
p
ublic
Integer
themeType
;
@ApiModelProperty
(
value
=
"内容"
)
@ApiModelProperty
(
value
=
"内容"
)
p
rivate
List
<
ThemeContentQo
>
content
;
p
ublic
List
<
ThemeContentQo
>
content
;
@ApiModelProperty
(
value
=
"作者id"
)
@ApiModelProperty
(
value
=
"作者id"
)
p
rivate
String
authorId
;
p
ublic
String
authorId
;
@ApiModelProperty
(
value
=
"所属的话题"
)
@ApiModelProperty
(
value
=
"所属的话题"
)
p
rivate
String
topicId
;
p
ublic
String
topicId
;
@ApiModelProperty
(
value
=
"话题名称"
)
@ApiModelProperty
(
value
=
"话题名称"
)
p
rivate
String
topicTitle
;
p
ublic
String
topicTitle
;
@ApiModelProperty
(
value
=
"昵称"
)
@ApiModelProperty
(
value
=
"昵称"
)
p
rivate
String
nickName
;
p
ublic
String
nickName
;
@ApiModelProperty
(
value
=
"用户头像"
)
@ApiModelProperty
(
value
=
"用户头像"
)
p
rivate
String
userImg
;
p
ublic
String
userImg
;
@ApiModelProperty
(
value
=
"用户简介"
)
@ApiModelProperty
(
value
=
"用户简介"
)
private
String
userIntroduction
;
private
String
userIntroduction
;
@ApiModelProperty
(
value
=
"当前用户是否关注该作者"
)
@ApiModelProperty
(
value
=
"当前用户是否关注该作者"
)
p
rivate
boolean
follow
;
p
ublic
boolean
follow
;
@ApiModelProperty
(
value
=
"作者认证"
)
@ApiModelProperty
(
value
=
"作者认证"
)
private
Integer
authLabel
;
private
Integer
authLabel
;
...
@@ -64,37 +64,37 @@ public class ThemeQo implements Serializable {
...
@@ -64,37 +64,37 @@ public class ThemeQo implements Serializable {
private
String
authOrg
;
private
String
authOrg
;
@ApiModelProperty
(
value
=
"发表时间"
)
@ApiModelProperty
(
value
=
"发表时间"
)
p
rivate
String
upToNowTime
;
p
ublic
String
upToNowTime
;
@ApiModelProperty
(
value
=
"转发量"
)
@ApiModelProperty
(
value
=
"转发量"
)
p
rivate
Integer
forwardCount
;
p
ublic
Integer
forwardCount
;
@ApiModelProperty
(
value
=
"评论量"
)
@ApiModelProperty
(
value
=
"评论量"
)
p
rivate
Integer
commentCount
;
p
ublic
Integer
commentCount
;
@ApiModelProperty
(
value
=
"点赞量"
)
@ApiModelProperty
(
value
=
"点赞量"
)
p
rivate
Integer
likeCount
;
p
ublic
Integer
likeCount
;
@ApiModelProperty
(
value
=
"当前用户是否点赞"
)
@ApiModelProperty
(
value
=
"当前用户是否点赞"
)
p
rivate
boolean
hasLiked
;
p
ublic
boolean
hasLiked
;
@ApiModelProperty
(
value
=
"当前用户是否转发"
)
@ApiModelProperty
(
value
=
"当前用户是否转发"
)
p
rivate
boolean
hasForward
;
p
ublic
boolean
hasForward
;
@ApiModelProperty
(
value
=
"当前用户是否收藏"
)
@ApiModelProperty
(
value
=
"当前用户是否收藏"
)
private
boolean
hasCollect
;
private
boolean
hasCollect
;
@ApiModelProperty
(
value
=
"图片九宫格"
)
@ApiModelProperty
(
value
=
"图片九宫格"
)
p
rivate
List
<
ImagesDTO
>
imgList
;
p
ublic
List
<
ImagesDTO
>
imgList
;
@ApiModelProperty
(
value
=
"转发的主题"
)
@ApiModelProperty
(
value
=
"转发的主题"
)
p
rivate
FormerThemeQo
formerTheme
;
p
ublic
FormerThemeQo
formerTheme
;
@ApiModelProperty
(
value
=
"评论Id(我的评论列表使用)"
)
@ApiModelProperty
(
value
=
"评论Id(我的评论列表使用)"
)
p
rivate
String
commentId
;
p
ublic
String
commentId
;
p
rivate
Long
createTime
;
p
ublic
Long
createTime
;
p
rivate
Long
updateTime
;
p
ublic
Long
updateTime
;
}
}
community-api/src/main/java/com/tanpu/community/api/beans/req/search/ThemeFullSearchReq.java
0 → 100644
View file @
9ee60c18
package
com
.
tanpu
.
community
.
api
.
beans
.
req
.
search
;
import
com.tanpu.community.api.beans.req.page.Pageable
;
import
lombok.Data
;
@Data
public
class
ThemeFullSearchReq
extends
Pageable
{
public
String
keyword
;
}
community-api/src/main/java/com/tanpu/community/api/beans/vo/TopicDO.java
→
community-api/src/main/java/com/tanpu/community/api/beans/vo/TopicD
T
O.java
View file @
9ee60c18
...
@@ -9,7 +9,7 @@ import java.time.LocalDateTime;
...
@@ -9,7 +9,7 @@ import java.time.LocalDateTime;
@Data
@Data
@ApiModel
(
value
=
"TopicDTO对象"
,
description
=
"话题"
)
@ApiModel
(
value
=
"TopicDTO对象"
,
description
=
"话题"
)
public
class
TopicDO
implements
Serializable
{
public
class
TopicD
T
O
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
...
...
community-service/pom.xml
View file @
9ee60c18
...
@@ -38,6 +38,18 @@
...
@@ -38,6 +38,18 @@
<artifactId>
spring-boot-starter-aop
</artifactId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-high-level-client
</artifactId>
<version>
7.10.0
</version>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
7.10.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
...
...
community-service/src/main/java/com/tanpu/community/CommunityApplication.java
View file @
9ee60c18
...
@@ -2,6 +2,7 @@ package com.tanpu.community;
...
@@ -2,6 +2,7 @@ package com.tanpu.community;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
...
@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
...
@@ -12,6 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableCaching
@EnableCaching
@EnableScheduling
@EnableScheduling
@EnableFeignClients
@EnableFeignClients
@EnableConfigurationProperties
public
class
CommunityApplication
{
public
class
CommunityApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
community-service/src/main/java/com/tanpu/community/cache/RedisCache.java
View file @
9ee60c18
package
com
.
tanpu
.
community
.
cache
;
package
com
.
tanpu
.
community
.
cache
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.redis.RedisHelper
;
import
com.tanpu.common.redis.RedisKeyHelper
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.util.SpringUtils
;
import
com.tanpu.community.util.SpringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
java.time.Duration
;
import
java.time.Duration
;
import
java.util.List
;
import
java.util.List
;
...
@@ -18,22 +22,26 @@ public class RedisCache {
...
@@ -18,22 +22,26 @@ public class RedisCache {
String
value
=
get
(
key
);
String
value
=
get
(
key
);
// todo 考虑缓存穿透的问题.
// todo 考虑缓存穿透的问题.
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
return
J
SON
.
parseObject
(
value
,
clz
);
return
J
sonUtil
.
toBean
(
value
,
clz
);
}
}
T
ret
=
func
.
get
();
T
ret
=
func
.
get
();
if
(
ret
!=
null
)
{
put
(
key
,
ret
,
expireSeconds
);
put
(
key
,
ret
,
expireSeconds
);
}
return
ret
;
return
ret
;
}
}
public
<
T
>
List
<
T
>
getList
(
String
key
,
Integer
expireSeconds
,
Supplier
<
List
<
T
>>
func
,
Class
<
T
>
clz
)
{
public
<
T
>
T
getList
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
TypeReference
<
T
>
ref
)
{
String
value
=
get
(
key
);
String
value
=
get
(
key
);
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
return
J
SON
.
parseArray
(
value
,
clz
);
return
J
sonUtil
.
toBean
(
value
,
ref
);
}
}
List
<
T
>
ret
=
func
.
get
();
T
ret
=
func
.
get
();
if
(
ret
!=
null
)
{
put
(
key
,
ret
,
expireSeconds
);
put
(
key
,
ret
,
expireSeconds
);
}
return
ret
;
return
ret
;
}
}
...
@@ -43,8 +51,6 @@ public class RedisCache {
...
@@ -43,8 +51,6 @@ public class RedisCache {
}
}
private
void
put
(
String
key
,
Object
obj
,
Integer
expireSeconds
)
{
private
void
put
(
String
key
,
Object
obj
,
Integer
expireSeconds
)
{
if
(
obj
==
null
)
return
;
key
=
cacheName
+
":"
+
key
;
key
=
cacheName
+
":"
+
key
;
String
value
=
JSON
.
toJSONString
(
obj
);
String
value
=
JSON
.
toJSONString
(
obj
);
if
(
expireSeconds
==
0
)
{
if
(
expireSeconds
==
0
)
{
...
...
community-service/src/main/java/com/tanpu/community/config/ESConfig.java
0 → 100644
View file @
9ee60c18
package
com
.
tanpu
.
community
.
config
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.nio.client.HttpAsyncClientBuilder
;
import
org.elasticsearch.client.RestClient
;
import
org.elasticsearch.client.RestClientBuilder
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
@Component
@ConfigurationProperties
(
prefix
=
"es"
)
public
class
ESConfig
{
private
String
userName
;
private
String
userPasswd
;
private
String
host
;
private
Integer
port
;
@Bean
public
RestHighLevelClient
client
()
{
CredentialsProvider
credentialsProvider
=
new
BasicCredentialsProvider
();
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
userName
,
userPasswd
));
RestHighLevelClient
restHighLevelClient
=
new
RestHighLevelClient
(
RestClient
.
builder
(
new
HttpHost
(
host
,
port
)).
setHttpClientConfigCallback
(
new
RestClientBuilder
.
HttpClientConfigCallback
()
{
@Override
public
HttpAsyncClientBuilder
customizeHttpClient
(
HttpAsyncClientBuilder
httpClientBuilder
)
{
return
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
);
}
}));
return
restHighLevelClient
;
}
}
community-service/src/main/java/com/tanpu/community/controller/SearchController.java
View file @
9ee60c18
package
com
.
tanpu
.
community
.
controller
;
public
class
SearchController
{
package
com
.
tanpu
.
community
.
controller
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.common.auth.UserInfoHelper
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.qo.TopicDetailQo
;
import
com.tanpu.community.api.beans.req.search.ThemeFullSearchReq
;
import
com.tanpu.community.manager.ThemeManager
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.List
;
@RestController
@Slf4j
@RequestMapping
(
value
=
"/api/search"
)
public
class
SearchController
{
@Resource
private
UserHolder
userHolder
;
@Autowired
private
ThemeManager
themeManager
;
// 内容全文搜索
public
CommonResp
<
List
<
ThemeQo
>>
themeSearch
(
ThemeFullSearchReq
req
)
{
List
<
ThemeQo
>
list
=
themeManager
.
themeFullSearch
(
req
.
keyword
,
req
.
getPageNumber
(),
req
.
getPageSize
(),
userHolder
.
getUserId
());
return
CommonResp
.
success
(
list
);
}
}
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/ThemeMapper.java
View file @
9ee60c18
...
@@ -2,6 +2,10 @@ package com.tanpu.community.dao.mapper.community;
...
@@ -2,6 +2,10 @@ package com.tanpu.community.dao.mapper.community;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
/**
* <p>
* <p>
...
...
community-service/src/main/java/com/tanpu/community/manager/FileManager.java
View file @
9ee60c18
...
@@ -38,7 +38,7 @@ public class FileManager {
...
@@ -38,7 +38,7 @@ public class FileManager {
String
originalName
=
file
.
getOriginalFilename
();
String
originalName
=
file
.
getOriginalFilename
();
if
(
data
.
length
==
0
||
StringUtils
.
isEmpty
(
originalName
)){
if
(
data
.
length
==
0
||
StringUtils
.
isEmpty
(
originalName
)){
throw
new
BizException
(
"上传文件为空"
);
throw
new
BizException
(
"上传文件为空"
);
}
}
FileRecordEntity
fileRecordEntity
=
ossFileService
.
uploadFile
(
data
,
originalName
);
FileRecordEntity
fileRecordEntity
=
ossFileService
.
uploadFile
(
data
,
originalName
);
...
...
community-service/src/main/java/com/tanpu/community/manager/HomePageManager.java
View file @
9ee60c18
...
@@ -36,6 +36,7 @@ import org.apache.commons.lang3.ObjectUtils;
...
@@ -36,6 +36,7 @@ import org.apache.commons.lang3.ObjectUtils;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.*
;
...
...
community-service/src/main/java/com/tanpu/community/manager/SearchManager.java
deleted
100644 → 0
View file @
b13e20e7
package
com
.
tanpu
.
community
.
manager
;
public
class
SearchManager
{
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
9ee60c18
...
@@ -2,6 +2,7 @@ package com.tanpu.community.manager;
...
@@ -2,6 +2,7 @@ package com.tanpu.community.manager;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.qo.ESThemeQo
;
import
com.tanpu.community.api.beans.qo.FormerThemeQo
;
import
com.tanpu.community.api.beans.qo.FormerThemeQo
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
...
@@ -19,8 +20,10 @@ import com.tanpu.community.dao.entity.community.*;
...
@@ -19,8 +20,10 @@ import com.tanpu.community.dao.entity.community.*;
import
com.tanpu.community.dao.entity.user.UserInfoEntity
;
import
com.tanpu.community.dao.entity.user.UserInfoEntity
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.BlackListService
;
import
com.tanpu.community.service.BlackListService
;
import
com.tanpu.community.service.base.ESService
;
import
com.tanpu.community.util.ConvertUtil
;
import
com.tanpu.community.util.ConvertUtil
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -61,6 +64,21 @@ public class ThemeManager {
...
@@ -61,6 +64,21 @@ public class ThemeManager {
@Autowired
@Autowired
private
VisitSummaryService
visitSummaryService
;
private
VisitSummaryService
visitSummaryService
;
@Autowired
private
ESService
esService
;
public
List
<
ThemeQo
>
themeFullSearch
(
String
keyword
,
Integer
pageNo
,
Integer
pageSize
,
String
userId
)
{
Integer
from
=
(
pageNo
-
1
)
*
pageSize
;
// 按时间倒叙查询
List
<
ESThemeQo
>
themes
=
esService
.
queryThemeIdByContentAndTitle
(
keyword
,
from
,
pageSize
);
if
(
themes
.
isEmpty
())
{
return
new
ArrayList
<>();
}
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryByThemeIds
(
themes
.
stream
().
map
(
ESThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
return
convertEntityToQo
(
themeEntities
,
userId
);
}
@Transactional
@Transactional
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
public
CreateThemeResp
publishTheme
(
CreateThemeReq
req
,
String
userId
)
{
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
9ee60c18
package
com
.
tanpu
.
community
.
manager
;
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.vo.TopicDO
;
import
com.tanpu.community.api.beans.vo.TopicD
T
O
;
import
com.tanpu.community.api.beans.vo.TopicDataAnalysDTO
;
import
com.tanpu.community.api.beans.vo.TopicDataAnalysDTO
;
import
com.tanpu.community.api.beans.qo.TopicDetailQo
;
import
com.tanpu.community.api.beans.qo.TopicDetailQo
;
import
com.tanpu.community.api.beans.qo.TopicHotQo
;
import
com.tanpu.community.api.beans.qo.TopicHotQo
;
...
@@ -55,7 +55,7 @@ public class TopicManager {
...
@@ -55,7 +55,7 @@ public class TopicManager {
}
}
//话题详情列表
//话题详情列表
public
List
<
TopicDO
>
getAllTopicDetail
()
{
public
List
<
TopicD
T
O
>
getAllTopicDetail
()
{
return
ConvertUtil
.
topicEntitiesToDTOs
(
topicService
.
queryAll
());
return
ConvertUtil
.
topicEntitiesToDTOs
(
topicService
.
queryAll
());
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
9ee60c18
...
@@ -138,7 +138,6 @@ public class ThemeService {
...
@@ -138,7 +138,6 @@ public class ThemeService {
return
themeMapper
.
selectList
(
queryWrapper
);
return
themeMapper
.
selectList
(
queryWrapper
);
}
}
/**
/**
* 根据话题查询最新主题(可分页)
* 根据话题查询最新主题(可分页)
*
*
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESHelper.java
0 → 100644
View file @
9ee60c18
package
com
.
tanpu
.
community
.
service
.
base
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.exception.ExceptionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.client.CredentialsProvider
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.nio.client.HttpAsyncClientBuilder
;
import
org.elasticsearch.action.ActionRequest
;
import
org.elasticsearch.action.index.IndexRequest
;
import
org.elasticsearch.action.index.IndexResponse
;
import
org.elasticsearch.action.search.SearchRequest
;
import
org.elasticsearch.action.search.SearchResponse
;
import
org.elasticsearch.common.xcontent.XContentType
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.rest.RestStatus
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.elasticsearch.client.*
;
import
javax.annotation.PostConstruct
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
@Slf4j
@Service
public
class
ESHelper
{
@Autowired
private
RestHighLevelClient
client
;
public
void
insert
(
String
index
,
String
type
,
String
id
,
String
json
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
index
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
req
.
source
(
json
,
XContentType
.
JSON
);
IndexResponse
resp
=
client
.
index
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
CREATED
);
}
catch
(
IOException
e
)
{
log
.
error
(
"ES Helper error:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
}
}
public
void
insert
(
String
index
,
String
type
,
String
id
,
Map
<
String
,
Object
>
data
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
index
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
req
.
source
(
data
);
IndexResponse
resp
=
client
.
index
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
CREATED
);
}
catch
(
IOException
e
)
{
log
.
error
(
"ES Helper error:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
}
}
public
SearchHit
[]
selectLike
(
String
index
,
SearchSourceBuilder
builder
)
{
try
{
SearchRequest
req
=
new
SearchRequest
(
index
);
req
.
source
(
builder
);
SearchResponse
resp
=
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
OK
);
return
resp
.
getHits
().
getHits
();
}
catch
(
IOException
e
)
{
log
.
error
(
"ES Helper error:{}"
,
ExceptionUtils
.
getStackTrace
(
e
));
}
return
new
SearchHit
[]{};
}
private
void
validStatus
(
RestStatus
status
,
RestStatus
expect
)
{
if
(
status
!=
expect
)
{
log
.
error
(
"ES Helper fail! status:{}"
,
status
.
toString
());
throw
new
RuntimeException
(
"ES fail"
);
}
}
public
static
void
main
(
String
[]
args
)
{
RestClientBuilder
builder
=
RestClient
.
builder
(
new
HttpHost
(
"42.194.224.208"
,
9200
))
.
setHttpClientConfigCallback
(
new
RestClientBuilder
.
HttpClientConfigCallback
()
{
@Override
public
HttpAsyncClientBuilder
customizeHttpClient
(
HttpAsyncClientBuilder
httpClientBuilder
)
{
return
httpClientBuilder
;
}
});
RestHighLevelClient
highClient
=
new
RestHighLevelClient
(
builder
);
ESHelper
helper
=
new
ESHelper
();
helper
.
client
=
highClient
;
System
.
out
.
println
(
"insert"
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
"小行星2"
);
map
.
put
(
"context"
,
"这里有一个小行星2"
);
// helper.insert("test_index", "2", map);
SearchSourceBuilder
search
=
new
SearchSourceBuilder
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
MatchQueryBuilder
matchQb
=
QueryBuilders
.
matchQuery
(
"context"
,
"星"
);
boolQb
.
must
(
matchQb
);
String
[]
includes
=
new
String
[]{
"id"
};
String
[]
excludes
=
new
String
[]{};
search
.
query
(
boolQb
).
fetchSource
(
includes
,
excludes
).
from
(
0
).
size
(
50
);
SearchHit
[]
hits
=
helper
.
selectLike
(
"test_index"
,
search
);
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
System
.
out
.
println
(
hit
.
getFields
());
}
}
}
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
View file @
9ee60c18
package
com
.
tanpu
.
community
.
service
.
base
;
public
class
ESService
{
package
com
.
tanpu
.
community
.
service
.
base
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.community.api.beans.qo.ESThemeQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.MatchQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Service
public
class
ESService
{
@Autowired
private
ESHelper
helper
;
private
static
final
String
INDEX_THEME
=
"theme"
;
public
void
insertTheme
(
ESThemeQo
qo
)
{
helper
.
insert
(
INDEX_THEME
,
String
.
valueOf
(
qo
.
themeType
),
qo
.
themeId
,
JSON
.
toJSONString
(
qo
));
}
public
List
<
ESThemeQo
>
queryThemeIdByContentAndTitle
(
String
keyword
,
int
from
,
int
size
)
{
SearchSourceBuilder
search
=
new
SearchSourceBuilder
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
MatchQueryBuilder
contentQb
=
QueryBuilders
.
matchQuery
(
"content"
,
keyword
);
MatchQueryBuilder
titleQb
=
QueryBuilders
.
matchQuery
(
"title"
,
keyword
);
boolQb
.
should
(
contentQb
);
boolQb
.
should
(
titleQb
);
String
[]
includes
=
new
String
[]{
"id"
,
"themeId"
,
"createTime"
};
String
[]
excludes
=
new
String
[]{};
search
.
query
(
boolQb
).
fetchSource
(
includes
,
excludes
).
sort
(
"createTime"
,
SortOrder
.
DESC
).
from
(
from
).
size
(
size
);
SearchHit
[]
hits
=
helper
.
selectLike
(
INDEX_THEME
,
search
);
return
Arrays
.
stream
(
hits
).
map
(
h
->
{
return
JSON
.
parseObject
(
h
.
toString
(),
ESThemeQo
.
class
);
}).
collect
(
Collectors
.
toList
());
}
}
}
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
9ee60c18
...
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
...
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.resp.FileUploadResp
;
import
com.tanpu.community.api.beans.resp.FileUploadResp
;
import
com.tanpu.community.api.beans.vo.ImagesDTO
;
import
com.tanpu.community.api.beans.vo.ImagesDTO
;
import
com.tanpu.community.api.beans.vo.TopicDO
;
import
com.tanpu.community.api.beans.vo.TopicD
T
O
;
import
com.tanpu.community.api.beans.qo.*
;
import
com.tanpu.community.api.beans.qo.*
;
import
com.tanpu.community.api.beans.req.theme.CreateThemeReq
;
import
com.tanpu.community.api.beans.req.theme.CreateThemeReq
;
import
com.tanpu.community.api.beans.req.theme.ThemeContentReq
;
import
com.tanpu.community.api.beans.req.theme.ThemeContentReq
;
...
@@ -76,10 +76,10 @@ public class ConvertUtil {
...
@@ -76,10 +76,10 @@ public class ConvertUtil {
}
}
public
static
TopicDO
topicEntityToDTO
(
TopicEntity
topicEntity
)
{
public
static
TopicD
T
O
topicEntityToDTO
(
TopicEntity
topicEntity
)
{
TopicD
O
topicDO
=
new
TopicD
O
();
TopicD
TO
topicDTO
=
new
TopicDT
O
();
BeanUtils
.
copyProperties
(
topicEntity
,
topicDO
);
BeanUtils
.
copyProperties
(
topicEntity
,
topicD
T
O
);
return
topicDO
;
return
topicD
T
O
;
}
}
public
static
TopicHotQo
topicEntityToHotQo
(
TopicEntity
topicEntity
)
{
public
static
TopicHotQo
topicEntityToHotQo
(
TopicEntity
topicEntity
)
{
...
@@ -119,7 +119,7 @@ public class ConvertUtil {
...
@@ -119,7 +119,7 @@ public class ConvertUtil {
return
entities
.
stream
().
map
(
ConvertUtil:
:
commentLv2Entity2Qo
).
collect
(
Collectors
.
toList
());
return
entities
.
stream
().
map
(
ConvertUtil:
:
commentLv2Entity2Qo
).
collect
(
Collectors
.
toList
());
}
}
public
static
List
<
TopicDO
>
topicEntitiesToDTOs
(
List
<
TopicEntity
>
topicEntities
)
{
public
static
List
<
TopicD
T
O
>
topicEntitiesToDTOs
(
List
<
TopicEntity
>
topicEntities
)
{
return
topicEntities
.
stream
().
map
(
ConvertUtil:
:
topicEntityToDTO
).
collect
(
Collectors
.
toList
());
return
topicEntities
.
stream
().
map
(
ConvertUtil:
:
topicEntityToDTO
).
collect
(
Collectors
.
toList
());
}
}
...
...
community-service/src/main/resources/application-dev.yml
View file @
9ee60c18
apollo.bootstrap.enabled
:
tru
e
apollo.bootstrap.enabled
:
fals
e
#app.id: tanpu-community
#app.id: tanpu-community
#apollo:
#apollo:
...
...
pom.xml
View file @
9ee60c18
...
@@ -75,12 +75,36 @@
...
@@ -75,12 +75,36 @@
<version>
1.0.5-SNAPSHOT
</version>
<version>
1.0.5-SNAPSHOT
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/org.elasticsearch.client/elasticsearch-rest-high-level-client -->
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-high-level-client
</artifactId>
<version>
7.10.0
</version>
</dependency>
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
7.10.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-dependencies
</artifactId>
<artifactId>
spring-boot-dependencies
</artifactId>
<version>
${spring.boot.version}
</version>
<version>
${spring.boot.version}
</version>
<type>
pom
</type>
<type>
pom
</type>
<scope>
import
</scope>
<scope>
import
</scope>
<exclusions>
<exclusion>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-high-level-client
</artifactId>
</exclusion>
<exclusion>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<dependency>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment