Commit 45a04a70 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/manager/ThemeManager.java
parents af110c15 bea7416d
...@@ -69,7 +69,7 @@ public class CommentManager { ...@@ -69,7 +69,7 @@ public class CommentManager {
List<CommentEntity> commentEntities = commentService.selectByThemeId(themeId); List<CommentEntity> commentEntities = commentService.selectByThemeId(themeId);
List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities); List<CommentQo> commentQos = ConvertUtil.commentEntity2Qos(commentEntities);
Set<String> likeCommentList = collectionService.getListByUser(userId, CollectionTypeEnum.LIKE_COMMENT); Set<String> likeCommentList = collectionService.getSetByUser(userId, CollectionTypeEnum.LIKE_COMMENT);
for (CommentQo commentQo : commentQos) { for (CommentQo commentQo : commentQos) {
//查询用户信息 //查询用户信息
......
...@@ -99,13 +99,8 @@ public class HomePageManager { ...@@ -99,13 +99,8 @@ public class HomePageManager {
userInfoNew.getUserInfoNewChief().setClientId(null); userInfoNew.getUserInfoNewChief().setClientId(null);
} }
} }
// app要求 首席的 名字及头像 放到外面
UserInfoNewChief userInfoNewChief = userInfoNew.getUserInfoNewChief();
if (ObjectUtils.allNotNull(userInfoNewChief)) {
userInfoNew.setNickName(userInfoNewChief.getUserName());
userInfoNew.setHeadImageUrl(userInfoNewChief.getHeadImageUrl());
}
} else if (UserTypeEnum.USER_ORG.getCode() == userInfoNew.getUserType()) { } else if (UserTypeEnum.USER_ORG.getCode() == userInfoNew.getUserType()) {
// 机构账号 // 机构账号
userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.ORG.getCode()); userInfoNew.setPersonalCenterType(PersonalCenterTypeEnum.ORG.getCode());
......
...@@ -127,35 +127,36 @@ public class ThemeManager { ...@@ -127,35 +127,36 @@ public class ThemeManager {
@Transactional @Transactional
public CreateThemeResp publishTheme(CreateThemeReq req, String userId) { public CreateThemeResp publishTheme(CreateThemeReq req, String userId) {
//保存主题表 // 保存主题表
ThemeEntity themeEntity = new ThemeEntity(); ThemeEntity themeEntity = new ThemeEntity();
BeanUtils.copyProperties(req, themeEntity); BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId); themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent())); themeEntity.setContent(JsonUtil.toJson(req.getContent()));
//讨论类型,将讨论中的文本放入到discussContent中 // 讨论类型,将讨论中的文本放入到discussContent中
if (ThemeTypeEnum.DISCUSSION.getCode().equals(themeEntity.getThemeType())) { if (ThemeTypeEnum.DISCUSSION.getCode().equals(themeEntity.getThemeType())) {
String content = req.getContent().get(0).getValue(); String content = req.getContent().get(0).getValue();
if (content.length()>256){ // discuss_content字段上限为256个字符
content= content.substring(0, 255); if (content.length() > 256) {
content = content.substring(0, 255);
} }
themeEntity.setDiscussContent(content); themeEntity.setDiscussContent(content);
} }
//腾讯云敏感词校验 // 腾讯云敏感词校验
checkContent(themeEntity.getContent()); checkContent(themeEntity.getContent());
if (StringUtils.isEmpty(req.getEditThemeId())) { if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建 // 新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
} else { } else {
//修改 // 修改
themeService.update(themeEntity, req.getEditThemeId()); themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId()); themeEntity.setThemeId(req.getEditThemeId());
} }
//保存附件表 // 保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId()); List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
if (StringUtils.isNotEmpty(req.getEditThemeId())) { if (StringUtils.isNotEmpty(req.getEditThemeId())) {
//修改需要刪除 // 修改需要刪除
themeAttachmentService.deleteByThemeId(req.getEditThemeId()); themeAttachmentService.deleteByThemeId(req.getEditThemeId());
} }
themeAttachmentService.insertList(themeAttachments); themeAttachmentService.insertList(themeAttachments);
...@@ -183,10 +184,10 @@ public class ThemeManager { ...@@ -183,10 +184,10 @@ public class ThemeManager {
.build(); .build();
if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId().equals(req.getFormerThemeId())) { if (StringUtils.isEmpty(req.getEditThemeId()) || req.getEditThemeId().equals(req.getFormerThemeId())) {
//新建 // 新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
} else { } else {
//修改 // 修改
themeService.update(themeEntity, req.getEditThemeId()); themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId()); themeEntity.setThemeId(req.getEditThemeId());
} }
...@@ -254,31 +255,31 @@ public class ThemeManager { ...@@ -254,31 +255,31 @@ public class ThemeManager {
return resp; return resp;
} }
//主题Entity转QO,组装所有信息 // 主题Entity转QO,组装所有信息
private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) { private List<ThemeQo> convertEntityToQo(List<ThemeEntity> themeEntities, String userId) {
//Entity转Qo //Entity转Qo
List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities); List<ThemeQo> themeQos = ConvertUtil.themeEntitiesToDTOs(themeEntities);
//批量查询附件detail // 批量查询附件detail
batchFeignCallService.getAttachDetailByBatch(themeQos); batchFeignCallService.getAttachDetailByBatch(themeQos);
//其他信息 //其他信息
for (ThemeQo themeQO : themeQos) { for (ThemeQo themeQO : themeQos) {
//通用信息 // 通用信息
buildThemeQoExtraInfo(themeQO); buildThemeQoExtraInfo(themeQO);
//和用户相关信息 // 和用户相关信息
buildThemeExtraInfoByUser(userId, themeQO); buildThemeExtraInfoByUser(userId, themeQO);
} }
return themeQos; return themeQos;
} }
//转发对象、点赞、收藏、转发数 // 转发对象、点赞、收藏、转发数
private void buildThemeQoExtraInfo(ThemeQo themeQo) { private void buildThemeQoExtraInfo(ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
//封装转发对象 // 封装转发对象
FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORMER_THEME_ID, themeId), 60, FormerThemeQo former = redisCache.getObject(StringUtils.joinWith("_", CACHE_FORMER_THEME_ID, themeId), 60,
() -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class); () -> this.getFormerTheme(themeQo.getFormerThemeId()), FormerThemeQo.class);
themeQo.setFormerTheme(former); themeQo.setFormerTheme(former);
//点赞,收藏,转发 // 点赞,收藏,转发
Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME); Integer likeCount = collectionService.getCountByTypeAndId(themeId, CollectionTypeEnum.LIKE_THEME);
Integer commentCount = commentService.getCommentCountByThemeId(themeId); Integer commentCount = commentService.getCommentCountByThemeId(themeId);
Integer forwardCount = themeService.getForwardCountById(themeId); Integer forwardCount = themeService.getForwardCountById(themeId);
...@@ -287,18 +288,18 @@ public class ThemeManager { ...@@ -287,18 +288,18 @@ public class ThemeManager {
themeQo.setForwardCount(forwardCount); themeQo.setForwardCount(forwardCount);
} }
//组装和当前用户相关信息 // 组装和当前用户相关信息
private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) { private void buildThemeExtraInfoByUser(String userId, ThemeQo themeQo) {
String themeId = themeQo.getThemeId(); String themeId = themeQo.getThemeId();
//是否关注作者 // 是否关注作者
themeQo.setFollow(followRelService.checkFollow(themeQo.getAuthorId(), userId)); themeQo.setFollow(followRelService.checkFollow(themeQo.getAuthorId(), userId));
//是否点赞 // 是否点赞
CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME); CollectionEntity likeEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.LIKE_THEME);
themeQo.setHasLiked(likeEntity != null); themeQo.setHasLiked(likeEntity != null);
//是否转发 // 是否转发
Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId); Integer forwardCountByUser = themeService.getForwardCountByUser(themeId, userId);
themeQo.setHasForward(forwardCountByUser > 0); themeQo.setHasForward(forwardCountByUser > 0);
//是否收藏 // 是否收藏
CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME); CollectionEntity collectionEntity = collectionService.getNotDeleteTargetCollection(themeId, userId, CollectionTypeEnum.COLLECT_THEME);
themeQo.setHasCollect(collectionEntity != null); themeQo.setHasCollect(collectionEntity != null);
} }
...@@ -315,12 +316,15 @@ public class ThemeManager { ...@@ -315,12 +316,15 @@ public class ThemeManager {
List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId); List<ThemeQo> commentThemeList = getCommentThemeQos(req, userId);
return commentThemeList; return commentThemeList;
case 3://点赞 case 3://点赞
Set<String> likeThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.LIKE_THEME); List<String> likeThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.LIKE_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(likeThemeIds), req.getLastId(), req.getPageSize()); themeEntities = themeService.queryByThemeIds(likeThemeIds, req.getLastId(), req.getPageSize());
themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, likeThemeIds);
break; break;
case 4://收藏 case 4://收藏
Set<String> collectThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.COLLECT_THEME); List<String> collectThemeIds = collectionService.getListByUser(req.getUserId(), CollectionTypeEnum.COLLECT_THEME);
themeEntities = themeService.queryByThemeIds(new ArrayList<>(collectThemeIds), req.getLastId(), req.getPageSize()); themeEntities = themeService.queryByThemeIds(collectThemeIds, req.getLastId(), req.getPageSize());
themeEntities = RankUtils.sortThemeEntityByIds(themeEntities, collectThemeIds);
break; break;
} }
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId); List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
...@@ -328,19 +332,19 @@ public class ThemeManager { ...@@ -328,19 +332,19 @@ public class ThemeManager {
} }
//查询正文 // 查询正文
public ThemeQo getThemeDetail(String themeId, String userId) { public ThemeQo getThemeDetail(String themeId, String userId) {
//TODO 临时埋点,接入新埋点后删除 //TODO 临时埋点,接入新埋点后删除
visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW); visitSummaryService.addPageView(userId, themeId, VisitTypeEnum.THEME_PAGE_VIEW);
//查询详情 // 查询详情
ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60, ThemeQo themeQo = redisCache.getObject(StringUtils.joinWith("_", CACHE_THEME_ID, themeId), 60,
() -> this.getDetailCommon(themeId), ThemeQo.class); () -> this.getDetailCommon(themeId), ThemeQo.class);
//添加用户相关信息 // 添加用户相关信息
buildThemeExtraInfoByUser(userId, themeQo); buildThemeExtraInfoByUser(userId, themeQo);
return themeQo; return themeQo;
} }
//正文通用信息,与用户无关,可使用缓存 // 正文通用信息,与用户无关,可使用缓存
private ThemeQo getDetailCommon(String themeId) { private ThemeQo getDetailCommon(String themeId) {
ThemeEntity themeEntity = themeService.queryByThemeId(themeId); ThemeEntity themeEntity = themeService.queryByThemeId(themeId);
if (themeEntity == null) { if (themeEntity == null) {
...@@ -476,9 +480,9 @@ public class ThemeManager { ...@@ -476,9 +480,9 @@ public class ThemeManager {
private List<ThemeQo> getCommentThemeQos(QueryRecordThemeReq req, String userId) { private List<ThemeQo> getCommentThemeQos(QueryRecordThemeReq req, String userId) {
List<ThemeQo> commentThemeList = new ArrayList<>(); List<ThemeQo> commentThemeList = new ArrayList<>();
List<ThemeEntity> themeEntities; List<ThemeEntity> themeEntities;
//评论列表 // 评论列表
List<CommentEntity> commentEntities = commentService.queryCommentsByUserId(req.getUserId(), req.getLastId(), req.getPageSize()); List<CommentEntity> commentEntities = commentService.queryCommentsByUserId(req.getUserId(), req.getLastId(), req.getPageSize());
//当前用户信息 // 当前用户信息
UserInfoNew userInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, req.getUserId()), UserInfoNew userInfo = redisCache.getObject(StringUtils.joinWith(CACHE_FEIGN_USER_INFO, req.getUserId()),
60 * 10, () -> this.getUserInfo(req.getUserId()), UserInfoNew.class); 60 * 10, () -> this.getUserInfo(req.getUserId()), UserInfoNew.class);
Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet()); Set<String> replyThemeIds = commentEntities.stream().map(CommentEntity::getThemeId).collect(Collectors.toSet());
...@@ -487,12 +491,12 @@ public class ThemeManager { ...@@ -487,12 +491,12 @@ public class ThemeManager {
} }
themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds)); themeEntities = themeService.queryByThemeIds(new ArrayList<>(replyThemeIds));
List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId); List<ThemeQo> themeQos = convertEntityToQo(themeEntities, userId);
//组装附件 // 组装附件
batchFeignCallService.getAttachDetailByBatch(themeQos); batchFeignCallService.getAttachDetailByBatch(themeQos);
//主题列表 // 主题列表
Map<String, ThemeQo> themeMap = themeQos.stream() Map<String, ThemeQo> themeMap = themeQos.stream()
.collect(Collectors.toMap(ThemeQo::getThemeId, o -> o)); .collect(Collectors.toMap(ThemeQo::getThemeId, o -> o));
//主题+评论封装转发对象 // 主题+评论封装转发对象
for (CommentEntity commentEntity : commentEntities) { for (CommentEntity commentEntity : commentEntities) {
String themeId = commentEntity.getThemeId(); String themeId = commentEntity.getThemeId();
//评论内容包装到ThemeContentQo里 //评论内容包装到ThemeContentQo里
......
...@@ -66,7 +66,7 @@ public class CollectionService { ...@@ -66,7 +66,7 @@ public class CollectionService {
} }
// 根据用户id和行为type获取target_id列表 // 根据用户id和行为type获取target_id列表
public Set<String> getListByUser(String userId, CollectionTypeEnum type) { public Set<String> getSetByUser(String userId, CollectionTypeEnum type) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>() return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getUserId, userId) .eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getCollectionType, type.getCode()) .eq(CollectionEntity::getCollectionType, type.getCode())
...@@ -74,6 +74,16 @@ public class CollectionService { ...@@ -74,6 +74,16 @@ public class CollectionService {
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toSet()); .stream().map(CollectionEntity::getTargetId).collect(Collectors.toSet());
} }
// 根据用户id和行为type获取target_id列表
public List<String> getListByUser(String userId, CollectionTypeEnum type) {
return collectionMapper.selectList(new LambdaQueryWrapper<CollectionEntity>()
.eq(CollectionEntity::getUserId, userId)
.eq(CollectionEntity::getCollectionType, type.getCode())
.eq(CollectionEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
.orderByDesc(CollectionEntity::getCollectionTime))
.stream().map(CollectionEntity::getTargetId).collect(Collectors.toList());
}
// 统计单个对象(主题、评论)的数量(点赞、收藏) // 统计单个对象(主题、评论)的数量(点赞、收藏)
public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) { public Integer getCountByTypeAndId(String targetId, CollectionTypeEnum type) {
......
...@@ -113,7 +113,7 @@ public class RankService { ...@@ -113,7 +113,7 @@ public class RankService {
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)) {
topic.setViewCount(0); topic.setViewCount(countMapByTargetIds.getOrDefault(topic.getTopicId(),0));
topic.setDisscussCount(0); topic.setDisscussCount(0);
continue; continue;
} }
......
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