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
3d002630
Commit
3d002630
authored
Jul 28, 2021
by
吴泽佳
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
http://47.100.44.39:10001/tp-backend/tanpu-community
into dev
parents
a44cf3e9
f7dcb998
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
805 additions
and
435 deletions
+805
-435
ThemeAnalysDO.java
.../java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
+1
-1
Pageable.java
...java/com/tanpu/community/api/beans/req/page/Pageable.java
+4
-0
ThemeListReq.java
...com/tanpu/community/api/beans/req/theme/ThemeListReq.java
+8
-10
ThemeListResp.java
...ava/com/tanpu/community/api/beans/resp/ThemeListResp.java
+12
-0
ESConfig.java
...ce/src/main/java/com/tanpu/community/config/ESConfig.java
+5
-1
MetricsController.java
...ava/com/tanpu/community/controller/MetricsController.java
+0
-3
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+3
-2
TimesCountEntity.java
...anpu/community/dao/entity/community/TimesCountEntity.java
+16
-0
CollectionMapper.java
...anpu/community/dao/mapper/community/CollectionMapper.java
+12
-1
CommentMapper.java
...m/tanpu/community/dao/mapper/community/CommentMapper.java
+11
-0
ThemeMapper.java
...com/tanpu/community/dao/mapper/community/ThemeMapper.java
+10
-0
VisitSummaryMapper.java
...pu/community/dao/mapper/community/VisitSummaryMapper.java
+6
-0
CommentManager.java
...main/java/com/tanpu/community/manager/CommentManager.java
+1
-1
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+58
-30
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+4
-11
VisitSummaryManager.java
...java/com/tanpu/community/manager/VisitSummaryManager.java
+1
-24
BatchFeignCallService.java
...va/com/tanpu/community/service/BatchFeignCallService.java
+12
-0
CollectionService.java
...n/java/com/tanpu/community/service/CollectionService.java
+19
-2
CommentService.java
...main/java/com/tanpu/community/service/CommentService.java
+34
-30
FeignService.java
...c/main/java/com/tanpu/community/service/FeignService.java
+23
-0
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+60
-52
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+59
-55
ReportLogService.java
...in/java/com/tanpu/community/service/ReportLogService.java
+0
-2
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+31
-63
VisitSummaryService.java
...java/com/tanpu/community/service/VisitSummaryService.java
+28
-2
ESHelper.java
.../main/java/com/tanpu/community/service/base/ESHelper.java
+11
-8
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+3
-4
BizUtils.java
...vice/src/main/java/com/tanpu/community/util/BizUtils.java
+18
-0
application-dev.yml
community-service/src/main/resources/application-dev.yml
+2
-1
application-test.yml
community-service/src/main/resources/application-test.yml
+113
-0
CollectionEntityMapper.xml
...ain/resources/mapper/community/CollectionEntityMapper.xml
+7
-0
create.sql
docs/create.sql
+233
-132
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
View file @
3d002630
...
...
@@ -50,7 +50,7 @@ public class ThemeAnalysDO {
private
Double
userWeight
=
0.0
;
public
Double
get
Score
()
{
public
Double
calc
Score
()
{
//质量=帖子质量+用户质量
double
w
=
(
double
)
(
viewCount
*
0.1
+
forwardCount
*
3
+
commentCount
*
2
+
likeCount
*
1
+
collectCount
*
3
)
+
userWeight
;
double
i
=
1
;
//初试权重
...
...
community-api/src/main/java/com/tanpu/community/api/beans/req/page/Pageable.java
View file @
3d002630
...
...
@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import
lombok.Builder
;
import
lombok.Data
;
import
javax.validation.constraints.NotEmpty
;
@Data
@Builder
@ApiModel
(
value
=
"分页"
)
...
...
@@ -15,8 +17,10 @@ public class Pageable {
public
static
final
Integer
DEFAULT_PAGE_NUMBER
=
0
;
@NotEmpty
(
message
=
"分页Number不能为空"
)
public
Integer
pageNumber
=
DEFAULT_PAGE_NUMBER
;
@NotEmpty
(
message
=
"分页pageSize不能为空"
)
public
Integer
pageSize
=
DEFAULT_PAGE_SIZE
;
public
Pageable
()
{
...
...
community-api/src/main/java/com/tanpu/community/api/beans/req/theme/ThemeListReq.java
View file @
3d002630
package
com
.
tanpu
.
community
.
api
.
beans
.
req
.
theme
;
import
com.tanpu.community.api.beans.req.page.Pageable
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.util.List
;
@Data
public
class
ThemeListReq
{
...
...
@@ -12,20 +14,16 @@ public class ThemeListReq {
@NotNull
(
message
=
"主题类型不能为空"
)
@ApiModelProperty
(
value
=
"类型,1:推荐 2:关注 3:话题-热门 4:话题-最新"
)
p
rivate
Integer
type
;
p
ublic
Integer
type
;
@ApiModelProperty
(
value
=
"话题Id"
)
p
rivate
String
topicId
;
p
ublic
String
topicId
;
@ApiModelProperty
(
value
=
"当前浏览的最后一个themeId,可以为空"
)
private
String
lastId
=
""
;
@NotNull
(
message
=
"PageSize不能为空"
)
@ApiModelProperty
(
value
=
"页面大小"
)
private
Integer
pageSize
;
public
String
lastId
=
""
;
@NotNull
(
message
=
"分页"
)
public
Pageable
page
;
public
List
<
String
>
excludeIds
;
}
community-api/src/main/java/com/tanpu/community/api/beans/resp/ThemeListResp.java
0 → 100644
View file @
3d002630
package
com
.
tanpu
.
community
.
api
.
beans
.
resp
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
ThemeListResp
{
public
List
<
ThemeQo
>
themes
;
public
List
<
String
>
excludeIds
;
}
community-service/src/main/java/com/tanpu/community/config/ESConfig.java
View file @
3d002630
package
com
.
tanpu
.
community
.
config
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpHost
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
...
...
@@ -17,6 +18,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
@Slf4j
@Data
@Component
@ConfigurationProperties
(
prefix
=
"es"
)
...
...
@@ -33,12 +35,14 @@ public class ESConfig {
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
userName
,
userPasswd
));
RestHighLevelClient
restHighLevelClient
=
new
RestHighLevelClient
(
RestClient
.
builder
(
new
HttpHost
(
host
,
port
)).
setHttpClientConfigCallback
(
new
RestClientBuilder
.
HttpClientConfigCallback
()
{
RestClient
.
builder
(
new
HttpHost
(
host
,
port
,
"http"
)).
setHttpClientConfigCallback
(
new
RestClientBuilder
.
HttpClientConfigCallback
()
{
@Override
public
HttpAsyncClientBuilder
customizeHttpClient
(
HttpAsyncClientBuilder
httpClientBuilder
)
{
return
httpClientBuilder
.
setDefaultCredentialsProvider
(
credentialsProvider
);
}
}));
log
.
info
(
"es client created. addr: {}:{}, userName: {}"
,
host
,
port
,
userName
);
return
restHighLevelClient
;
}
}
community-service/src/main/java/com/tanpu/community/controller/MetricsController.java
View file @
3d002630
...
...
@@ -22,7 +22,6 @@ public class MetricsController {
@ApiOperation
(
"浏览话题"
)
@GetMapping
(
"/view/topic"
)
public
CommonResp
pageViewTopic
(
@RequestParam
String
topicId
){
visitSummaryManager
.
addTopicPageView
(
topicId
);
return
CommonResp
.
success
();
}
...
...
@@ -30,7 +29,6 @@ public class MetricsController {
@ApiOperation
(
"浏览主题"
)
@GetMapping
(
"/view/theme"
)
public
CommonResp
pageViewTheme
(
@RequestParam
String
themeId
){
visitSummaryManager
.
addFollowThemeView
(
themeId
);
return
CommonResp
.
success
();
}
...
...
@@ -38,7 +36,6 @@ public class MetricsController {
@ApiOperation
(
"浏览关注主题"
)
@GetMapping
(
"/view/follow"
)
public
CommonResp
pageViewTheme
(){
visitSummaryManager
.
addFollowThemeView
();
return
CommonResp
.
success
();
}
...
...
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
3d002630
...
...
@@ -7,6 +7,7 @@ import com.tanpu.common.auth.UserHolder;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
import
com.tanpu.community.api.beans.req.theme.*
;
import
com.tanpu.community.api.beans.resp.CreateThemeResp
;
import
com.tanpu.community.api.beans.resp.ThemeListResp
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.manager.ThemeManager
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -43,9 +44,9 @@ public class ThemeController {
@ApiOperation
(
"主题列表-推荐/关注/热门/最新"
)
@PostMapping
(
value
=
"/list"
)
@ResponseBody
public
CommonResp
<
List
<
ThemeQo
>
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
public
CommonResp
<
ThemeListResp
>
selectInterestList
(
@Validated
@RequestBody
ThemeListReq
req
)
{
String
userId
=
userHolder
.
getUserId
();
List
<
ThemeQo
>
result
=
themeManager
.
queryThemes
(
req
,
userId
);
ThemeListResp
result
=
themeManager
.
queryThemes
(
req
,
userId
);
return
CommonResp
.
success
(
result
);
}
...
...
community-service/src/main/java/com/tanpu/community/dao/entity/community/TimesCountEntity.java
0 → 100644
View file @
3d002630
package
com
.
tanpu
.
community
.
dao
.
entity
.
community
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
public
class
TimesCountEntity
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"次数"
)
private
Integer
times
;
@ApiModelProperty
(
value
=
"目标id"
)
private
String
id
;
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/CollectionMapper.java
View file @
3d002630
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.
tanpu.community.dao.entity.community.CollectionEntity
;
import
com.
baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.CollectionEntity
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
* <p>
...
...
@@ -13,4 +20,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public
interface
CollectionMapper
extends
BaseMapper
<
CollectionEntity
>
{
@Select
(
"select target_id as id, count(1) as times from collection ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByTargetIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/CommentMapper.java
View file @
3d002630
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.CommentEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
* <p>
...
...
@@ -13,4 +20,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public
interface
CommentMapper
extends
BaseMapper
<
CommentEntity
>
{
@Select
(
"select theme_id as id, count(1) as times from comment ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/ThemeMapper.java
View file @
3d002630
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
java.util.List
;
/**
* <p>
...
...
@@ -13,4 +20,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public
interface
ThemeMapper
extends
BaseMapper
<
ThemeEntity
>
{
@Select
(
"select former_theme_id as id, count(1) as times from theme ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
}
community-service/src/main/java/com/tanpu/community/dao/mapper/community/VisitSummaryMapper.java
View file @
3d002630
package
com
.
tanpu
.
community
.
dao
.
mapper
.
community
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Constants
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.VisitSummaryEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -25,4 +28,7 @@ public interface VisitSummaryMapper extends BaseMapper<VisitSummaryEntity> {
@Select
(
"select ref_id from visit_summary where visitor_id=#{visitorId} and ref_id in (#{refIds})"
)
List
<
String
>
selectRefIdByUserId
(
@Param
(
"visitorId"
)
String
visitorId
,
@Param
(
"refIds"
)
String
refIds
);
@Select
(
"select ref_id as id, count(1) as times from visit_summary ${ew.customSqlSegment}"
)
List
<
TimesCountEntity
>
selectCountByThemeIds
(
@Param
(
Constants
.
WRAPPER
)
LambdaQueryWrapper
wrapper
);
}
community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
View file @
3d002630
...
...
@@ -109,7 +109,7 @@ public class CommentManager {
//点赞评论/取消点赞
public
void
likeComment
(
LikeCommentReq
req
,
String
userId
)
{
if
(
OperationTypeEnum
.
CONFIRM
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
addIfNotExist
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
collectionService
.
saveOrUpdate
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
}
else
if
(
OperationTypeEnum
.
CANCEL
.
getCode
().
equals
(
req
.
getType
()))
{
collectionService
.
delete
(
req
.
getCommentId
(),
userId
,
CollectionTypeEnum
.
LIKE_COMMENT
);
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
3d002630
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
3d002630
package
com
.
tanpu
.
community
.
manager
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.qo.TopicRankQo
;
import
com.tanpu.community.api.beans.req.page.Page
;
import
com.tanpu.community.api.beans.req.topic.TopicSearchReq
;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.service.*
;
import
com.tanpu.community.service.RankService
;
import
com.tanpu.community.service.TopicService
;
import
com.tanpu.community.service.VisitSummaryService
;
import
com.tanpu.community.util.PageUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -28,14 +29,6 @@ public class TopicManager {
@Resource
private
UserHolder
userHolder
;
// 新增话题
public
void
insertTopic
(
String
topicTitle
,
String
userId
)
{
if
(
topicService
.
queryByTitile
(
topicTitle
)
==
null
)
{
throw
new
BizException
(
"话题名称已存在:"
+
topicTitle
);
}
topicService
.
addTopic
(
topicTitle
,
userId
);
}
// 首页-话题标签
public
List
<
TopicRankQo
>
getTop4TopicTitles
()
{
...
...
@@ -52,7 +45,7 @@ public class TopicManager {
// 话题详情页
public
TopicRankQo
getDetail
(
String
topicId
)
{
//
话题详情
//
TODO 临时埋点,接入新埋点后删除
visitSummaryService
.
addPageView
(
userHolder
.
getUserId
(),
topicId
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
return
rankService
.
getTopicDetail
(
topicId
);
}
...
...
community-service/src/main/java/com/tanpu/community/manager/VisitSummaryManager.java
View file @
3d002630
package
com
.
tanpu
.
community
.
manager
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.common.auth.UserHolder
;
import
com.tanpu.community.api.beans.vo.KafkaDurationUptMsg
;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.dao.entity.community.VisitSummaryEntity
;
import
com.tanpu.community.service.VisitSummaryService
;
import
com.tanpu.community.util.ConvertUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.elasticsearch.common.recycler.Recycler
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.kafka.annotation.KafkaListener
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
@Slf4j
@Service
public
class
VisitSummaryManager
{
...
...
@@ -28,31 +23,13 @@ public class VisitSummaryManager {
@Autowired
private
VisitSummaryService
visitSummaryService
;
@Autowired
private
UserHolder
userHolder
;
@KafkaListener
(
topics
=
kafakTopic
)
public
void
updateVisitSummary
(
String
message
)
{
log
.
info
(
"receive kafka msg: {}"
,
message
);
KafkaDurationUptMsg
msg
=
JSON
.
parseObject
(
message
,
KafkaDurationUptMsg
.
class
);
// ident在每次进入新页面 & 回退 的时候都会随机生成一个,所以用ident做唯一key即可。
VisitSummaryEntity
vs
=
ConvertUtil
.
convertFromKafka
(
msg
);
visitSummaryService
.
insertOrUpdateDur
(
vs
);
}
public
void
addTopicPageView
(
String
topicId
)
{
String
userId
=
userHolder
.
getUserId
();
visitSummaryService
.
addPageView
(
userId
,
topicId
,
VisitTypeEnum
.
TOPIC_PAGE_VIEW
);
}
public
void
addFollowThemeView
(
String
themeId
)
{
String
userId
=
userHolder
.
getUserId
();
visitSummaryService
.
addPageView
(
userId
,
themeId
,
VisitTypeEnum
.
THEME_PAGE_VIEW
);
}
public
void
addFollowThemeView
()
{
String
userId
=
userHolder
.
getUserId
();
visitSummaryService
.
addPageView
(
userId
,
userId
,
VisitTypeEnum
.
FOLLOW_THEME_VIEW
);
}
}
community-service/src/main/java/com/tanpu/community/service/BatchFeignCallService.java
View file @
3d002630
...
...
@@ -16,6 +16,7 @@ import com.tanpu.community.api.beans.vo.feign.product.FundInfoBaseResp;
import
com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO
;
import
com.tanpu.community.api.beans.vo.feign.zhibo.ZhiboListResp
;
import
com.tanpu.community.api.enums.RelTypeEnum
;
import
com.tanpu.community.api.enums.UserLevelEnum
;
import
com.tanpu.community.dao.entity.community.FileRecordEntity
;
import
com.tanpu.community.dao.entity.community.TopicEntity
;
import
com.tanpu.community.feign.course.FeignClientForCourse
;
...
...
@@ -392,6 +393,17 @@ public class BatchFeignCallService {
themeQo
.
setUserInvestorType
(
userInfo
.
getUserInvestorType
());
themeQo
.
setBelongUserOrgId
(
userInfo
.
getBelongUserOrgId
());
themeQo
.
setBelongUserOrgName
(
userInfo
.
getBelongUserOrgName
());
//工作室相关
themeQo
.
setWorkshopName
(
userInfo
.
getWorkshopName
());
themeQo
.
setWorkshopStatus
(
userInfo
.
getWorkshopStatus
());
themeQo
.
setWorkshopIntroduction
(
userInfo
.
getWorkshopIntroduction
());
//首席投顾
if
(
UserLevelEnum
.
USER_CHIEF_FINANCIAL_ADVISER
.
getCode
()
==
userInfo
.
getLevelGrade
()
&&
userInfo
.
getUserInfoNewChief
()
!=
null
)
{
themeQo
.
setNickName
(
userInfo
.
getUserInfoNewChief
().
getUserName
());
themeQo
.
setUserImg
(
userInfo
.
getUserInfoNewChief
().
getHeadImageUrl
());
themeQo
.
setUserIntroduction
(
userInfo
.
getUserInfoNewChief
().
getPersonalProfile
());
}
}
if
(
themeQo
.
getContent
()
==
null
)
{
continue
;
...
...
community-service/src/main/java/com/tanpu/community/service/CollectionService.java
View file @
3d002630
...
...
@@ -4,13 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.tanpu.community.api.enums.CollectionTypeEnum
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.dao.entity.community.CollectionEntity
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.mapper.community.CollectionMapper
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
...
...
@@ -22,7 +26,7 @@ public class CollectionService {
// 若不存在则新增,若存在则修改deleteTag
@Transactional
public
void
addIfNotExist
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
public
void
saveOrUpdate
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
// 判断记录是否存在,无论是否删除
CollectionEntity
queryCollection
=
getTargetCollection
(
themeId
,
userId
,
type
);
if
(
queryCollection
!=
null
)
{
...
...
@@ -64,7 +68,7 @@ public class CollectionService {
// 根据用户id和行为type获取target_id列表
public
Set
<
String
>
getListByUser
(
String
userId
,
CollectionTypeEnum
type
)
{
return
collectionMapper
.
selectList
(
new
LambdaQueryWrapper
<
CollectionEntity
>()
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getUserId
,
userId
)
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
())
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()))
.
stream
().
map
(
CollectionEntity:
:
getTargetId
).
collect
(
Collectors
.
toSet
());
...
...
@@ -79,6 +83,18 @@ public class CollectionService {
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())));
}
// 统计多个对象(主题、评论)的数量(点赞、收藏)
public
Map
<
String
,
Integer
>
getCountMapByType
(
List
<
String
>
targetIds
,
CollectionTypeEnum
type
)
{
if
(
CollectionUtils
.
isEmpty
(
targetIds
)){
return
new
HashMap
<>();
}
LambdaQueryWrapper
<
CollectionEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CollectionEntity
>().
eq
(
CollectionEntity:
:
getCollectionType
,
1
)
.
in
(
CollectionEntity:
:
getTargetId
,
targetIds
).
groupBy
(
CollectionEntity:
:
getTargetId
);
return
collectionMapper
.
selectCountByTargetIds
(
queryWrapper
).
stream
()
.
collect
(
Collectors
.
toMap
(
TimesCountEntity:
:
getId
,
TimesCountEntity:
:
getTimes
));
}
// 统计多个对象(主题、评论)的数量(点赞、收藏)
public
Integer
getCountByTypeAndIds
(
List
<
String
>
targetIds
,
CollectionTypeEnum
type
)
{
return
collectionMapper
.
selectCount
((
new
LambdaQueryWrapper
<
CollectionEntity
>()
...
...
@@ -86,6 +102,7 @@ public class CollectionService {
.
eq
(
CollectionEntity:
:
getCollectionType
,
type
.
getCode
()))
.
eq
(
CollectionEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()));
}
//逻辑删除,修改delete_tag
@Transactional
public
void
delete
(
String
themeId
,
String
userId
,
CollectionTypeEnum
type
)
{
...
...
community-service/src/main/java/com/tanpu/community/service/CommentService.java
View file @
3d002630
...
...
@@ -9,6 +9,7 @@ import com.tanpu.community.api.enums.DeleteTagEnum;
import
com.tanpu.community.api.enums.ReportStatusEnum
;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.dao.entity.community.CommentEntity
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.mapper.community.CommentMapper
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -17,12 +18,12 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.
Set
;
import
java.util.
Map
;
import
java.util.stream.Collectors
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.
CACHE_COMMENT_THEMEID
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.
CAHCE_COMMENT_ID
;
import
static
com
.
tanpu
.
community
.
api
.
constants
.
RedisKeyConstant
.*;
@Service
public
class
CommentService
{
...
...
@@ -42,6 +43,7 @@ public class CommentService {
commentMapper
.
insert
(
commentEntity
);
//失效缓存
redisCache
.
evict
(
StringUtils
.
joinWith
(
"_"
,
CACHE_COMMENT_THEMEID
,
commentEntity
.
getThemeId
()));
redisCache
.
evict
(
StringUtils
.
joinWith
(
"_"
,
CACHE_THEME_ID
,
commentEntity
.
getThemeId
()));
}
...
...
@@ -51,47 +53,49 @@ public class CommentService {
}
//统计主题集合的评论量
public
Integer
get
Comment
CountByThemeIds
(
List
<
String
>
themeIds
)
{
if
(
CollectionUtils
.
isEmpty
(
themeIds
)){
public
Integer
get
Total
CountByThemeIds
(
List
<
String
>
themeIds
)
{
if
(
CollectionUtils
.
isEmpty
(
themeIds
))
{
return
0
;
}
return
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
return
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
.
in
(
CommentEntity:
:
getThemeId
,
themeIds
)))
.
size
();
}
//统计主题集合的评论量
public
Integer
getCommentCountByThemeId
(
String
themeId
)
{
return
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
return
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getThemeId
,
themeId
)))
.
size
();
}
public
Set
<
String
>
getCommentUserCount
(
List
<
String
>
themeIds
)
{
return
commentMapper
.
selectList
((
new
LambdaQueryWrapper
<
CommentEntity
>()
.
in
(
CommentEntity:
:
getThemeId
,
themeIds
)))
.
stream
().
map
(
CommentEntity:
:
getAuthorId
).
collect
(
Collectors
.
toSet
());
//统计主题集合的评论量
public
Map
<
String
,
Integer
>
getCountMapByThemeIds
(
List
<
String
>
themeIds
)
{
if
(
CollectionUtils
.
isEmpty
(
themeIds
)){
return
new
HashMap
<>();
}
LambdaQueryWrapper
<
CommentEntity
>
wrapper
=
(
new
LambdaQueryWrapper
<
CommentEntity
>()
.
in
(
CommentEntity:
:
getThemeId
,
themeIds
))
.
eq
(
CommentEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
)
.
groupBy
(
CommentEntity:
:
getThemeId
);
return
commentMapper
.
selectCountByThemeIds
(
wrapper
).
stream
()
.
collect
(
Collectors
.
toMap
(
TimesCountEntity:
:
getId
,
TimesCountEntity:
:
getTimes
));
}
public
List
<
CommentEntity
>
selectByThemeId
(
String
themeId
)
{
return
redisCache
.
getList
(
StringUtils
.
joinWith
(
"_"
,
CACHE_COMMENT_THEMEID
,
themeId
),
60
,
()
->
{
LambdaQueryWrapper
<
CommentEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getThemeId
,
themeId
)
.
eq
(
CommentEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
.
orderByDesc
(
CommentEntity:
:
getCreateTime
);
return
commentMapper
.
selectList
(
queryWrapper
);
},
new
TypeReference
<
List
<
CommentEntity
>>()
{});
LambdaQueryWrapper
<
CommentEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getThemeId
,
themeId
)
.
eq
(
CommentEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
.
orderByDesc
(
CommentEntity:
:
getCreateTime
);
return
commentMapper
.
selectList
(
queryWrapper
);
},
new
TypeReference
<
List
<
CommentEntity
>>()
{
});
}
public
List
<
CommentEntity
>
queryCommentsByUserId
(
String
userId
)
{
return
commentMapper
.
selectList
(
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getAuthorId
,
userId
)
.
eq
(
CommentEntity:
:
getCommentType
,
CommentTypeEnum
.
THEME
.
getCode
())
.
eq
(
CommentEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
()));
}
public
List
<
CommentEntity
>
queryCommentsByUserId
(
String
userId
,
String
lastId
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
CommentEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
CommentEntity
>()
...
...
@@ -101,20 +105,20 @@ public class CommentService {
.
orderByDesc
(
CommentEntity:
:
getCreateTime
);
if
(
StringUtils
.
isNotEmpty
(
lastId
))
{
CommentEntity
commentEntity
=
commentMapper
.
selectOne
(
new
LambdaQueryWrapper
<
CommentEntity
>()
.
eq
(
CommentEntity:
:
getCommentId
,
lastId
));
if
(
commentEntity
==
null
)
throw
new
BizException
(
"评论未找到,id:"
+
lastId
);
.
eq
(
CommentEntity:
:
getCommentId
,
lastId
));
if
(
commentEntity
==
null
)
throw
new
BizException
(
"评论未找到,id:"
+
lastId
);
queryWrapper
.
lt
(
CommentEntity:
:
getUpdateTime
,
commentEntity
.
getCreateTime
());
}
if
(
pageSize
!=
null
)
{
queryWrapper
.
last
(
"limit "
+
pageSize
);
if
(
pageSize
!=
null
)
{
queryWrapper
.
last
(
"limit "
+
pageSize
);
}
return
commentMapper
.
selectList
(
queryWrapper
);
}
public
void
updateReportStatus
(
String
commentId
)
{
CommentEntity
commentEntity
=
queryByCommentId
(
commentId
);
if
(
commentEntity
==
null
)
{
throw
new
BizException
(
"评论未找到,id:"
+
commentId
);
if
(
commentEntity
==
null
)
{
throw
new
BizException
(
"评论未找到,id:"
+
commentId
);
}
commentEntity
.
setReportStatus
(
ReportStatusEnum
.
REPORTED
.
getCode
());
commentMapper
.
updateById
(
commentEntity
);
...
...
community-service/src/main/java/com/tanpu/community/service/FeignService.java
0 → 100644
View file @
3d002630
package
com
.
tanpu
.
community
.
service
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew
;
import
com.tanpu.community.feign.fatools.FeignClientForFatools
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
@Service
public
class
FeignService
{
@Autowired
private
FeignClientForFatools
fatools
;
public
UserInfoNew
getUserInfoById
(
String
userId
)
{
CommonResp
<
UserInfoNew
>
userInfoNewCommonResp
=
fatools
.
queryUsersListNew
(
userId
);
if
(
userInfoNewCommonResp
.
isNotSuccess
())
{
throw
new
BizException
(
"内部接口调用失败"
);
}
return
userInfoNewCommonResp
.
getData
();
}
}
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
3d002630
This diff is collapsed.
Click to expand it.
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
3d002630
...
...
@@ -4,8 +4,10 @@ import com.tanpu.common.util.JsonUtil;
import
com.tanpu.community.api.beans.qo.ThemeAnalysDO
;
import
com.tanpu.community.api.beans.resp.PythonResponse
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.util.BizUtils
;
import
com.tanpu.community.util.ConvertUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -42,56 +44,40 @@ public class RecommendService {
@Autowired
private
VisitSummaryService
visitSummaryService
;
//最新
//
最新
private
List
<
ThemeAnalysDO
>
recentThemeList
=
new
ArrayList
<>();
//推荐
//
推荐
private
Map
<
String
,
List
<
String
>>
recommondList
=
new
HashMap
<>();
//
private
Map
<
String
,
Set
<
String
>>
returnedIdsMap
=
new
HashMap
<>();
public
List
<
String
>
getRecommendThemes
(
String
lastId
,
Integer
pageSize
,
String
userId
)
{
public
List
<
String
>
getRecommendThemes
(
Integer
pageStart
,
Integer
pageSize
,
String
userId
)
{
//最热话题,剔除当前用户的主题
List
<
String
>
hotThemeIds
=
rankService
.
getRankThemeList
().
stream
()
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
())
)
// todo pageNo , pageSize
List
<
String
>
hotThemeIds
=
rankService
.
getHotestThemes
().
stream
(
)
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
collect
(
Collectors
.
toList
());
//最新话题,剔除当前用户的主题
List
<
String
>
newThemeIds
=
this
.
getRecentThemeList
().
stream
()
.
filter
(
o
->
!
userId
.
equals
(
o
.
getAuthorId
()))
List
<
String
>
newThemeIds
=
getNewestThemes
().
stream
()
.
map
(
ThemeAnalysDO:
:
getThemeId
)
.
collect
(
Collectors
.
toList
());
//推荐话题
List
<
String
>
recThemeIds
=
getPythonRecommendList
(
userId
);
//混合
Set
<
String
>
returnedIds
=
(
StringUtils
.
isEmpty
(
lastId
))
||
!
returnedIdsMap
.
containsKey
(
userId
)
||
returnedIdsMap
.
get
(
userId
)
==
null
?
new
HashSet
<>()
:
returnedIdsMap
.
get
(
userId
);
List
<
String
>
result
=
new
ArrayList
<>();
getResultList
(
hotThemeIds
,
0
,
newThemeIds
,
0
,
recThemeIds
,
0
,
returnedIds
,
result
,
pageSize
,
userId
);
List
<
String
>
result
=
mergeRecommend
(
hotThemeIds
,
newThemeIds
,
recThemeIds
);
result
=
result
.
stream
().
limit
(
pageSize
).
collect
(
Collectors
.
toList
());
//记录已返回主题id
if
(
StringUtils
.
isEmpty
(
lastId
))
{
returnedIdsMap
.
put
(
userId
,
new
HashSet
<>(
result
));
}
else
{
HashSet
<
String
>
newSet
=
new
HashSet
<>();
newSet
.
addAll
(
returnedIdsMap
.
get
(
userId
));
newSet
.
addAll
(
result
);
returnedIdsMap
.
put
(
userId
,
newSet
);
}
return
result
;
}
public
List
<
ThemeAnalysDO
>
getRecentThemeList
()
{
// 获取最新话题
public
List
<
ThemeAnalysDO
>
getNewestThemes
()
{
if
(
recentThemeList
.
size
()
==
0
)
{
refreshNewestThemes
();
}
return
recentThemeList
;
}
//从数据库查询最新主题
//
从数据库查询最新主题
public
void
refreshNewestThemes
()
{
List
<
ThemeEntity
>
themeEntities
=
themeService
.
queryLatestThemes
(
100
);
this
.
recentThemeList
=
ConvertUtil
.
themeEntityToAnalysDOs
(
themeEntities
);
...
...
@@ -106,8 +92,7 @@ public class RecommendService {
}
}
//HTTP查询python推荐主题
//HTTP查询python推荐主题 python返回最多50个
public
List
<
String
>
refreshPythonRecommendList
(
String
userId
)
{
if
(!
"true"
.
equals
(
enablePython
))
{
return
Collections
.
emptyList
();
...
...
@@ -128,53 +113,72 @@ public class RecommendService {
}
//
逐个插入
private
void
getResultList
(
List
<
String
>
hotThemeIds
,
Integer
hotTag
,
List
<
String
>
newThemeIds
,
Integer
newTag
,
List
<
String
>
recThemeIds
,
Integer
recTag
,
Set
<
String
>
returnedIds
,
List
<
String
>
result
,
Integer
pageSize
,
String
userId
)
{
if
(
hotThemeIds
.
size
()
<=
hotTag
&&
newThemeIds
.
size
()
<=
newTag
&&
recThemeIds
.
size
()
<=
recTag
)
{
//所有列表已循环结束,返回
return
;
}
while
(
result
.
size
()
<
pageSize
*
1.5
)
{
//
合并,去重
private
List
<
String
>
mergeList
(
List
<
String
>
hotThemeIds
,
List
<
String
>
newThemeIds
,
List
<
String
>
recThemeIds
,
Set
<
String
>
set
)
{
ArrayList
<
String
>
result
=
new
ArrayList
<>();
// 3个集合的指针
Integer
hotIdx
=
0
;
Integer
newIdx
=
0
;
Integer
recIdx
=
0
;
while
(
hotThemeIds
.
size
()
>
hotIdx
||
newThemeIds
.
size
()
>
newIdx
||
recThemeIds
.
size
()
>
recIdx
)
{
int
hotTimes
=
hotRatio
;
int
newTimes
=
newRatio
;
int
recTimes
=
pythonRatio
;
String
id
;
while
(
hotTimes
>
0
&&
hotThemeIds
.
size
()
>
hot
Tag
)
{
id
=
hotThemeIds
.
get
(
hot
Tag
);
if
(!
returnedIds
.
contains
(
id
))
{
while
(
hotTimes
>
0
&&
hotThemeIds
.
size
()
>
hot
Idx
)
{
id
=
hotThemeIds
.
get
(
hot
Idx
);
if
(!
set
.
contains
(
id
))
{
result
.
add
(
id
);
returnedIds
.
add
(
id
);
set
.
add
(
id
);
}
hotTag
++;
hotIdx
++;
hotTimes
--;
}
while
(
newTimes
>
0
&&
newThemeIds
.
size
()
>
new
Tag
)
{
id
=
newThemeIds
.
get
(
new
Tag
);
if
(!
returnedIds
.
contains
(
id
))
{
while
(
newTimes
>
0
&&
newThemeIds
.
size
()
>
new
Idx
)
{
id
=
newThemeIds
.
get
(
new
Idx
);
if
(!
set
.
contains
(
id
))
{
result
.
add
(
id
);
returnedIds
.
add
(
id
);
set
.
add
(
id
);
}
newTag
++;
newIdx
++;
newTimes
--;
}
while
(
recTimes
>
0
&&
recThemeIds
.
size
()
>
rec
Tag
)
{
id
=
recThemeIds
.
get
(
rec
Tag
);
if
(!
returnedIds
.
contains
(
id
))
{
while
(
recTimes
>
0
&&
recThemeIds
.
size
()
>
rec
Idx
)
{
id
=
recThemeIds
.
get
(
rec
Idx
);
if
(!
set
.
contains
(
id
))
{
result
.
add
(
id
);
returnedIds
.
add
(
id
);
set
.
add
(
id
);
}
recTag
++;
recIdx
++;
recTimes
--;
}
}
//去重已看过(查看正文)
result
=
visitSummaryService
.
filterUserNotVisited
(
userId
,
result
);
return
result
;
}
// 按照 6,3,1的比例
private
List
<
String
>
mergeRecommend
(
List
<
String
>
hotIds
,
List
<
String
>
newestIds
,
List
<
String
>
recmdIds
)
{
List
<
String
>
retList
=
new
ArrayList
<>();
int
round
=
0
;
while
(
true
)
{
int
hotStart
=
round
*
6
;
int
newestStart
=
round
*
3
;
int
recmdStart
=
round
;
if
(
hotStart
>=
hotIds
.
size
()
&&
newestStart
>=
newestIds
.
size
()
&&
recmdStart
>=
recmdIds
.
size
())
{
break
;
}
retList
.
addAll
(
BizUtils
.
subList
(
hotIds
,
hotStart
,
hotStart
+
6
));
retList
.
addAll
(
BizUtils
.
subList
(
newestIds
,
newestStart
,
newestStart
+
3
));
retList
.
addAll
(
BizUtils
.
subList
(
recmdIds
,
recmdStart
,
recmdStart
+
1
));
if
(
result
.
size
()
<
pageSize
)
{
getResultList
(
hotThemeIds
,
hotTag
,
newThemeIds
,
newTag
,
recThemeIds
,
recTag
,
returnedIds
,
result
,
pageSize
,
userId
);
round
++;
}
return
retList
;
}
...
...
community-service/src/main/java/com/tanpu/community/service/ReportLogService.java
View file @
3d002630
...
...
@@ -25,7 +25,5 @@ public class ReportLogService {
.
reportTime
(
LocalDateTime
.
now
())
.
build
();
reportLogMapper
.
insert
(
entity
);
}
}
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
3d002630
...
...
@@ -8,6 +8,7 @@ import com.tanpu.common.uuid.UuidGenHelper;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.ReportStatusEnum
;
import
com.tanpu.community.dao.entity.community.ThemeEntity
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.mapper.community.ThemeMapper
;
import
com.tanpu.community.util.TimeUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
...
...
@@ -19,8 +20,9 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.
Set
;
import
java.util.
Map
;
import
java.util.stream.Collectors
;
@Service
...
...
@@ -46,7 +48,7 @@ public class ThemeService {
themeMapper
.
update
(
themeEntity
,
new
LambdaUpdateWrapper
<
ThemeEntity
>().
eq
(
ThemeEntity:
:
getThemeId
,
themeId
));
}
//n天内所有主题
//n天内
发表的
所有主题
public
List
<
ThemeEntity
>
queryRecentdays
(
Integer
days
)
{
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
())
...
...
@@ -197,29 +199,19 @@ public class ThemeService {
}
/**
* 根据话题查询最新主题(可分页)
*
* @param topidId 话题Id
* @param lastId 查询此主题Id之前的主题
* @param pageSize 查询数量
* @return
*/
public
List
<
ThemeEntity
>
query
ByTopic
(
String
topidId
,
String
lastId
,
Integer
pageSize
)
{
public
List
<
ThemeEntity
>
query
NewestByTopic
(
String
topidId
,
Integer
pageNo
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getTopicId
,
topidId
);
if
(
StringUtils
.
isNotEmpty
(
lastId
))
{
ThemeEntity
lastEntity
=
queryByThemeId
(
lastId
);
if
(
lastEntity
==
null
)
throw
new
BizException
(
"主题未找到,id:"
+
lastId
);
queryWrapper
.
lt
(
ThemeEntity:
:
getUpdateTime
,
lastEntity
.
getCreateTime
());
}
if
(
pageSize
!=
null
)
{
queryWrapper
.
last
(
"limit "
+
pageSize
);
}
queryWrapper
.
orderByDesc
(
ThemeEntity:
:
getCreateTime
);
queryWrapper
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
.
eq
(
ThemeEntity:
:
getTopicId
,
topidId
)
.
last
(
"limit "
+
pageNo
+
", "
+
pageSize
)
.
orderByDesc
(
ThemeEntity:
:
getCreateTime
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
return
themeMapper
.
selectList
(
queryWrapper
);
}
...
...
@@ -234,64 +226,26 @@ public class ThemeService {
return
themeMapper
.
selectList
(
queryWrapper
).
stream
().
map
(
ThemeEntity:
:
getThemeId
).
collect
(
Collectors
.
toList
());
}
/**
* 根据作者查询主题列表(可分页)
*
* 根据作者查询主题分页列表
* @param userIds
* @param
lastId
* @param
pageStart
* @param pageSize
* @return
*/
public
List
<
ThemeEntity
>
queryByUserIds
(
List
<
String
>
userIds
,
String
lastId
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
);
if
(
StringUtils
.
isNotEmpty
(
lastId
))
{
ThemeEntity
lastEntity
=
queryByThemeId
(
lastId
);
if
(
lastEntity
==
null
)
throw
new
BizException
(
"主题未找到,id:"
+
lastId
);
queryWrapper
.
lt
(
ThemeEntity:
:
getUpdateTime
,
lastEntity
.
getCreateTime
());
}
queryWrapper
.
last
(
"limit "
+
pageSize
);
queryWrapper
.
orderByDesc
(
ThemeEntity:
:
getCreateTime
);
queryWrapper
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
return
themeMapper
.
selectList
(
queryWrapper
);
}
/**
* 根据关键字搜索
*
* @param keyword
* @param lastId
* @param pageSize
* @return
*/
public
List
<
ThemeEntity
>
search
(
String
keyword
,
String
lastId
,
Integer
pageSize
)
{
if
(
StringUtils
.
isEmpty
(
keyword
))
{
public
List
<
ThemeEntity
>
queryByUserIds
(
List
<
String
>
userIds
,
Integer
pageStart
,
Integer
pageSize
)
{
if
(
CollectionUtils
.
isEmpty
(
userIds
)){
return
Collections
.
emptyList
();
}
LambdaQueryWrapper
<
ThemeEntity
>
queryWrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
like
(
ThemeEntity:
:
getTitle
,
keyword
);
if
(
StringUtils
.
isNotEmpty
(
lastId
))
{
ThemeEntity
lastEntity
=
queryByThemeId
(
lastId
);
if
(
lastEntity
==
null
)
throw
new
BizException
(
"主题未找到,id:"
+
lastId
);
queryWrapper
.
lt
(
ThemeEntity:
:
getUpdateTime
,
lastEntity
.
getCreateTime
());
}
queryWrapper
.
last
(
"limit "
+
pageSize
);
queryWrapper
.
orderByDesc
(
ThemeEntity:
:
getCreateTime
);
queryWrapper
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
.
in
(
ThemeEntity:
:
getAuthorId
,
userIds
)
.
last
(
"limit "
+
pageStart
+
", "
+
pageSize
)
.
orderByDesc
(
ThemeEntity:
:
getCreateTime
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
.
getCode
());
return
themeMapper
.
selectList
(
queryWrapper
);
}
//查询对应话题的发表用户集合
public
Set
<
String
>
getPostUserCount
(
List
<
String
>
themeIds
)
{
return
themeMapper
.
selectBatchIds
(
themeIds
).
stream
()
.
map
(
ThemeEntity:
:
getAuthorId
)
.
collect
(
Collectors
.
toSet
());
}
public
Integer
getForwardCountById
(
String
themeId
)
{
return
themeMapper
.
selectCount
(
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getFormerThemeId
,
themeId
)
...
...
@@ -345,4 +299,18 @@ public class ThemeService {
themeEntity
.
setReportStatus
(
ReportStatusEnum
.
REPORTED
.
getCode
());
themeMapper
.
updateById
(
themeEntity
);
}
//统计主题集合的浏览量
public
Map
<
String
,
Integer
>
getForwardCountMap
(
List
<
String
>
themeIds
)
{
if
(
CollectionUtils
.
isEmpty
(
themeIds
)){
return
new
HashMap
<
String
,
Integer
>();
}
LambdaQueryWrapper
<
ThemeEntity
>
wrapper
=
new
LambdaQueryWrapper
<
ThemeEntity
>()
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
)
.
in
(
ThemeEntity:
:
getFormerThemeId
,
themeIds
)
.
groupBy
(
ThemeEntity:
:
getFormerThemeId
);
return
themeMapper
.
selectCountByThemeIds
(
wrapper
).
stream
()
.
collect
(
Collectors
.
toMap
(
TimesCountEntity:
:
getId
,
TimesCountEntity:
:
getTimes
));
}
}
community-service/src/main/java/com/tanpu/community/service/VisitSummaryService.java
View file @
3d002630
package
com
.
tanpu
.
community
.
service
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.
baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.
tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.VisitTypeEnum
;
import
com.tanpu.community.dao.entity.community.TimesCountEntity
;
import
com.tanpu.community.dao.entity.community.VisitSummaryEntity
;
import
com.tanpu.community.dao.mapper.community.VisitSummaryMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.ListUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@Slf4j
...
...
@@ -24,6 +26,7 @@ public class VisitSummaryService {
@Resource
private
VisitSummaryMapper
visitSummaryMapper
;
// 从refIds中去掉用户已经访问过的
public
List
<
String
>
filterUserNotVisited
(
String
userId
,
List
<
String
>
refIds
)
{
if
(
refIds
.
isEmpty
())
{
return
refIds
;
...
...
@@ -34,6 +37,14 @@ public class VisitSummaryService {
.
stream
().
map
(
VisitSummaryEntity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
return
ListUtils
.
subtract
(
refIds
,
visited
);
}
public
List
<
String
>
queryUserVisited
(
String
userId
)
{
List
<
String
>
visited
=
visitSummaryMapper
.
selectList
(
new
LambdaQueryWrapper
<
VisitSummaryEntity
>()
.
eq
(
VisitSummaryEntity:
:
getVisitorId
,
userId
))
.
stream
().
map
(
VisitSummaryEntity:
:
getRefId
).
distinct
().
collect
(
Collectors
.
toList
());
return
visited
;
}
@Transactional
public
void
insertOrUpdateDur
(
VisitSummaryEntity
vs
)
{
...
...
@@ -45,6 +56,7 @@ public class VisitSummaryService {
}
@Transactional
//TODO 临时埋点,接入新埋点后删除
public
void
addPageView
(
String
userId
,
String
targetId
,
VisitTypeEnum
type
)
{
visitSummaryMapper
.
insert
(
VisitSummaryEntity
.
builder
()
.
visitorId
(
userId
)
...
...
@@ -89,4 +101,18 @@ public class VisitSummaryService {
return
visitSummaryEntities
.
get
(
0
).
getCreateTime
();
}
}
//统计主题集合的浏览量
public
Map
<
String
,
Integer
>
getCountMapByTargetIds
(
List
<
String
>
refIds
,
VisitTypeEnum
type
)
{
if
(
CollectionUtils
.
isEmpty
(
refIds
)){
return
new
HashMap
<>();
}
LambdaQueryWrapper
<
VisitSummaryEntity
>
wrapper
=
(
new
LambdaQueryWrapper
<
VisitSummaryEntity
>()
.
in
(
VisitSummaryEntity:
:
getRefId
,
refIds
))
.
eq
(
VisitSummaryEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
)
.
eq
(
VisitSummaryEntity:
:
getRefType
,
type
.
getCode
())
.
groupBy
(
VisitSummaryEntity:
:
getRefId
);
return
visitSummaryMapper
.
selectCountByThemeIds
(
wrapper
).
stream
()
.
collect
(
Collectors
.
toMap
(
TimesCountEntity:
:
getId
,
TimesCountEntity:
:
getTimes
));
}
}
community-service/src/main/java/com/tanpu/community/service/base/ESHelper.java
View file @
3d002630
...
...
@@ -22,6 +22,7 @@ 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.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.elasticsearch.client.*
;
...
...
@@ -35,14 +36,16 @@ import java.util.Map;
@Service
public
class
ESHelper
{
@Value
(
"${es.index}"
)
private
String
esIndex
;
@Autowired
private
RestHighLevelClient
client
;
public
void
insert
(
String
index
,
String
type
,
String
id
,
String
json
)
{
public
void
insert
(
String
type
,
String
id
,
String
json
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
i
ndex
);
IndexRequest
req
=
new
IndexRequest
(
esI
ndex
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
...
...
@@ -55,9 +58,9 @@ public class ESHelper {
}
}
public
void
insert
(
String
index
,
String
type
,
String
id
,
Map
<
String
,
Object
>
data
)
{
public
void
insert
(
String
type
,
String
id
,
Map
<
String
,
Object
>
data
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
i
ndex
);
IndexRequest
req
=
new
IndexRequest
(
esI
ndex
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
...
...
@@ -70,9 +73,9 @@ public class ESHelper {
}
}
public
SearchHit
[]
selectLike
(
S
tring
index
,
S
earchSourceBuilder
builder
)
{
public
SearchHit
[]
selectLike
(
SearchSourceBuilder
builder
)
{
try
{
SearchRequest
req
=
new
SearchRequest
(
i
ndex
);
SearchRequest
req
=
new
SearchRequest
(
esI
ndex
);
req
.
source
(
builder
);
SearchResponse
resp
=
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
OK
);
...
...
@@ -149,7 +152,7 @@ public class ESHelper {
search
.
query
(
boolQb
).
from
(
0
).
size
(
50
);
SearchHit
[]
hits
=
helper
.
selectLike
(
"theme"
,
search
);
SearchHit
[]
hits
=
helper
.
selectLike
(
search
);
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
View file @
3d002630
...
...
@@ -16,6 +16,7 @@ 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.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
...
...
@@ -29,8 +30,6 @@ public class ESService {
@Autowired
private
ESHelper
helper
;
private
static
final
String
INDEX_THEME
=
"theme"
;
public
void
insertOrUpdateThemes
(
List
<
ESThemeQo
>
qos
)
{
for
(
ESThemeQo
qo
:
qos
)
{
insertOrUpdateTheme
(
qo
);
...
...
@@ -38,7 +37,7 @@ public class ESService {
}
// 只要设置了_id,则直接覆盖
public
void
insertOrUpdateTheme
(
ESThemeQo
qo
)
{
helper
.
insert
(
INDEX_THEME
,
String
.
valueOf
(
qo
.
themeType
),
qo
.
themeId
,
JSON
.
toJSONString
(
qo
));
helper
.
insert
(
String
.
valueOf
(
qo
.
themeType
),
qo
.
themeId
,
JSON
.
toJSONString
(
qo
));
}
public
List
<
ESThemeQo
>
queryThemeIdByContentAndTitle
(
String
keyword
,
int
from
,
int
size
)
{
...
...
@@ -55,7 +54,7 @@ public class ESService {
search
.
query
(
boolQb
).
fetchSource
(
includes
,
excludes
).
sort
(
"createTime"
,
SortOrder
.
DESC
).
from
(
from
).
size
(
size
);
search
.
query
(
boolQb
).
sort
(
"createTime"
,
SortOrder
.
DESC
).
from
(
from
).
size
(
size
);
SearchHit
[]
hits
=
helper
.
selectLike
(
INDEX_THEME
,
search
);
SearchHit
[]
hits
=
helper
.
selectLike
(
search
);
return
Arrays
.
stream
(
hits
).
map
(
h
->
{
return
JsonUtil
.
toBean
(
h
.
getSourceAsString
(),
ESThemeQo
.
class
);
}).
collect
(
Collectors
.
toList
());
...
...
community-service/src/main/java/com/tanpu/community/util/BizUtils.java
0 → 100644
View file @
3d002630
package
com
.
tanpu
.
community
.
util
;
import
com.alibaba.fastjson.JSON
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
BizUtils
{
public
static
<
T
>
List
<
T
>
subList
(
List
<
T
>
list
,
int
start
,
int
size
)
{
if
(
list
.
isEmpty
()
||
start
>=
list
.
size
()
||
start
<
0
)
{
return
new
ArrayList
<>();
}
int
realEnd
=
Math
.
min
(
start
+
size
,
list
.
size
());
return
list
.
subList
(
start
,
realEnd
);
}
}
community-service/src/main/resources/application-dev.yml
View file @
3d002630
apollo.bootstrap.enabled
:
fals
e
apollo.bootstrap.enabled
:
tru
e
#app.id: tanpu-community
#apollo:
...
...
@@ -97,6 +97,7 @@ es:
port
:
9200
userName
:
1
userPasswd
:
2
index
:
dev
tencent
:
cloud
:
...
...
community-service/src/main/resources/application-test.yml
0 → 100644
View file @
3d002630
apollo.bootstrap.enabled
:
true
#app.id: tanpu-community
#apollo:
# meta: http://dev-apollo.tamp-innner.com:8080
# cacheDir: ./apollocache/
# bootstrap:
# namespaces: application.yml
server
:
port
:
8060
servlet
:
context-path
:
/community
spring.datasource
:
community
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_community?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username
:
tamp_admin
password
:
'
@imeng123'
maxActive
:
2
minIdle
:
2
initialSize
:
2
user
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
password
:
'
@imeng123'
maxActive
:
2
minIdle
:
2
initialSize
:
2
jydb
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_jydb?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username
:
tamp_admin
password
:
'
@imeng123'
maxActive
:
2
minIdle
:
2
initialSize
:
2
fund
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://rm-uf6r22t3d798q4kmk.mysql.rds.aliyuncs.com:3306/tamp_fund?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull
username
:
tamp_admin
password
:
'
@imeng123'
maxActive
:
2
minIdle
:
2
initialSize
:
2
spring.redis
:
host
:
118.190.63.109
port
:
56379
password
:
qimeng123
timeout
:
2000
max-active
:
5
max-wait
:
5
max-idle
:
5
jedis
:
pool
:
max-active
:
3
max-idle
:
3
min-idle
:
3
spring.kafka
:
bootstrap-servers
:
118.190.63.109:9092
consumer
:
group-id
:
tp_group_new_community
auto-offset-reset
:
latest
fetch-min-size
:
64
fetch-max-wait
:
500
max-poll-records
:
500
key-deserializer
:
org.apache.kafka.common.serialization.StringDeserializer
value-deserializer
:
org.apache.kafka.common.serialization.StringDeserializer
producer
:
acks
:
1
batch-size
:
10000
key-serializer
:
org.apache.kafka.common.serialization.StringSerializer
value-serializer
:
org.apache.kafka.common.serialization.StringSerializer
spring
:
sleuth
:
enabled
:
false
zipkin
:
enabled
:
false
aliyun
:
oss
:
endpoint
:
http://oss-cn-shanghai.aliyuncs.com
accessId
:
LTAIAKEzVydP0Q9P
accessSK
:
59V9ke9txaIFzWxHFKTb1eoOOpmKpJ
bucketName
:
tamp-sit
es
:
host
:
42.194.224.208
port
:
9200
userName
:
1
userPasswd
:
2
tencent
:
cloud
:
secretId
:
AKIDTjjV2IhK4ZKBm8z5g14vPedNSJuFnTIq
secretKey
:
PaVBZfeQwDVXKr7TZOzM6c9VZNwGJGyA
region
:
ap-shanghai
recommend
:
ratio
:
#主题推荐比例(热门、最新、机器学习)
hot
:
3
new
:
2
python
:
1
python
:
enable
:
false
url
:
http://172.168.0.164:9000/api/get_recommend?user_id=2431614397151511
\ No newline at end of file
community-service/src/main/resources/mapper/community/CollectionEntityMapper.xml
View file @
3d002630
...
...
@@ -15,4 +15,11 @@
<result
column=
"delete_tag"
property=
"deleteTag"
/>
</resultMap>
<resultMap
id=
"CountResultMap"
type=
"com.tanpu.community.dao.entity.community.TimesCountEntity"
>
<id
column=
"id"
property=
"id"
/>
<result
column=
"collection_type"
property=
"collectionType"
/>
<result
column=
"target_id"
property=
"targetId"
/>
<result
column=
"times"
property=
"times"
/>
</resultMap>
</mapper>
docs/create.sql
View file @
3d002630
This diff is collapsed.
Click to expand it.
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