1018653686@qq.com 1 rok pred
rodič
commit
f57326e4bd

+ 70 - 6
hx-xmhjc/src/main/java/com/fjhx/xmhjc/controller/open/OpenTopicController.java

@@ -1,6 +1,7 @@
 package com.fjhx.xmhjc.controller.open;
 
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -9,7 +10,12 @@ import com.fjhx.xmhjc.entity.product.vo.ProductCategoryVo;
 import com.fjhx.xmhjc.entity.topic.dto.TopicContentDto;
 import com.fjhx.xmhjc.entity.topic.dto.TopicContentSelectDto;
 import com.fjhx.xmhjc.entity.topic.dto.TopicRepliesDto;
+import com.fjhx.xmhjc.entity.topic.dto.TopicRepliesSelectDto;
+import com.fjhx.xmhjc.entity.topic.po.TopicContent;
+import com.fjhx.xmhjc.entity.topic.po.TopicReplies;
+import com.fjhx.xmhjc.entity.topic.vo.OpenTopicContentVO;
 import com.fjhx.xmhjc.entity.topic.vo.TopicContentVo;
+import com.fjhx.xmhjc.entity.topic.vo.TopicRepliesVo;
 import com.fjhx.xmhjc.entity.website.po.WebsiteUsers;
 import com.fjhx.xmhjc.service.topic.TopicContentService;
 import com.fjhx.xmhjc.service.topic.TopicRepliesService;
@@ -31,7 +37,7 @@ public class OpenTopicController {
     private WebsiteUsersService websiteUsersService;
 
     @PostMapping("/contentPage")
-    public Page<TopicContentVo> categoryList(TopicContentSelectDto dto) {
+    public Page<TopicContentVo> contentPage(TopicContentSelectDto dto) {
         dto.setType("1");
         Page<TopicContentVo> page = topicContentService.contentPage(dto);
         page.getRecords().forEach(topicContentVo -> {
@@ -43,7 +49,7 @@ public class OpenTopicController {
 
     @LoginValid
     @PostMapping("/createQuestion")
-    public void categoryList(@RequestBody TopicContentDto topicContentDto) {
+    public void createQuestion(@RequestBody TopicContentDto topicContentDto) {
         if (StrUtil.isBlank(topicContentDto.getTitle())) {
             throw new RuntimeException("标题不能为空");
         }
@@ -58,13 +64,71 @@ public class OpenTopicController {
 
     @LoginValid
     @PostMapping("/reply/{topicId}")
-    public void categoryList(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
-        if (StrUtil.isBlank(topicRepliesDto.getContent())) {
-            throw new RuntimeException("回复不能为空");
+    public void reply(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
+        validateReply(topicRepliesDto, topicId);
+        WebsiteUsers loginWebsiteUser = WebsiteUserUtil.getLoginWebsiteUser();
+        topicRepliesDto.setAuthor(loginWebsiteUser.getId());
+        topicRepliesService.add(topicRepliesDto);
+    }
+
+    @LoginValid
+    @PostMapping("/detail/{topicId}")
+    public void detail(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
+        TopicContent topicContent = topicContentService.getById(topicId);
+        if (ObjectUtil.isNull(topicContent)) {
+            throw new RuntimeException("主题不存在");
         }
-        topicRepliesDto.setTopicId(topicId);
+        OpenTopicContentVO openTopicContentVO = BeanUtil.copyProperties(topicContent, OpenTopicContentVO.class);
+        //分页查出楼层回复
+        TopicRepliesSelectDto dto = new TopicRepliesSelectDto();
+        Page<TopicRepliesVo> page = topicRepliesService.getPageByOpen(dto);
+
+        validateReply(topicRepliesDto, topicId);
         WebsiteUsers loginWebsiteUser = WebsiteUserUtil.getLoginWebsiteUser();
         topicRepliesDto.setAuthor(loginWebsiteUser.getId());
         topicRepliesService.add(topicRepliesDto);
     }
+
+    @LoginValid
+    @PostMapping("/replyPage/{topicId}")
+    public void subReplyList(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
+        TopicContent topicContent = topicContentService.getById(topicId);
+        if (ObjectUtil.isNull(topicContent)) {
+            throw new RuntimeException("主题不存在");
+        }
+        //分页查出楼层回复
+        validateReply(topicRepliesDto, topicId);
+        WebsiteUsers loginWebsiteUser = WebsiteUserUtil.getLoginWebsiteUser();
+        topicRepliesDto.setAuthor(loginWebsiteUser.getId());
+        topicRepliesService.add(topicRepliesDto);
+    }
+
+
+    private void validateReply(TopicRepliesDto topicRepliesDto, Long topicId) {
+        if (StrUtil.isBlank(topicRepliesDto.getContent())) {
+            throw new RuntimeException("回复不能为空");
+        }
+        if (StrUtil.isBlank(topicRepliesDto.getReplyType())) {
+            throw new RuntimeException("回复类型不能为空");
+        }
+        if ("2".equals(topicRepliesDto.getReplyType()) && ObjectUtil.isNull(topicRepliesDto.getFloorId())) {
+            throw new RuntimeException("回复对象不能为空");
+        }
+        if ("3".equals(topicRepliesDto.getReplyType()) && ObjectUtil.isNull(topicRepliesDto.getFloorId()) && ObjectUtil.isNull(topicRepliesDto.getReplyId())) {
+            throw new RuntimeException("回复对象不能为空");
+        }
+        if ("2".equals(topicRepliesDto.getReplyType()) || "3".equals(topicRepliesDto.getReplyType())) {
+            TopicReplies floorReply = topicRepliesService.getById(topicRepliesDto.getFloorId());
+            if (ObjectUtil.isNull(floorReply)) {
+                throw new RuntimeException("回复对象不存在");
+            }
+        }
+        if ("3".equals(topicRepliesDto.getReplyType())) {
+            TopicReplies replyTo = topicRepliesService.getById(topicRepliesDto.getReplyId());
+            if (ObjectUtil.isNull(replyTo)) {
+                throw new RuntimeException("回复对象不存在");
+            }
+        }
+        topicRepliesDto.setTopicId(topicId);
+    }
 }

+ 1 - 1
hx-xmhjc/src/main/java/com/fjhx/xmhjc/entity/topic/dto/TopicRepliesDto.java

@@ -13,5 +13,5 @@ import lombok.Setter;
 @Getter
 @Setter
 public class TopicRepliesDto extends TopicReplies {
-
+    String replyType;
 }

+ 1 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/entity/topic/dto/TopicRepliesSelectDto.java

@@ -13,5 +13,6 @@ import lombok.Setter;
 @Getter
 @Setter
 public class TopicRepliesSelectDto extends BaseSelectDto {
+    private Long topicId;
 
 }

+ 15 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/entity/topic/vo/OpenTopicContentVO.java

@@ -0,0 +1,15 @@
+package com.fjhx.xmhjc.entity.topic.vo;
+
+import com.fjhx.xmhjc.entity.topic.po.TopicContent;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * @author hj
+ * @date 2023年11月21日 10:19
+ */
+@Getter
+@Setter
+public class OpenTopicContentVO extends TopicContent {
+    private String authorName;
+}

+ 1 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/topic/TopicRepliesService.java

@@ -49,4 +49,5 @@ public interface TopicRepliesService extends BaseService<TopicReplies> {
      */
     void delete(Long id);
 
+    Page<TopicRepliesVo> getPageByOpen(TopicRepliesSelectDto dto);
 }

+ 8 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/topic/impl/TopicRepliesServiceImpl.java

@@ -63,4 +63,12 @@ public class TopicRepliesServiceImpl extends ServiceImpl<TopicRepliesMapper, Top
         this.removeById(id);
     }
 
+    @Override
+    public Page<TopicRepliesVo> getPageByOpen(TopicRepliesSelectDto dto) {
+        IWrapper<TopicReplies> wrapper = getWrapper();
+        wrapper.orderByAsc("tr", TopicReplies::getId);
+        wrapper.eq("tr", TopicReplies::getTopicId, dto.getTopicId());
+        Page<TopicRepliesVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        return page;
+    }
 }