Commit 4e912b47 authored by 张辰's avatar 张辰

Merge branch 'dev' of http://47.100.44.39:10001/tp-backend/tanpu-community into dev

# Conflicts:
#	community-service/src/main/java/com/tanpu/community/service/RecommendService.java
parents 402709b6 455de35f
......@@ -6,11 +6,13 @@ 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;
......@@ -83,6 +85,9 @@ public class CollectionService {
// 统计多个对象(主题、评论)的数量(点赞、收藏)
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()
......
......@@ -18,6 +18,7 @@ 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.Map;
import java.util.stream.Collectors;
......@@ -71,6 +72,9 @@ public class CommentService {
//统计主题集合的评论量
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)
......
package com.tanpu.community.service;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.exception.BizException;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoNew;
......@@ -59,6 +57,9 @@ public class RankService {
public void rankThemes() {
//7天内所有主题进行热度值排序
List<ThemeEntity> themeEntities = themeService.queryRecentdays(7);
if (CollectionUtils.isEmpty(themeEntities)){
return;
}
List<ThemeAnalysDO> themeAnalysDOS = ConvertUtil.themeEntityToAnalysDOs(themeEntities);
//批量查询
List<String> themeIds = themeAnalysDOS.stream().map(ThemeAnalysDO::getThemeId).collect(Collectors.toList());
......@@ -66,19 +67,15 @@ public class RankService {
Map<String, Integer> bookCountMap = collectionService.getCountMapByType(themeIds, CollectionTypeEnum.COLLECT_THEME);
Map<String, Integer> commentCountMap = commentService.getCountMapByThemeIds(themeIds);
Map<String, Integer> forwardCountMap = themeService.getForwardCountMap(themeIds);
Map<String, Integer> visitCountMap = visitSummaryService.getCountMapByThemeIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW);
Map<String, Integer> visitCountMap = visitSummaryService.getCountMapByTargetIds(themeIds, VisitTypeEnum.THEME_PAGE_VIEW);
for (ThemeAnalysDO theme : themeAnalysDOS) {
String themeId = theme.getThemeId();
Integer likeCount = likeCountMap.getOrDefault(themeId, 0);
Integer bookCount = bookCountMap.getOrDefault(themeId,0);
Integer commentCount = commentCountMap.getOrDefault(themeId,0);
Integer forwardCount = forwardCountMap.getOrDefault(themeId,0);
Integer viewCount = visitCountMap.getOrDefault(themeId,0);
theme.setCommentCount(commentCount);
theme.setLikeCount(likeCount);
theme.setForwardCount(forwardCount);
theme.setCollectCount(bookCount);
theme.setViewCount(viewCount);
theme.setCommentCount(commentCountMap.getOrDefault(themeId,0));
theme.setLikeCount(likeCountMap.getOrDefault(themeId, 0));
theme.setForwardCount(forwardCountMap.getOrDefault(themeId,0));
theme.setCollectCount(bookCountMap.getOrDefault(themeId,0));
theme.setViewCount(visitCountMap.getOrDefault(themeId,0));
//查询用户质量
String authorId = theme.getAuthorId();
UserInfoNew authorInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, authorId),
......@@ -107,10 +104,12 @@ public class RankService {
*/
public void rankTopics() {
List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
if (topicRankQos.size() == 0) {
if (CollectionUtils.isEmpty(topicEntities)) {
return;
}
List<TopicRankQo> topicRankQos = ConvertUtil.topicEntityToHotQos(topicEntities);
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) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
if (CollectionUtils.isEmpty(themeIds)) {
......@@ -119,8 +118,7 @@ public class RankService {
continue;
}
// 浏览量
// todo 批量查询
Integer topicPV = visitSummaryService.queryTopicDetailVisit(topic.getTopicId());
Integer topicPV = countMapByTargetIds.getOrDefault(topic.getTopicId(),0);
Integer themePV = visitSummaryService.queryThemeVisit(themeIds);
topic.setViewCount(topicPV + themePV);
//讨论数=发布主题贴数+回复总数
......
......@@ -113,8 +113,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<>();
// 3个集合的指针
Integer hotIdx = 0;
Integer newIdx = 0;
Integer recIdx = 0;
......@@ -125,19 +127,31 @@ public class RecommendService {
String id;
while (hotTimes > 0 && hotThemeIds.size() > hotIdx) {
id = hotThemeIds.get(hotIdx);
result.add(id);
if (!set.contains(id)){
result.add(id);
set.add(id);
}
hotIdx++;
hotTimes--;
}
while (newTimes > 0 && newThemeIds.size() > newIdx) {
id = newThemeIds.get(newIdx);
result.add(id);
if (!set.contains(id)){
result.add(id);
set.add(id);
}
newIdx++;
newTimes--;
}
while (recTimes > 0 && recThemeIds.size() > recIdx) {
id = recThemeIds.get(recIdx);
result.add(id);
if (!set.contains(id)){
result.add(id);
set.add(id);
}
recIdx++;
recTimes--;
}
......
......@@ -20,6 +20,7 @@ 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.Map;
import java.util.stream.Collectors;
......@@ -234,6 +235,9 @@ public class ThemeService {
* @return
*/
public List<ThemeEntity> queryByUserIds(List<String> userIds, String lastId, Integer pageSize) {
if (CollectionUtils.isEmpty(userIds)){
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds);
if (StringUtils.isNotEmpty(lastId)) {
......@@ -304,6 +308,9 @@ public class ThemeService {
//统计主题集合的浏览量
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)
......
......@@ -14,6 +14,7 @@ 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;
......@@ -36,6 +37,14 @@ public class VisitSummaryService {
.stream().map(VisitSummaryEntity::getRefId).distinct().collect(Collectors.toList());
return ListUtils.subtract(refIds, visited);
}
public List<String> queryUseVisited(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) {
......@@ -83,9 +92,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>()
.in(VisitSummaryEntity::getRefId,themeIds))
.in(VisitSummaryEntity::getRefId,refIds))
.eq(VisitSummaryEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.eq(VisitSummaryEntity::getRefType,type.getCode())
.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
CREATE TABLE `home_page` (
`id` int(32) auto_increment PRIMARY KEY COMMENT 'id',
`user_id` varchar(64) NOT NULL COMMENT '用户id',
......@@ -29,15 +30,17 @@ CREATE TABLE `follow_rel` (
CREATE TABLE `theme` (
`id` int(32) auto_increment PRIMARY KEY COMMENT 'id',
`theme_id` varchar(64) NOT NULL COMMENT 'UUID',
`theme_id` varchar(64) NOT NULL COMMENT '主题主键Id',
`title` varchar(64) COMMENT '标题',
`theme_type` int(4) NOT NULL COMMENT '类型',
`content` text COMMENT '文本内容',
`theme_type` int(4) NOT NULL COMMENT '类型 1:讨论无标题 2:长文有标题 3:转发',
`content` text COMMENT '文本内容(json),type:附件类型(8:文本,88:产品 3:直播 6:短视频 300:课程,9:图片 10:多图),productType:基金类型(0 公募,1 私募,2 白名单,3 私有)',
`attach_type` int(4) NOT NULL COMMENT '附件类型',
`attachment` text NOT NULL COMMENT '附件内容',
`discuss_content` text NOT NULL COMMENT '讨论中的文本',
`author_id` varchar(64) NOT NULL COMMENT '作者id',
`former_theme_id` varchar(64) COMMENT '被转发的主题',
`topic_id` varchar(64) NOT NULL COMMENT '所属的话题',
`is_pass` int(4) default 0 NOT NULL COMMENT '是否通过 0:初始值 1:已通过(管理后台使用)',
`report_status` int(4) default 0 NOT NULL COMMENT '举报状态 0:未被举报 1:被举报 2:已处理',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
......@@ -62,18 +65,18 @@ CREATE TABLE `theme_attachment` (
CREATE TABLE `comment` (
`id` int(32) auto_increment PRIMARY KEY NOT NULL COMMENT 'id',
`comment_id` varchar(64) NOT NULL COMMENT 'uuid',
`comment_id` varchar(64) NOT NULL COMMENT '评论主键Id',
`comment_type` int(4) NOT NULL COMMENT '类型',
`content` varchar(1024) DEFAULT NULL COMMENT '文本内容',
`author_id` varchar(64) NOT NULL COMMENT '作者id',
`theme_id` varchar(64) DEFAULT NULL COMMENT '主题id',
`parent_id` varchar(64) DEFAULT NULL COMMENT '一级评论id',
`reply_id` varchar(64) DEFAULT NULL COMMENT '回复评论id',
`is_block` int(4) NOT NULL DEFAULT '0' COMMENT '是否屏蔽',
`is_pass` int(4) default 0 NOT NULL COMMENT '是否通过 0:初始值 1:已通过(管理后台使用)',
`report_status` int(4) default 0 NOT NULL COMMENT '举报状态 0:未被举报 1:被举报 2:已处理',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `idx_author` (`author_id`) USING BTREE,
KEY `idx_target` (`reply_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='评论';
......@@ -129,7 +132,6 @@ CREATE TABLE `black_list` (
`blocker` varchar(64) NOT NULL COMMENT '屏蔽发起人',
`blocked_type` int(4) NOT NULL COMMENT '屏蔽类型,1:用户,2:内容',
`blocked_id` varchar(64) NOT NULL COMMENT '被屏蔽的',
`create_by` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
......@@ -137,21 +139,6 @@ CREATE TABLE `black_list` (
INDEX `uk_blocked` (`blocked_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='黑名单';
CREATE TABLE `black_list` (
`id` int(32) auto_increment PRIMARY KEY COMMENT 'id',
`blocker` varchar(64) NOT NULL COMMENT '屏蔽发起人',
`blocked_type` int(4) NOT NULL COMMENT '屏蔽类型',
`blocked_id` varchar(64) NOT NULL COMMENT '被屏蔽的',
`create_by` varchar(64) DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`delete_tag` int(3) NOT NULL DEFAULT '0',
INDEX `uk_blocker` (`blocker`),
INDEX `uk_blocked` (`blocked_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='黑名单';
CREATE TABLE `visit_summary` (
`id` int(32) auto_increment PRIMARY KEY COMMENT 'id',
`session_id` varchar(64) NOT NULL COMMENT 'session_id',
......@@ -176,6 +163,7 @@ CREATE TABLE `report_log` (
`report_type` int(4) NOT NULL COMMENT '举报类型,1:主题,2:评论 3、用户',
`target_id` varchar(64) NOT NULL COMMENT '举报对象id',
`target_user_id` varchar(64) NOT NULL COMMENT '举报对象作者id',
`report_reason` varchar(64) COMMENT '举报理由',
`report_time` datetime NOT NULL COMMENT '上报时间',
`deal_result` int(4) COMMENT '处理结果 0:无操作 1:屏蔽 2:删除 ',
`deal_user_id` int(4) COMMENT '处理管理员',
......
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