|
@@ -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);
|
|
|
+ }
|
|
|
}
|