Commit d29ce8f9 authored by 张辰's avatar 张辰

Merge branch 'v2.3.1' of http://47.100.44.39:10001/tp-backend/tanpu-community into v2.3.1

# Conflicts:
#	community-service/src/main/java/com/tanpu/community/service/TopicService.java
parents 90e0a5fb 988f0de7
package com.tanpu.community.api.beans.vo.feign.product; package com.tanpu.community.api.beans.vo.feign.product;
import com.tanpu.community.api.beans.vo.feign.product.Net;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -16,6 +15,9 @@ public class FundCompanyVO { ...@@ -16,6 +15,9 @@ public class FundCompanyVO {
@ApiModelProperty("icon") @ApiModelProperty("icon")
private String img; private String img;
@ApiModelProperty("公司类型,0 公募,1 私募,2 白名单,3 私有 ")
private String type;
@ApiModelProperty("公司简介") @ApiModelProperty("公司简介")
private String companyProfile; private String companyProfile;
......
...@@ -23,7 +23,6 @@ import io.swagger.annotations.ApiOperation; ...@@ -23,7 +23,6 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -41,10 +40,10 @@ import java.util.List; ...@@ -41,10 +40,10 @@ import java.util.List;
@RequestMapping(value = "/api/homepage") @RequestMapping(value = "/api/homepage")
public class HomePageController { public class HomePageController {
@Autowired @Resource
private HomePageManager homePageManager; private HomePageManager homePageManager;
@Autowired @Resource
private ThemeManager themeManager; private ThemeManager themeManager;
@Resource @Resource
......
...@@ -21,9 +21,11 @@ import com.tanpu.community.dao.entity.community.ThemeEntity; ...@@ -21,9 +21,11 @@ import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools; import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.service.CollectionService; import com.tanpu.community.service.CollectionService;
import com.tanpu.community.service.CommentService; import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.FeignService;
import com.tanpu.community.service.NotificationService; import com.tanpu.community.service.NotificationService;
import com.tanpu.community.service.ReportLogService; import com.tanpu.community.service.ReportLogService;
import com.tanpu.community.service.ThemeService; import com.tanpu.community.service.ThemeService;
import com.tanpu.community.service.TopicService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -62,6 +64,10 @@ public class CommentManager { ...@@ -62,6 +64,10 @@ public class CommentManager {
@Autowired @Autowired
private ThemeService themeService; private ThemeService themeService;
@Resource
private TopicService topicService;
@Resource
private FeignService feignService;
// 评论(对主题) // 评论(对主题)
// 发表评论(对主题) // 发表评论(对主题)
...@@ -124,16 +130,25 @@ public class CommentManager { ...@@ -124,16 +130,25 @@ public class CommentManager {
} else { } else {
likeCommentList = Sets.newHashSetWithExpectedSize(0); likeCommentList = Sets.newHashSetWithExpectedSize(0);
} }
// 查询管理员
ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
Set<String> managerId = topicService.getManagerId(themeEntity.getTopicId());
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
// 封装用户信息 // 封装用户信息
buildUserInfo(commentQo); buildUserInfo(commentQo);
// 是否点赞及点赞数 // 是否点赞及点赞数
String commentId = commentQo.getCommentId(); String commentId = commentQo.getCommentId();
Integer likeCount = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT);
commentQo.setLikeCount(likeCount);
commentQo.setHasLiked(likeCommentList.contains(commentId)); commentQo.setHasLiked(likeCommentList.contains(commentId));
Integer countByTypeAndId = collectionService.getCountByTypeAndId(commentId, CollectionTypeEnum.LIKE_COMMENT); // 是否管理员
commentQo.setLikeCount(countByTypeAndId); if (managerId.contains(commentQo.getAuthorId())) {
commentQo.setManager(true); commentQo.setManager(true);
} else {
commentQo.setManager(false);
}
} }
//排序:点赞降序+时间降序 //排序:点赞降序+时间降序
...@@ -157,11 +172,10 @@ public class CommentManager { ...@@ -157,11 +172,10 @@ public class CommentManager {
commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName()); commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
} }
// 回复用户名 // 回复用户名
if (StringUtils.isNotBlank(commentQo.getReplyUserId())){ if (StringUtils.isNotBlank(commentQo.getReplyUserId())) {
UserInfoResp replyUser = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId), UserInfoResp userResp = feignService.getUserInfoById(commentQo.getReplyUserId());
60, () -> this.getUserInfo(commentQo.getReplyUserId()), UserInfoResp.class); if (userResp != null) {
if (replyUser != null) { commentQo.setReplyUserName(userResp.getNickName());
commentQo.setReplyUserName(replyUser.getNickName());
} }
} }
......
...@@ -467,8 +467,7 @@ public class ThemeManager { ...@@ -467,8 +467,7 @@ public class ThemeManager {
/** /**
* 查询主题列表:推荐/关注/热门/最新 * 查询主题列表:推荐/关注/热门/最新
*/ */
// 查询主题列表:推荐/关注/热门/最新 public ThemeListResp queryList(ThemeListReq req, String userId) {
public ThemeListResp queryList(ThemeListReq req, String userId111) {
List<String> excludeIds = new ArrayList<>(); List<String> excludeIds = new ArrayList<>();
LocalDateTime firstThemeTime = LocalDateTime.now(); LocalDateTime firstThemeTime = LocalDateTime.now();
if (req.page.pageNumber > 1) { if (req.page.pageNumber > 1) {
...@@ -492,6 +491,7 @@ public class ThemeManager { ...@@ -492,6 +491,7 @@ public class ThemeManager {
// 需要筛掉用户访问过详情的 & 最近出现在列表页过的. // 需要筛掉用户访问过详情的 & 最近出现在列表页过的.
List<String> visitedIds = StringUtils.isEmpty(req.getUserId()) ? Lists.newArrayListWithCapacity(0) : visitLogService.queryUserRecentVisited(req.getUserId()); List<String> visitedIds = StringUtils.isEmpty(req.getUserId()) ? Lists.newArrayListWithCapacity(0) : visitLogService.queryUserRecentVisited(req.getUserId());
List<String> excludes = ListUtils.union(excludeIds, visitedIds); List<String> excludes = ListUtils.union(excludeIds, visitedIds);
// 计算推荐列表
List<String> recmdIds = recommendService.getRecommendThemes(pageStart, pageSize, req.getUserId(), excludes, firstThemeTime); List<String> recmdIds = recommendService.getRecommendThemes(pageStart, pageSize, req.getUserId(), excludes, firstThemeTime);
// 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子 // 加载第一页时,为防止首页显示空列表,从推荐池中再捞出已看过帖子
...@@ -501,8 +501,12 @@ public class ThemeManager { ...@@ -501,8 +501,12 @@ public class ThemeManager {
} }
themes = themeService.queryByThemeIds(recmdIds); themes = themeService.queryByThemeIds(recmdIds);
// 权限控制,筛选出当前用户有权限的话题
Set<String> userPermitTopics = topicService.getUserPermitTopics(userId);
// 排序并去重 // 排序并去重
themes = RankUtils.sortThemeEntityByIds(themes, recmdIds).stream().limit(pageSize).collect(Collectors.toList()); themes = RankUtils.sortThemeEntityByIds(themes, recmdIds, userPermitTopics).stream().limit(pageSize).collect(Collectors.toList());
} else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) { } else if (ThemeListTypeEnum.FOLLOW.getCode().equals(req.getType())) {
...@@ -512,7 +516,12 @@ public class ThemeManager { ...@@ -512,7 +516,12 @@ public class ThemeManager {
} else { } else {
// 根据关注列表查询,按时间倒序 // 根据关注列表查询,按时间倒序
List<String> fansList = followRelService.queryIdolsByFansId(req.getUserId()); List<String> fansList = followRelService.queryIdolsByFansId(req.getUserId());
themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize);
// 权限控制,筛选出当前用户有权限的话题
Set<String> userPermitTopics = topicService.getUserPermitTopics(userId);
// 查库
themes = themeService.queryByUserIdsCreateDesc(fansList, pageStart, pageSize, userPermitTopics);
if (CollectionUtils.isEmpty(excludeIds) && !themes.isEmpty()) { if (CollectionUtils.isEmpty(excludeIds) && !themes.isEmpty()) {
// 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月 // 说明是从头开始刷,则直接把最新的lastId放到redis中,保留一个月
...@@ -551,7 +560,7 @@ public class ThemeManager { ...@@ -551,7 +560,7 @@ public class ThemeManager {
// 讨论区添加是否管理员,是否顶置 // 讨论区添加是否管理员,是否顶置
if (ThemeListTypeEnum.TOPIC_LATEST.getCode().equals(req.getType()) if (ThemeListTypeEnum.TOPIC_LATEST.getCode().equals(req.getType())
|| ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) { || ThemeListTypeEnum.TOPIC_HOT.getCode().equals(req.getType())) {
topicService.checkManager(req.getTopicId(),resp.themes); topicService.checkManager(req.getTopicId(), resp.themes);
} }
// 保存缓存、记录已浏览 // 保存缓存、记录已浏览
...@@ -668,22 +677,26 @@ public class ThemeManager { ...@@ -668,22 +677,26 @@ public class ThemeManager {
public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) { public List<ThemeQo> queryThemesByUser(QueryRecordThemeReq req, String userId) {
List<ThemeEntity> themeEntities = Collections.emptyList(); List<ThemeEntity> themeEntities = Collections.emptyList();
// 权限控制,筛选出当前用户有权限的话题
Set<String> userPermitTopics = topicService.getUserPermitTopics(userId);
switch (req.getRecordType()) { switch (req.getRecordType()) {
case 1://发布 case 1://发布
themeEntities = themeService.queryThemesByUserIdCreateDesc(req.getUserId(), req.getLastId(), req.getPageSize()); themeEntities = themeService.queryThemesByUserIdCreateDesc(req.getUserId(), req.getLastId(), req.getPageSize(), userPermitTopics);
break; break;
case 2://回复 case 2://回复
List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId); List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId);
return commentThemeList; return commentThemeList;
case 3://点赞 case 3://点赞
List<String> likeThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.LIKE_THEME, req.getLastId(), req.getPageSize()); List<String> likeThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.LIKE_THEME, req.getLastId(), req.getPageSize());
themeEntities = themeService.queryByThemeIds(likeThemeIds); themeEntities = themeService.queryByThemeIds(likeThemeIds, req.getLastId(), req.getPageSize(), userPermitTopics);
themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, likeThemeIds); themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, likeThemeIds);
break; break;
case 4://收藏 case 4://收藏
List<String> collectThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.COLLECT_THEME, req.getLastId(), req.getPageSize()); List<String> collectThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.COLLECT_THEME, req.getLastId(), req.getPageSize());
themeEntities = themeService.queryByThemeIds(collectThemeIds, req.getLastId(), req.getPageSize()); themeEntities = themeService.queryByThemeIds(collectThemeIds, req.getLastId(), req.getPageSize(), userPermitTopics);
themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, collectThemeIds); themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, collectThemeIds);
break; break;
} }
......
...@@ -56,7 +56,11 @@ public class TopicManager { ...@@ -56,7 +56,11 @@ public class TopicManager {
// 首页-话题标签 // 首页-话题标签
public List<TopicRankQo> getTop4TopicTitles() { public List<TopicRankQo> getTop4TopicTitles() {
return rankService.getRankTopicListTop4(); List<TopicRankQo> rankTopicListTop4 = rankService.getRankTopicListTop4();
//检查权限
topicService.batchCheckPermission(rankTopicListTop4, userHolder.getUserId());
return rankTopicListTop4;
} }
// 话题列表 // 话题列表
...@@ -98,6 +102,7 @@ public class TopicManager { ...@@ -98,6 +102,7 @@ public class TopicManager {
topicFollowQos.stream().forEach(o -> { topicFollowQos.stream().forEach(o -> {
TopicRankQo topicRankQo = topicMap.get(o.getTopicId()); TopicRankQo topicRankQo = topicMap.get(o.getTopicId());
BeanUtils.copyProperties(topicRankQo, o); BeanUtils.copyProperties(topicRankQo, o);
o.setHasPermission(true);
}); });
...@@ -126,7 +131,7 @@ public class TopicManager { ...@@ -126,7 +131,7 @@ public class TopicManager {
return CommonResp.error(ErrorCodeConstant.TOPIC_NOT_FOUND.getCode(), "抱歉!该话题已下线。"); return CommonResp.error(ErrorCodeConstant.TOPIC_NOT_FOUND.getCode(), "抱歉!该话题已下线。");
} }
// // 检验权限
if (TopicSpecialPermissionEnum.TRUE.getCode().equals(topicEntity.getSpecialPermission()) && if (TopicSpecialPermissionEnum.TRUE.getCode().equals(topicEntity.getSpecialPermission()) &&
!topicService.checkPermission(topicId, userHolder.getUserId())) { !topicService.checkPermission(topicId, userHolder.getUserId())) {
return CommonResp.error(ErrorCodeConstant.TOPIC_PERMISSION_ABORT.getCode(), topicService.getPermissionToast(topicId)); return CommonResp.error(ErrorCodeConstant.TOPIC_PERMISSION_ABORT.getCode(), topicService.getPermissionToast(topicId));
...@@ -138,7 +143,7 @@ public class TopicManager { ...@@ -138,7 +143,7 @@ public class TopicManager {
BeanUtils.copyProperties(topicDetail, result); BeanUtils.copyProperties(topicDetail, result);
// 查询管理员 // 查询管理员
result.setManagers(topicService.queryManagers(result.getTopicId())); result.setManagers(topicService.queryManagerNames(result.getTopicId()));
// 查询关联产品 // 查询关联产品
topicService.queryAttachments(result); topicService.queryAttachments(result);
// 是否关注 // 是否关注
......
...@@ -20,6 +20,7 @@ import com.tanpu.community.feign.product.FeignForPublicFund; ...@@ -20,6 +20,7 @@ import com.tanpu.community.feign.product.FeignForPublicFund;
import com.tanpu.community.feign.tanpuroom.FeignClientForTanpuroom; import com.tanpu.community.feign.tanpuroom.FeignClientForTanpuroom;
import com.tanpu.community.feign.zhibo.FeignClientForZhibo; import com.tanpu.community.feign.zhibo.FeignClientForZhibo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -63,11 +64,12 @@ public class FeignService { ...@@ -63,11 +64,12 @@ public class FeignService {
public UserInfoResp getUserInfoById(String userId) { public UserInfoResp getUserInfoById(String userId) {
CommonResp<UserInfoResp> userInfoNewCommonResp = feignClientForFatools.queryUserInfoNew(userId);
if (userInfoNewCommonResp.isNotSuccess()) { List<UserInfoResp> userList = getUserList(Arrays.asList(userId));
if (CollectionUtils.isEmpty(userList)) {
throw new BizException("内部接口调用失败"); throw new BizException("内部接口调用失败");
} }
return userInfoNewCommonResp.getData(); return userList.get(0);
} }
public List<ShortVideoBaseInfoResp> batchGetShortVideoBaseInfo(List<String> sourceIds) { public List<ShortVideoBaseInfoResp> batchGetShortVideoBaseInfo(List<String> sourceIds) {
......
...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; ...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -163,7 +164,8 @@ public class RankService { ...@@ -163,7 +164,8 @@ public class RankService {
// 统计话题下的所有主题数据 // 统计话题下的所有主题数据
List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList()); List<String> topicIds = topicRankQos.stream().map(TopicRankQo::getTopicId).collect(Collectors.toList());
Map<String, Integer> topicViewMap = visitLogService.getCountMapByTargetIds(topicIds, PageEnum.COMM_VISIT_TOPIC_DETAIL.getId()); Map<String, Integer> topicViewMap = visitLogService.getCountMapByTargetIds(topicIds,
Arrays.asList(PageEnum.COMM_VISIT_TOPIC_DETAIL_HOT.getId(),PageEnum.COMM_VISIT_TOPIC_DETAIL_NEW.getId(),PageEnum.COMM_VISIT_TOPIC_DETAIL.getId()));
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)) {
......
...@@ -12,6 +12,7 @@ import com.tanpu.community.api.beans.qo.ThemeQo; ...@@ -12,6 +12,7 @@ import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.qo.TopicFollowQo; import com.tanpu.community.api.beans.qo.TopicFollowQo;
import com.tanpu.community.api.beans.req.comment.CreateCommentReq; import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.theme.ThemeContentReq; import com.tanpu.community.api.beans.req.theme.ThemeContentReq;
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.api.enums.ThemeTypeEnum; import com.tanpu.community.api.enums.ThemeTypeEnum;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
...@@ -43,6 +44,8 @@ public class ThemeService { ...@@ -43,6 +44,8 @@ public class ThemeService {
private RedisHelper redisHelper; private RedisHelper redisHelper;
@Resource @Resource
private VisitLogMapper visitLogMapper; private VisitLogMapper visitLogMapper;
@Resource
private FeignService feignService;
@Transactional @Transactional
public void insertTheme(ThemeEntity themeEntity) { public void insertTheme(ThemeEntity themeEntity) {
...@@ -93,10 +96,11 @@ public class ThemeService { ...@@ -93,10 +96,11 @@ public class ThemeService {
} }
//根据用户id查询主题list //根据用户id查询主题list
public List<ThemeEntity> queryThemesByUserIdCreateDesc(String userId, String lastId, Integer pageSize) { public List<ThemeEntity> queryThemesByUserIdCreateDesc(String userId, String lastId, Integer pageSize, Set<String> userPermitTopics) {
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.eq(ThemeEntity::getAuthorId, userId) .eq(ThemeEntity::getAuthorId, userId)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()) .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.in(ThemeEntity::getTopicId, userPermitTopics)
.orderByDesc(ThemeEntity::getCreateTime); .orderByDesc(ThemeEntity::getCreateTime);
if (StringUtils.isNotEmpty(lastId)) { if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId); ThemeEntity lastEntity = queryByThemeId(lastId);
...@@ -128,6 +132,26 @@ public class ThemeService { ...@@ -128,6 +132,26 @@ public class ThemeService {
return themeMapper.selectList(queryWrapper); return themeMapper.selectList(queryWrapper);
} }
//根据ids返回主题详情,带分页
public List<ThemeEntity> queryByThemeIds(List<String> themeIds, String lastId, Integer pageSize, Set<String> userPermitTopics) {
if (CollectionUtils.isEmpty(themeIds)) {
return Collections.emptyList();
}
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getThemeId, themeIds)
.in(ThemeEntity::getTopicId, userPermitTopics)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
if (StringUtils.isNotEmpty(lastId)) {
ThemeEntity lastEntity = queryByThemeId(lastId);
if (lastEntity == null) throw new BizException("主题未找到,id:" + lastId);
queryWrapper.lt(ThemeEntity::getCreateTime, lastEntity.getCreateTime());
}
if (pageSize != null) {
queryWrapper.last("limit " + pageSize);
}
return themeMapper.selectList(queryWrapper);
}
/** /**
* 根据主题Id查询列表 * 根据主题Id查询列表
* *
...@@ -193,14 +217,18 @@ public class ThemeService { ...@@ -193,14 +217,18 @@ public class ThemeService {
* @param userIds * @param userIds
* @param pageStart * @param pageStart
* @param pageSize * @param pageSize
* @param userPermitTopics
* @return * @return
*/ */
public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize) { public List<ThemeEntity> queryByUserIdsCreateDesc(List<String> userIds, Integer pageStart, Integer pageSize, Set<String> userPermitTopics) {
if (CollectionUtils.isEmpty(userIds)) { if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
// 权限控制,添加主题为空的情况
userPermitTopics.add("");
LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>() LambdaQueryWrapper<ThemeEntity> queryWrapper = new LambdaQueryWrapper<ThemeEntity>()
.in(ThemeEntity::getAuthorId, userIds) .in(ThemeEntity::getAuthorId, userIds)
.in(ThemeEntity::getTopicId, userPermitTopics)
.last("limit " + pageStart + ", " + pageSize) .last("limit " + pageStart + ", " + pageSize)
.orderByDesc(ThemeEntity::getCreateTime) .orderByDesc(ThemeEntity::getCreateTime)
.eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()); .eq(ThemeEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode());
...@@ -316,6 +344,7 @@ public class ThemeService { ...@@ -316,6 +344,7 @@ public class ThemeService {
ThemeEntity themeEntity = themeMapper.queryOneByTopicIdOrderByUpdateTimeDesc(topicId); ThemeEntity themeEntity = themeMapper.queryOneByTopicIdOrderByUpdateTimeDesc(topicId);
if (themeEntity != null) { if (themeEntity != null) {
ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity); ThemeQo themeQo = ConvertUtil.themeEntityToQo(themeEntity);
topic.setLastTheme(getUserName(themeQo.getAuthorId()) + ":" + themeQo.content.get(0).getValue()); topic.setLastTheme(getUserName(themeQo.getAuthorId()) + ":" + themeQo.content.get(0).getValue());
topic.setLastThemeTime(TimeUtils.formatTopicListTime(themeEntity.getUpdateTime())); topic.setLastThemeTime(TimeUtils.formatTopicListTime(themeEntity.getUpdateTime()));
...@@ -336,7 +365,10 @@ public class ThemeService { ...@@ -336,7 +365,10 @@ public class ThemeService {
} }
private String getUserName(String authorId) { private String getUserName(String authorId) {
UserInfoResp userInfoById = feignService.getUserInfoById(authorId);
return "理财师Jack"; if (StringUtils.isNotBlank(userInfoById.getNickName())){
return userInfoById.getNickName();
}
return "理财师";
} }
} }
...@@ -11,9 +11,9 @@ import com.tanpu.community.api.beans.qo.TopicPageDetailQo; ...@@ -11,9 +11,9 @@ import com.tanpu.community.api.beans.qo.TopicPageDetailQo;
import com.tanpu.community.api.beans.qo.TopicRankQo; import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.beans.req.topic.TopicDiscussionReq; import com.tanpu.community.api.beans.req.topic.TopicDiscussionReq;
import com.tanpu.community.api.beans.resp.CoursePackageSimpleResp; import com.tanpu.community.api.beans.resp.CoursePackageSimpleResp;
import com.tanpu.community.api.beans.vo.feign.product.FundCompanyVO;
import com.tanpu.community.api.beans.vo.feign.activity.OfflineActivitySimpleResp; import com.tanpu.community.api.beans.vo.feign.activity.OfflineActivitySimpleResp;
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.beans.vo.feign.product.FundCompanyVO;
import com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO; import com.tanpu.community.api.beans.vo.feign.product.ProductInfoVO;
import com.tanpu.community.api.enums.DeleteTagEnum; import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.StatusEnum; import com.tanpu.community.api.enums.StatusEnum;
...@@ -161,9 +161,15 @@ public class TopicService { ...@@ -161,9 +161,15 @@ public class TopicService {
} }
public void batchCheckPermission(List<TopicRankQo> content, String userId) { public void batchCheckPermission(List<TopicRankQo> content, String userId) {
if (StringUtils.isBlank(userId)) { Set<String> userPermitTopics = getUserPermitTopics(userId);
return; content.forEach(o -> {
} if (userPermitTopics.contains(o.getTopicId())) {
o.setHasPermission(true);
} else {
o.setHasPermission(false);
}
});
} }
...@@ -196,8 +202,20 @@ public class TopicService { ...@@ -196,8 +202,20 @@ public class TopicService {
// return "该话题仅限" + permission + "可参与哦~"; // return "该话题仅限" + permission + "可参与哦~";
} }
public String queryManagers(String topicId) { public String queryManagerNames(String topicId) {
return "小王、小李、小刘";
List<TopicManagerEntity> topicManagerEntities = topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId));
List<String> managerIds = topicManagerEntities.stream().map(TopicManagerEntity::getUserId).collect(Collectors.toList());
List<UserInfoResp> userList = feignService.getUserList(managerIds);
if (CollectionUtils.isEmpty(userList)) {
return "";
}
List<String> userNames = userList.stream().map(UserInfoResp::getNickName).collect(Collectors.toList());
return StringUtils.join(userNames, "、");
} }
public void queryAttachments(TopicPageDetailQo topic) { public void queryAttachments(TopicPageDetailQo topic) {
...@@ -226,8 +244,10 @@ public class TopicService { ...@@ -226,8 +244,10 @@ public class TopicService {
} else if (RelTypeEnum.FUND_COMPANY.type.equals(entity.getSubjectType().toString())) { } else if (RelTypeEnum.FUND_COMPANY.type.equals(entity.getSubjectType().toString())) {
// 资管人 // 资管人
List<FundCompanyVO> fundCompany = feignService.getFundCompany(Collections.singletonList(entity.getSubjectId())); List<FundCompanyVO> fundCompany = feignService.getFundCompany(Collections.singletonList(entity.getSubjectId()));
FundCompanyVO company = fundCompany.get(0);
company.setType(String.valueOf(entity.getSubjectSubType())); // 公司类型
TopicAttachment attach = TopicAttachment.builder().type(RelTypeEnum.FUND_COMPANY.type) TopicAttachment attach = TopicAttachment.builder().type(RelTypeEnum.FUND_COMPANY.type)
.detail(TopicAttachmentDetail.builder().fundCompany(fundCompany.get(0)).build()).build(); .detail(TopicAttachmentDetail.builder().fundCompany(company).build()).build();
attachements.add(attach); attachements.add(attach);
} else if (RelTypeEnum.NEW_COURSE_WARE.type.equals(entity.getSubjectType().toString())) { } else if (RelTypeEnum.NEW_COURSE_WARE.type.equals(entity.getSubjectType().toString())) {
...@@ -261,9 +281,9 @@ public class TopicService { ...@@ -261,9 +281,9 @@ public class TopicService {
public void checkManager(String topicId, List<ThemeQo> themes) { public void checkManager(String topicId, List<ThemeQo> themes) {
String managerId = getManagerId(topicId); Set<String> managerId = getManagerId(topicId);
for (ThemeQo theme : themes) { for (ThemeQo theme : themes) {
theme.setManager(theme.getAuthorId().equals(managerId)); theme.setManager(managerId.contains(theme.getAuthorId()));
} }
} }
...@@ -271,24 +291,17 @@ public class TopicService { ...@@ -271,24 +291,17 @@ public class TopicService {
return topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId)); return topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId));
} }
public String getManagerId(String topicId) { public Set<String> getManagerId(String topicId) {
List<TopicManagerEntity> topicManagerEntities = topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId)); if (StringUtils.isBlank(topicId)) {
return new HashSet<>();
List<String> managerIds = topicManagerEntities.stream().map(TopicManagerEntity::getUserId).collect(Collectors.toList());
List<UserInfoResp> userList = feignService.getUserList(managerIds);
if (CollectionUtils.isEmpty(userList)) {
return "";
} }
List<String> userNames = userList.stream().map(UserInfoResp::getNickName).collect(Collectors.toList()); List<TopicManagerEntity> topicManagerEntities = topicManagerMapper.selectList(new LambdaQueryWrapper<TopicManagerEntity>().eq(TopicManagerEntity::getTopicId, topicId));
return topicManagerEntities.stream().map(TopicManagerEntity::getUserId).collect(Collectors.toSet());
return StringUtils.join(userNames, "、");
} }
/** /**
* 查询资源关联的话题 * 查询资源关联的话题
*
* @param req * @param req
* @return * @return
*/ */
...@@ -298,7 +311,7 @@ public class TopicService { ...@@ -298,7 +311,7 @@ public class TopicService {
.eq(TopicSubjectEntity::getSubjectType, req.getSubjectType()) .eq(TopicSubjectEntity::getSubjectType, req.getSubjectType())
.orderByDesc(TopicSubjectEntity::getCreateTime)); .orderByDesc(TopicSubjectEntity::getCreateTime));
if (CollectionUtils.isEmpty(topicSubjectEntities)){ if (CollectionUtils.isEmpty(topicSubjectEntities)) {
return null; return null;
} }
String topicId = topicSubjectEntities.get(0).getTopicId(); String topicId = topicSubjectEntities.get(0).getTopicId();
...@@ -309,4 +322,26 @@ public class TopicService { ...@@ -309,4 +322,26 @@ public class TopicService {
} }
public Set<String> getUserPermitTopics(String userId) {
// 公开权限的话题
List<TopicEntity> openTopics = topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getSpecialPermission, StatusEnum.TRUE.getCode())
.eq(TopicEntity::getDeleteTag, StatusEnum.FALSE.getCode())
.eq(TopicEntity::getIsConceal, StatusEnum.FALSE.getCode()));
Set<String> openTopicIds = openTopics.stream().map(TopicEntity::getTopicId).collect(Collectors.toSet());
openTopicIds.add("");
if (StringUtils.isBlank(userId)) {
return openTopicIds;
}
// 拥有权限的话题
List<String> followTopics = topicFollowRelMapper.selectTopicIdByUserId(userId);
HashSet<String> res = new HashSet<>(followTopics);
res.addAll(openTopicIds);
return res;
}
} }
...@@ -139,6 +139,20 @@ public class VisitLogService { ...@@ -139,6 +139,20 @@ public class VisitLogService {
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes)); .collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
} }
//统计行为集合的浏览量
public Map<String, Integer> getCountMapByTargetIds(List<String> refIds, List<String> refTypes) {
if (CollectionUtils.isEmpty(refIds)) {
return new HashMap<>();
}
LambdaQueryWrapper<VisitLogEntity> wrapper = (new LambdaQueryWrapper<VisitLogEntity>()
.in(VisitLogEntity::getRefId, refIds))
.eq(VisitLogEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED)
.in(VisitLogEntity::getRefType, refTypes)
.groupBy(VisitLogEntity::getRefId);
return visitLogMapper.selectCountByThemeIds(wrapper).stream()
.collect(Collectors.toMap(TimesCountEntity::getId, TimesCountEntity::getTimes));
}
// 查询讨论区最近浏览 // 查询讨论区最近浏览
public Integer queryLastTopicVisit(String theme) { public Integer queryLastTopicVisit(String theme) {
return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>() return visitLogMapper.selectCount(new LambdaQueryWrapper<VisitLogEntity>()
......
package com.tanpu.community.util; package com.tanpu.community.util;
import com.tanpu.community.dao.entity.community.ThemeEntity; import com.tanpu.community.dao.entity.community.ThemeEntity;
import org.apache.commons.lang3.StringUtils;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class RankUtils { public class RankUtils {
...@@ -31,4 +33,20 @@ public class RankUtils { ...@@ -31,4 +33,20 @@ public class RankUtils {
.collect(Collectors.toList()); .collect(Collectors.toList());
return collect; return collect;
} }
/**
* 根据id排序主题对象(同时过滤权限)
* @param list
* @param recmdIds
* @param topicIds
* @return
*/
public static List<ThemeEntity> sortThemeEntityByIds(List<ThemeEntity> list, List<String> recmdIds, Set<String> topicIds){
List<ThemeEntity> themes = list.stream().filter(o -> {
if (StringUtils.isBlank(o.getTopicId())) return true;
return topicIds.contains(o.getTopicId());
}).collect(Collectors.toList());
return sortThemeEntityByIds(themes, recmdIds);
}
} }
...@@ -2,7 +2,9 @@ package com.tanpu.community.util; ...@@ -2,7 +2,9 @@ package com.tanpu.community.util;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
...@@ -41,16 +43,20 @@ public class TimeUtils { ...@@ -41,16 +43,20 @@ public class TimeUtils {
/** /**
* 格式化话题列表时间 * 格式化话题列表时间
* 发布时间 = Today,显示时间格式:00:00 ,24小时制
* 发布时间 = Today-1,显示时间格式:昨日 00:00 ,24小时制
* 发布时间 <Today-1,显示时间格式:yyyy年mm月dd日
*/ */
public static String formatTopicListTime(LocalDateTime start) { public static String formatTopicListTime(LocalDateTime target) {
Duration between = Duration.between(start, LocalDateTime.now()); LocalDateTime dayBegin = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
long duration = between.toMinutes(); LocalDateTime lastDayBegin = dayBegin.minusDays(1);
if (duration < 60 * 24) {
return start.format(DateTimeFormatter.ofPattern(" HH:mm")); if (target.isAfter(dayBegin)) {
} else if (duration < 60 * 48) { return target.format(DateTimeFormatter.ofPattern(" HH:mm"));
return start.format(DateTimeFormatter.ofPattern("昨天 HH:mm")); } else if (target.isAfter(lastDayBegin)) {
return target.format(DateTimeFormatter.ofPattern("昨天 HH:mm"));
} }
return start.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")); return target.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
} }
public static String format(LocalDateTime start) { public static String format(LocalDateTime start) {
......
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