Commit 594e922c authored by 刘基明's avatar 刘基明

空值修复

parent 3b52355a
...@@ -112,6 +112,8 @@ public class RankService { ...@@ -112,6 +112,8 @@ public class RankService {
if (topicRankQos.size() == 0) { if (topicRankQos.size() == 0) {
return; return;
} }
List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList());
Map<String, Integer> countMapByTargetIds = visitSummaryService.getCountMapByTargetIds(topicIds, VisitTypeEnum.TOPIC_PAGE_VIEW);
for (TopicRankQo topic : topicRankQos) { for (TopicRankQo topic : topicRankQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId()); List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)) { if (CollectionUtils.isEmpty(themeIds)) {
...@@ -120,8 +122,7 @@ public class RankService { ...@@ -120,8 +122,7 @@ public class RankService {
continue; continue;
} }
// 浏览量 // 浏览量
// todo 批量查询 Integer topicPV = countMapByTargetIds.getOrDefault(topic.getTopicId(),0);
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
Integer themePV = visitSummaryService.queryThemeVisit(themeIds); Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV); topic.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数 //讨论数=发布主题贴数+回复总数
......
...@@ -66,12 +66,16 @@ public class RecommendService { ...@@ -66,12 +66,16 @@ public class RecommendService {
List<String> recThemeIds = getPythonRecommendList(userId); List<String> recThemeIds = getPythonRecommendList(userId);
// 混合 如果重新搜索,则刷新返回id // 混合 如果重新搜索,则刷新返回id
Set<String> returnedIds = (StringUtils.isEmpty(lastId)) || !returnedIdsMap.containsKey(userId) Set<String> viewedThemeIds = (StringUtils.isEmpty(lastId)) || !returnedIdsMap.containsKey(userId)
|| returnedIdsMap.get(userId) == null ? || returnedIdsMap.get(userId) == null ?
new HashSet<>() : returnedIdsMap.get(userId); new HashSet<>() : returnedIdsMap.get(userId);
viewedThemeIds.addAll(visitSummaryService.queryUseVisited(userId));
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
getResultList(hotThemeIds, 0, newThemeIds, 0, recThemeIds, 0, returnedIds, result, pageSize, userId); getResultList(hotThemeIds, 0, newThemeIds, 0, recThemeIds, 0, viewedThemeIds, result, pageSize, userId);
// List<String> result = mergeList(hotThemeIds, newThemeIds, recThemeIds,viewedThemeIds);
result = result.stream().limit(pageSize).collect(Collectors.toList()); result = result.stream().limit(pageSize).collect(Collectors.toList());
//记录已返回主题id //记录已返回主题id
if (StringUtils.isEmpty(lastId)) { if (StringUtils.isEmpty(lastId)) {
returnedIdsMap.put(userId, new HashSet<>(result)); returnedIdsMap.put(userId, new HashSet<>(result));
...@@ -127,8 +131,10 @@ public class RecommendService { ...@@ -127,8 +131,10 @@ public class RecommendService {
} }
private List<String> mergeList(List<String> hotThemeIds, List<String> newThemeIds, List<String> recThemeIds) { // 合并,去重
private List<String> mergeList(List<String> hotThemeIds, List<String> newThemeIds, List<String> recThemeIds, Set<String> set) {
ArrayList<String> result = new ArrayList<>(); ArrayList<String> result = new ArrayList<>();
// 3个集合的指针
Integer hotIdx = 0; Integer hotIdx = 0;
Integer newIdx = 0; Integer newIdx = 0;
Integer recIdx = 0; Integer recIdx = 0;
...@@ -139,19 +145,31 @@ public class RecommendService { ...@@ -139,19 +145,31 @@ public class RecommendService {
String id; String id;
while (hotTimes > 0 && hotThemeIds.size() > hotIdx) { while (hotTimes > 0 && hotThemeIds.size() > hotIdx) {
id = hotThemeIds.get(hotIdx); id = hotThemeIds.get(hotIdx);
if (!set.contains(id)){
result.add(id); result.add(id);
set.add(id);
}
hotIdx++; hotIdx++;
hotTimes--; hotTimes--;
} }
while (newTimes > 0 && newThemeIds.size() > newIdx) { while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = newThemeIds.get(newIdx); id = newThemeIds.get(newIdx);
if (!set.contains(id)){
result.add(id); result.add(id);
set.add(id);
}
newIdx++; newIdx++;
newTimes--; newTimes--;
} }
while (recTimes > 0 && recThemeIds.size() > recIdx) { while (recTimes > 0 && recThemeIds.size() > recIdx) {
id = recThemeIds.get(recIdx); id = recThemeIds.get(recIdx);
if (!set.contains(id)){
result.add(id); result.add(id);
set.add(id);
}
recIdx++; recIdx++;
recTimes--; recTimes--;
} }
......
...@@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -92,9 +93,12 @@ public class VisitSummaryService { ...@@ -92,9 +93,12 @@ public class VisitSummaryService {
} }
//统计主题集合的浏览量 //统计主题集合的浏览量
public Map<String, Integer> getCountMapByThemeIds(List<String> themeIds,VisitTypeEnum type) { public Map<String, Integer> getCountMapByTargetIds(List<String> refIds, VisitTypeEnum type) {
if (CollectionUtils.isEmpty(refIds)){
return new HashMap<>();
}
LambdaQueryWrapper<VisitSummaryEntity> wrapper = (new LambdaQueryWrapper<VisitSummaryEntity>() LambdaQueryWrapper<VisitSummaryEntity> wrapper = (new LambdaQueryWrapper<VisitSummaryEntity>()
.in(VisitSummaryEntity::getRefId,themeIds)) .in(VisitSummaryEntity::getRefId,refIds))
.eq(VisitSummaryEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED) .eq(VisitSummaryEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitSummaryEntity::getRefType,type.getCode()) .eq(VisitSummaryEntity::getRefType,type.getCode())
.groupBy(VisitSummaryEntity::getRefId); .groupBy(VisitSummaryEntity::getRefId);
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment