From 686ce02535bcaf1e3f58a6f13b2ff2b81a1642c6 Mon Sep 17 00:00:00 2001
From: liujiming <liujm@wealthgrow.cn>
Date: Mon, 21 Feb 2022 10:54:14 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../api/beans/qo/TopicAttachement.java        |  4 +--
 .../community/api/beans/qo/TopicFollowQo.java |  7 ++++
 .../api/beans/qo/TopicPageDetailQo.java       |  6 ++++
 .../community/controller/TopicController.java |  7 ++--
 .../community/manager/CommentManager.java     | 12 ++++---
 .../tanpu/community/manager/TopicManager.java | 30 ++++++++++++++---
 .../tanpu/community/service/TopicService.java | 32 ++++++++++++++++---
 7 files changed, 79 insertions(+), 19 deletions(-)

diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicAttachement.java b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicAttachement.java
index db1d53d..4d588f9 100644
--- a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicAttachement.java
+++ b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicAttachement.java
@@ -8,13 +8,13 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 @Data
-@ApiModel(value = "主题关联产品")
+@ApiModel(value = "主题关联产品 RelTypeEnum")
 @Builder
 @AllArgsConstructor
 @NoArgsConstructor
 public class TopicAttachement {
 
-    @ApiModelProperty(value = "RelTypeEnum类型,108:文本,88:产品 3:直播 6:短视频 303:新版课程-音频,304: 新版课程-视频,109:单图(长文) 110:多图(讨论)")
+    @ApiModelProperty(value = " 88:产品 300:课程包 323: 线下活动 未定:资管人")
     private String type;
 
     @ApiModelProperty(value = "对象详情")
diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicFollowQo.java b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicFollowQo.java
index b7b80d1..3b4fb34 100644
--- a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicFollowQo.java
+++ b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicFollowQo.java
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
 import lombok.NoArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
 
 @Data
 @Builder
@@ -47,4 +48,10 @@ public class TopicFollowQo {
     @ApiModelProperty(value = "最近一条讨论发表时间-格式化")
     public String lastThemeTime;
 
+    public boolean checkTopicName(String keyword) {
+        if (StringUtils.isBlank(keyword)) {
+            return true;
+        }
+        return this.topicTitle.contains(keyword);
+    }
 }
diff --git a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicPageDetailQo.java b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicPageDetailQo.java
index 61e46cc..1851646 100644
--- a/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicPageDetailQo.java
+++ b/community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicPageDetailQo.java
@@ -40,6 +40,12 @@ public class TopicPageDetailQo {
     @ApiModelProperty(value = "是否有权限")
     private boolean hasPermission;
 
+    @ApiModelProperty(value = "是否关注,非专属话题时有效")
+    private boolean hasFollow;
+
+    @ApiModelProperty(value = "管理员")
+    private String managers;
+
     @ApiModelProperty(value = "关联产品")
     private List<TopicAttachement> attachments;
 }
diff --git a/community-service/src/main/java/com/tanpu/community/controller/TopicController.java b/community-service/src/main/java/com/tanpu/community/controller/TopicController.java
index cf406ef..ee6bdbc 100644
--- a/community-service/src/main/java/com/tanpu/community/controller/TopicController.java
+++ b/community-service/src/main/java/com/tanpu/community/controller/TopicController.java
@@ -4,6 +4,7 @@ import com.tanpu.common.api.CommonResp;
 import com.tanpu.common.auth.AuthLogin;
 import com.tanpu.common.auth.UserHolder;
 import com.tanpu.community.api.beans.qo.TopicFollowQo;
+import com.tanpu.community.api.beans.qo.TopicPageDetailQo;
 import com.tanpu.community.api.beans.qo.TopicRankQo;
 import com.tanpu.community.api.beans.req.page.Page;
 import com.tanpu.community.api.beans.req.topic.FollowTopicReq;
@@ -38,9 +39,9 @@ public class TopicController {
     @AuthLogin
     @GetMapping(value = "/followList")
     @ApiOperation("关注话题列表")
-    public CommonResp<List<TopicFollowQo>> getFollowList() {
+    public CommonResp<List<TopicFollowQo>> getFollowList(@RequestParam(required = false,value = "keyword") String keyword) {
 
-        return CommonResp.success(topicManager.getFollowTopicList());
+        return CommonResp.success(topicManager.getFollowTopicList(keyword));
     }
 
 
@@ -52,7 +53,7 @@ public class TopicController {
 
     @GetMapping(value = "/detailPage")
     @ApiOperation("话题详情页")
-    public CommonResp<TopicRankQo> getDetail(@RequestParam String topicId) {
+    public CommonResp<TopicPageDetailQo> getDetail(@RequestParam String topicId) {
         return topicManager.getDetail(topicId);
     }
 
diff --git a/community-service/src/main/java/com/tanpu/community/manager/CommentManager.java b/community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
index f244b80..9fb31d7 100644
--- a/community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
+++ b/community-service/src/main/java/com/tanpu/community/manager/CommentManager.java
@@ -157,12 +157,14 @@ public class CommentManager {
             commentQo.setBelongUserOrgName(userInfo.getBelongUserOrgName());
         }
         // 回复用户名
-        String replyUserId = commentQo.getReplyUserId();
-        UserInfoResp replyUser = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
-                60, () -> this.getUserInfo(replyUserId), UserInfoResp.class);
-        if (replyUser != null) {
-            commentQo.setReplyUserName(replyUser.getNickName());
+        if (StringUtils.isNotBlank(commentQo.getReplyUserId())){
+            UserInfoResp replyUser = redisCache.getObject(StringUtils.joinWith("_", CACHE_FEIGN_USER_INFO, authorId),
+                    60, () -> this.getUserInfo(commentQo.getReplyUserId()), UserInfoResp.class);
+            if (replyUser != null) {
+                commentQo.setReplyUserName(replyUser.getNickName());
+            }
         }
+
         commentQo.setHasLiked(false);
         commentQo.setLikeCount(0);
     }
diff --git a/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java b/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
index 5e51c72..3a38ab5 100644
--- a/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
+++ b/community-service/src/main/java/com/tanpu/community/manager/TopicManager.java
@@ -4,6 +4,7 @@ import com.tanpu.common.api.CommonResp;
 import com.tanpu.common.auth.UserHolder;
 import com.tanpu.common.constant.ErrorCodeConstant;
 import com.tanpu.community.api.beans.qo.TopicFollowQo;
+import com.tanpu.community.api.beans.qo.TopicPageDetailQo;
 import com.tanpu.community.api.beans.qo.TopicRankQo;
 import com.tanpu.community.api.beans.req.page.Page;
 import com.tanpu.community.api.beans.req.topic.FollowTopicReq;
@@ -60,13 +61,15 @@ public class TopicManager {
 
     /**
      * 关注话题(讨论区)列表
+     *
+     * @param keyword
      */
 
-    public List<TopicFollowQo> getFollowTopicList() {
+    public List<TopicFollowQo> getFollowTopicList(String keyword) {
 
         String userId = userHolder.getUserId();
         // 查库
-        List<TopicFollowQo> topicFollowQos = topicService.queryFollowTopic(userId);
+        List<TopicFollowQo> topicFollowQos = topicService.queryFollowTopic(keyword, userId);
         // 先从缓存中获取浏览量
         Map<String, TopicRankQo> topicMap = rankService.getRankTopicList(null).stream().collect(Collectors.toMap(TopicRankQo::getTopicId, o -> o, (a, b) -> a));
 
@@ -80,7 +83,7 @@ public class TopicManager {
         themeService.queryCommentForTopic(topicFollowQos, userId);
 
         // 排序
-        topicFollowQos.stream().sorted(Comparator.comparing(TopicFollowQo::getSpecialPermission, Comparator.reverseOrder()).
+        topicFollowQos.stream().filter(o -> o.checkTopicName(keyword)).sorted(Comparator.comparing(TopicFollowQo::getSpecialPermission, Comparator.reverseOrder()).
                 thenComparing(TopicFollowQo::getLastThemeTime, Comparator.nullsFirst(String::compareTo).reversed()))
                 .collect(Collectors.toList());
 
@@ -93,7 +96,7 @@ public class TopicManager {
      * @param topicId
      * @return
      */
-    public CommonResp<TopicRankQo> getDetail(String topicId) {
+    public CommonResp<TopicPageDetailQo> getDetail(String topicId) {
 
 
         TopicEntity topicEntity = topicService.queryOnlineTopicById(topicId);
@@ -107,7 +110,20 @@ public class TopicManager {
             return CommonResp.error(ErrorCodeConstant.TOPIC_PERMISSION_ABORT.getCode(), topicService.getPermissionToast(topicId));
         }
 
-        return CommonResp.success(rankService.getTopicDetail(topicId));
+        // DATA Transform
+        TopicRankQo topicDetail = rankService.getTopicDetail(topicId);
+        TopicPageDetailQo result = new TopicPageDetailQo();
+        BeanUtils.copyProperties(topicDetail, result);
+
+        // 查询管理员
+        result.setManagers(topicService.queryManagers(result.getTopicId()));
+        // 查询关联产品
+        topicService.queryAttachments(result);
+        // 是否关注
+        result.setHasFollow(topicService.checkFollow(result.getTopicId(), userHolder.getUserId()));
+
+
+        return CommonResp.success(result);
     }
 
 
@@ -122,6 +138,10 @@ public class TopicManager {
 
         // 检验话题权限是否专属
         TopicEntity topicEntity = topicService.queryOnlineTopicById(req.getTopicId());
+        if (topicEntity == null) {
+            return CommonResp.error(ErrorCodeConstant.TOPIC_NOT_FOUND.getCode(), "抱歉!该话题已下线。");
+        }
+
         if (TopicSpecialPermissionEnum.TRUE.getCode().equals(topicEntity.getSpecialPermission())) {
             return CommonResp.error(ErrorCodeConstant.ILLEGAL_ARGEMENT.getCode(), "专属话题不支持关注");
         }
diff --git a/community-service/src/main/java/com/tanpu/community/service/TopicService.java b/community-service/src/main/java/com/tanpu/community/service/TopicService.java
index 4f44b01..80099bb 100644
--- a/community-service/src/main/java/com/tanpu/community/service/TopicService.java
+++ b/community-service/src/main/java/com/tanpu/community/service/TopicService.java
@@ -2,7 +2,9 @@ package com.tanpu.community.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.tanpu.common.uuid.UuidGenHelper;
+import com.tanpu.community.api.beans.qo.TopicAttachement;
 import com.tanpu.community.api.beans.qo.TopicFollowQo;
+import com.tanpu.community.api.beans.qo.TopicPageDetailQo;
 import com.tanpu.community.api.beans.qo.TopicRankQo;
 import com.tanpu.community.api.enums.DeleteTagEnum;
 import com.tanpu.community.api.enums.StatusEnum;
@@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -79,10 +82,10 @@ public class TopicService {
         return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
     }
 
-    public List<TopicFollowQo> queryFollowTopic(String userId) {
+    public List<TopicFollowQo> queryFollowTopic(String keyword, String userId) {
         // 用户的关注列表(包括专属)
         List<String> followTopicIds = topicFollowRelMapper.selectTopicIdByUserId(userId);
-        if (CollectionUtils.isEmpty(followTopicIds)){
+        if (CollectionUtils.isEmpty(followTopicIds)) {
             return Collections.emptyList();
         }
 
@@ -114,7 +117,7 @@ public class TopicService {
 
     public void deleteFollowTopic(String topicId, String userId) {
         TopicFollowRelEntity searchResult = topicFollowRelMapper.queryOneByTopicIdAndUserId(topicId, userId);
-        if (searchResult != null){
+        if (searchResult != null) {
             searchResult.setUnfollowTime(LocalDateTime.now());
             searchResult.setDeleteTag(DeleteTagEnum.DELETED.getCode());
             topicFollowRelMapper.updateById(searchResult);
@@ -122,7 +125,7 @@ public class TopicService {
     }
 
     public void batchCheckPermission(List<TopicRankQo> content, String userId) {
-        if (StringUtils.isBlank(userId)){
+        if (StringUtils.isBlank(userId)) {
             return;
         }
     }
@@ -156,4 +159,25 @@ public class TopicService {
         return "暂无权限参与此话题~您可联系官方客服 021- 了解详情";
         // return "该话题仅限" + permission + "可参与哦~";
     }
+
+    public String queryManagers(String topicId) {
+        return "小王、小李、小刘";
+    }
+
+    public void queryAttachments(TopicPageDetailQo topic) {
+        TopicAttachement a1 = TopicAttachement.builder().type("88").detail(null).build();
+        TopicAttachement a2 = TopicAttachement.builder().type("300").detail(null).build();
+        TopicAttachement a3 = TopicAttachement.builder().type("323").detail(null).build();
+
+
+        topic.setAttachments(Arrays.asList(a1, a2, a3));
+    }
+
+    public boolean checkFollow(String topicId, String userId) {
+        if (StringUtils.isBlank(userId)) {
+            return false;
+        }
+        TopicFollowRelEntity topicFollowRelEntity = topicFollowRelMapper.queryOneByTopicIdAndUserId(topicId, userId);
+        return topicFollowRelEntity != null;
+    }
 }
-- 
2.18.1