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