fangqing 6 місяців тому
батько
коміт
64975e4c92

+ 380 - 245
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -14,10 +14,7 @@ import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
 import com.ruoyi.generator.service.*;
-import com.ruoyi.generator.vo.CommunityArticleVo;
-import com.ruoyi.generator.vo.CommunityCircleVo;
-import com.ruoyi.generator.vo.CommunityCollectionArticleVo;
-import com.ruoyi.generator.vo.CommunityCollectionVo;
+import com.ruoyi.generator.vo.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.logging.log4j.util.Strings;
@@ -120,7 +117,11 @@ public class CommunityArticleController extends BaseController {
             return AjaxResult.error("板块不能为空");
         }
 
-        communityArticleService.insertCommunityArticle(communityArticle);
+        try {
+            communityArticleService.insertCommunityArticle(communityArticle);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success("文章发布成功!");
     }
 
@@ -135,12 +136,15 @@ public class CommunityArticleController extends BaseController {
         if (Strings.isEmpty(id)) {
             return AjaxResult.error("参数异常!");
         }
-
-        CommunityArticle communityArticle = new CommunityArticle();
-        communityArticle.setIsDelete(true);
-        boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
-        if (result) {
-            return success("删除成功!");
+        try {
+            CommunityArticle communityArticle = new CommunityArticle();
+            communityArticle.setIsDelete(true);
+            boolean result = communityArticleService.update(communityArticle, new UpdateWrapper<CommunityArticle>().eq("id", id));
+            if (result) {
+                return success("删除成功!");
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
         return error("删除失败!");
     }
@@ -150,7 +154,12 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("获取文章分类列表")
     //@Anonymous
     public AjaxResult getClassList() {
-        List<CommunityClass> communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>());
+        List<CommunityClass> communityClasses = null;
+        try {
+            communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success(communityClasses);
     }
 
@@ -158,10 +167,15 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("获取文章圈子列表")
     //@Anonymous
     public AjaxResult getCircleList() {
-        List<CommunityCircle> communityClasses = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>());
-        for (CommunityCircle communityCircle : communityClasses) {
-            String className = communityClassCircleMapper.getClassNameByCircleId(communityCircle.getId());
-            communityCircle.setCircleName(className + "·" + communityCircle.getCircleName());
+        List<CommunityCircle> communityClasses = null;
+        try {
+            communityClasses = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>());
+            for (CommunityCircle communityCircle : communityClasses) {
+                String className = communityClassCircleMapper.getClassNameByCircleId(communityCircle.getId());
+                communityCircle.setCircleName(className + "·" + communityCircle.getCircleName());
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
         return AjaxResult.success(communityClasses);
     }
@@ -174,16 +188,19 @@ public class CommunityArticleController extends BaseController {
         if (null == communityArticleComment.getArticleId()) {
             return AjaxResult.error("文章不存在或异常!");
         }
-        System.out.println("communityArticleComment: " + communityArticleComment);
         Long userId = SecurityUtils.getUserId();
-        //调用方法去判断当前评论的用户 是不是文章作者的关注列表
-        Boolean aBoolean = communityArticleService.checkCommentPermission(userId, null, communityArticleComment.getArticleId());
-        communityArticleComment.setUserId(SecurityUtils.getUserId());
-        if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
-            return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
-        }
-        //新增评论
-        communityArticleService.sendComment(communityArticleComment);
+        try {
+            //调用方法去判断当前评论的用户 是不是文章作者的关注列表
+            Boolean aBoolean = communityArticleService.checkCommentPermission(userId, null, communityArticleComment.getArticleId());
+            communityArticleComment.setUserId(SecurityUtils.getUserId());
+            if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
+                return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
+            }
+            //新增评论
+            communityArticleService.sendComment(communityArticleComment);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success();
     }
 
@@ -191,14 +208,17 @@ public class CommunityArticleController extends BaseController {
     @DeleteMapping("/comment")
     @Transactional
     public AjaxResult deleteComment(@RequestBody CommunityArticleComment communityArticleComment) {
-        //获取评论信息
-        CommunityArticleComment articleComment = communityArticleCommentMapper.selectById(communityArticleComment.getId());
-
-        if (!articleComment.getCreateBy().equals(SecurityUtils.getUserId())) {
-            return AjaxResult.error("不允许删除别人的评论!");
+        try {
+            //获取评论信息
+            CommunityArticleComment articleComment = communityArticleCommentMapper.selectById(communityArticleComment.getId());
+            if (!articleComment.getCreateBy().equals(SecurityUtils.getUserId())) {
+                return AjaxResult.error("不允许删除别人的评论!");
+            }
+            //删除评论
+            communityArticleService.deleteComment(articleComment);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
-        //删除评论
-        communityArticleService.deleteComment(articleComment);
         return AjaxResult.success();
     }
 
@@ -215,25 +235,30 @@ public class CommunityArticleController extends BaseController {
         }
         boolean isSuccess = true;
         String message = "";
-        CommunityLike like = communityArticleService.selectCommunityLikeById(communityLike);
-        if (Objects.isNull(like)) {
-            //新增点赞
-            communityLike.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
-            communityLike.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
-            communityLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-            communityLike.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
-            isSuccess = communityArticleService.insertCommunityLikeById(communityLike);
-            message = "感谢点赞";
-        } else {
-            //删除点赞
-            isSuccess = communityArticleService.deleteCommunityLikeById(like);
-            message = "取消点赞";
-        }
-
-        if (!isSuccess) {
-            message = "操作失败!";
-            return AjaxResult.error(message);
+        try {
+            CommunityLike like = communityArticleService.selectCommunityLikeById(communityLike);
+            if (Objects.isNull(like)) {
+                //新增点赞
+                communityLike.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
+                communityLike.setUpdateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
+                communityLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityLike.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                isSuccess = communityArticleService.insertCommunityLikeById(communityLike);
+                message = "感谢点赞";
+            } else {
+                //删除点赞
+                isSuccess = communityArticleService.deleteCommunityLikeById(like);
+                message = "取消点赞";
+            }
+
+            if (!isSuccess) {
+                message = "操作失败!";
+                return AjaxResult.error(message);
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(message);
     }
 
@@ -251,34 +276,39 @@ public class CommunityArticleController extends BaseController {
         boolean isSuccess = true;
         String message = "";
         Long userId = SecurityUtils.getUserId();
-        CommunityArticleRecommend recommend = communityArticleRecommendService.getOne(new QueryWrapper<CommunityArticleRecommend>()
-                .eq("article_id", articleRecommend.getArticleId())
-                .eq("user_id", userId).and((wrapper) -> {
-                    wrapper.ne("is_delete", true).or().isNull("is_delete");
-                }));
-        if (Objects.isNull(recommend)) {
-            //新增推荐值
-            recommend = new CommunityArticleRecommend();
-            recommend.setArticleId(articleRecommend.getArticleId());
-            recommend.setCreateBy(userId);
-            recommend.setUserId(userId);
-            recommend.setDelete(false);
-            recommend.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-            isSuccess = communityArticleRecommendService.save(recommend);
-            message = "感谢推荐";
-        } else {
-            //删除点赞
-            recommend.setDelete(true);
-            recommend.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
-            recommend.setUpdateBy(userId);
-            isSuccess = communityArticleRecommendService.updateById(recommend);
-            message = "取消推荐";
-        }
-
-        if (!isSuccess) {
-            message = "操作失败!";
-            return AjaxResult.error(message);
+        try {
+            CommunityArticleRecommend recommend = communityArticleRecommendService.getOne(new QueryWrapper<CommunityArticleRecommend>()
+                    .eq("article_id", articleRecommend.getArticleId())
+                    .eq("user_id", userId).and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }));
+            if (Objects.isNull(recommend)) {
+                //新增推荐值
+                recommend = new CommunityArticleRecommend();
+                recommend.setArticleId(articleRecommend.getArticleId());
+                recommend.setCreateBy(userId);
+                recommend.setUserId(userId);
+                recommend.setDelete(false);
+                recommend.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                isSuccess = communityArticleRecommendService.save(recommend);
+                message = "感谢推荐";
+            } else {
+                //删除点赞
+                recommend.setDelete(true);
+                recommend.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                recommend.setUpdateBy(userId);
+                isSuccess = communityArticleRecommendService.updateById(recommend);
+                message = "取消推荐";
+            }
+
+            if (!isSuccess) {
+                message = "操作失败!";
+                return AjaxResult.error(message);
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(message);
     }
 
@@ -296,21 +326,27 @@ public class CommunityArticleController extends BaseController {
         }
         boolean isSuccess = true;
         String message = "";
-        CommunityArticleCollect collect = communityArticleService.selectCommunityCollectById(communityArticleCollect);
-        if (Objects.isNull(collect) || Objects.isNull(collect.getId())) {
-            //新增收藏
-            isSuccess = communityArticleService.insertCommunityCollectById(communityArticleCollect);
-            message = "收藏成功";
-        } else {
-            //删除收藏
-            isSuccess = communityArticleService.deleteCommunityCollectById(collect);
-            message = "取消收藏";
-        }
 
-        if (!isSuccess) {
-            message = "操作失败!";
-            return AjaxResult.error(message);
+        try {
+            CommunityArticleCollect collect = communityArticleService.selectCommunityCollectById(communityArticleCollect);
+            if (Objects.isNull(collect) || Objects.isNull(collect.getId())) {
+                //新增收藏
+                isSuccess = communityArticleService.insertCommunityCollectById(communityArticleCollect);
+                message = "收藏成功";
+            } else {
+                //删除收藏
+                isSuccess = communityArticleService.deleteCommunityCollectById(collect);
+                message = "取消收藏";
+            }
+
+            if (!isSuccess) {
+                message = "操作失败!";
+                return AjaxResult.error(message);
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(message);
     }
 
@@ -326,39 +362,44 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(commentLike.getCommentId())) {
             return AjaxResult.error("评论或用户信息异常!");
         }
-
         Long userId = SecurityUtils.getLoginUser().getUserId();
         String message = "";
-        //评论点赞
-        //查询该评论是否已点赞
-        QueryWrapper<CommunityCommentLike> queryWrapper = null;
-        if (commentLike.isReply()) {
-            //回复的点赞
-            queryWrapper = new QueryWrapper<CommunityCommentLike>()
-                    .eq("reply_id", commentLike.getCommentId())
-                    .eq("user_id", userId);
-            commentLike.setReplyId(commentLike.getCommentId());
-            commentLike.setCommentId(null);
-        } else {
-            //评论的点赞
-            queryWrapper = new QueryWrapper<CommunityCommentLike>()
-                    .eq("comment_id", commentLike.getCommentId())
-                    .eq("user_id", userId);
-        }
-
-        CommunityCommentLike communityCommentLike = communityCommentLikeMapper.selectOne(queryWrapper);
-        if (Objects.isNull(communityCommentLike) || Objects.isNull(communityCommentLike.getId())) {
-            //新增点赞
-            commentLike.setCreateBy(userId);
-            commentLike.setUserId(userId);
-            commentLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-            communityCommentLikeMapper.insert(commentLike);
-            message = "感谢点赞";
-        } else {
-            //删除点赞
-            communityCommentLikeMapper.deleteById(communityCommentLike);
-            message = "取消点赞";
+
+        try {
+            //评论点赞
+            //查询该评论是否已点赞
+            QueryWrapper<CommunityCommentLike> queryWrapper = null;
+            if (commentLike.isReply()) {
+                //回复的点赞
+                queryWrapper = new QueryWrapper<CommunityCommentLike>()
+                        .eq("reply_id", commentLike.getCommentId())
+                        .eq("user_id", userId);
+                commentLike.setReplyId(commentLike.getCommentId());
+                commentLike.setCommentId(null);
+            } else {
+                //评论的点赞
+                queryWrapper = new QueryWrapper<CommunityCommentLike>()
+                        .eq("comment_id", commentLike.getCommentId())
+                        .eq("user_id", userId);
+            }
+
+            CommunityCommentLike communityCommentLike = communityCommentLikeMapper.selectOne(queryWrapper);
+            if (Objects.isNull(communityCommentLike) || Objects.isNull(communityCommentLike.getId())) {
+                //新增点赞
+                commentLike.setCreateBy(userId);
+                commentLike.setUserId(userId);
+                commentLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityCommentLikeMapper.insert(commentLike);
+                message = "感谢点赞";
+            } else {
+                //删除点赞
+                communityCommentLikeMapper.deleteById(communityCommentLike);
+                message = "取消点赞";
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(message);
     }
 
@@ -370,7 +411,12 @@ public class CommunityArticleController extends BaseController {
         if (Strings.isBlank(classId)) {
             return AjaxResult.error("板块信息有误!");
         }
-        List<CommunityCircleVo> communityCircles = communityArticleService.selectCommunityCircleList(classId);
+        List<CommunityCircleVo> communityCircles = null;
+        try {
+            communityCircles = communityArticleService.selectCommunityCircleList(classId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success(communityCircles);
     }
 
@@ -379,22 +425,29 @@ public class CommunityArticleController extends BaseController {
     //@Anonymous
     public AjaxResult myCircle(@RequestParam(required = false) String circleName) {
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        List<CommunityUserCircle> communityUserCircles = communityUserCircleMapper.selectList(new QueryWrapper<CommunityUserCircle>()
-                .eq("user_id", userId)
-                .and((wrapper) -> {
-                    wrapper.ne("is_delete", 1).or().isNull("is_delete");
-                }));
 
-        List<Long> circleIds = new ArrayList<>();
-        for (CommunityUserCircle communityUserCircle : communityUserCircles) {
-            circleIds.add(communityUserCircle.getCircleId());
-        }
         List<CommunityCircle> communityCircles = null;
-        if (!circleIds.isEmpty()) {
-            communityCircles = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>()
-                    .in("id", circleIds)
-                    .like("circle_name", circleName));
+        try {
+            List<CommunityUserCircle> communityUserCircles = communityUserCircleMapper.selectList(new QueryWrapper<CommunityUserCircle>()
+                    .eq("user_id", userId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+
+            List<Long> circleIds = new ArrayList<>();
+            for (CommunityUserCircle communityUserCircle : communityUserCircles) {
+                circleIds.add(communityUserCircle.getCircleId());
+            }
+
+            if (!circleIds.isEmpty()) {
+                communityCircles = communityCircleMapper.selectList(new QueryWrapper<CommunityCircle>()
+                        .in("id", circleIds)
+                        .like("circle_name", circleName));
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success("获取成功!", communityCircles);
     }
 
@@ -408,33 +461,39 @@ public class CommunityArticleController extends BaseController {
             return AjaxResult.error("关注圈子异常,请刷新页面重试!");
         }
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        CommunityUserCircle userCircle = communityUserCircleMapper
-                .selectOne(new QueryWrapper<CommunityUserCircle>()
-                        .eq("circle_id", communityUserCircle.getCircleId())
-                        .eq("user_id", userId)
-                        .eq("is_delete", 0));
         String msg = "";
-        if (Objects.isNull(userCircle) || Objects.isNull(userCircle.getId())) {
-            //如果未找到数据,则进行关注
-            userCircle = new CommunityUserCircle();
-            userCircle.setCircleId(communityUserCircle.getCircleId());
-            userCircle.setUserId(userId);
-            userCircle.setCreateBy(userId);
-            userCircle.setUpdateBy(userId);
-            userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-            userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
-            communityUserCircleMapper.insert(userCircle);
-            msg = "已关注";
-        } else {
-            //更新删除标识
-            userCircle.setDelete(true);
-            userCircle.setCreateBy(userId);
-            userCircle.setUpdateBy(userId);
-            userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-            userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
-            communityUserCircleMapper.updateById(userCircle);
-            msg = "已取关";
+        try {
+            CommunityUserCircle userCircle = communityUserCircleMapper
+                    .selectOne(new QueryWrapper<CommunityUserCircle>()
+                            .eq("circle_id", communityUserCircle.getCircleId())
+                            .eq("user_id", userId)
+                            .eq("is_delete", 0));
+
+            if (Objects.isNull(userCircle) || Objects.isNull(userCircle.getId())) {
+                //如果未找到数据,则进行关注
+                userCircle = new CommunityUserCircle();
+                userCircle.setCircleId(communityUserCircle.getCircleId());
+                userCircle.setUserId(userId);
+                userCircle.setCreateBy(userId);
+                userCircle.setUpdateBy(userId);
+                userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityUserCircleMapper.insert(userCircle);
+                msg = "已关注";
+            } else {
+                //更新删除标识
+                userCircle.setDelete(true);
+                userCircle.setCreateBy(userId);
+                userCircle.setUpdateBy(userId);
+                userCircle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                userCircle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityUserCircleMapper.updateById(userCircle);
+                msg = "已取关";
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(msg);
     }
 
@@ -454,11 +513,16 @@ public class CommunityArticleController extends BaseController {
         }
         String msg = "";
         CommunityUserLike communityUserLike = communityArticleService.addOrDeleteUserLike(likeUserId);
-        if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
-            msg = "取消关注";
-        } else {
-            msg = "已关注";
+        try {
+            if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
+                msg = "取消关注";
+            } else {
+                msg = "已关注";
+            }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return AjaxResult.success(msg);
     }
 
@@ -468,7 +532,13 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(userId)) {
             userId = SecurityUtils.getLoginUser().getUserId();
         }
-        return AjaxResult.success(communityArticleService.selectCommunityUserInfoById(userId));
+        CommunityUserInfoVo communityUserInfoVo = null;
+        try {
+            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+        return AjaxResult.success(communityUserInfoVo);
     }
 
 
@@ -478,7 +548,15 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(SearchValue)) {
             return AjaxResult.error();
         }
-        return AjaxResult.success(communityArticleService.selectUserBySearchValue(SearchValue));
+        List<CommunityUserInfoVo> communityUserInfoVos = null;
+        try {
+            communityUserInfoVos = communityArticleService.selectUserBySearchValue(SearchValue);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
+        return AjaxResult.success(communityUserInfoVos);
     }
 
     @ApiOperation("根据条件查询账户")
@@ -487,26 +565,54 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(SearchValue)) {
             return AjaxResult.error();
         }
-        return AjaxResult.success(communityArticleService.selectUsersByAccountOrName(SearchValue));
+        List<CommunityUserInfoVo> communityUserInfoVos = null;
+        try {
+            communityUserInfoVos = communityArticleService.selectUsersByAccountOrName(SearchValue);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserInfoVos);
     }
 
 
     @ApiOperation("获取关注列表")
     @GetMapping("/likeUserList")
     public AjaxResult likeUserList() {
-        return AjaxResult.success(communityArticleService.selectCommunityUserLikeList(SecurityUtils.getLoginUser().getUserId()));
+        List<CommunityUserLikeVo> communityUserLikeVos = null;
+        try {
+            communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(SecurityUtils.getLoginUser().getUserId());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserLikeVos);
     }
 
     @ApiOperation("获取粉丝列表")
     @GetMapping("/userFans")
     public AjaxResult userFans() {
-        return AjaxResult.success(communityArticleService.selectUserFansList(SecurityUtils.getLoginUser().getUserId()));
+        List<CommunityUserLikeVo> communityUserLikeVos = null;
+        try {
+            communityUserLikeVos = communityArticleService.selectUserFansList(SecurityUtils.getLoginUser().getUserId());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserLikeVos);
     }
 
     @ApiOperation("互相关注列表")
     @GetMapping("/mutualAttention")
     public AjaxResult mutualAttention() {
-        return AjaxResult.success(communityArticleService.selectMutualAttention(SecurityUtils.getLoginUser().getUserId()));
+        List<CommunityUserLikeVo> communityUserLikeVos = null;
+        try {
+            communityUserLikeVos = communityArticleService.selectMutualAttention(SecurityUtils.getLoginUser().getUserId());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserLikeVos);
     }
 
     @ApiOperation("发送用户验证码")
@@ -529,14 +635,17 @@ public class CommunityArticleController extends BaseController {
         if (backImage == null) {
             return AjaxResult.error("背景图不能为空");
         }
-
         Long userId = SecurityUtils.getLoginUser().getUserId();
-        CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
-        if (Objects.isNull(communityUserInfo) || Objects.isNull(communityUserInfo.getId())) {
-            return AjaxResult.error("系统出错");
+        try {
+            CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
+            if (Objects.isNull(communityUserInfo) || Objects.isNull(communityUserInfo.getId())) {
+                return AjaxResult.error("系统出错");
+            }
+            communityUserInfo.setBackImage(backImage);
+            communityUserInfoMapper.updateById(communityUserInfo);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
-        communityUserInfo.setBackImage(backImage);
-        communityUserInfoMapper.updateById(communityUserInfo);
         return AjaxResult.success("背景图片上传成功!");
     }
 
@@ -558,7 +667,14 @@ public class CommunityArticleController extends BaseController {
 //                .or()
 //                .isNull("is_delete"));
 
-        List<CommunityCollectionVo> communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId);
+        List<CommunityCollectionVo> communityCollectionVos = null;
+        try {
+          communityCollectionVos = communityCollectionService.selectUserCollection(userId, articleId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
 
         return AjaxResult.success(communityCollectionVos);
     }
@@ -583,26 +699,29 @@ public class CommunityArticleController extends BaseController {
             return AjaxResult.error("合集图片不能为空");
         }
 
-        CommunityCollection collection = communityCollectionService
-                .getOne(new QueryWrapper<CommunityCollection>()
-                        .eq("collection_name", communityCollection.getCollectionName())
-                        .eq("user_id", SecurityUtils.getLoginUser().getUserId())
-                        .and((wrapper) -> {
-                            wrapper.ne("is_delete", true)
-                                    .or()
-                                    .isNull("is_delete");
-                        }));
-
-        if (!Objects.isNull(collection)) {
-            return AjaxResult.error("合集名称不能重复!");
+        try {
+            CommunityCollection collection = communityCollectionService
+                    .getOne(new QueryWrapper<CommunityCollection>()
+                            .eq("collection_name", communityCollection.getCollectionName())
+                            .eq("user_id", SecurityUtils.getLoginUser().getUserId())
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true)
+                                        .or()
+                                        .isNull("is_delete");
+                            }));
+
+            if (!Objects.isNull(collection)) {
+                return AjaxResult.error("合集名称不能重复!");
+            }
+            communityCollection.setUserId(SecurityUtils.getLoginUser().getUserId());
+            communityCollection.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+            communityCollection.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCollection.setDelete(false);
+            communityCollectionService.save(communityCollection);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
 
-        communityCollection.setUserId(SecurityUtils.getLoginUser().getUserId());
-        communityCollection.setCreateBy(SecurityUtils.getLoginUser().getUserId());
-        communityCollection.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-        communityCollection.setDelete(false);
-        communityCollectionService.save(communityCollection);
-
         return AjaxResult.success(communityCollection);
     }
 
@@ -619,8 +738,11 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(collectionId)) {
             return AjaxResult.error("参数异常!");
         }
-
-        communityCollectionService.deleteCollectionById(collectionId);
+        try {
+            communityCollectionService.deleteCollectionById(collectionId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success("删除成功!");
     }
 
@@ -653,55 +775,60 @@ public class CommunityArticleController extends BaseController {
         Long articleId = collectionArticle.getArticleId();
         Long userId = SecurityUtils.getLoginUser().getUserId();
 
-        //查询当前文章是不是属于该用户的
-        List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
-                .eq("user_id", userId)
-                .eq("id", articleId)
-                .and((wrapper) -> {
-                    wrapper.ne("is_delete", 1).or().isNull("is_delete");
-                }));
-
-        if (communityArticles.isEmpty()) {
-            return AjaxResult.success("文章ID不属于当前用户!");
-        }
-
-        //查询当前用户有没有这个合集
-        List<CommunityCollection> communityCollections = communityCollectionMapper.selectList(new QueryWrapper<CommunityCollection>()
-                .eq("user_id", userId)
-                .eq("id", collectionId)
-                .and((wrapper) -> {
-                    wrapper.ne("is_delete", 1).or().isNull("is_delete");
-                }));
-
-        if (communityCollections.isEmpty()) {
-            return AjaxResult.success("合集ID不属于当前登录用户!");
-        }
-
-        System.out.println("communityCollections: " + communityCollections);
-        //根据创建人ID,合集ID,文章ID保持唯一性 查询表如果没有则插入,有了则更新ID
-        List<CommunityCollectionArticle> communityCollectionArticles = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
-                .eq("create_by", userId)
-                .eq("article_id", articleId)
-                .and((wrapper) -> {
-                    wrapper.ne("is_delete", 1).or().isNull("is_delete");
-                }));
-        System.out.println("communityCollectionArticles: " + communityCollectionArticles);
-
-        if (!communityCollectionArticles.isEmpty()) {
-            for (CommunityCollectionArticle communityCollectionArticle : communityCollectionArticles) {
-                Long collectionId1 = communityCollectionArticle.getCollectionId();
-                // 如果 id 与 collectionId 相等,直接返回
-                if (collectionId1.equals(collectionId)) {
-                    return AjaxResult.success("该文章在合集已经存在!");
-                } else {
-                    // 如果不相等,执行删除操作
-                    communityCollectionService.deleteArticleToCollection(collectionId1, articleId);
+
+        try {
+            //查询当前文章是不是属于该用户的
+            List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .eq("user_id", userId)
+                    .eq("id", articleId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+
+            if (communityArticles.isEmpty()) {
+                return AjaxResult.success("文章ID不属于当前用户!");
+            }
+
+            //查询当前用户有没有这个合集
+            List<CommunityCollection> communityCollections = communityCollectionMapper.selectList(new QueryWrapper<CommunityCollection>()
+                    .eq("user_id", userId)
+                    .eq("id", collectionId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+
+            if (communityCollections.isEmpty()) {
+                return AjaxResult.success("合集ID不属于当前登录用户!");
+            }
+
+            System.out.println("communityCollections: " + communityCollections);
+            //根据创建人ID,合集ID,文章ID保持唯一性 查询表如果没有则插入,有了则更新ID
+            List<CommunityCollectionArticle> communityCollectionArticles = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                    .eq("create_by", userId)
+                    .eq("article_id", articleId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+            System.out.println("communityCollectionArticles: " + communityCollectionArticles);
+
+            if (!communityCollectionArticles.isEmpty()) {
+                for (CommunityCollectionArticle communityCollectionArticle : communityCollectionArticles) {
+                    Long collectionId1 = communityCollectionArticle.getCollectionId();
+                    // 如果 id 与 collectionId 相等,直接返回
+                    if (collectionId1.equals(collectionId)) {
+                        return AjaxResult.success("该文章在合集已经存在!");
+                    } else {
+                        // 如果不相等,执行删除操作
+                        communityCollectionService.deleteArticleToCollection(collectionId1, articleId);
+                    }
                 }
             }
+            collectionArticle.setCreateBy(userId);
+            collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCollectionService.addArticleToCollection(collectionArticle);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
-        collectionArticle.setCreateBy(userId);
-        collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-        communityCollectionService.addArticleToCollection(collectionArticle);
 
         return AjaxResult.success("加入合集成功!");
     }
@@ -720,8 +847,11 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(collectionId) || Objects.isNull(articleId)) {
             return AjaxResult.error("参数异常!");
         }
-
-        communityCollectionService.deleteArticleToCollection(collectionId, articleId);
+        try {
+            communityCollectionService.deleteArticleToCollection(collectionId, articleId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success("文章删除成功!");
     }
 
@@ -737,7 +867,12 @@ public class CommunityArticleController extends BaseController {
         if (Objects.isNull(collectionId)) {
             return AjaxResult.error("合集不存在!");
         }
-        List<CommunityCollectionArticleVo> collectionArticleVos = communityCollectionService.selectArticleInfoInCollection(collectionId);
+        List<CommunityCollectionArticleVo> collectionArticleVos = null;
+        try {
+            collectionArticleVos = communityCollectionService.selectArticleInfoInCollection(collectionId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success(collectionArticleVos);
     }
 

+ 46 - 33
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityChatMsgController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.domain.CommunityChatMsg;
@@ -47,42 +48,49 @@ public class CommunityChatMsgController extends BaseController {
     @GetMapping()
     public AjaxResult chatRecord(Long otherUserId, String type) {
         Long userId = SecurityUtils.getUserId();
-        List<CommunityChatMsg> chatMsgList = communityChatMsgService.list(new QueryWrapper<CommunityChatMsg>()
-                .eq("sender_id", userId)
-                .eq("receiver_id", otherUserId)
-                .or()
-                .eq("sender_id", otherUserId)
-                .eq("receiver_id", userId)
-                .eq("type", type)
-                .orderByDesc("create_time"));
-        //更新该消息标记为已读
-        List<Long> msgId = chatMsgList.stream()
-                .filter(item -> !item.isReceiverIsRead() && Objects.equals(item.getReceiverId(), SecurityUtils.getUserId()))
-                .map(CommunityChatMsg::getId)
-                .collect(Collectors.toList());
-        if (!msgId.isEmpty()) {
-            communityChatMsgService.update(new UpdateWrapper<CommunityChatMsg>().in("id", msgId).set("receiver_is_read", true));
-        }
-
         List<CommunityChatMsgVo> chatMsgVos = new ArrayList<>();
-        CommunityChatMsgVo chatMsgVo = null;
-        for (CommunityChatMsg chatMsg : chatMsgList) {
-            chatMsgVo = new CommunityChatMsgVo();
-            BeanUtils.copyProperties(chatMsg, chatMsgVo);
-            SysUser senderUser = sysUserMapper.selectUserById(chatMsgVo.getSenderId());
-            SysUser receiveUser = sysUserMapper.selectUserById(chatMsgVo.getReceiverId());
+        try {
+            List<CommunityChatMsg> chatMsgList = communityChatMsgService.list(new QueryWrapper<CommunityChatMsg>()
+                    .eq("sender_id", userId)
+                    .eq("receiver_id", otherUserId)
+                    .or()
+                    .eq("sender_id", otherUserId)
+                    .eq("receiver_id", userId)
+                    .eq("type", type)
+                    .orderByDesc("create_time"));
+            //更新该消息标记为已读
+            List<Long> msgId = chatMsgList.stream()
+                    .filter(item -> !item.isReceiverIsRead() && Objects.equals(item.getReceiverId(), SecurityUtils.getUserId()))
+                    .map(CommunityChatMsg::getId)
+                    .collect(Collectors.toList());
             if (!msgId.isEmpty()) {
-                boolean contains = msgId.contains(chatMsg.getId());
-                if (contains) {
-                    chatMsgVo.setReceiverIsRead(true);
+                communityChatMsgService.update(new UpdateWrapper<CommunityChatMsg>().in("id", msgId).set("receiver_is_read", true));
+            }
+
+
+            CommunityChatMsgVo chatMsgVo = null;
+            for (CommunityChatMsg chatMsg : chatMsgList) {
+                chatMsgVo = new CommunityChatMsgVo();
+                BeanUtils.copyProperties(chatMsg, chatMsgVo);
+                SysUser senderUser = sysUserMapper.selectUserById(chatMsgVo.getSenderId());
+                SysUser receiveUser = sysUserMapper.selectUserById(chatMsgVo.getReceiverId());
+                if (!msgId.isEmpty()) {
+                    boolean contains = msgId.contains(chatMsg.getId());
+                    if (contains) {
+                        chatMsgVo.setReceiverIsRead(true);
+                    }
                 }
+                chatMsgVo.setSenderNickName(senderUser.getNickName());
+                chatMsgVo.setSenderAvatar(senderUser.getAvatar());
+                chatMsgVo.setReceiverNickName(receiveUser.getNickName());
+                chatMsgVo.setReceiverAvatar(receiveUser.getAvatar());
+                chatMsgVos.add(chatMsgVo);
             }
-            chatMsgVo.setSenderNickName(senderUser.getNickName());
-            chatMsgVo.setSenderAvatar(senderUser.getAvatar());
-            chatMsgVo.setReceiverNickName(receiveUser.getNickName());
-            chatMsgVo.setReceiverAvatar(receiveUser.getAvatar());
-            chatMsgVos.add(chatMsgVo);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
+
         return AjaxResult.success(chatMsgVos);
     }
 
@@ -93,7 +101,12 @@ public class CommunityChatMsgController extends BaseController {
     @GetMapping("/list")
     public AjaxResult chatList(String type) {
         Long userId = SecurityUtils.getUserId();
-        List<SysUserVo> sysUserChatVos = communityChatMsgService.getChatListWithLatestMessage(userId, type);
+        List<SysUserVo> sysUserChatVos = null;
+        try {
+            sysUserChatVos = communityChatMsgService.getChatListWithLatestMessage(userId, type);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return AjaxResult.success(sysUserChatVos);
     }
-}
+}

+ 114 - 88
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.generator.domain.Community.CommunityArticleComment;
@@ -72,57 +73,64 @@ public class CommunityCommentController extends BaseController {
         if (Objects.isNull(articleId)) {
             return AjaxResult.error("参数异常!");
         }
-        Page<CommunityArticleComment> page = new Page<>(currentPage, limit);
-        List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>().eq("article_id", articleId).and((wrapper) -> {
-            wrapper.ne("is_delete", true).or().isNull("is_delete");
-        }).orderByDesc("create_time")).getRecords();
-
-        CommunityArticleCommentVo commentVo = null;
         List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
-        for (CommunityArticleComment record : records) {
-            commentVo = new CommunityArticleCommentVo();
-            BeanUtils.copyProperties(record, commentVo);
-            commentVos.add(commentVo);
-        }
-
-        Long userId = SecurityUtils.getUserId();
-        for (CommunityArticleCommentVo vo : commentVos) {
-            Long commentUserId = vo.getUserId();
-            //获取评论的用户信息
-            SysUser sysUser = sysUserMapper.selectUserById(commentUserId);
-            vo.setNickName(sysUser.getNickName());
-            vo.setAvatar(sysUser.getAvatar());
-            //当前登录用户是否已点赞
-            List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId()).eq("user_id", userId));
-            vo.setCommentLike(!commentLikes.isEmpty());
-            //该评论的点赞数量
-            vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
-            //设置首条评论
-            List<CommunityCommentReply> replies = communityCommentReplyService.list(new QueryWrapper<CommunityCommentReply>().eq("comment_id", vo.getId()).and((wrapper) -> {
+        try {
+            Page<CommunityArticleComment> page = new Page<>(currentPage, limit);
+            List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>().eq("article_id", articleId).and((wrapper) -> {
                 wrapper.ne("is_delete", true).or().isNull("is_delete");
-            }).orderByAsc("create_time"));
+            }).orderByDesc("create_time")).getRecords();
 
-            CommunityCommentReplyVo replyVo = null;
-            List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
-            for (CommunityCommentReply reply : replies) {
-                replyVo = new CommunityCommentReplyVo();
-                BeanUtils.copyProperties(reply, replyVo);
-                replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
-                replyVo.setReply(true);
-                replyVos.add(replyVo);
-                //设置点赞数量和当前登录用户是否已点赞
-                List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
-                        .eq("reply_id", replyVo.getId()));
-                replyVo.setLikeCount(commentLikeList.size());
-                replyVo.setLike(commentLikeList.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
-                break;
+            CommunityArticleCommentVo commentVo = null;
+
+            for (CommunityArticleComment record : records) {
+                commentVo = new CommunityArticleCommentVo();
+                BeanUtils.copyProperties(record, commentVo);
+                commentVos.add(commentVo);
+            }
+
+            Long userId = SecurityUtils.getUserId();
+            for (CommunityArticleCommentVo vo : commentVos) {
+                Long commentUserId = vo.getUserId();
+                //获取评论的用户信息
+                SysUser sysUser = sysUserMapper.selectUserById(commentUserId);
+                vo.setNickName(sysUser.getNickName());
+                vo.setAvatar(sysUser.getAvatar());
+                //当前登录用户是否已点赞
+                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId()).eq("user_id", userId));
+                vo.setCommentLike(!commentLikes.isEmpty());
+                //该评论的点赞数量
+                vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", vo.getId())).size());
+                //设置首条评论
+                List<CommunityCommentReply> replies = communityCommentReplyService.list(new QueryWrapper<CommunityCommentReply>().eq("comment_id", vo.getId()).and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                }).orderByAsc("create_time"));
+
+                CommunityCommentReplyVo replyVo = null;
+                List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
+                for (CommunityCommentReply reply : replies) {
+                    replyVo = new CommunityCommentReplyVo();
+                    BeanUtils.copyProperties(reply, replyVo);
+                    replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
+                    replyVo.setReply(true);
+                    replyVos.add(replyVo);
+                    //设置点赞数量和当前登录用户是否已点赞
+                    List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                            .eq("reply_id", replyVo.getId()));
+                    replyVo.setLikeCount(commentLikeList.size());
+                    replyVo.setLike(commentLikeList.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
+                    break;
+                }
+                vo.setFirstReply(replyVos);
+                //设置还剩多少评论
+                vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
+                vo.setReply(false);
             }
-            vo.setFirstReply(replyVos);
-            //设置还剩多少评论
-            vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
-            vo.setReply(false);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
 
+
+
         return AjaxResult.success(commentVos);
     }
 
@@ -137,34 +145,41 @@ public class CommunityCommentController extends BaseController {
         if (Objects.isNull(commentId)) {
             return AjaxResult.error("参数异常!");
         }
-        Page<CommunityCommentReply> page = new Page<>(currentPage, limit);
-        List<CommunityCommentReply> replies = communityCommentReplyService.page(page, new QueryWrapper<CommunityCommentReply>().eq("comment_id", commentId).and((wrapper) -> {
-            wrapper.ne("is_delete", true).or().isNull("is_delete");
-        }).orderByAsc("create_time")).getRecords();
-        CommunityCommentReplyVo replyVo = null;
         List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
-        for (final CommunityCommentReply reply : replies) {
-            replyVo = new CommunityCommentReplyVo();
-            SysUser sysUser = sysUserService.selectUserById(reply.getUserId());
-            final Long parentReplyId = reply.getParentReplyId();
-            BeanUtils.copyProperties(reply, replyVo);
-            if (Objects.nonNull(parentReplyId) && !commentId.equalsIgnoreCase(Long.toString(parentReplyId))) {
-                CommunityCommentReply communityCommentReply = replies.stream().filter(item -> item.getId().equals(parentReplyId)).collect(Collectors.toList()).get(0);
-                SysUser sysUser1 = sysUserService.selectUserById(communityCommentReply.getUserId());
-                replyVo.setParentNickName(sysUser1.getNickName());
-                replyVo.setParentUserId(sysUser1.getUserId());
-                replyVo.setParentAvatar(sysUser1.getAvatar());
+        try {
+            Page<CommunityCommentReply> page = new Page<>(currentPage, limit);
+            List<CommunityCommentReply> replies = communityCommentReplyService.page(page, new QueryWrapper<CommunityCommentReply>().eq("comment_id", commentId).and((wrapper) -> {
+                wrapper.ne("is_delete", true).or().isNull("is_delete");
+            }).orderByAsc("create_time")).getRecords();
+            CommunityCommentReplyVo replyVo = null;
+
+            for (final CommunityCommentReply reply : replies) {
+                replyVo = new CommunityCommentReplyVo();
+                SysUser sysUser = sysUserService.selectUserById(reply.getUserId());
+                final Long parentReplyId = reply.getParentReplyId();
+                BeanUtils.copyProperties(reply, replyVo);
+                if (Objects.nonNull(parentReplyId) && !commentId.equalsIgnoreCase(Long.toString(parentReplyId))) {
+                    CommunityCommentReply communityCommentReply = replies.stream().filter(item -> item.getId().equals(parentReplyId)).collect(Collectors.toList()).get(0);
+                    SysUser sysUser1 = sysUserService.selectUserById(communityCommentReply.getUserId());
+                    replyVo.setParentNickName(sysUser1.getNickName());
+                    replyVo.setParentUserId(sysUser1.getUserId());
+                    replyVo.setParentAvatar(sysUser1.getAvatar());
+                }
+                replyVo.setNickName(sysUser.getNickName());
+                replyVo.setAvatar(sysUser.getAvatar());
+                replyVo.setReply(true);
+                //设置点赞数量和当前登录用户是否已点赞
+                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                        .eq("reply_id", replyVo.getId()));
+                replyVo.setLikeCount(commentLikes.size());
+                replyVo.setLike(commentLikes.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
+                replyVos.add(replyVo);
             }
-            replyVo.setNickName(sysUser.getNickName());
-            replyVo.setAvatar(sysUser.getAvatar());
-            replyVo.setReply(true);
-            //设置点赞数量和当前登录用户是否已点赞
-            List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
-                    .eq("reply_id", replyVo.getId()));
-            replyVo.setLikeCount(commentLikes.size());
-            replyVo.setLike(commentLikes.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
-            replyVos.add(replyVo);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
+
         return AjaxResult.success(replyVos);
     }
 
@@ -181,15 +196,21 @@ public class CommunityCommentController extends BaseController {
             return AjaxResult.error("参数异常!");
         }
         Long userId = SecurityUtils.getUserId();
-        Boolean aBoolean = communityArticleService.checkCommentPermission(userId, communityCommentReply.getCommentId(), null);
-        if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
-            return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
+        try {
+            Boolean aBoolean = communityArticleService.checkCommentPermission(userId, communityCommentReply.getCommentId(), null);
+            if (!aBoolean) {  // 当 aBoolean 为 false 时,进入这个条件
+                return AjaxResult.success("您没有权限评论此文章,因为只允许关注的人评论您!");
+            }
+            communityCommentReply.setUserId(userId);
+            communityCommentReply.setDelete(false);
+            communityCommentReply.setCreateBy(userId);
+            communityCommentReply.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCommentReplyService.save(communityCommentReply);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
-        communityCommentReply.setUserId(userId);
-        communityCommentReply.setDelete(false);
-        communityCommentReply.setCreateBy(userId);
-        communityCommentReply.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-        communityCommentReplyService.save(communityCommentReply);
+
+
         return AjaxResult.success(communityCommentReply);
     }
 
@@ -204,19 +225,24 @@ public class CommunityCommentController extends BaseController {
         if (Objects.isNull(replyId)) {
             return AjaxResult.error("参数异常!");
         }
+        try {
+            CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>().eq("id", replyId).and((wrapper) -> {
+                wrapper.ne("is_delete", true).or().isNull("is_delete");
+            }));
+            if (Objects.isNull(communityCommentReply)) {
+                return AjaxResult.error("未找到该回复!");
+            }
 
-        CommunityCommentReply communityCommentReply = communityCommentReplyService.getOne(new QueryWrapper<CommunityCommentReply>().eq("id", replyId).and((wrapper) -> {
-            wrapper.ne("is_delete", true).or().isNull("is_delete");
-        }));
-        if (Objects.isNull(communityCommentReply)) {
-            return AjaxResult.error("未找到该回复!");
+            Long userId = SecurityUtils.getUserId();
+            communityCommentReply.setDelete(true);
+            communityCommentReply.setUpdateBy(userId);
+            communityCommentReply.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCommentReplyService.updateById(communityCommentReply);
+        } catch (Exception e) {
+            throw new ProjectException();
         }
 
-        Long userId = SecurityUtils.getUserId();
-        communityCommentReply.setDelete(true);
-        communityCommentReply.setUpdateBy(userId);
-        communityCommentReply.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
-        communityCommentReplyService.updateById(communityCommentReply);
+
         return AjaxResult.success("删除回复成功!");
     }
 }

+ 24 - 12
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityReportController.java

@@ -3,6 +3,7 @@ package com.ruoyi.generator.controller;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDictData;
+import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.generator.domain.Community.CommunityReport;
 import com.ruoyi.generator.service.ICommunityReportService;
@@ -40,19 +41,24 @@ public class CommunityReportController extends BaseController {
      */
     @GetMapping(value = "/type/{dictType}")
     public AjaxResult dictType(@PathVariable String dictType) {
-        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
         List<SysDictDataVo> dictDataVos = null;
-        SysDictDataVo dictDataVo = null;
-        if (StringUtils.isNull(data)) {
-            dictDataVos = new ArrayList<>();
-        } else {
-            dictDataVos = new ArrayList<>();
-            for (SysDictData dictData : data) {
-                dictDataVo = new SysDictDataVo();
-                BeanUtils.copyProperties(dictData, dictDataVo);
-                dictDataVos.add(dictDataVo);
+        try {
+            List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
+            SysDictDataVo dictDataVo = null;
+            if (StringUtils.isNull(data)) {
+                dictDataVos = new ArrayList<>();
+            } else {
+                dictDataVos = new ArrayList<>();
+                for (SysDictData dictData : data) {
+                    dictDataVo = new SysDictDataVo();
+                    BeanUtils.copyProperties(dictData, dictDataVo);
+                    dictDataVos.add(dictDataVo);
+                }
             }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
+
         return success(dictDataVos);
     }
 
@@ -67,7 +73,13 @@ public class CommunityReportController extends BaseController {
         if (Objects.isNull(communityReport.getReportCode()) || Objects.isNull(communityReport.getArticleId())) {
             return AjaxResult.error("参数异常!");
         }
-        communityReportService.save(communityReport);
+        try {
+            communityReportService.save(communityReport);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
         return AjaxResult.success("您的举报已记录!");
     }
-}
+}

+ 37 - 4
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunitySettingsController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.generator.controller;
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.generator.domain.Community.CommunityArticle;
 import com.ruoyi.generator.domain.Community.CommunityUserNotification;
@@ -8,11 +9,15 @@ import com.ruoyi.generator.domain.Community.CommunityUserPrivacy;
 import com.ruoyi.generator.service.ICommunityArticleService;
 import com.ruoyi.generator.service.ICommunityNotificationService;
 import com.ruoyi.generator.service.ICommunityPrivacyService;
+import com.ruoyi.generator.vo.CommunityUserNotificationVo;
+import com.ruoyi.generator.vo.CommunityUserPrivacyVo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * 社区设置管理
  *
@@ -40,7 +45,14 @@ public class CommunitySettingsController {
     @GetMapping("/userNotification")
     //@Anonymous
     public AjaxResult userNotification() {
-        return AjaxResult.success(communityNotificationService.selectUserNotification(SecurityUtils.getLoginUser().getUserId()));
+        List<CommunityUserNotificationVo> communityUserNotificationVos = null;
+        try {
+            communityUserNotificationVos = communityNotificationService.selectUserNotification(SecurityUtils.getLoginUser().getUserId());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserNotificationVos);
     }
 
     /**
@@ -51,7 +63,14 @@ public class CommunitySettingsController {
     @ApiOperation("更新通知权限")
     @PostMapping("/modifyUserNotification")
     public AjaxResult modifyUserNotification(@RequestBody CommunityUserNotification communityUserNotification) {
-        return AjaxResult.success(communityNotificationService.modifyUserNotification(communityUserNotification));
+        List<CommunityUserNotificationVo> communityUserNotificationVos = null;
+        try {
+            communityUserNotificationVos = communityNotificationService.modifyUserNotification(communityUserNotification);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserNotificationVos);
     }
 
     /**
@@ -63,7 +82,14 @@ public class CommunitySettingsController {
     @GetMapping("/userPrivacy")
     //@Anonymous
     public AjaxResult userPrivacy() {
-        return AjaxResult.success(communityPrivacyService.selectUserPrivacy(SecurityUtils.getLoginUser().getUserId()));
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = null;
+        try {
+            communityUserPrivacyVos = communityPrivacyService.selectUserPrivacy(SecurityUtils.getLoginUser().getUserId());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserPrivacyVos);
     }
 
     /**
@@ -74,7 +100,14 @@ public class CommunitySettingsController {
     @ApiOperation("更新通知权限")
     @PostMapping("/modifyUserPrivacy")
     public AjaxResult modifyUserNotification(@RequestBody CommunityUserPrivacy communityUserPrivacy) {
-        return AjaxResult.success(communityPrivacyService.modifyUserPrivacy(communityUserPrivacy));
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = null;
+        try {
+            communityUserPrivacyVos = communityPrivacyService.modifyUserPrivacy(communityUserPrivacy);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+        return AjaxResult.success(communityUserPrivacyVos);
     }
 
 

+ 69 - 45
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -48,14 +49,20 @@ public class CommunityTagController extends BaseController {
     @Transactional
     //@Anonymous
     public AjaxResult tags(String tagName) {
-        Page<CommunityTag> page = new Page<>(1, 20);
-        List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
-                    wrapper.ne("is_delete", 1)
-                            .or()
-                            .isNull("is_delete");
-                })
-                .like("tag_name", tagName)
-                .orderByDesc("tag_hot")).getRecords();
+        List<CommunityTag> communityTags = null;
+        try {
+            Page<CommunityTag> page = new Page<>(1, 20);
+            communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
+                        wrapper.ne("is_delete", 1)
+                                .or()
+                                .isNull("is_delete");
+                    })
+                    .like("tag_name", tagName)
+                    .orderByDesc("tag_hot")).getRecords();
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return AjaxResult.success(communityTags);
     }
 
@@ -68,39 +75,44 @@ public class CommunityTagController extends BaseController {
     @Transactional
     //@Anonymous
     public AjaxResult tagsTakeBlock(String tagName) {
-        Page<CommunityTag> page = new Page<>(1, 10);
-        List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
-                    wrapper.ne("is_delete", 1)
-                            .or()
-                            .isNull("is_delete");
-                })
-                .like("tag_name", tagName)
-                .orderByDesc("tag_hot")).getRecords();
-
         List<CommunityTagVo> communityTagVos = new ArrayList<>();
-        CommunityTagVo communityTagVo = null;
-        for (CommunityTag communityTag : communityTags) {
-            communityTagVo = new CommunityTagVo();
-            BeanUtils.copyProperties(communityTag, communityTagVo);
-            communityTagVos.add(communityTagVo);
-        }
+        try {
+            Page<CommunityTag> page = new Page<>(1, 10);
+            List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
+                        wrapper.ne("is_delete", 1)
+                                .or()
+                                .isNull("is_delete");
+                    })
+                    .like("tag_name", tagName)
+                    .orderByDesc("tag_hot")).getRecords();
+            CommunityTagVo communityTagVo = null;
+            for (CommunityTag communityTag : communityTags) {
+                communityTagVo = new CommunityTagVo();
+                BeanUtils.copyProperties(communityTag, communityTagVo);
+                communityTagVos.add(communityTagVo);
+            }
+
+            //查询是否被当前用户拉黑
+            List<Long> tagIds = communityTagVos.stream().map(CommunityTagVo::getId).collect(Collectors.toList());
+            Long userId = SecurityUtils.getUserId();
+            List<CommunityTagBlock> communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>().eq("user_id", userId).in("tag_id", tagIds));
 
-        //查询是否被当前用户拉黑
-        List<Long> tagIds = communityTagVos.stream().map(CommunityTagVo::getId).collect(Collectors.toList());
-        Long userId = SecurityUtils.getUserId();
-        List<CommunityTagBlock> communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>().eq("user_id", userId).in("tag_id", tagIds));
-
-        //设置是否已拉黑
-        for (CommunityTagVo tagVo : communityTagVos) {
-            Long id = tagVo.getId();
-            for (CommunityTagBlock communityTagBlock : communityTagBlocks) {
-                if (communityTagBlock.getTagId().equals(id)) {
-                    tagVo.setBlock(communityTagBlock.isBlock());
-                    break;
+            //设置是否已拉黑
+            for (CommunityTagVo tagVo : communityTagVos) {
+                Long id = tagVo.getId();
+                for (CommunityTagBlock communityTagBlock : communityTagBlocks) {
+                    if (communityTagBlock.getTagId().equals(id)) {
+                        tagVo.setBlock(communityTagBlock.isBlock());
+                        break;
+                    }
                 }
             }
+        } catch (Exception e) {
+            throw new ProjectException();
         }
 
+
+
         return AjaxResult.success(communityTagVos);
     }
 
@@ -115,14 +127,20 @@ public class CommunityTagController extends BaseController {
         if (StringUtils.isEmpty(tagName)) {
             return AjaxResult.error("参数异常!");
         }
-        CommunityTag communityTag = new CommunityTag();
-        Long userId = SecurityUtils.getUserId();
-        communityTag.setTagName(tagName);
-        communityTag.setTagHot(0L);
-        communityTag.setDelete(false);
-        communityTag.setCreateBy(userId);
-        communityTag.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
-        communityTagService.save(communityTag);
+
+        try {
+            CommunityTag communityTag = new CommunityTag();
+            Long userId = SecurityUtils.getUserId();
+            communityTag.setTagName(tagName);
+            communityTag.setTagHot(0L);
+            communityTag.setDelete(false);
+            communityTag.setCreateBy(userId);
+            communityTag.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityTagService.save(communityTag);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return AjaxResult.success("添加标签成功!");
     }
 
@@ -138,7 +156,13 @@ public class CommunityTagController extends BaseController {
             return AjaxResult.error("参数异常!");
         }
 
-        CommunityTagBlock communityTagBlock = communityTagService.blockTag(tagBlock);
+        CommunityTagBlock communityTagBlock = null;
+        try {
+            communityTagBlock = communityTagService.blockTag(tagBlock);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return AjaxResult.success(communityTagBlock);
     }
-}
+}

+ 110 - 37
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java

@@ -6,6 +6,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.exception.user.ProjectException;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -37,7 +39,7 @@ import com.ruoyi.generator.service.IGenTableService;
 
 /**
  * 代码生成 操作处理
- * 
+ *
  * @author ruoyi
  */
 @RestController
@@ -57,8 +59,14 @@ public class GenController extends BaseController
     @GetMapping("/list")
     public TableDataInfo genList(GenTable genTable)
     {
-        startPage();
-        List<GenTable> list = genTableService.selectGenTableList(genTable);
+        List<GenTable> list = null;
+        try {
+            startPage();
+            list = genTableService.selectGenTableList(genTable);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return getDataTable(list);
     }
 
@@ -69,13 +77,20 @@ public class GenController extends BaseController
     @GetMapping(value = "/{tableId}")
     public AjaxResult getInfo(@PathVariable Long tableId)
     {
-        GenTable table = genTableService.selectGenTableById(tableId);
-        List<GenTable> tables = genTableService.selectGenTableAll();
-        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
         Map<String, Object> map = new HashMap<String, Object>();
-        map.put("info", table);
-        map.put("rows", list);
-        map.put("tables", tables);
+        try {
+            GenTable table = genTableService.selectGenTableById(tableId);
+            List<GenTable> tables = genTableService.selectGenTableAll();
+            List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
+
+            map.put("info", table);
+            map.put("rows", list);
+            map.put("tables", tables);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
         return success(map);
     }
 
@@ -86,8 +101,15 @@ public class GenController extends BaseController
     @GetMapping("/db/list")
     public TableDataInfo dataList(GenTable genTable)
     {
-        startPage();
-        List<GenTable> list = genTableService.selectDbTableList(genTable);
+        List<GenTable> list = null;
+        try {
+            startPage();
+            list = genTableService.selectDbTableList(genTable);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
         return getDataTable(list);
     }
 
@@ -99,9 +121,15 @@ public class GenController extends BaseController
     public TableDataInfo columnList(Long tableId)
     {
         TableDataInfo dataInfo = new TableDataInfo();
-        List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
-        dataInfo.setRows(list);
-        dataInfo.setTotal(list.size());
+        try {
+            List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
+            dataInfo.setRows(list);
+            dataInfo.setTotal(list.size());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
         return dataInfo;
     }
 
@@ -113,10 +141,14 @@ public class GenController extends BaseController
     @PostMapping("/importTable")
     public AjaxResult importTableSave(String tables)
     {
-        String[] tableNames = Convert.toStrArray(tables);
-        // 查询表信息
-        List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
-        genTableService.importGenTable(tableList, SecurityUtils.getUsername());
+        try {
+            String[] tableNames = Convert.toStrArray(tables);
+            // 查询表信息
+            List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
+            genTableService.importGenTable(tableList, SecurityUtils.getUsername());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return success();
     }
 
@@ -153,6 +185,7 @@ public class GenController extends BaseController
         catch (Exception e)
         {
             logger.error(e.getMessage(), e);
+
             return AjaxResult.error("创建表结构异常");
         }
     }
@@ -165,8 +198,12 @@ public class GenController extends BaseController
     @PutMapping
     public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
     {
-        genTableService.validateEdit(genTable);
-        genTableService.updateGenTable(genTable);
+        try {
+            genTableService.validateEdit(genTable);
+            genTableService.updateGenTable(genTable);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return success();
     }
 
@@ -178,7 +215,11 @@ public class GenController extends BaseController
     @DeleteMapping("/{tableIds}")
     public AjaxResult remove(@PathVariable Long[] tableIds)
     {
-        genTableService.deleteGenTableByIds(tableIds);
+        try {
+            genTableService.deleteGenTableByIds(tableIds);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
         return success();
     }
 
@@ -189,7 +230,14 @@ public class GenController extends BaseController
     @GetMapping("/preview/{tableId}")
     public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
     {
-        Map<String, String> dataMap = genTableService.previewCode(tableId);
+        Map<String, String> dataMap = null;
+        try {
+            dataMap = genTableService.previewCode(tableId);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
+
         return success(dataMap);
     }
 
@@ -201,8 +249,13 @@ public class GenController extends BaseController
     @GetMapping("/download/{tableName}")
     public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
     {
-        byte[] data = genTableService.downloadCode(tableName);
-        genCode(response, data);
+        try {
+            byte[] data = genTableService.downloadCode(tableName);
+            genCode(response, data);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
     }
 
     /**
@@ -213,7 +266,13 @@ public class GenController extends BaseController
     @GetMapping("/genCode/{tableName}")
     public AjaxResult genCode(@PathVariable("tableName") String tableName)
     {
-        genTableService.generatorCode(tableName);
+
+        try {
+            genTableService.generatorCode(tableName);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return success();
     }
 
@@ -225,7 +284,13 @@ public class GenController extends BaseController
     @GetMapping("/synchDb/{tableName}")
     public AjaxResult synchDb(@PathVariable("tableName") String tableName)
     {
-        genTableService.synchDb(tableName);
+
+        try {
+            genTableService.synchDb(tableName);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
+
         return success();
     }
 
@@ -237,9 +302,13 @@ public class GenController extends BaseController
     @GetMapping("/batchGenCode")
     public void batchGenCode(HttpServletResponse response, String tables) throws IOException
     {
-        String[] tableNames = Convert.toStrArray(tables);
-        byte[] data = genTableService.downloadCode(tableNames);
-        genCode(response, data);
+        try {
+            String[] tableNames = Convert.toStrArray(tables);
+            byte[] data = genTableService.downloadCode(tableNames);
+            genCode(response, data);
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
     }
 
     /**
@@ -247,12 +316,16 @@ public class GenController extends BaseController
      */
     private void genCode(HttpServletResponse response, byte[] data) throws IOException
     {
-        response.reset();
-        response.addHeader("Access-Control-Allow-Origin", "*");
-        response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
-        response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
-        response.addHeader("Content-Length", "" + data.length);
-        response.setContentType("application/octet-stream; charset=UTF-8");
-        IOUtils.write(data, response.getOutputStream());
+        try {
+            response.reset();
+            response.addHeader("Access-Control-Allow-Origin", "*");
+            response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
+            response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\"");
+            response.addHeader("Content-Length", "" + data.length);
+            response.setContentType("application/octet-stream; charset=UTF-8");
+            IOUtils.write(data, response.getOutputStream());
+        } catch (Exception e) {
+            throw new ProjectException();
+        }
     }
-}
+}