Commit e3616ad3 authored by 刘基明's avatar 刘基明

增加返回接口参数

parent af5e219d
...@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Configuration; ...@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@Slf4j @Slf4j
@Service @Service
@Configuration @Configuration
...@@ -38,6 +40,8 @@ public class ConJobManager { ...@@ -38,6 +40,8 @@ public class ConJobManager {
*/ */
@Scheduled(cron = "0 */2 * * * ?") @Scheduled(cron = "0 */2 * * * ?")
public void themeRank() { public void themeRank() {
System.out.println(LocalDateTime.now());
rankService.rankThemes(); rankService.rankThemes();
rankService.rankTopics();
} }
} }
...@@ -185,6 +185,7 @@ public class ThemeManager { ...@@ -185,6 +185,7 @@ public class ThemeManager {
FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(themeQo); FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(themeQo);
//ThemeContentQo和原主题包装到FormerThemeQo中包装到ThemeQo中 //ThemeContentQo和原主题包装到FormerThemeQo中包装到ThemeQo中
ThemeQo commentThemeQo = ThemeQo.builder() ThemeQo commentThemeQo = ThemeQo.builder()
.authorId(userInfoEntity.getId())
.nickName(userInfoEntity.getUiUsernameMp()) .nickName(userInfoEntity.getUiUsernameMp())
.userImg(userInfoEntity.getUiHeadimgMp()) .userImg(userInfoEntity.getUiHeadimgMp())
.content(Arrays.asList(commentContent)) .content(Arrays.asList(commentContent))
...@@ -345,7 +346,7 @@ public class ThemeManager { ...@@ -345,7 +346,7 @@ public class ThemeManager {
private void buildFormerTheme(ThemeQo themeQo) { private void buildFormerTheme(ThemeQo themeQo) {
String formerThemeId = themeQo.getFormerThemeId(); String formerThemeId = themeQo.getFormerThemeId();
if (StringUtils.isNotEmpty(formerThemeId)) { if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId)); ThemeQo formerTheme = ConvertUtil.themeEntityToQo(themeService.queryByThemeId(formerThemeId));
if (formerTheme != null) { if (formerTheme != null) {
//单个查询详情 //单个查询详情
......
...@@ -107,26 +107,11 @@ public class TopicManager { ...@@ -107,26 +107,11 @@ public class TopicManager {
public List<TopicHotQo> getHotTopicTitles() { public List<TopicHotQo> getHotTopicTitles() {
// List<TopicEntity> topicEntities = topicService.queryAll(); List<TopicHotQo> rankTopicList = rankService.rankTopicList;
// List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities); if (rankTopicList.size()==0){
// for (TopicHotQo topic : topicHotQos) { rankService.rankTopics();
// List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId()); }
// //浏览量 return rankService.rankTopicList;
// 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();
} }
public void setTopTopic(String topicId, boolean setTop) { public void setTopTopic(String topicId, boolean setTop) {
......
...@@ -27,8 +27,9 @@ public class RankService { ...@@ -27,8 +27,9 @@ public class RankService {
private VisitSummaryService visitSummaryService; private VisitSummaryService visitSummaryService;
public List<String> rankThemeList = new ArrayList<>();
public List<String> rankThemeList=new ArrayList<>(); public List<TopicHotQo> rankTopicList = new ArrayList<>();
public void rankThemes() { public void rankThemes() {
...@@ -52,15 +53,17 @@ public class RankService { ...@@ -52,15 +53,17 @@ public class RankService {
} }
/**
public List<TopicHotQo> rankTopics() { * 计算话题热度
*
* @return
*/
public void rankTopics() {
List<TopicEntity> topicEntities = topicService.queryAll(); List<TopicEntity> topicEntities = topicService.queryAll();
List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities); List<TopicHotQo> topicHotQos = ConvertUtil.topicEntityToHotQos(topicEntities);
if (topicHotQos.size() == 0) { if (topicHotQos.size() == 0) {
return topicHotQos; return;
} }
TopicHotQo lastTopic = topicHotQos.get(0);
lastTopic.setType(TopicStatusEnum.NEWEST.getCode());
for (TopicHotQo topic : topicHotQos) { for (TopicHotQo topic : topicHotQos) {
List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId()); List<String> themeIds = themeService.queryThemeIdsByTopic(topic.getTopicId());
//浏览量 //浏览量
...@@ -72,16 +75,15 @@ public class RankService { ...@@ -72,16 +75,15 @@ public class RankService {
topic.setDisscussCount(themeIds.size() + commentCount); topic.setDisscussCount(themeIds.size() + commentCount);
} }
Map<TopicHotQo, Integer> map = topicHotQos.stream().collect(Collectors.toMap(o -> o, TopicHotQo::getRank)); 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()); rankList.get(0).setType(TopicStatusEnum.HOTTEST.getCode());
Set<TopicHotQo> resultSet = rankList.stream().limit(4).collect(Collectors.toSet()); rankTopicList = rankList;
resultSet.add(lastTopic); return;
return new ArrayList<>(resultSet);
} }
public List<String> getHotAndNewThemes(Integer hotCount,Integer newCount){ public List<String> getHotAndNewThemes(Integer hotCount, Integer newCount) {
Set<String> hotThemeIds=this.rankThemeList.stream().limit(hotCount).collect(Collectors.toSet()); Set<String> hotThemeIds = this.rankThemeList.stream().limit(hotCount).collect(Collectors.toSet());
Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount) Set<String> newThemeIds = themeService.selectExcludeUser(null, null, newCount)
.stream().map(ThemeEntity::getThemeId).collect(Collectors.toSet()); .stream().map(ThemeEntity::getThemeId).collect(Collectors.toSet());
hotThemeIds.addAll(newThemeIds); hotThemeIds.addAll(newThemeIds);
......
...@@ -10,6 +10,7 @@ import com.tanpu.community.api.beans.req.theme.CreateThemeReq; ...@@ -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.beans.req.theme.ThemeContentReq;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.RelTypeEnum; 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.community.*;
import com.tanpu.community.dao.entity.user.UserInfoEntity; import com.tanpu.community.dao.entity.user.UserInfoEntity;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -24,20 +25,6 @@ import java.util.stream.Collectors; ...@@ -24,20 +25,6 @@ import java.util.stream.Collectors;
public class ConvertUtil { public class ConvertUtil {
public static ThemeQo themeEntityToQo(ThemeEntity themeEntity) { 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) { if (themeEntity == null) {
return null; return null;
} }
...@@ -48,13 +35,7 @@ public class ConvertUtil { ...@@ -48,13 +35,7 @@ public class ConvertUtil {
themeQO.setUpToNowTime(TimeUtil.calUpToNowTime(themeEntity.getCreateTime())); themeQO.setUpToNowTime(TimeUtil.calUpToNowTime(themeEntity.getCreateTime()));
List<ThemeContentQo> themeContentQos = JsonUtil.toBean(themeEntity.getContent(), new TypeReference<List<ThemeContentQo>>() { 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); themeQO.setContent(themeContentQos);
// }
return themeQO; return themeQO;
} }
...@@ -73,7 +54,7 @@ public class ConvertUtil { ...@@ -73,7 +54,7 @@ public class ConvertUtil {
} }
public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) { public static List<ThemeQo> themeEntitiesToDTOs(List<ThemeEntity> themeEntities) {
return themeEntities.stream().map(ConvertUtil::themeEntityToQo2).collect(Collectors.toList()); return themeEntities.stream().map(ConvertUtil::themeEntityToQo).collect(Collectors.toList());
} }
...@@ -86,6 +67,10 @@ public class ConvertUtil { ...@@ -86,6 +67,10 @@ public class ConvertUtil {
public static TopicHotQo topicEntityToHotQo(TopicEntity topicEntity) { public static TopicHotQo topicEntityToHotQo(TopicEntity topicEntity) {
TopicHotQo topicHotQo = new TopicHotQo(); TopicHotQo topicHotQo = new TopicHotQo();
BeanUtils.copyProperties(topicEntity, topicHotQo); BeanUtils.copyProperties(topicEntity, topicHotQo);
//2小时内发帖,添加新话题标签
if(TimeUtil.calMinuteTillNow(topicEntity.getCreateTime())<120){
topicHotQo.setType(TopicStatusEnum.NEWEST.getCode());
}
return topicHotQo; return topicHotQo;
} }
......
...@@ -22,14 +22,6 @@ spring.datasource: ...@@ -22,14 +22,6 @@ spring.datasource:
maxActive: 2 maxActive: 2
minIdle: 2 minIdle: 2
initialSize: 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: user:
driver-class-name: com.mysql.cj.jdbc.Driver 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 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: ...@@ -38,14 +30,6 @@ spring.datasource:
maxActive: 2 maxActive: 2
minIdle: 2 minIdle: 2
initialSize: 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: jydb:
driver-class-name: com.mysql.cj.jdbc.Driver 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 jdbc-url: jdbc:mysql://47.101.189.151:31931/jydb?autoReconnect=true&characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false
......
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