|
@@ -2,6 +2,7 @@ package com.fjhx.xmhjc.controller.open;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -24,7 +25,9 @@ import com.fjhx.xmhjc.utils.WebsiteUserUtil;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/open/topic")
|
|
@@ -36,17 +39,52 @@ public class OpenTopicController {
|
|
|
@Resource
|
|
|
private WebsiteUsersService websiteUsersService;
|
|
|
|
|
|
- @PostMapping("/contentPage")
|
|
|
- public Page<TopicContentVo> contentPage(TopicContentSelectDto dto) {
|
|
|
+ /**
|
|
|
+ * @description: 主题列表
|
|
|
+ * @author hj
|
|
|
+ * @date 2023/11/23 22:29
|
|
|
+ */
|
|
|
+ @PostMapping("/contentPage/{sortType}")
|
|
|
+ public Page<TopicContentVo> contentPage(TopicContentSelectDto dto, @PathVariable String sortType) {
|
|
|
dto.setType("1");
|
|
|
- Page<TopicContentVo> page = topicContentService.contentPage(dto);
|
|
|
+ Page<TopicContentVo> page = topicContentService.contentPage(dto, sortType);
|
|
|
page.getRecords().forEach(topicContentVo -> {
|
|
|
- WebsiteUsers websiteUsers = websiteUsersService.getById(topicContentVo.getAuthor());
|
|
|
- topicContentVo.setAuthorName(ObjectUtil.isNull(websiteUsers) ? "匿名" : websiteUsers.getUserName());
|
|
|
+ topicContentVo.setAuthorName(topicContentService.getAuthorName(topicContentVo.getAuthor()));
|
|
|
});
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回复列表
|
|
|
+ * @author hj
|
|
|
+ * @date 2023/11/23 22:29
|
|
|
+ */
|
|
|
+ @PostMapping("/replyPage")
|
|
|
+ public Page<TopicRepliesVo> replyPage(@RequestBody TopicRepliesSelectDto dto) {
|
|
|
+ if(!NumberUtil.isValidNumber(dto.getFloorId())){
|
|
|
+ throw new RuntimeException("参数错误");
|
|
|
+ }
|
|
|
+ Map<Long, WebsiteUsers> websiteUsersMap = new HashMap<>();
|
|
|
+ Page<TopicRepliesVo> page = topicRepliesService.replyPage(dto);
|
|
|
+ page.getRecords().forEach(topicContentVo -> {
|
|
|
+ topicContentVo.setAuthorName(topicContentService.getAuthorName(topicContentVo.getAuthor(), websiteUsersMap));
|
|
|
+
|
|
|
+ WebsiteUsers websiteUsers = websiteUsersMap.get(topicContentVo.getAuthor());
|
|
|
+ if(ObjectUtil.isNull(websiteUsers)){
|
|
|
+ websiteUsers = websiteUsersService.getById(topicContentVo.getAuthor());
|
|
|
+ websiteUsersMap.put(topicContentVo.getAuthor(),websiteUsers);
|
|
|
+ }
|
|
|
+ topicContentVo.setCiteAuthorName(topicContentService.getAuthorName(topicContentVo.getCiteAuthor(), websiteUsersMap));
|
|
|
+ });
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建提问
|
|
|
+ * @author hj
|
|
|
+ * @date 2023/11/23 22:29
|
|
|
+ */
|
|
|
@LoginValid
|
|
|
@PostMapping("/createQuestion")
|
|
|
public void createQuestion(@RequestBody TopicContentDto topicContentDto) {
|
|
@@ -62,6 +100,12 @@ public class OpenTopicController {
|
|
|
topicContentService.add(topicContentDto);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回复主题/楼层
|
|
|
+ * @author hj
|
|
|
+ * @date 2023/11/23 22:30
|
|
|
+ */
|
|
|
@LoginValid
|
|
|
@PostMapping("/reply/{topicId}")
|
|
|
public void reply(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
|
|
@@ -71,50 +115,36 @@ public class OpenTopicController {
|
|
|
topicRepliesService.add(topicRepliesDto);
|
|
|
}
|
|
|
|
|
|
- @LoginValid
|
|
|
+ /**
|
|
|
+ * 主题详情
|
|
|
+ * @author hj
|
|
|
+ * @date 2023/11/23 22:30
|
|
|
+ */
|
|
|
@PostMapping("/detail/{topicId}")
|
|
|
- public OpenTopicContentVO detail(@RequestBody TopicRepliesSelectDto topicRepliesSelectDto, @PathVariable Long topicId) {
|
|
|
+ public OpenTopicContentVO detail(@PathVariable Long topicId) {
|
|
|
TopicContent topicContent = topicContentService.getById(topicId);
|
|
|
if (ObjectUtil.isNull(topicContent)) {
|
|
|
throw new RuntimeException("主题不存在");
|
|
|
}
|
|
|
+ topicContent.setViews(topicContent.getViews() + 1);
|
|
|
+ topicContentService.updateById(topicContent);
|
|
|
+
|
|
|
OpenTopicContentVO openTopicContentVO = BeanUtil.copyProperties(topicContent, OpenTopicContentVO.class);
|
|
|
- openTopicContentVO.setAuthorName(getAuthorName(topicContent.getAuthor()));
|
|
|
+ openTopicContentVO.setAuthorName(topicContentService.getAuthorName(topicContent.getAuthor()));
|
|
|
//分页查出楼层回复
|
|
|
TopicRepliesSelectDto dto = new TopicRepliesSelectDto();
|
|
|
Page<TopicRepliesVo> page = topicRepliesService.getPageByOpen(dto);
|
|
|
List<TopicRepliesVo> records = page.getRecords();
|
|
|
records.forEach(topicRepliesVo -> {
|
|
|
- topicRepliesVo.setAuthorName(getAuthorName(topicRepliesVo.getAuthor()));
|
|
|
+ topicRepliesVo.setAuthorName(topicContentService.getAuthorName(topicRepliesVo.getAuthor()));
|
|
|
dto.setFloorId(topicRepliesVo.getId());
|
|
|
Page<TopicRepliesVo> floorPage = topicRepliesService.getPageByOpen(dto);
|
|
|
topicRepliesVo.setFloorPage(floorPage);
|
|
|
});
|
|
|
-
|
|
|
openTopicContentVO.setRepliesPage(page);
|
|
|
-
|
|
|
return openTopicContentVO;
|
|
|
}
|
|
|
|
|
|
- private String getAuthorName(Long author) {
|
|
|
- WebsiteUsers websiteUsers = websiteUsersService.getById(author);
|
|
|
- return ObjectUtil.isNull(websiteUsers) ? "匿名" : websiteUsers.getUserName();
|
|
|
- }
|
|
|
-
|
|
|
- @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())) {
|
|
@@ -140,6 +170,7 @@ public class OpenTopicController {
|
|
|
if (ObjectUtil.isNull(replyTo)) {
|
|
|
throw new RuntimeException("回复对象不存在");
|
|
|
}
|
|
|
+ topicRepliesDto.setCiteAuthor(replyTo.getAuthor());
|
|
|
}
|
|
|
topicRepliesDto.setTopicId(topicId);
|
|
|
}
|