|
@@ -0,0 +1,70 @@
|
|
|
+package com.fjhx.xmhjc.controller.open;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.xmhjc.anno.LoginValid;
|
|
|
+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.vo.TopicContentVo;
|
|
|
+import com.fjhx.xmhjc.entity.website.po.WebsiteUsers;
|
|
|
+import com.fjhx.xmhjc.service.topic.TopicContentService;
|
|
|
+import com.fjhx.xmhjc.service.topic.TopicRepliesService;
|
|
|
+import com.fjhx.xmhjc.service.website.WebsiteUsersService;
|
|
|
+import com.fjhx.xmhjc.utils.WebsiteUserUtil;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/open/topic")
|
|
|
+public class OpenTopicController {
|
|
|
+ @Resource
|
|
|
+ private TopicContentService topicContentService;
|
|
|
+ @Resource
|
|
|
+ private TopicRepliesService topicRepliesService;
|
|
|
+ @Resource
|
|
|
+ private WebsiteUsersService websiteUsersService;
|
|
|
+
|
|
|
+ @PostMapping("/contentPage")
|
|
|
+ public Page<TopicContentVo> categoryList(TopicContentSelectDto dto) {
|
|
|
+ dto.setType("1");
|
|
|
+ Page<TopicContentVo> page = topicContentService.contentPage(dto);
|
|
|
+ page.getRecords().forEach(topicContentVo -> {
|
|
|
+ WebsiteUsers websiteUsers = websiteUsersService.getById(topicContentVo.getAuthor());
|
|
|
+ topicContentVo.setAuthorName(ObjectUtil.isNull(websiteUsers) ? "匿名" : websiteUsers.getUserName());
|
|
|
+ });
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @LoginValid
|
|
|
+ @PostMapping("/createQuestion")
|
|
|
+ public void categoryList(@RequestBody TopicContentDto topicContentDto) {
|
|
|
+ if (StrUtil.isBlank(topicContentDto.getTitle())) {
|
|
|
+ throw new RuntimeException("标题不能为空");
|
|
|
+ }
|
|
|
+ if (StrUtil.isBlank(topicContentDto.getContent())) {
|
|
|
+ throw new RuntimeException("内容不能为空");
|
|
|
+ }
|
|
|
+ topicContentDto.setType("1");
|
|
|
+ WebsiteUsers loginWebsiteUser = WebsiteUserUtil.getLoginWebsiteUser();
|
|
|
+ topicContentDto.setAuthor(loginWebsiteUser.getId());
|
|
|
+ topicContentService.add(topicContentDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @LoginValid
|
|
|
+ @PostMapping("/reply/{topicId}")
|
|
|
+ public void categoryList(@RequestBody TopicRepliesDto topicRepliesDto, @PathVariable Long topicId) {
|
|
|
+ if (StrUtil.isBlank(topicRepliesDto.getContent())) {
|
|
|
+ throw new RuntimeException("回复不能为空");
|
|
|
+ }
|
|
|
+ topicRepliesDto.setTopicId(topicId);
|
|
|
+ WebsiteUsers loginWebsiteUser = WebsiteUserUtil.getLoginWebsiteUser();
|
|
|
+ topicRepliesDto.setAuthor(loginWebsiteUser.getId());
|
|
|
+ topicRepliesService.add(topicRepliesDto);
|
|
|
+ }
|
|
|
+}
|