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
e3616ad3
Commit
e3616ad3
authored
Jul 20, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加返回接口参数
parent
af5e219d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
70 deletions
+31
-70
ConJobManager.java
.../main/java/com/tanpu/community/manager/ConJobManager.java
+4
-0
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+2
-1
TopicManager.java
...c/main/java/com/tanpu/community/manager/TopicManager.java
+5
-20
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+14
-12
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+6
-21
application-dev.yml
community-service/src/main/resources/application-dev.yml
+0
-16
No files found.
community-service/src/main/java/com/tanpu/community/manager/ConJobManager.java
View file @
e3616ad3
...
...
@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
@Slf4j
@Service
@Configuration
...
...
@@ -38,6 +40,8 @@ public class ConJobManager {
*/
@Scheduled
(
cron
=
"0 */2 * * * ?"
)
public
void
themeRank
()
{
System
.
out
.
println
(
LocalDateTime
.
now
());
rankService
.
rankThemes
();
rankService
.
rankTopics
();
}
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
e3616ad3
...
...
@@ -185,6 +185,7 @@ public class ThemeManager {
FormerThemeQo
f
=
ConvertUtil
.
themeQo2FormerThemeQo
(
themeQo
);
//ThemeContentQo和原主题包装到FormerThemeQo中包装到ThemeQo中
ThemeQo
commentThemeQo
=
ThemeQo
.
builder
()
.
authorId
(
userInfoEntity
.
getId
())
.
nickName
(
userInfoEntity
.
getUiUsernameMp
())
.
userImg
(
userInfoEntity
.
getUiHeadimgMp
())
.
content
(
Arrays
.
asList
(
commentContent
))
...
...
@@ -345,7 +346,7 @@ public class ThemeManager {
private
void
buildFormerTheme
(
ThemeQo
themeQo
)
{
String
formerThemeId
=
themeQo
.
getFormerThemeId
();
if
(
StringUtils
.
isNotEmpty
(
formerThemeId
))
{
ThemeQo
formerTheme
=
ConvertUtil
.
themeEntityToQo
2
(
themeService
.
queryByThemeId
(
formerThemeId
));
ThemeQo
formerTheme
=
ConvertUtil
.
themeEntityToQo
(
themeService
.
queryByThemeId
(
formerThemeId
));
if
(
formerTheme
!=
null
)
{
//单个查询详情
...
...
community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
View file @
e3616ad3
...
...
@@ -107,26 +107,11 @@ public class TopicManager {
public
List
<
TopicHotQo
>
getHotTopicTitles
()
{
// List<TopicEntity> topicEntities = topicService.queryAll();
// List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
// for (TopicHotQo topic : topicHotQos) {
// List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
// //浏览量
// Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
// Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
// topic.setViewCount(topicPV + themePV);
// //讨论数=发布主题贴数+回复总数
// Integer commentCount = commentService.getCommentCountByThemeIds(themeIds);
// topic.setDisscussCount(themeIds.size() + commentCount);
// }
// Map<TopicHotQo, Integer> map = topicHotQos.stream().collect(Collectors.toMap(o -> o, TopicHotQo::getRank));
// map.entrySet().stream().sorted(Comparator.)
//
// //TODO 添加类型:热 新 顶
// topicHotQos.get(0).setType(1);
// topicHotQos.get(2).setType(2);
// return topicHotQos;
return
rankService
.
rankTopics
();
List
<
TopicHotQo
>
rankTopicList
=
rankService
.
rankTopicList
;
if
(
rankTopicList
.
size
()==
0
){
rankService
.
rankTopics
();
}
return
rankService
.
rankTopicList
;
}
public
void
setTopTopic
(
String
topicId
,
boolean
setTop
)
{
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
e3616ad3
...
...
@@ -27,8 +27,9 @@ public class RankService {
private
VisitSummaryService
visitSummaryService
;
public
List
<
String
>
rankThemeList
=
new
ArrayList
<>();
public
List
<
String
>
rankThemeList
=
new
ArrayList
<>();
public
List
<
TopicHotQo
>
rankTopicList
=
new
ArrayList
<>();
public
void
rankThemes
()
{
...
...
@@ -52,15 +53,17 @@ public class RankService {
}
public
List
<
TopicHotQo
>
rankTopics
()
{
/**
* 计算话题热度
*
* @return
*/
public
void
rankTopics
()
{
List
<
TopicEntity
>
topicEntities
=
topicService
.
queryAll
();
List
<
TopicHotQo
>
topicHotQos
=
ConvertUtil
.
topicEntityToHotQos
(
topicEntities
);
if
(
topicHotQos
.
size
()
==
0
)
{
return
topicHotQos
;
return
;
}
TopicHotQo
lastTopic
=
topicHotQos
.
get
(
0
);
lastTopic
.
setType
(
TopicStatusEnum
.
NEWEST
.
getCode
());
for
(
TopicHotQo
topic
:
topicHotQos
)
{
List
<
String
>
themeIds
=
themeService
.
queryThemeIdsByTopic
(
topic
.
getTopicId
());
//浏览量
...
...
@@ -72,16 +75,15 @@ public class RankService {
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
}
Map
<
TopicHotQo
,
Integer
>
map
=
topicHotQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicHotQo:
:
getRank
));
List
<
TopicHotQo
>
rankList
=
map
.
entrySet
().
stream
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
e
->
e
.
getKey
()).
collect
(
Collectors
.
toList
());
List
<
TopicHotQo
>
rankList
=
map
.
entrySet
().
stream
().
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
())).
map
(
e
->
e
.
getKey
()).
limit
(
4
).
collect
(
Collectors
.
toList
());
rankList
.
get
(
0
).
setType
(
TopicStatusEnum
.
HOTTEST
.
getCode
());
Set
<
TopicHotQo
>
resultSet
=
rankList
.
stream
().
limit
(
4
).
collect
(
Collectors
.
toSet
());
resultSet
.
add
(
lastTopic
);
return
new
ArrayList
<>(
resultSet
);
rankTopicList
=
rankList
;
return
;
}
public
List
<
String
>
getHotAndNewThemes
(
Integer
hotCount
,
Integer
newCount
)
{
Set
<
String
>
hotThemeIds
=
this
.
rankThemeList
.
stream
().
limit
(
hotCount
).
collect
(
Collectors
.
toSet
());
public
List
<
String
>
getHotAndNewThemes
(
Integer
hotCount
,
Integer
newCount
)
{
Set
<
String
>
hotThemeIds
=
this
.
rankThemeList
.
stream
().
limit
(
hotCount
).
collect
(
Collectors
.
toSet
());
Set
<
String
>
newThemeIds
=
themeService
.
selectExcludeUser
(
null
,
null
,
newCount
)
.
stream
().
map
(
ThemeEntity:
:
getThemeId
).
collect
(
Collectors
.
toSet
());
hotThemeIds
.
addAll
(
newThemeIds
);
...
...
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
e3616ad3
...
...
@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.theme.CreateThemeReq;
import
com.tanpu.community.api.beans.req.theme.ThemeContentReq
;
import
com.tanpu.community.api.enums.DeleteTagEnum
;
import
com.tanpu.community.api.enums.RelTypeEnum
;
import
com.tanpu.community.api.enums.TopicStatusEnum
;
import
com.tanpu.community.dao.entity.community.*
;
import
com.tanpu.community.dao.entity.user.UserInfoEntity
;
import
org.springframework.beans.BeanUtils
;
...
...
@@ -24,20 +25,6 @@ import java.util.stream.Collectors;
public
class
ConvertUtil
{
public
static
ThemeQo
themeEntityToQo
(
ThemeEntity
themeEntity
)
{
if
(
themeEntity
==
null
)
{
return
null
;
}
ThemeQo
themeQO
=
new
ThemeQo
();
BeanUtils
.
copyProperties
(
themeEntity
,
themeQO
);
themeQO
.
setUpdateTime
(
TimeUtil
.
getTimestampOfDateTime
(
themeEntity
.
getUpdateTime
()));
themeQO
.
setCreateTime
(
TimeUtil
.
getTimestampOfDateTime
(
themeEntity
.
getCreateTime
()));
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
themeEntity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{
});
themeQO
.
setContent
(
themeContentQos
);
return
themeQO
;
}
public
static
ThemeQo
themeEntityToQo2
(
ThemeEntity
themeEntity
)
{
if
(
themeEntity
==
null
)
{
return
null
;
}
...
...
@@ -48,13 +35,7 @@ public class ConvertUtil {
themeQO
.
setUpToNowTime
(
TimeUtil
.
calUpToNowTime
(
themeEntity
.
getCreateTime
()));
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
themeEntity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{
});
//首页列表使用,限制附件个数为1(1文本+1附件),-》已经改为全部返回
// if (themeContentQos != null && themeContentQos.size() > 2) {
// themeQO.setContent(themeContentQos.subList(0, 2));
// }else{
themeQO
.
setContent
(
themeContentQos
);
// }
return
themeQO
;
}
...
...
@@ -73,7 +54,7 @@ public class ConvertUtil {
}
public
static
List
<
ThemeQo
>
themeEntitiesToDTOs
(
List
<
ThemeEntity
>
themeEntities
)
{
return
themeEntities
.
stream
().
map
(
ConvertUtil:
:
themeEntityToQo
2
).
collect
(
Collectors
.
toList
());
return
themeEntities
.
stream
().
map
(
ConvertUtil:
:
themeEntityToQo
).
collect
(
Collectors
.
toList
());
}
...
...
@@ -86,6 +67,10 @@ public class ConvertUtil {
public
static
TopicHotQo
topicEntityToHotQo
(
TopicEntity
topicEntity
)
{
TopicHotQo
topicHotQo
=
new
TopicHotQo
();
BeanUtils
.
copyProperties
(
topicEntity
,
topicHotQo
);
//2小时内发帖,添加新话题标签
if
(
TimeUtil
.
calMinuteTillNow
(
topicEntity
.
getCreateTime
())<
120
){
topicHotQo
.
setType
(
TopicStatusEnum
.
NEWEST
.
getCode
());
}
return
topicHotQo
;
}
...
...
community-service/src/main/resources/application-dev.yml
View file @
e3616ad3
...
...
@@ -22,14 +22,6 @@ spring.datasource:
maxActive
:
2
minIdle
:
2
initialSize
:
2
course
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://47.101.189.151:31931/tamp_course?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true
username
:
dev
password
:
qimeng123
maxActive
:
2
minIdle
:
2
initialSize
:
2
user
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://47.101.189.151:31931/tamp_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true
...
...
@@ -38,14 +30,6 @@ spring.datasource:
maxActive
:
2
minIdle
:
2
initialSize
:
2
zhibo
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://47.101.189.151:31931/tamp_zhibo?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&rewriteBatchedStatements=true
username
:
dev
password
:
qimeng123
maxActive
:
2
minIdle
:
2
initialSize
:
2
jydb
:
driver-class-name
:
com.mysql.cj.jdbc.Driver
jdbc-url
:
jdbc:mysql://47.101.189.151:31931/jydb?autoReconnect=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false
...
...
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