Commit 9f1f1469 authored by 张辰's avatar 张辰

Merge branch 'dev' into 'master'

Dev

See merge request !8
parents 8f5c23ee cd3bac90
...@@ -23,4 +23,11 @@ public final class CommunityConstant { ...@@ -23,4 +23,11 @@ public final class CommunityConstant {
//图片压缩比例:50% //图片压缩比例:50%
public static final String OSS_RESIZE_RATIO = "?x-oss-process=image/resize,p_50"; public static final String OSS_RESIZE_RATIO = "?x-oss-process=image/resize,p_50";
public static final String THEME_PREFIX ="NEW_THEME_";
public static final String OLD_FILE_UPLOAD_URL ="http://tp-fatools-svc/fatools/h5/rest/common/uploadSingleFile";
} }
...@@ -24,11 +24,13 @@ public class CreateThemeReq { ...@@ -24,11 +24,13 @@ public class CreateThemeReq {
private List<ThemeContentReq> content; private List<ThemeContentReq> content;
@ApiModelProperty(value = "所属的话题id") @ApiModelProperty(value = "所属的话题id")
private String topicId=""; private String topicId = "";
@ApiModelProperty(value = "修改,则传入正在编辑的ThemeId") @ApiModelProperty(value = "修改,则传入正在编辑的ThemeId")
private String editThemeId=""; private String editThemeId = "";
@ApiModelProperty("是否同步到社区 0为不同步 1为同步 不传也为同步")
private Integer syncToNewComm = 0;
} }
package com.tanpu.community.api.beans.req.theme;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 专栏同步到圈子
*/
@Data
public class SynchroThemeReq {
@NotNull(message = "类型不能为空")
@ApiModelProperty(value = "类型 1:讨论无标题 2:长文有标题")
private Integer themeType;
@ApiModelProperty(value = "专栏id")
private String themeId = "";
@NotEmpty(message = "内容不能为空")
@ApiModelProperty(value = "文本内容")
private List<ThemeContentReq> content;
public String userId = "";
}
package com.tanpu.community.api.beans.vo.feign.newsfeed;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class NewsFeedResReq {
/**
* 关联类型
*/
@ApiModelProperty("关联类型 产品:88 直播:3 短视频:6 图片:122")
private Integer relType;
/**
* 关联id
*/
@ApiModelProperty("关联id")
private String relId;
/**
* 产品类型 rel_type等于产品生效
*/
private Integer productType;
/**
* 备注说明
*/
private String remark;
}
package com.tanpu.community.api.beans.vo.feign.newsfeed;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 发布动态
*
* @author hudingguo
*/
@ApiModel("发布动态")
@Data
public class NewsFeedSave4NewCommReq {
@ApiModelProperty("专栏id")
private String newsFeedId;
@ApiModelProperty("专栏内容内容")
private String content;
@ApiModelProperty("关联多个内容")
private List<NewsFeedResReq> newsFeedResList;
@ApiModelProperty("用户id")
public String userId = "";
}
...@@ -3,6 +3,7 @@ package com.tanpu.community.config; ...@@ -3,6 +3,7 @@ package com.tanpu.community.config;
import feign.Logger; import feign.Logger;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
/** /**
* @description: * @description:
...@@ -16,4 +17,9 @@ public class FeignConfiguration { ...@@ -16,4 +17,9 @@ public class FeignConfiguration {
//这里记录所有,根据实际情况选择合适的日志level //这里记录所有,根据实际情况选择合适的日志level
return Logger.Level.FULL; return Logger.Level.FULL;
} }
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
} }
...@@ -113,4 +113,13 @@ public class ThemeController { ...@@ -113,4 +113,13 @@ public class ThemeController {
return CommonResp.success(themeManager.getFollowUpdateCount(userId)); return CommonResp.success(themeManager.getFollowUpdateCount(userId));
} }
@ApiOperation("专栏同步主题")
@PostMapping(value = "/convertFromNewsFeed")
@ResponseBody
public CommonResp<Void> convertFromNewsFeed(@Validated @RequestBody SynchroThemeReq req) {
themeManager.convertFromNewsFeed(req);
return CommonResp.success();
}
} }
package com.tanpu.community.feign.community;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class FeignBackClientForCommunity implements FallbackFactory<FeignClientForCommunity> {
@Override
public FeignClientForCommunity create(Throwable throwable) {
return new FeignClientForCommunity() {
@Override
public CommonResp saveNewsFeed4NewComm(NewsFeedSave4NewCommReq req) {
log.error("请求信息", throwable);
log.error("FeignBackClientForCommunity.saveNewsFeed4NewComm-同步专栏频ids:{}", req.getNewsFeedId());
return null;
}
};
}
}
package com.tanpu.community.feign.community;
import com.tanpu.common.api.CommonResp;
import com.tanpu.community.api.beans.vo.feign.newsfeed.NewsFeedSave4NewCommReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
@FeignClient(value = "service-community", contextId = "community", fallbackFactory = FeignBackClientForCommunity.class, url = "http://tp-tamp-community-svc", path = "/community")
// @FeignClient(value = "service-community", contextId = "community", fallbackFactory = FeignBackClientForCommunity.class, url = "http://127.0.0.1:8202/community")
public interface FeignClientForCommunity {
@ApiOperation("发布专栏 圈子用feign")
@PostMapping("/newsFeed/save4NewComm")
CommonResp saveNewsFeed4NewComm(NewsFeedSave4NewCommReq req);
}
...@@ -135,7 +135,7 @@ public class RankService { ...@@ -135,7 +135,7 @@ public class RankService {
//排序 //排序
hotestThemes = map.entrySet().stream() hotestThemes = map.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(e -> e.getKey()).collect(Collectors.toList()); .map(Map.Entry::getKey).collect(Collectors.toList());
//落库 //落库
rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start)); rankLogService.logThemeRank(hotestThemes, start, TimeUtils.calMillisTillNow(start));
} }
......
...@@ -6,12 +6,15 @@ import com.tanpu.community.api.beans.resp.PythonResponse; ...@@ -6,12 +6,15 @@ import com.tanpu.community.api.beans.resp.PythonResponse;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.util.BizUtils; import com.tanpu.community.util.BizUtils;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.TimeUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -40,27 +43,33 @@ public class RecommendService { ...@@ -40,27 +43,33 @@ public class RecommendService {
private ThemeService themeService; private ThemeService themeService;
@Resource
private RestTemplate restTemplate;
// 最新 // 最新
private List<ThemeAnalysDO> recentThemeList = new ArrayList<>(); private List<ThemeAnalysDO> recentThemeList = new ArrayList<>();
// 推荐 // 推荐
private Map<String, List<String>> recommondList = new HashMap<>(); private Map<String, List<String>> recommondList = new HashMap<>();
public List<String> getRecommendThemes(Integer pageStart, Integer pageSize, String userId, List<String> excludeIds) { public List<String> getRecommendThemes(Integer pageStart, Integer pageSize, String userId, List<String> excludeIds, LocalDateTime timeAfter) {
// 最热话题,筛掉用户发表的 & 最近看过的 & excludeIds // 最热话题,筛掉用户发表的 & 最近看过的 & excludeIds
List<String> hotThemeIds = rankService.getHotestThemes().stream() List<String> hotThemeIds = rankService.getHotestThemes().stream()
.filter(theme -> { .filter(theme -> {
return !excludeIds.contains(theme.getThemeId()) && !userId.equals(theme.getAuthorId()); // 暂时不过滤用户自己发的 !userId.equals(theme.getAuthorId());
return !excludeIds.contains(theme.getThemeId());
}) })
.map(ThemeAnalysDO::getThemeId).collect(Collectors.toList()); .map(ThemeAnalysDO::getThemeId).collect(Collectors.toList());
hotThemeIds = BizUtils.subList(hotThemeIds, pageStart, pageSize); hotThemeIds = BizUtils.subList(hotThemeIds, 0, pageSize);
//最新话题,筛掉用户发表的 & 最近看过的 & excludeIds //最新话题,筛掉用户发表的 & 最近看过的 & excludeIds && 上次查询后发帖的
long margin = TimeUtils.calMinuteTillNow(timeAfter);
List<String> newThemeIds = getNewestThemes().stream() List<String> newThemeIds = getNewestThemes().stream()
.filter(theme -> { .filter(theme -> {
return !excludeIds.contains(theme.getThemeId()) && !userId.equals(theme.getAuthorId()); // 暂时不过滤用户自己发的 !userId.equals(theme.getAuthorId());
return !excludeIds.contains(theme.getThemeId()) && theme.getMinutesTillNow() > margin;
}) })
.map(ThemeAnalysDO::getThemeId).collect(Collectors.toList()); .map(ThemeAnalysDO::getThemeId).collect(Collectors.toList());
newThemeIds = BizUtils.subList(newThemeIds, pageStart, pageSize); newThemeIds = BizUtils.subList(newThemeIds, 0, pageSize);
//推荐话题 //推荐话题
List<String> recThemeIds = getPythonRecommendList(userId).stream() List<String> recThemeIds = getPythonRecommendList(userId).stream()
...@@ -101,7 +110,6 @@ public class RecommendService { ...@@ -101,7 +110,6 @@ public class RecommendService {
if (!"true".equals(enablePython)) { if (!"true".equals(enablePython)) {
return Collections.emptyList(); return Collections.emptyList();
} }
RestTemplate restTemplate = new RestTemplate();
HashMap<String, String> param = new HashMap<>(); HashMap<String, String> param = new HashMap<>();
param.put("user_id", userId); param.put("user_id", userId);
try { try {
......
...@@ -40,7 +40,10 @@ public class ThemeService { ...@@ -40,7 +40,10 @@ public class ThemeService {
@Transactional @Transactional
public void insertTheme(ThemeEntity themeEntity) { public void insertTheme(ThemeEntity themeEntity) {
themeEntity.setThemeId(uuidGenHelper.getUuidStr()); if (StringUtils.isBlank(themeEntity.getThemeId())){
themeEntity.setThemeId(uuidGenHelper.getUuidStr());
}
themeMapper.insert(themeEntity); themeMapper.insert(themeEntity);
} }
......
...@@ -4,7 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference; ...@@ -4,7 +4,14 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.tanpu.biz.common.enums.RelTypeEnum; import com.tanpu.biz.common.enums.RelTypeEnum;
import com.tanpu.biz.common.enums.community.TopicStatusEnum; import com.tanpu.biz.common.enums.community.TopicStatusEnum;
import com.tanpu.common.util.JsonUtil; import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.*; import com.tanpu.community.api.beans.qo.CommentQo;
import com.tanpu.community.api.beans.qo.ESThemeQo;
import com.tanpu.community.api.beans.qo.FollowQo;
import com.tanpu.community.api.beans.qo.FormerThemeQo;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.theme.CreateThemeReq; 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.beans.resp.FileUploadResp; import com.tanpu.community.api.beans.resp.FileUploadResp;
...@@ -12,7 +19,12 @@ import com.tanpu.community.api.beans.vo.ImagesDTO; ...@@ -12,7 +19,12 @@ import com.tanpu.community.api.beans.vo.ImagesDTO;
import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg; import com.tanpu.community.api.beans.vo.KafkaDurationUptMsg;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.*; import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.FileRecordEntity;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.dao.entity.community.TopicEntity;
import com.tanpu.community.dao.entity.community.VisitLogEntity;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
......
...@@ -44,24 +44,36 @@ public class TimeUtils { ...@@ -44,24 +44,36 @@ public class TimeUtils {
//计算迄今分钟 //计算迄今分钟
public static long calMinuteTillNow(LocalDateTime start) { public static long calMinuteTillNow(LocalDateTime start) {
if (start==null){
return 0L;
}
Duration between = Duration.between(start, LocalDateTime.now()); Duration between = Duration.between(start, LocalDateTime.now());
return between.toMinutes(); return between.toMinutes();
} }
//计算迄今毫秒数 //计算迄今毫秒数
public static long calMillisTillNow(LocalDateTime start) { public static long calMillisTillNow(LocalDateTime start) {
if (start==null){
return 0L;
}
Duration between = Duration.between(start, LocalDateTime.now()); Duration between = Duration.between(start, LocalDateTime.now());
return between.toMillis(); return between.toMillis();
} }
//计算迄今天数 //计算迄今天数
public static long calDaysTillNow(LocalDateTime start) { public static long calDaysTillNow(LocalDateTime start) {
if (start==null){
return 0L;
}
Duration between = Duration.between(start, LocalDateTime.now()); Duration between = Duration.between(start, LocalDateTime.now());
return between.toDays(); return between.toDays();
} }
//计算迄今小时数 //计算迄今小时数
public static long calHoursTillNow(LocalDateTime start) { public static long calHoursTillNow(LocalDateTime start) {
if (start==null){
return 0L;
}
Duration between = Duration.between(start, LocalDateTime.now()); Duration between = Duration.between(start, LocalDateTime.now());
return between.toHours(); return between.toHours();
} }
......
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