Browse Source

在线问答

1018653686@qq.com 1 year ago
parent
commit
92cdc7f6ba

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

@@ -49,7 +49,7 @@ public class OpenTopicController {
         dto.setType("1");
         dto.setType("1");
         Page<TopicContentVo> page = topicContentService.contentPage(dto, sortType);
         Page<TopicContentVo> page = topicContentService.contentPage(dto, sortType);
         page.getRecords().forEach(topicContentVo -> {
         page.getRecords().forEach(topicContentVo -> {
-            topicContentVo.setAuthorName(topicContentService.getAuthorName(topicContentVo.getAuthor()));
+            topicContentVo.setAuthorName(websiteUsersService.getAuthorName(topicContentVo.getAuthor()));
         });
         });
         return page;
         return page;
     }
     }
@@ -68,14 +68,14 @@ public class OpenTopicController {
         Map<Long, WebsiteUsers> websiteUsersMap = new HashMap<>();
         Map<Long, WebsiteUsers> websiteUsersMap = new HashMap<>();
         Page<TopicRepliesVo> page = topicRepliesService.replyPage(dto);
         Page<TopicRepliesVo> page = topicRepliesService.replyPage(dto);
         page.getRecords().forEach(topicContentVo -> {
         page.getRecords().forEach(topicContentVo -> {
-            topicContentVo.setAuthorName(topicContentService.getAuthorName(topicContentVo.getAuthor(), websiteUsersMap));
+            topicContentVo.setAuthorName(websiteUsersService.getAuthorName(topicContentVo.getAuthor(), websiteUsersMap));
 
 
             WebsiteUsers websiteUsers = websiteUsersMap.get(topicContentVo.getAuthor());
             WebsiteUsers websiteUsers = websiteUsersMap.get(topicContentVo.getAuthor());
             if(ObjectUtil.isNull(websiteUsers)){
             if(ObjectUtil.isNull(websiteUsers)){
                 websiteUsers = websiteUsersService.getById(topicContentVo.getAuthor());
                 websiteUsers = websiteUsersService.getById(topicContentVo.getAuthor());
                 websiteUsersMap.put(topicContentVo.getAuthor(),websiteUsers);
                 websiteUsersMap.put(topicContentVo.getAuthor(),websiteUsers);
             }
             }
-            topicContentVo.setCiteAuthorName(topicContentService.getAuthorName(topicContentVo.getCiteAuthor(), websiteUsersMap));
+            topicContentVo.setCiteAuthorName(websiteUsersService.getAuthorName(topicContentVo.getCiteAuthor(), websiteUsersMap));
         });
         });
         return page;
         return page;
     }
     }
@@ -130,13 +130,13 @@ public class OpenTopicController {
         topicContentService.updateById(topicContent);
         topicContentService.updateById(topicContent);
 
 
         OpenTopicContentVO openTopicContentVO = BeanUtil.copyProperties(topicContent, OpenTopicContentVO.class);
         OpenTopicContentVO openTopicContentVO = BeanUtil.copyProperties(topicContent, OpenTopicContentVO.class);
-        openTopicContentVO.setAuthorName(topicContentService.getAuthorName(topicContent.getAuthor()));
+        openTopicContentVO.setAuthorName(websiteUsersService.getAuthorName(topicContent.getAuthor()));
         //分页查出楼层回复
         //分页查出楼层回复
         TopicRepliesSelectDto dto = new TopicRepliesSelectDto();
         TopicRepliesSelectDto dto = new TopicRepliesSelectDto();
         Page<TopicRepliesVo> page = topicRepliesService.getPageByOpen(dto);
         Page<TopicRepliesVo> page = topicRepliesService.getPageByOpen(dto);
         List<TopicRepliesVo> records = page.getRecords();
         List<TopicRepliesVo> records = page.getRecords();
         records.forEach(topicRepliesVo -> {
         records.forEach(topicRepliesVo -> {
-            topicRepliesVo.setAuthorName(topicContentService.getAuthorName(topicRepliesVo.getAuthor()));
+            topicRepliesVo.setAuthorName(websiteUsersService.getAuthorName(topicRepliesVo.getAuthor()));
             dto.setFloorId(topicRepliesVo.getId());
             dto.setFloorId(topicRepliesVo.getId());
             Page<TopicRepliesVo> floorPage = topicRepliesService.getPageByOpen(dto);
             Page<TopicRepliesVo> floorPage = topicRepliesService.getPageByOpen(dto);
             topicRepliesVo.setFloorPage(floorPage);
             topicRepliesVo.setFloorPage(floorPage);

+ 0 - 4
hx-xmhjc/src/main/java/com/fjhx/xmhjc/controller/topic/TopicContentController.java

@@ -78,9 +78,5 @@ public class TopicContentController {
         topicContentService.delete(dto.getId());
         topicContentService.delete(dto.getId());
     }
     }
 
 
-    @PostMapping("/hasReply")
-    public Boolean hasReply(@RequestBody TopicContentDto topicContentDto) {
-        return topicRepliesService.hasReply(topicContentDto.getId());
-    }
 
 
 }
 }

+ 19 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/controller/topic/TopicRepliesController.java

@@ -1,5 +1,6 @@
 package com.fjhx.xmhjc.controller.topic;
 package com.fjhx.xmhjc.controller.topic;
 
 
+import com.fjhx.xmhjc.entity.topic.dto.TopicContentDto;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.xmhjc.entity.topic.vo.TopicRepliesVo;
 import com.fjhx.xmhjc.entity.topic.vo.TopicRepliesVo;
@@ -74,4 +75,22 @@ public class TopicRepliesController {
         topicRepliesService.delete(dto.getId());
         topicRepliesService.delete(dto.getId());
     }
     }
 
 
+
+    @PostMapping("/hasReply")
+    public Boolean hasReply(@RequestBody TopicRepliesSelectDto topicRepliesSelectDto) {
+        return topicRepliesService.hasReply(topicRepliesSelectDto.getTopicId());
+    }
+
+    @PostMapping("/hasFloorReply")
+    public Boolean hasFloorReply(@RequestBody TopicRepliesSelectDto topicRepliesSelectDto) {
+        return topicRepliesService.hasFloorReply(topicRepliesSelectDto.getFloorId());
+    }
+
+    /**
+     * 主题回复删除
+     */
+    @PostMapping("/deleteAndChild")
+    public void deleteAndChild(@RequestBody BaseSelectDto dto) {
+        topicRepliesService.deleteAndChild(dto.getId());
+    }
 }
 }

+ 0 - 3
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/topic/TopicContentService.java

@@ -54,7 +54,4 @@ public interface TopicContentService extends BaseService<TopicContent> {
 
 
     Page<TopicContentVo> contentPage(TopicContentSelectDto dto, String sortType);
     Page<TopicContentVo> contentPage(TopicContentSelectDto dto, String sortType);
 
 
-    String getAuthorName(Long author);
-
-    String getAuthorName(Long author, Map<Long, WebsiteUsers> websiteUsersMap);
 }
 }

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

@@ -53,5 +53,9 @@ public interface TopicRepliesService extends BaseService<TopicReplies> {
 
 
     Page<TopicRepliesVo> replyPage(TopicRepliesSelectDto dto);
     Page<TopicRepliesVo> replyPage(TopicRepliesSelectDto dto);
 
 
-    Boolean hasReply(Long id);
+    Boolean hasReply(Long topicId);
+
+    Boolean hasFloorReply(Long floorId);
+
+    void deleteAndChild(Long id);
 }
 }

+ 1 - 18
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/topic/impl/TopicContentServiceImpl.java

@@ -51,7 +51,7 @@ public class TopicContentServiceImpl extends ServiceImpl<TopicContentMapper, Top
         Page<TopicContentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         Page<TopicContentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         List<TopicContentVo> records = page.getRecords();
         List<TopicContentVo> records = page.getRecords();
         for (TopicContentVo record : records) {
         for (TopicContentVo record : records) {
-            record.setAuthorName(getAuthorName(record.getAuthor()));
+            record.setAuthorName(websiteUsersService.getAuthorName(record.getAuthor()));
         }
         }
         return page;
         return page;
     }
     }
@@ -93,21 +93,4 @@ public class TopicContentServiceImpl extends ServiceImpl<TopicContentMapper, Top
         Page<TopicContentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         Page<TopicContentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         return page;
         return page;
     }
     }
-
-
-    @Override
-    public String getAuthorName(Long author) {
-        WebsiteUsers websiteUsers = websiteUsersService.getById(author);
-        return ObjectUtil.isNull(websiteUsers) ? "" : websiteUsers.getUserName();
-    }
-
-    @Override
-    public String getAuthorName(Long author, Map<Long, WebsiteUsers> websiteUsersMap) {
-        WebsiteUsers websiteUsers = websiteUsersMap.get(author);
-        if (ObjectUtil.isNull(websiteUsers)) {
-            websiteUsers = websiteUsersService.getById(author);
-            websiteUsersMap.put(author, websiteUsers);
-        }
-        return ObjectUtil.isNull(websiteUsers) ? "" : websiteUsers.getUserName();
-    }
 }
 }

+ 31 - 2
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/topic/impl/TopicRepliesServiceImpl.java

@@ -4,9 +4,11 @@ import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
 import com.fjhx.xmhjc.entity.topic.po.TopicReplies;
 import com.fjhx.xmhjc.entity.topic.po.TopicReplies;
+import com.fjhx.xmhjc.entity.topic.vo.TopicContentVo;
 import com.fjhx.xmhjc.mapper.topic.TopicRepliesMapper;
 import com.fjhx.xmhjc.mapper.topic.TopicRepliesMapper;
 import com.fjhx.xmhjc.service.topic.TopicRepliesService;
 import com.fjhx.xmhjc.service.topic.TopicRepliesService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.xmhjc.service.website.WebsiteUsersService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.xmhjc.entity.topic.vo.TopicRepliesVo;
 import com.fjhx.xmhjc.entity.topic.vo.TopicRepliesVo;
@@ -14,7 +16,9 @@ import com.fjhx.xmhjc.entity.topic.dto.TopicRepliesSelectDto;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.fjhx.xmhjc.entity.topic.dto.TopicRepliesDto;
 import com.fjhx.xmhjc.entity.topic.dto.TopicRepliesDto;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.BeanUtil;
+import org.springframework.transaction.annotation.Transactional;
 
 
+import javax.annotation.Resource;
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -28,6 +32,9 @@ import java.util.List;
 @Service
 @Service
 public class TopicRepliesServiceImpl extends ServiceImpl<TopicRepliesMapper, TopicReplies> implements TopicRepliesService {
 public class TopicRepliesServiceImpl extends ServiceImpl<TopicRepliesMapper, TopicReplies> implements TopicRepliesService {
 
 
+    @Resource
+    private WebsiteUsersService websiteUsersService;
+
     @Override
     @Override
     public List<TopicRepliesVo> getList(TopicRepliesSelectDto dto) {
     public List<TopicRepliesVo> getList(TopicRepliesSelectDto dto) {
         IWrapper<TopicReplies> wrapper = getWrapper();
         IWrapper<TopicReplies> wrapper = getWrapper();
@@ -42,6 +49,10 @@ public class TopicRepliesServiceImpl extends ServiceImpl<TopicRepliesMapper, Top
         wrapper.orderByDesc("tr", TopicReplies::getId);
         wrapper.orderByDesc("tr", TopicReplies::getId);
         wrapper.eq(NumberUtil.isValidNumber(dto.getTopicId()), "topic_id", dto.getTopicId());
         wrapper.eq(NumberUtil.isValidNumber(dto.getTopicId()), "topic_id", dto.getTopicId());
         Page<TopicRepliesVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         Page<TopicRepliesVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        List<TopicRepliesVo> repliesVos = page.getRecords();
+        for (TopicRepliesVo repliesVo : repliesVos) {
+            repliesVo.setAuthorName(websiteUsersService.getAuthorName(repliesVo.getAuthor()));
+        }
         return page;
         return page;
     }
     }
 
 
@@ -88,12 +99,30 @@ public class TopicRepliesServiceImpl extends ServiceImpl<TopicRepliesMapper, Top
     }
     }
 
 
     @Override
     @Override
-    public Boolean hasReply(Long id) {
+    public Boolean hasReply(Long topicId) {
+        Boolean hasReply = false;
+        Long count = lambdaQuery().eq(TopicReplies::getTopicId, topicId).count();
+        if (count > 0) {
+            hasReply = true;
+        }
+        return hasReply;
+    }
+
+    @Override
+    public Boolean hasFloorReply(Long floorId) {
         Boolean hasReply = false;
         Boolean hasReply = false;
-        Long count = lambdaQuery().eq(TopicReplies::getTopicId, id).count();
+        Long count = lambdaQuery().eq(TopicReplies::getFloorId, floorId).count();
         if (count > 0) {
         if (count > 0) {
             hasReply = true;
             hasReply = true;
         }
         }
         return hasReply;
         return hasReply;
     }
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteAndChild(Long id) {
+        removeById(id);
+        lambdaUpdate().eq(TopicReplies::getFloorId, id).remove();
+    }
+
 }
 }

+ 5 - 0
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/website/WebsiteUsersService.java

@@ -8,6 +8,7 @@ import com.fjhx.xmhjc.entity.website.dto.WebsiteUsersSelectDto;
 import com.fjhx.xmhjc.entity.website.dto.WebsiteUsersDto;
 import com.fjhx.xmhjc.entity.website.dto.WebsiteUsersDto;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Optional;
 
 
 /**
 /**
@@ -59,4 +60,8 @@ public interface WebsiteUsersService extends BaseService<WebsiteUsers> {
     void register(WebsiteUsersDto websiteUsersDto);
     void register(WebsiteUsersDto websiteUsersDto);
 
 
     Optional<WebsiteUsers> getByUserName(String userName);
     Optional<WebsiteUsers> getByUserName(String userName);
+
+    String getAuthorName(Long author);
+
+    String getAuthorName(Long author, Map<Long, WebsiteUsers> websiteUsersMap);
 }
 }

+ 19 - 1
hx-xmhjc/src/main/java/com/fjhx/xmhjc/service/website/impl/WebsiteUsersServiceImpl.java

@@ -1,11 +1,11 @@
 package com.fjhx.xmhjc.service.website.impl;
 package com.fjhx.xmhjc.service.website.impl;
 
 
+import cn.hutool.core.util.ObjectUtil;
 import com.fjhx.xmhjc.constants.LoginConstant;
 import com.fjhx.xmhjc.constants.LoginConstant;
 import com.fjhx.xmhjc.entity.website.po.WebsiteUsers;
 import com.fjhx.xmhjc.entity.website.po.WebsiteUsers;
 import com.fjhx.xmhjc.mapper.website.WebsiteUsersMapper;
 import com.fjhx.xmhjc.mapper.website.WebsiteUsersMapper;
 import com.fjhx.xmhjc.service.website.WebsiteUsersService;
 import com.fjhx.xmhjc.service.website.WebsiteUsersService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.sign.Md5Utils;
 import com.ruoyi.common.utils.sign.Md5Utils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -16,6 +16,7 @@ import com.fjhx.xmhjc.entity.website.dto.WebsiteUsersDto;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.BeanUtil;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Optional;
 
 
 /**
 /**
@@ -78,4 +79,21 @@ public class WebsiteUsersServiceImpl extends ServiceImpl<WebsiteUsersMapper, Web
     public Optional<WebsiteUsers> getByUserName(String userName) {
     public Optional<WebsiteUsers> getByUserName(String userName) {
         return this.lambdaQuery().eq(WebsiteUsers::getUserName, userName).oneOpt();
         return this.lambdaQuery().eq(WebsiteUsers::getUserName, userName).oneOpt();
     }
     }
+
+
+    @Override
+    public String getAuthorName(Long author) {
+        WebsiteUsers websiteUsers = this.getById(author);
+        return ObjectUtil.isNull(websiteUsers) ? "" : websiteUsers.getUserName();
+    }
+
+    @Override
+    public String getAuthorName(Long author, Map<Long, WebsiteUsers> websiteUsersMap) {
+        WebsiteUsers websiteUsers = websiteUsersMap.get(author);
+        if (ObjectUtil.isNull(websiteUsers)) {
+            websiteUsers = this.getById(author);
+            websiteUsersMap.put(author, websiteUsers);
+        }
+        return ObjectUtil.isNull(websiteUsers) ? "" : websiteUsers.getUserName();
+    }
 }
 }