Commit 08e0f0eb authored by 刘基明's avatar 刘基明

Merge branch 'bugfix_1208' into 'master'

Bugfix 1208

See merge request !31
parents 4a3fa523 0552c522
...@@ -49,4 +49,7 @@ public class CourseSimpleResp { ...@@ -49,4 +49,7 @@ public class CourseSimpleResp {
@ApiModelProperty("状态 0:待上架 1:上架 2:下架") @ApiModelProperty("状态 0:待上架 1:上架 2:下架")
private Integer status; private Integer status;
@ApiModelProperty("付费模式 1:免费 2:积分 3:现金")
private Integer modal;
} }
...@@ -14,7 +14,7 @@ public class RedisCache { ...@@ -14,7 +14,7 @@ public class RedisCache {
private String cacheName; private String cacheName;
private RedisHelper redisHelper; private RedisHelper redisHelper;
public<T> T getObject(String key, Integer expireSeconds, Supplier<T> func, Class<T> clz) { public <T> T getObject(String key, Integer expireSeconds, Supplier<T> func, Class<T> clz) {
String value = get(key); String value = get(key);
// todo 考虑缓存穿透的问题. // todo 考虑缓存穿透的问题.
if (StringUtils.isNotBlank(value)) { if (StringUtils.isNotBlank(value)) {
...@@ -80,6 +80,15 @@ public class RedisCache { ...@@ -80,6 +80,15 @@ public class RedisCache {
} }
} }
public boolean setIfAbsent(String key, String value, Integer expireSeconds) {
key = cacheName + ":" + key;
if (expireSeconds == 0) {
return redisHelper.setIfAbsent(key, value);
} else {
return redisHelper.setIfAbsent(key, value, Duration.ofSeconds(expireSeconds));
}
}
private void delete(String key) { private void delete(String key) {
redisHelper.delete(key); redisHelper.delete(key);
} }
......
...@@ -11,6 +11,6 @@ public class TimesCountEntity { ...@@ -11,6 +11,6 @@ public class TimesCountEntity {
@ApiModelProperty(value = "次数") @ApiModelProperty(value = "次数")
private Integer times; private Integer times;
@ApiModelProperty(value = "目标id") @ApiModelProperty(value = "统计对象id")
private String id; private String id;
} }
...@@ -30,7 +30,7 @@ public class ConJobManager { ...@@ -30,7 +30,7 @@ public class ConJobManager {
/** /**
* 定时统计 话题 访问数据,并刷到redis * 定时统计 话题 访问数据,并刷到redis
*/ */
@Scheduled(cron = "*/10 * * * * ?") // @Scheduled(cron = "*/10 * * * * ?")
public void topicVisitorStats() { public void topicVisitorStats() {
String topicId = "123"; String topicId = "123";
Integer detailVisitTimes = visitLogService.queryTopicDetailVisit(topicId); Integer detailVisitTimes = visitLogService.queryTopicDetailVisit(topicId);
...@@ -40,16 +40,16 @@ public class ConJobManager { ...@@ -40,16 +40,16 @@ public class ConJobManager {
/** /**
* 定时统计主题、话题排行 * 定时统计主题、话题排行
*/ */
@Scheduled(cron = "*/30 * * * * ?") @Scheduled(cron = "10 0/2 * * * ?")
public void themeRank() { public void themeRank() {
rankService.rankThemes(); rankService.rankThemes();
rankService.rankTopics(); rankService.rankTopics();
} }
/** /**
* 定时统计主题、话题排行 * 定时刷新最新帖子
*/ */
@Scheduled(cron = "*/5 * * * * ?") @Scheduled(cron = "*/10 * * * * ?")
public void getThemeNewest() { public void getThemeNewest() {
recommendService.refreshNewestThemes(); recommendService.refreshNewestThemes();
} }
......
...@@ -555,11 +555,12 @@ public class ThemeManager { ...@@ -555,11 +555,12 @@ public class ThemeManager {
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities); List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
// 批量查询附件detail // 批量查询附件detail
batchFeignCallService.getAttachDetailByBatch(themeQos); batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息 // 转赞评
for (ThemeQo themeQO : themeQos) { batchBuildThemeCountInfo(themeQos);
// 通用信息
buildThemeQoExtraInfo(themeQO);
// 转发对象
for (ThemeQo themeQO : themeQos) {
buildThemeForwardObj(themeQO);
} }
// 和用户相关信息 // 和用户相关信息
if (StringUtils.isNotEmpty(userId)) { if (StringUtils.isNotEmpty(userId)) {
...@@ -568,29 +569,50 @@ public class ThemeManager { ...@@ -568,29 +569,50 @@ public class ThemeManager {
return themeQos; return themeQos;
} }
// 转发对象、点赞、收藏、转发数 // 转发对象
private void buildThemeQoExtraInfo(ThemeQo themeQo) { private void buildThemeForwardObj(ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
// 封装转发对象 // 封装转发对象
FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORWARD_THEME_ID, themeQo.getFormerThemeId()), 60, FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORWARD_THEME_ID, themeQo.getFormerThemeId()), 60,
() -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class); () -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class);
themeQo.setFormerTheme(former); themeQo.setFormerTheme(former);
}
// 单个查询 点赞、收藏、转发数
private void buildThemeCountInfo(ThemeQo themeQo) {
String themeId = themeQo.getThemeId();
// 点赞,收藏,转发 // 点赞,收藏,转发
Integer likeCount = redisCache.getObject(StringUtils.joinWith("_", THEME_LIKE_COUNT, themeId), 60, Integer likeCount = redisCache.getObject(StringUtils.joinWith("_", THEME_LIKE_COUNT, themeId), 60 * 60 * 24,
() -> collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME), Integer.class); () -> collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME), Integer.class);
Integer commentCount = redisCache.getObject(StringUtils.joinWith("_", THEME_COMMENT_COUNT, themeId), 60, Integer commentCount = redisCache.getObject(StringUtils.joinWith("_", THEME_COMMENT_COUNT, themeId), 60 * 60 * 24,
() -> commentService.getCommentCountByThemeId(themeId), Integer.class); () -> commentService.getCommentCountByThemeId(themeId), Integer.class);
Integer forwardCount = redisCache.getObject(StringUtils.joinWith("_", THEME_FORWARD_COUNT, themeId), 60, Integer forwardCount = redisCache.getObject(StringUtils.joinWith("_", THEME_FORWARD_COUNT, themeId), 60 * 60 * 24,
() -> themeService.getForwardCountById(themeId), Integer.class); () -> themeService.getForwardCountById(themeId), Integer.class);
themeQo.setCommentCount(commentCount); themeQo.setCommentCount(commentCount);
themeQo.setLikeCount(likeCount); themeQo.setLikeCount(likeCount);
themeQo.setForwardCount(forwardCount); themeQo.setForwardCount(forwardCount);
} }
// 批量-点赞、收藏、转发数
private void batchBuildThemeCountInfo(List<ThemeQo> themeQos) {
List<String> themeIds = themeQos.stream().map(ThemeQo::getThemeId).collect(Collectors.toList());
// 点赞,收藏,转发
Map<String, Integer> likeCountMap = collectionService.getCountMapByType(themeIds, CollectionTypeEnum.LIKE_THEME);
Map<String, Integer> commentCountMap = commentService.getCountMapByThemeIds(themeIds);
Map<String, Integer> forwardCountMap = themeService.getForwardCountMap(themeIds);
themeQos.stream().forEach(o -> {
o.setCommentCount(commentCountMap.getOrDefault(o.getThemeId(), 0));
o.setLikeCount(likeCountMap.getOrDefault(o.getThemeId(), 0));
o.setForwardCount(forwardCountMap.getOrDefault(o.getThemeId(), 0));
});
}
// 组装和当前用户相关信息(单个查询) // 组装和当前用户相关信息(单个查询)
private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) { private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
...@@ -688,7 +710,8 @@ public class ThemeManager { ...@@ -688,7 +710,8 @@ public class ThemeManager {
batchFeignCallService.getAttachDetail(themeQo); batchFeignCallService.getAttachDetail(themeQo);
//转发、收藏、点赞 //转发、收藏、点赞
buildThemeQoExtraInfo(themeQo); buildThemeForwardObj(themeQo);
buildThemeCountInfo(themeQo);
// 添加用户相关信息 // 添加用户相关信息
if (StringUtils.isNotEmpty(userId)) { if (StringUtils.isNotEmpty(userId)) {
...@@ -832,13 +855,13 @@ public class ThemeManager { ...@@ -832,13 +855,13 @@ public class ThemeManager {
while (content.length() > 5000) { while (content.length() > 5000) {
b = TencentcloudUtils.textModeration(content.substring(0, 5000)); b = TencentcloudUtils.textModeration(content.substring(0, 5000));
if (StringUtils.isNotBlank(b)) { if (StringUtils.isNotBlank(b)) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(),"疑似违规词汇:"+b); throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(), "疑似违规词汇:" + b);
} }
content = content.substring(5000); content = content.substring(5000);
} }
b = TencentcloudUtils.textModeration(content); b = TencentcloudUtils.textModeration(content);
if (StringUtils.isNotBlank(b)) { if (StringUtils.isNotBlank(b)) {
throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(),"疑似违规词汇:"+b); throw new BizException(ErrorCodeConstant.CONTENT_ILLEGAL.getCode(), "疑似违规词汇:" + b);
} }
......
...@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils; ...@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.time.DateUtils;
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 org.springframework.transaction.annotation.Transactional;
...@@ -20,7 +19,6 @@ import javax.annotation.Resource; ...@@ -20,7 +19,6 @@ import javax.annotation.Resource;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
......
...@@ -135,9 +135,17 @@ public class RankService { ...@@ -135,9 +135,17 @@ public class RankService {
hotestThemes = themeAnalysDOS.stream() hotestThemes = themeAnalysDOS.stream()
.sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed()) .sorted(Comparator.comparing(ThemeAnalysDO::getScore).reversed())
.collect(Collectors.toList()); .collect(Collectors.toList());
//落库
// 落库
try {
if (redisCache.setIfAbsent("logThemeRank","1",15)){
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start)); rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
} }
}finally {
redisCache.evict("logThemeRank");
}
}
/** /**
......
...@@ -95,7 +95,7 @@ tmpfile: ...@@ -95,7 +95,7 @@ tmpfile:
tanpu: tanpu:
fatools: fatools:
svc: 127.0.0.1:8189 svc: https://testtamper.tanpuyun.com
product: product:
svc: https://testtamper.tanpuyun.com svc: https://testtamper.tanpuyun.com
jifen: jifen:
...@@ -118,7 +118,7 @@ tanpu: ...@@ -118,7 +118,7 @@ tanpu:
#打印SQL语句 #打印SQL语句
logging: logging:
level: level:
com.tanpu.community.dao: debug com.tanpu.community.dao: info
org.springframework.jdbc.core.JdbcTemplate: debug org.springframework.jdbc.core.JdbcTemplate: debug
pagehelper: pagehelper:
......
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