Procházet zdrojové kódy

1.优化发布文章时间过长的问题

fangzhen před 2 dny
rodič
revize
d12a4d1721
35 změnil soubory, kde provedl 4155 přidání a 123 odebrání
  1. 148 72
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/OssUtils.java
  2. 44 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/config/AsyncConfig.java
  3. 37 49
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java
  4. 1 2
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityChatMsgController.java
  5. 1 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java
  6. 8 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleImagesService.java
  7. 198 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityAccompanyImpl.java
  8. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleAtServiceImpl.java
  9. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleClassImpl.java
  10. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleCollectServiceImpl.java
  11. 34 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleCommentServiceImpl.java
  12. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleImagesImpl.java
  13. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleRecommendServiceImpl.java
  14. 1774 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleServiceImpl.java
  15. 11 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleTagImpl.java
  16. 13 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionArticleImpl.java
  17. 309 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionServiceImpl.java
  18. 68 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionUserImpl.java
  19. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCommentLikeServiceImpl.java
  20. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCommentReplyServiceImpl.java
  21. 115 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityFeedbackUserServiceImpl.java
  22. 142 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityImageProcessService.java
  23. 14 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityLikeServiceImpl.java
  24. 119 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityNotificationServiceImpl.java
  25. 151 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityPrivacyServiceImpl.java
  26. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportDataServiceImpl.java
  27. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportServiceImpl.java
  28. 81 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportUserServiceImpl.java
  29. 49 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReturnRecordServiceImpl.java
  30. 52 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityTagServiceImpl.java
  31. 52 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserBlockServiceImpl.java
  32. 12 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserLikeServiceImpl.java
  33. 13 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserProtocolServiceImpl.java
  34. 70 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableColumnServiceImpl.java
  35. 533 0
      ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java

+ 148 - 72
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/OssUtils.java

@@ -13,6 +13,8 @@ import java.io.*;
 import java.time.LocalDateTime;
 import java.util.Base64;
 import java.util.UUID;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * Oss服务调用
@@ -26,22 +28,64 @@ public class OssUtils {
 
     /**
      * bucket名称
-     *
-     * @return
      */
     private final static String bucketName = "cysd";
 
-    private static OSS ossClient;
+    private static volatile OSS ossClient;
+    private static final Lock lock = new ReentrantLock();
 
-    static {
-        ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
-        log.info("oss服务连接成功!");
+    /**
+     * 获取OSS客户端实例
+     * 使用双重检查锁定模式确保线程安全
+     * 
+     * @return OSS客户端实例
+     */
+    private static OSS getOssClient() {
+        if (ossClient == null) {
+            lock.lock();
+            try {
+                if (ossClient == null) {
+                    log.info("初始化OSS客户端连接...");
+                    ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
+                }
+            } finally {
+                lock.unlock();
+            }
+        }
+        
+        // 检查连接是否有效,如果无效则重新创建
+        try {
+            // 尝试一个简单操作来验证连接
+            ossClient.doesBucketExist(bucketName);
+        } catch (Exception e) {
+            log.warn("OSS连接已失效,正在重新创建连接: {}", e.getMessage());
+            lock.lock();
+            try {
+                // 关闭旧连接
+                try {
+                    if (ossClient != null) {
+                        ossClient.shutdown();
+                    }
+                } catch (Exception ex) {
+                    log.error("关闭旧OSS连接失败", ex);
+                }
+                
+                // 创建新连接
+                ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
+                log.info("OSS连接已重新创建");
+            } finally {
+                lock.unlock();
+            }
+        }
+        
+        return ossClient;
     }
 
     /**
      * 默认路径上传本地文件
      *
-     * @param filePath
+     * @param filePath 文件路径
+     * @return 上传后的URL
      */
     public static String uploadFile(String filePath) {
         return uploadFileForBucket(bucketName, getOssFilePath(filePath), filePath);
@@ -50,7 +94,8 @@ public class OssUtils {
     /**
      * 默认路径上传multipartFile文件
      *
-     * @param multipartFile
+     * @param multipartFile 多部分文件
+     * @return 上传后的URL
      */
     public static String uploadMultipartFile(MultipartFile multipartFile) throws IOException {
         return uploadMultipartFile(bucketName, getOssFilePath(multipartFile.getOriginalFilename()), multipartFile);
@@ -67,7 +112,7 @@ public class OssUtils {
             request.setProcess(image);
             // 将处理后的图片命名为dest.png并保存到本地。
             // 如果未指定本地路径只填写了文件名称(例如dest.png),则文件默认保存到示例程序所属项目对应本地路径中。
-            ossClient.getObject(request, new File("D:\\dest.png"));
+            getOssClient().getObject(request, new File("D:\\dest.png"));
         } catch (OSSException oe) {
             System.out.println("Caught an OSSException, which means your request made it to OSS, "
                     + "but was rejected with an error response for some reason.");
@@ -75,19 +120,19 @@ public class OssUtils {
             System.out.println("Error Code:" + oe.getErrorCode());
             System.out.println("Request ID:" + oe.getRequestId());
             System.out.println("Host ID:" + oe.getHostId());
-        } finally {
-            if (ossClient != null) {
-                ossClient.shutdown();
-            }
+        } catch (Exception e) {
+            log.error("OSS操作异常", e);
         }
+        // 注意:不要在这里关闭ossClient,它是全局共享的
     }
 
     /**
      * 上传 multipartFile 类型文件
      *
-     * @param bucketName
-     * @param ossPath
-     * @param multipartFile
+     * @param bucketName 存储桶名称
+     * @param ossPath OSS存储路径
+     * @param multipartFile 多部分文件
+     * @return 上传后的URL
      */
     public static String uploadMultipartFile(String bucketName, String ossPath, MultipartFile multipartFile) throws IOException {
         InputStream inputStream = null;
@@ -95,89 +140,126 @@ public class OssUtils {
             inputStream = multipartFile.getInputStream();
             uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("上传文件失败", e);
+            throw e;
         } finally {
-            inputStream.close();
+            if (inputStream != null) {
+                inputStream.close();
+            }
         }
 
         return accessPre + ossPath;
-        //这是返回的图片路径,我们要用这个
-//        return ossPath;
     }
 
     /**
-     * 使用File上传PutObject上传文件 ** 程序默认使用方法上传
+     * 使用File上传PutObject上传文件 ** 程序默认使用方法上传
      *
-     * @param bucketName 实例名称
-     * @param ossPath    oss存储路径
-     * @param filePath   本地文件路径
+     * @param bucketName 存储桶名称
+     * @param ossPath OSS存储路径
+     * @param filePath 本地文件路径
+     * @return 上传后的URL
      */
     public static String uploadFileForBucket(String bucketName, String ossPath, String filePath) {
-        // 创建PutObjectRequest对象。
-        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
-
-        // 上传
-        ossClient.putObject(putObjectRequest);
-        return accessPre + ossPath;
-//        return ossPath;
+        try {
+            // 创建PutObjectRequest对象
+            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
+            // 上传
+            getOssClient().putObject(putObjectRequest);
+            return accessPre + ossPath;
+        } catch (Exception e) {
+            log.error("上传文件失败: {}", filePath, e);
+            throw e;
+        }
     }
 
     /**
      * 使用文件流上传到指定的bucket实例
      *
-     * @param bucketName 实例名称
-     * @param ossPath    oss存储路径
-     * @param filePath   本地文件路径
+     * @param bucketName 存储桶名称
+     * @param ossPath OSS存储路径
+     * @param filePath 本地文件路径
+     * @return 上传后的URL
      */
     public static String uploadFileInputStreamForBucket(String bucketName, String ossPath, String filePath) {
-
-        // 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
         InputStream inputStream = null;
         try {
+            // 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
             inputStream = new FileInputStream(filePath);
+            // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
+            uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
+            return accessPre + ossPath;
         } catch (FileNotFoundException e) {
-            e.printStackTrace();
+            log.error("文件不存在: {}", filePath, e);
+            throw new RuntimeException("文件不存在: " + filePath, e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    log.error("关闭输入流失败", e);
+                }
+            }
         }
-        // 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
-        uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
-        return accessPre + ossPath;
-//        return ossPath;
     }
 
+    /**
+     * 使用输入流上传到指定的bucket实例
+     * 
+     * @param bucketName 存储桶名称
+     * @param ossPath OSS存储路径
+     * @param inputStream 输入流
+     */
     public static void uploadFileInputStreamForBucket(String bucketName, String ossPath, InputStream inputStream) {
-        ossClient.putObject(bucketName, ossPath, inputStream);
+        try {
+            getOssClient().putObject(bucketName, ossPath, inputStream);
+        } catch (Exception e) {
+            log.error("上传文件流失败: {}", ossPath, e);
+            throw e;
+        }
     }
 
     /**
-     * 下载
+     * 下载文件
      *
-     * @param ossFilePath
-     * @param filePath
+     * @param ossFilePath OSS文件路径
+     * @param filePath 本地文件路径
      */
     public static void downloadFile(String ossFilePath, String filePath) {
         downloadFileForBucket(bucketName, ossFilePath, filePath);
     }
 
     /**
-     * 下载
+     * 从指定bucket下载文件
      *
-     * @param bucketName  实例名称
-     * @param ossFilePath oss存储路径
-     * @param filePath    本地文件路径
+     * @param bucketName 存储桶名称
+     * @param ossFilePath OSS文件路径
+     * @param filePath 本地文件路径
      */
     public static void downloadFileForBucket(String bucketName, String ossFilePath, String filePath) {
-        ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
+        try {
+            getOssClient().getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
+        } catch (Exception e) {
+            log.error("下载文件失败: {} -> {}", ossFilePath, filePath, e);
+            throw e;
+        }
     }
 
     /**
-     * @return
+     * 获取OSS默认路径
+     * 
+     * @return 默认路径
      */
     public static String getOssDefaultPath() {
         LocalDateTime now = LocalDateTime.now();
-        String url = now.getYear() + "/" + now.getMonth() + "/" + now.getDayOfMonth() + "/" + now.getHour() + "/" + now.getMinute() + "/";
-        return url;
+        return now.getYear() + "/" + now.getMonth() + "/" + now.getDayOfMonth() + "/" + now.getHour() + "/" + now.getMinute() + "/";
     }
 
+    /**
+     * 获取OSS文件路径
+     * 
+     * @param filePath 文件路径
+     * @return OSS文件路径
+     */
     public static String getOssFilePath(String filePath) {
         String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
         return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
@@ -186,7 +268,8 @@ public class OssUtils {
     /**
      * 添加全屏水印
      *
-     * @param destFile       文件路径
+     * @param objectName OSS对象名称
+     * @param destFile 目标文件
      * @param watermarkText 水印信息
      * @throws Exception 异常
      */
@@ -202,26 +285,19 @@ public class OssUtils {
             String style = "image/watermark,text_" + watermarkText + ",pady_10,size_100,fill_1,t_30,rotate_45,type_d3F5LW1pY3JvaGVp";
             GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
             request.setProcess(style);
-            // 将处理后的图片命名为example-new.jpg并保存到本地。
-            // 如果未指定本地路径只填写了文件名称(例如example-new.jpg),则文件默认保存到示例程序所属项目对应本地路径中。
-            ossClient.getObject(request, destFile);
+            // 将处理后的图片保存到本地
+            getOssClient().getObject(request, destFile);
         } catch (OSSException oe) {
-            System.out.println("请求已发送到OSS,但由于某种原因被拒绝并返回错误响应。");
-            System.out.println("Error Message:" + oe.getErrorMessage());
-            System.out.println("Error Code:" + oe.getErrorCode());
-            System.out.println("Request ID:" + oe.getRequestId());
-            System.out.println("Host ID:" + oe.getHostId());
+            log.error("OSS请求被拒绝: {}", oe.getErrorMessage());
+            log.error("Error Code: {}, Request ID: {}, Host ID: {}", oe.getErrorCode(), oe.getRequestId(), oe.getHostId());
+            throw oe;
         } catch (ClientException ce) {
-            System.out.println("Caught an ClientException, which means the client encountered "
-                    + "a serious internal problem while trying to communicate with OSS, "
-                    + "such as not being able to access the network.");
-            System.out.println("Error Message:" + ce.getMessage());
+            log.error("OSS客户端异常: {}", ce.getMessage());
+            throw ce;
+        } catch (Exception e) {
+            log.error("添加水印失败", e);
+            throw e;
         }
-//        finally {
-//            if (ossClient != null) {
-//                ossClient.shutdown();
-//            }
-//        }
     }
 
-}
+}

+ 44 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/config/AsyncConfig.java

@@ -0,0 +1,44 @@
+package com.ruoyi.generator.config;
+
+
+
+/**
+ * 异步任务配置
+ *
+ * @author fangzhen
+ */
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+@EnableAsync
+public class AsyncConfig {
+
+    /**
+     * 图片处理线程池
+     */
+    @Bean("imageProcessExecutor")
+    public Executor imageProcessExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        // 核心线程数
+        executor.setCorePoolSize(5);
+        // 最大线程数
+        executor.setMaxPoolSize(10);
+        // 队列大小
+        executor.setQueueCapacity(100);
+        // 线程前缀名
+        executor.setThreadNamePrefix("image-process-");
+        // 拒绝策略:由调用线程处理
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 等待所有任务结束后再关闭线程池
+        executor.setWaitForTasksToCompleteOnShutdown(true);
+        executor.initialize();
+        return executor;
+    }
+}

+ 37 - 49
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -14,13 +14,11 @@ import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.*;
-import com.ruoyi.common.utils.file.FileUtils;
-import com.ruoyi.common.utils.file.ImageUtils;
-import com.ruoyi.common.utils.file.OssUtils;
 import com.ruoyi.common.utils.ip.IpUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
 import com.ruoyi.generator.service.*;
+import com.ruoyi.generator.service.impl.CommunityImageProcessService;
 import com.ruoyi.generator.vo.*;
 import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.service.ISysUserService;
@@ -33,7 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
-import java.io.File;
 import java.text.ParseException;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -142,6 +139,9 @@ public class CommunityArticleController extends BaseController {
     @Autowired
     private SysUserMapper sysUserMapper;
 
+    @Autowired
+    private CommunityImageProcessService communityImageProcessService;
+
     /**
      * 获取文章列表信息
      */
@@ -213,63 +213,51 @@ public class CommunityArticleController extends BaseController {
                 return AjaxResult.error(MessageUtils.message("article.content.error"));
             }
 
-            //检查附近是否需要加水印
+            //检查是否需要加水印
             boolean isWaterMark = communityArticle.isWaterMark();
             boolean isFillWater = communityArticle.isFillWater();
             log.info("isWaterMark:{},isFillWater:{},Images:{}", isWaterMark, isFillWater, communityArticle.getImages());
-            if (isWaterMark && null != communityArticle.getImages() && !communityArticle.getImages().isEmpty()) {
+
+            // 保存原始图片信息的副本,用于异步处理
+            List<CommunityImagesVo> originalImages = null;
+            if (isWaterMark && communityArticle.getImages() != null && !communityArticle.getImages().isEmpty()) {
+                // 验证图片是否有效
                 for (CommunityImagesVo image : communityArticle.getImages()) {
                     if (null == image) {
-                        throw new RuntimeException("图片上传失败!");
+                        return AjaxResult.error("图片上传失败!");
                     }
                 }
-                log.info("需要做图片/视频修改...");
-                //获取用户名
-                String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
-                // 添加水印
-                for (CommunityImagesVo image : communityArticle.getImages()) {
-                    String fileType = FileUtils.getFileTypeFromUrl(image.getImages());
-                    log.info("fileType:{}", fileType);
-                    if ("image".equals(fileType)) {
-                        if (image.getImages().contains(".gif") || image.getImages().contains(".GIF")) {
-                            continue;
-                        }
-                        // 本地临时水印文件路径
-                        String tempWatermarkFile = System.getProperty("java.io.tmpdir") + File.separator + "watermark_" + FileUtils.getName(image.getImages());
-                        String tempSourceFile = System.getProperty("java.io.tmpdir") + File.separator + "source_" + FileUtils.getName(image.getImages());
-                        OssUtils.downloadFile(image.getImages().replace("http://file.iciyuanshidai.com/", ""), tempSourceFile);
-                        ImageUtils.addWatermark(
-                                isFillWater,
-                                image.getImages().replace("http://file.iciyuanshidai.com/", ""),
-                                new File(tempSourceFile),
-                                new File(tempWatermarkFile),
-                                "@" + nickName,
-                                "次元时代-ACG爱好者社区"
-                        );
-                        // 上传加水印的文件到OSS
-                        String fileNameResult = OssUtils.uploadFile(tempWatermarkFile);
-                        image.setImages(fileNameResult.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", "http://file.iciyuanshidai.com/"));
-                    }
-
-
-                    if ("video".equals(fileType)) {
-                        String tempThumbnailFile = System.getProperty("java.io.tmpdir") + File.separator + "thumbnail.jpg";
 
-                        boolean screenshotSuccess = FileUtils.screenShots(image.getImages(), tempThumbnailFile, "00:00:01");
-                        if (!screenshotSuccess) {
-                            throw new RuntimeException("生成视频缩略图失败");
-                        }
-
-                        // 上传缩略图到OSS
-                        String thumbnailPath = OssUtils.uploadFile(tempThumbnailFile);
-                        image.setCompressedImages(thumbnailPath.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", "http://file.iciyuanshidai.com/"));
-                        // 删除临时缩略图文件
-                        new File(tempThumbnailFile).delete();
-                    }
+                // 创建原始图片的深拷贝
+                originalImages = new ArrayList<>();
+                for (CommunityImagesVo image : communityArticle.getImages()) {
+                    CommunityImagesVo copy = new CommunityImagesVo();
+                    copy.setImages(image.getImages());
+                    copy.setCompressedImages(image.getCompressedImages());
+                    originalImages.add(copy);
                 }
+
+                log.info("需要做图片/视频修改,将在后台异步处理...");
             }
 
+            // 插入文章基本信息
             communityArticleService.insertCommunityArticle(communityArticle);
+
+            // 如果需要水印处理,启动异步处理
+            if (isWaterMark && originalImages != null && !originalImages.isEmpty()) {
+                // 获取用户名
+                String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
+                // 异步处理图片水印
+                communityImageProcessService.processImagesWithWatermark(
+                        communityArticle.getId(),
+                        originalImages,
+                        isFillWater,
+                        nickName,
+                        SecurityUtils.getUserId()
+                );
+
+                log.info("文章[{}]的图片水印处理已提交到后台异步处理", communityArticle.getId());
+            }
         } catch (Exception e) {
             log.info(e.getMessage());
             throw new ProjectException();

+ 1 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityChatMsgController.java

@@ -7,7 +7,6 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
-import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.ServletUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
@@ -15,7 +14,7 @@ import com.ruoyi.generator.domain.Community.CommunityReturnRecord;
 import com.ruoyi.generator.domain.Community.CommunityUserBlock;
 import com.ruoyi.generator.domain.ReqEntity.UpdateAnonName;
 import com.ruoyi.generator.mapper.community.CommunityUserBlockMapper;
-import com.ruoyi.generator.service.CommunityReturnRecordServiceImpl;
+import com.ruoyi.generator.service.impl.CommunityReturnRecordServiceImpl;
 import com.ruoyi.system.domain.CommunityChatMsg;
 import com.ruoyi.system.domain.vo.CommunityChatMsgVo;
 import com.ruoyi.system.domain.vo.SysUserVo;

+ 1 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -15,6 +15,7 @@ import com.ruoyi.common.utils.ip.AddressUtils;
 import com.ruoyi.generator.domain.Community.*;
 import com.ruoyi.generator.mapper.community.*;
 import com.ruoyi.generator.service.*;
+import com.ruoyi.generator.service.impl.*;
 import com.ruoyi.generator.vo.*;
 import com.ruoyi.system.mapper.SysUserMapper;
 import com.ruoyi.system.service.impl.SysUserServiceImpl;

+ 8 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleImagesService.java

@@ -0,0 +1,8 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityArticleImages;
+
+public interface ICommunityArticleImagesService extends IService<CommunityArticleImages> {
+
+}

+ 198 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityAccompanyImpl.java

@@ -0,0 +1,198 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.generator.domain.Community.*;
+import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
+import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
+import com.ruoyi.generator.mapper.community.CommunityCommentReplyMapper;
+import com.ruoyi.generator.mapper.community.CommunityUserLikeMapper;
+import com.ruoyi.generator.service.ICommunityAccompanyService;
+import com.ruoyi.system.mapper.SysUserMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.DecimalFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * @author fangqing
+ * @date 2024/12/30 15:26
+ */
+@Service
+public class CommunityAccompanyImpl implements ICommunityAccompanyService {
+
+
+    @Autowired
+    private SysUserMapper userMapper;
+
+    @Autowired
+    private CommunityArticleMapper communityArticleMapper;
+
+    @Autowired
+    private CommunityUserLikeMapper communityUserLikeMapper;
+
+    @Autowired
+    private CommunityArticleCommentMapper communityArticleCommentMapper;
+
+    @Autowired
+    private CommunityCommentReplyMapper communityCommentReplyMapper;
+
+    @Override
+    public CommunityAccompany selectCommunityAccompanyById(Long userId) {
+        DecimalFormat df = new DecimalFormat("#.00");
+        CommunityAccompany communityAccompany = new CommunityAccompany();
+
+        //获取当前用户信息 天数
+        SysUser sysUsers = userMapper.selectOne( new QueryWrapper<SysUser>().select("create_time").eq("user_id", userId).and((wrapper) -> {wrapper.ne("status", true).or().isNull("status");}));
+
+        if (sysUsers == null){
+            return  communityAccompany;
+        }
+        Date createTime = sysUsers.getCreateTime();
+        // 将 Date 对象转换为 LocalDate 对象
+        LocalDate localCreateTime = createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 计算两个日期之间的天数差
+        long daysDifference = ChronoUnit.DAYS.between(localCreateTime, today);
+        communityAccompany.setAccompanyDays(daysDifference);
+
+        //查询当前用户下文章的数量
+        List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                .eq("create_by", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                }));
+        //如果用户文章数量不为空则执行以下的操作
+        if (communityArticles != null){
+
+            //设置用户创作数
+            communityAccompany.setCreationCount((long) communityArticles.size());
+
+            //计算小于自己粉丝的有多少人
+            List<CommunityArticle> communityArticlesLess = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id", "COUNT(1) as count")
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+                    .groupBy("user_id")
+                    .having("COUNT(*) <= {0}", (long) communityArticles.size())
+                    .orderByDesc("count"))) ;
+
+            //计算所有文章的数量
+            List<CommunityArticle> communityArticlesTotal = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id", "COUNT(1) as count")
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+                    .groupBy("user_id")
+                    .orderByDesc("count")));
+
+            //计算创作数的百分比 计算百分比
+            Double CreationCountPercent = Double.valueOf(df.format((double) communityArticlesLess.size() / communityArticlesTotal.size() * 100));
+            communityAccompany.setCreationCountPercent(CreationCountPercent);
+
+
+            //计算用户阅览量
+            long read = communityArticles.stream()
+                    .mapToLong(article -> article.getPageViews()).sum();
+            communityAccompany.setRead(read);
+
+
+            //计算阅览量百分比
+            List<CommunityArticle> communityArticlesReadSumLess = new ArrayList<>(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .select("user_id","sum(page_views) page_views","COUNT(1) as count")
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+                    .groupBy("user_id")
+                    .having("page_views <= {0}", read )
+                    .orderByDesc("count"))) ;
+
+            Double ReadPercent = Double.valueOf(df.format((double)  communityArticlesReadSumLess.size() / communityArticlesTotal.size() * 100));
+            communityAccompany.setReadPercent(ReadPercent);
+
+        }
+
+
+        //粉丝数
+        Long fans = communityUserLikeMapper.selectCount(new QueryWrapper<CommunityUserLike>()
+                .eq("like_user_id", userId));
+
+
+        communityAccompany.setFan(fans);
+        //计算小于自己粉丝的有多少人
+        List<CommunityUserLike> userLikeFan = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
+                .select("like_user_id", "COUNT(1) as count")
+                .groupBy("like_user_id")
+                .having("COUNT(*) <= {0}", fans)
+                .orderByDesc("count"))) ;
+
+        //计算总人数
+        List<CommunityUserLike> userLikeFans = new ArrayList<>(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
+                .select("like_user_id", "COUNT(1) as count")
+                .groupBy("like_user_id")));
+        //粉丝数占比
+        Double  ReadPercent = Double.valueOf(df.format((double) userLikeFan.size() / userLikeFans.size() * 100));
+        communityAccompany.setFanPercent(ReadPercent);
+
+
+        //查询评论数
+        /*//一级评论
+        Long comment = communityArticleCommentMapper.selectCount(new QueryWrapper<CommunityArticleComment>()
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })
+        );
+        //二级评论
+        Long commentReply = communityCommentReplyMapper.selectCount(new QueryWrapper<CommunityCommentReply>()
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })
+        );*/
+        //查询哪几篇文章是我发布的
+        List<Long> articleIds = communityArticles.stream().map(item -> item.getId()).collect(Collectors.toList());
+        System.out.println(articleIds);
+        Integer commentSum = 0;
+        //查询评论数 别人评论我的数量 首先自己得有文章才能有评论
+        if (articleIds.size() > 0 ) {
+            commentSum = communityArticleCommentMapper.queryCommentReplyCount(articleIds);
+        }
+        communityAccompany.setComment(Long.valueOf(commentSum));
+
+        //评论数占比
+        if (commentSum > 0 ){
+            Integer commentless = communityArticleCommentMapper.queryCommentReplyCountPerson(commentSum);
+            Integer commentCount = communityArticleCommentMapper.queryCommentReplyCountPerson(0);
+            Double  commentPercent = Double.valueOf(df.format((double) commentless / commentCount * 100));
+            communityAccompany.setCommentPercent(commentPercent);
+        }
+
+        //用户文章 和 评论收货多少点赞
+        Integer likeCount = Optional.ofNullable(communityArticleCommentMapper.queryCommentReplyLikeCount(userId))
+                .orElse(0);
+        communityAccompany.setLike(Long.valueOf(likeCount));
+
+        if (likeCount >0 ){
+            Integer likeless = communityArticleCommentMapper.queryCommentReplyLikeCountPerson(likeCount);
+            Integer likesCount = communityArticleCommentMapper.queryCommentReplyLikeCountPerson(0);
+            Double likePercent = Double.valueOf(df.format((double) likeless / likesCount * 100));
+            communityAccompany.setLikePercent(likePercent);
+        }
+        //
+
+        return communityAccompany;
+    }
+
+
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleAtServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleAt;
+import com.ruoyi.generator.mapper.community.CommunityArticleAtMapper;
+import com.ruoyi.generator.service.ICommunityArticleAtService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleAtServiceImpl extends ServiceImpl<CommunityArticleAtMapper, CommunityArticleAt> implements ICommunityArticleAtService {
+
+}

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleClassImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleClass;
+import com.ruoyi.generator.mapper.community.CommunityArticleCircleMapper;
+import com.ruoyi.generator.service.ICommunityArticleClassService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleClassImpl extends ServiceImpl<CommunityArticleCircleMapper, CommunityArticleClass> implements ICommunityArticleClassService {
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleCollectServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleCollect;
+import com.ruoyi.generator.mapper.community.CommunityArticleCollectMapper;
+import com.ruoyi.generator.service.ICommunityArticleCollectService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleCollectServiceImpl extends ServiceImpl<CommunityArticleCollectMapper, CommunityArticleCollect> implements ICommunityArticleCollectService {
+
+}

+ 34 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleCommentServiceImpl.java

@@ -0,0 +1,34 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleComment;
+import com.ruoyi.generator.mapper.community.CommunityArticleCommentMapper;
+import com.ruoyi.generator.service.ICommunityArticleCommentService;
+import com.ruoyi.generator.vo.CommentVo;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+public class CommunityArticleCommentServiceImpl extends ServiceImpl<CommunityArticleCommentMapper, CommunityArticleComment> implements ICommunityArticleCommentService {
+
+    @Resource
+    private CommunityArticleCommentMapper communityArticleCommentMapper;
+
+    /**
+     * 获取当前用户文章的所有评论信息
+     *
+     * @param userId 当前用户id
+     * @return 该用户的文章信息
+     */
+    @Override
+    public List<CommentVo> getCommentInfoByUserId(long userId, int offset, int limit, int searchType) {
+        return communityArticleCommentMapper.getCommentListByUserId(userId,offset,limit,searchType);
+    }
+
+    @Override
+    public List<CommentVo> getCommentInfoByUserId2(long userId, int searchType) {
+        return communityArticleCommentMapper.getCommentListByUserId2(userId,searchType);
+    }
+}

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleImagesImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleImages;
+import com.ruoyi.generator.mapper.community.CommunityArticleImagesMapper;
+import com.ruoyi.generator.service.ICommunityArticleImagesService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleImagesImpl extends ServiceImpl<CommunityArticleImagesMapper, CommunityArticleImages> implements ICommunityArticleImagesService {
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleRecommendServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleRecommend;
+import com.ruoyi.generator.mapper.community.CommunityArticleRecommendMapper;
+import com.ruoyi.generator.service.ICommunityArticleRecommendService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleRecommendServiceImpl extends ServiceImpl<CommunityArticleRecommendMapper, CommunityArticleRecommend> implements ICommunityArticleRecommendService {
+
+}

+ 1774 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleServiceImpl.java

@@ -0,0 +1,1774 @@
+package com.ruoyi.generator.service.impl;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.common.utils.ip.AddressUtils;
+import com.ruoyi.generator.domain.Community.*;
+import com.ruoyi.generator.mapper.community.*;
+import com.ruoyi.generator.service.*;
+import com.ruoyi.generator.vo.*;
+import com.ruoyi.system.mapper.SysUserMapper;
+import org.apache.ibatis.annotations.Param;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.text.ParseException;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * 业务 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMapper, CommunityArticle> implements ICommunityArticleService {
+    private static final Logger log = LoggerFactory.getLogger(CommunityArticleServiceImpl.class);
+
+    @Autowired
+    private CommunityArticleMapper communityArticleMapper;
+
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private CommunityLikeMapper communityLikeMapper;
+
+    @Autowired
+    private CommunityCollectMapper communityCollectMapper;
+
+    @Autowired
+    private CommunityArticleCommentMapper communityArticleCommentMapper;
+
+    @Autowired
+    private CommunityCommentLikeMapper communityCommentLikeMapper;
+
+    @Autowired
+    private CommunityArticleTagMapper articleTagMapper;
+
+    @Autowired
+    private CommunityArticleTagMapper communityArticleTagMapper;
+
+    @Autowired
+    private CommunityTagMapper communityTagMapper;
+
+    @Autowired
+    private CommunityArticleImagesMapper communityArticleImagesMapper;
+
+    @Autowired
+    private CommunityClassCircleMapper communityClassCircleMapper;
+
+    @Autowired
+    private CommunityCircleMapper communityCircleMapper;
+
+    @Autowired
+    private CommunityUserCircleMapper communityUserCircleMapper;
+
+    @Autowired
+    private CommunityUserLikeMapper communityUserLikeMapper;
+
+    @Autowired
+    private CommunityUserInfoMapper communityUserInfoMapper;
+
+    @Autowired
+    private ICommunityArticleClassService communityArticleClassService;
+
+    @Autowired
+    private CommunityCollectionArticleMapper communityCollectionArticleMapper;
+
+    @Autowired
+    private ICommunityCollectionArticleService collectionArticleService;
+
+    @Autowired
+    private CommunityTagBlockMapper communityTagBlockMapper;
+
+    @Autowired
+    private CommunityArticleRecommendMapper recommendMapper;
+
+    @Autowired
+    private ICommunityArticleService communityArticleService;
+
+    @Autowired
+    private ICommunityPrivacyService communityPrivacyService;
+    @Autowired
+    private CommunityCollectionMapper communityCollectionMapper;
+
+    @Autowired
+    private CommunityUserBlockMapper communityUserBlockMapper;
+
+    @Autowired
+    private CommunityUserPromptMapper communityUserPromptMapper;
+
+    @Autowired
+    private CommunityArticleCollectMapper communityArticleCollectMapper;
+
+    @Autowired
+    private CommunityCommentRaffleMapper communityCommentRaffleMapper;
+
+    @Autowired
+    private CommunityArticleCircleMapper communityArticleCircleMapper;
+    @Autowired
+    private RedisCache redisCache;
+    @Autowired
+    private RedisTemplate<Object, Object> redisTemplate;
+
+    @Autowired
+    private ICommunityArticleAtService communityArticleAtService;
+
+    /**
+     * 查询文章列表
+     *
+     * @param communityArticle 文章信息
+     * @return 文章信息集合
+     */
+    @Override
+    public List<CommunityArticleVo> selectCommunityArticleList(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
+
+        List<CommunityArticleVo> communityArticleVos = null;
+        //找出板块下的分类
+        List<Long> classIds = communityArticle.getClassIds();
+        System.out.println("classIds: " + classIds);
+        if (classIds != null && classIds.contains(19L)) { // Check for null and then use contains()
+            classIds = null;
+            searchType = 3;
+        }
+
+        Long id = communityArticle.getId();
+        List<Long> articleIds = communityArticle.getArticleIds();
+        Integer pageTagType = communityArticle.getPageTagType();
+        Integer noCollection = communityArticle.getNoCollection();
+        if (pageTagType != null && pageTagType == 1) {
+            List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(SecurityUtils.getUserId(), null, 1, 999999, 1);
+            if (communityUserLikeVos.isEmpty()) {
+                return null;
+            }
+            List<Long> likeUserIds = communityUserLikeVos.stream().map(CommunityUserLikeVo::getLikeUserId).collect(Collectors.toList());
+            communityArticle.setUserIds(likeUserIds);
+        }
+
+        if (Objects.nonNull(id)) {
+            //获取指定文章详细内容,文章浏览量+1
+            CommunityArticle article = communityArticleMapper.selectById(id);
+            article.setPageViews(article.getPageViews() + 1);
+            communityArticleMapper.updateById(article);
+        }
+
+        if (articleIds != null && !articleIds.isEmpty()) {
+            for (Long articleId : articleIds) {
+                //获取指定文章详细内容,文章浏览量+1
+                CommunityArticle article = communityArticleMapper.selectById(articleId);
+                article.setPageViews(article.getPageViews() + 1);
+                communityArticleMapper.updateById(article);
+            }
+        }
+
+        Boolean isDraft = communityArticle.getIsDraft();
+        //判断草稿箱是否为空 为空则为false
+        if (isDraft == null) {
+            communityArticle.setIsDraft(false);
+        }
+
+        //根据分类查找文章
+        int offset = (pageNum - 1) * pageSize;
+        communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType, userId);
+
+        List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
+        if (noCollection != null) {
+            if (noCollection == 1) {
+                //剔除是否有合集文章
+                List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
+                if (!ids.isEmpty()) {
+                    List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                            .in("article_id", ids)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+
+                    for (CommunityArticleVo communityArticleVo : articleVos_copy) {
+                        for (CommunityCollectionArticle collection : collections) {
+                            if (collection.getArticleId().equals(communityArticleVo.getId())) {
+                                communityArticleVos.remove(communityArticleVo);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        rspData.setTotal(communityArticleVos.size());
+        List<CommunityArticleVo> communityArticleVos_copy = new ArrayList<>(communityArticleVos);
+        for (CommunityArticleVo articleVo : communityArticleVos_copy) {
+            //判断当前文章是否被用户拉黑
+            List<CommunityUserBlock> communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>()
+                    .eq("user_id", userId)
+                    .eq("peer_id", articleVo.getUserId()));
+
+            for (CommunityUserBlock userBlock : communityUserBlocks) {
+                if (userBlock.isBlock()) {
+                    articleVo.setBlock(userBlock.isBlock());
+                    break;
+                }
+            }
+
+            //获取文章是否被关注
+            List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>()
+                    .eq("user_id", userId)
+                    .eq("like_user_id", articleVo.getUserId())
+            );
+
+            for (CommunityUserLike communityUserLike : communityUserLikes) {
+                articleVo.setCare(communityUserLike.getUserId() != null);
+            }
+
+        /*    communityArticleMapper.selectList();
+            articleVo.setCare();*/
+
+            List<Map<String, Object>> imageList = articleVo.getImageList();
+
+            //设置文章的板块
+            List<CommunityArticleClass> articleId = communityArticleCircleMapper.selectList(
+                    new QueryWrapper<CommunityArticleClass>()
+                            .eq("article_id", articleVo.getId())
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            })
+            );
+            // 使用 Java Streams API 提取 classId,并转换成 List<Long>
+            List<Long> classIdss = articleId.stream()
+                    .map(CommunityArticleClass::getClassId)
+                    .collect(Collectors.toList());
+            articleVo.setClassIds(classIdss);
+
+
+            List<CommunityArticleImages> videoList = new ArrayList<>();
+            CommunityArticleImages videos = null;
+            List<Map<String, Object>> imageList_copy = new ArrayList<>(imageList);
+            for (Map<String, Object> image : imageList_copy) {
+                String imageUrl = image.get("imageUrl").toString();
+                //判断是否是视频
+                boolean isVideo = isVideoFile(imageUrl);
+                if (isVideo) {
+                    imageList.remove(image);
+                    videos = JSONObject.parseObject(JSONObject.toJSONString(image), CommunityArticleImages.class);
+                    //BeanUtils.copyProperties(image, videos);
+                    videoList.add(videos);
+                }
+            }
+            articleVo.setVideoList(videoList);
+
+            //设置评论回复数量
+            articleVo.setCommentCount(communityArticleCommentMapper.queryCommentCount(articleVo.getId()));
+            //设置文章的点赞数量
+            articleVo.setLikeCount(communityLikeMapper.selectList(new QueryWrapper<CommunityLike>().eq("article_id", articleVo.getId())).size());
+            //设置文章的收藏数量
+            articleVo.setCollectCount(communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>().eq("article_id", articleVo.getId())).size());
+            //设置文章推荐数量
+            articleVo.setRecommendCount(recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>()
+                    .eq("article_id", articleVo.getId())
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })).size());
+            //设置文章所属合集
+            articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
+
+
+            //设置中奖信息
+            CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
+            CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
+                    new QueryWrapper<CommunityCommentRaffle>()
+                            .eq("article_id", articleVo.getId())
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+            if (communityCommentRaffle != null) {
+                BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
+                CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(), false);
+                communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
+                communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
+                articleVo.setCommentRaffleVo(communityCommentRaffleVo);
+            }
+            //文章下的评论
+//            List<Map<String, Object>> comments = articleVo.getComments();
+//            for (Map<String, Object> communityArticleCommentVo : comments) {
+//                String commentUserId = communityArticleCommentVo.get("userId").toString();
+//                if (Objects.isNull(commentUserId)) {
+//                    break;
+//                }
+//                //获取评论的用户信息
+//                SysUser sysUser = sysUserMapper.selectUserById(Long.parseLong(commentUserId));
+//                communityArticleCommentVo.put("username", sysUser.getUserName());
+//                communityArticleCommentVo.put("avatar", sysUser.getAvatar());
+//                //当前登录用户是否已点赞
+//                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id")).eq("user_id", userId));
+//                communityArticleCommentVo.put("commentLike", !commentLikes.isEmpty());
+//
+//                //该评论的点赞数量
+//                communityArticleCommentVo.put("commentLikeCount", communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>().eq("comment_id", communityArticleCommentVo.get("id"))).size());
+//            }
+
+            //判断是否已收藏
+            CommunityArticleCollect collect = communityCollectMapper.selectOne(new QueryWrapper<CommunityArticleCollect>().eq("user_id", userId).eq("article_id", articleVo.getId()));
+            articleVo.setCollect(!Objects.isNull(collect));
+
+            //判断是否已点赞
+            CommunityLike like = communityLikeMapper.selectOne(new QueryWrapper<CommunityLike>().eq("user_id", userId).eq("article_id", articleVo.getId()));
+            articleVo.setLike(!Objects.isNull(like));
+
+            //判断是否已推荐
+            CommunityArticleRecommend recommend = recommendMapper.selectOne(new QueryWrapper<CommunityArticleRecommend>()
+                    .eq("user_id", userId)
+                    .eq("article_id", articleVo.getId()).and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }));
+            articleVo.setRecommend(!Objects.isNull(recommend));
+
+            //获取文章标签
+            List<CommunityArticleTag> articleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>()
+                    .eq("article_id", articleVo.getId())
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }));
+            List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
+            List<Long> tagIds = new ArrayList<>();
+
+            if (!tagList.isEmpty()) {
+                //判断当前标签是否被当前登录用户拉黑
+                List<CommunityTagBlock> communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>()
+                        .in("tag_id", tagList)
+                        .eq("user_id", userId)
+                        .eq("is_block", 1));
+
+                for (CommunityTagBlock tagBlock : communityTagBlocks) {
+                    if (tagBlock.isBlock()) {
+                        communityArticleVos.remove(articleVo);
+                        break;
+                    }
+                    tagIds.add(tagBlock.getTagId());
+                }
+
+                if (communityTagBlocks.isEmpty()) {
+                    tagIds.addAll(tagList);
+                }
+
+                if (!tagIds.isEmpty()) {
+                    List<CommunityTag> communityTags = communityTagMapper.selectBatchIds(tagIds);
+                    articleVo.setTags(communityTags);
+                }
+            }
+        }
+        return communityArticleVos;
+    }
+
+    /**
+     * 查询文章列表
+     *
+     * @param communityArticle 文章信息
+     * @return 文章信息集合
+     */
+    @Override
+    public List<CommunityArticleVo> selectCommunityArticleList1(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
+
+        List<CommunityArticleVo> communityArticleVos = null;
+        //找出板块下的分类
+        List<Long> classIds = communityArticle.getClassIds();
+        Long id = communityArticle.getId();
+        List<Long> articleIds = communityArticle.getArticleIds();
+        Integer pageTagType = communityArticle.getPageTagType();
+        Integer noCollection = communityArticle.getNoCollection();
+        if (pageTagType != null && pageTagType == 1) {
+            List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(SecurityUtils.getUserId(), null, 1, 999999, 1);
+            if (communityUserLikeVos.isEmpty()) {
+                return null;
+            }
+            List<Long> likeUserIds = communityUserLikeVos.stream().map(CommunityUserLikeVo::getLikeUserId).collect(Collectors.toList());
+            communityArticle.setUserIds(likeUserIds);
+        }
+
+        if (Objects.nonNull(id)) {
+            //获取指定文章详细内容,文章浏览量+1
+            CommunityArticle article = communityArticleMapper.selectById(id);
+            article.setPageViews(article.getPageViews() + 1);
+            communityArticleMapper.updateById(article);
+        }
+
+        if (articleIds != null && !articleIds.isEmpty()) {
+            for (Long articleId : articleIds) {
+                //获取指定文章详细内容,文章浏览量+1
+                CommunityArticle article = communityArticleMapper.selectById(articleId);
+                article.setPageViews(article.getPageViews() + 1);
+                communityArticleMapper.updateById(article);
+            }
+        }
+
+        //根据分类查找文章
+        int offset = (pageNum - 1) * pageSize;
+        communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType, userId);
+
+        List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
+        if (noCollection != null) {
+            if (noCollection == 1) {
+                //剔除是否有合集文章
+                List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
+                if (!ids.isEmpty()) {
+                    List<CommunityCollectionArticle> collections = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                            .in("article_id", ids)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", true).or().isNull("is_delete");
+                            }));
+
+                    for (CommunityArticleVo communityArticleVo : articleVos_copy) {
+                        for (CommunityCollectionArticle collection : collections) {
+                            if (collection.getArticleId().equals(communityArticleVo.getId())) {
+                                communityArticleVos.remove(communityArticleVo);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        //数据拉取区域
+        //判断当前文章是否被用户拉黑
+        //用户拉黑数据
+        List<CommunityUserBlock> communityUserBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_BLOCK);
+        if (communityUserBlocks.isEmpty()) {
+            communityUserBlocks = communityUserBlockMapper.selectList(new QueryWrapper<CommunityUserBlock>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_BLOCK, communityUserBlocks);
+            redisCache.expire(CacheConstants.COMMUNITY_USER_BLOCK, 24, TimeUnit.HOURS);
+        }
+
+        //关注数据
+        List<CommunityUserLike> communityUserLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_USER_LIKE);
+        if (communityUserLikes.isEmpty()) {
+            communityUserLikes = communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_USER_LIKE, communityUserLikes);
+            redisCache.expire(CacheConstants.COMMUNITY_USER_LIKE, 24, TimeUnit.HOURS);
+        }
+
+        //文章板块数据
+        List<CommunityArticleClass> communityArticleClasses = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS);
+        if (communityArticleClasses.isEmpty()) {
+            communityArticleClasses = communityArticleCircleMapper.selectList(new QueryWrapper<CommunityArticleClass>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_CLASS, communityArticleClasses);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_CLASS, 24, TimeUnit.HOURS);
+        }
+
+        //文章点赞数据
+        List<CommunityLike> communityLikes = redisCache.getCacheList(CacheConstants.COMMUNITY_LIKE);
+        if (communityLikes.isEmpty()) {
+            communityLikes = communityLikeMapper.selectList(new QueryWrapper<CommunityLike>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_LIKE, communityLikes);
+            redisCache.expire(CacheConstants.COMMUNITY_LIKE, 24, TimeUnit.HOURS);
+        }
+
+        //文章收藏数据
+        List<CommunityArticleCollect> communityArticleCollects = redisCache.getCacheList(CacheConstants.COMMUNITY_COLLECT);
+        if (communityArticleCollects.isEmpty()) {
+            communityArticleCollects = communityCollectMapper.selectList(new QueryWrapper<CommunityArticleCollect>());
+            redisCache.setCacheList(CacheConstants.COMMUNITY_COLLECT, communityArticleCollects);
+            redisCache.expire(CacheConstants.COMMUNITY_COLLECT, 24, TimeUnit.HOURS);
+        }
+
+        //文章推荐数据
+        List<CommunityArticleRecommend> communityArticleRecommends = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND);
+        if (communityArticleRecommends.isEmpty()) {
+            communityArticleRecommends = recommendMapper.selectList(new QueryWrapper<CommunityArticleRecommend>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, communityArticleRecommends);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_RECOMMEND, 24, TimeUnit.HOURS);
+        }
+
+        //中奖信息数据
+        List<CommunityCommentRaffle> communityCommentRaffles = redisCache.getCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE);
+        if (communityCommentRaffles.isEmpty()) {
+            communityCommentRaffles = communityCommentRaffleMapper.selectList(new QueryWrapper<CommunityCommentRaffle>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_COMMENT_RAFFLE, communityCommentRaffles);
+            redisCache.expire(CacheConstants.COMMUNITY_COMMENT_RAFFLE, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签数据
+        List<CommunityArticleTag> communityArticleTags = redisCache.getCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG);
+        if (communityArticleTags.isEmpty()) {
+            communityArticleTags = communityArticleTagMapper.selectList(new QueryWrapper<CommunityArticleTag>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_ARTICLE_TAG, communityArticleTags);
+            redisCache.expire(CacheConstants.COMMUNITY_ARTICLE_TAG, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签拉黑数据
+        List<CommunityTagBlock> communityTagBlocks = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG_BLOCK);
+        if (communityTagBlocks.isEmpty()) {
+            communityTagBlocks = communityTagBlockMapper.selectList(new QueryWrapper<CommunityTagBlock>().eq("is_block", 1));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_TAG_BLOCK, communityTagBlocks);
+            redisCache.expire(CacheConstants.COMMUNITY_TAG_BLOCK, 24, TimeUnit.HOURS);
+        }
+
+        //文章标签
+        List<CommunityTag> communityTags = redisCache.getCacheList(CacheConstants.COMMUNITY_TAG);
+        if (communityTags.isEmpty()) {
+            communityTags = communityTagMapper.selectList(new QueryWrapper<CommunityTag>().eq("is_delete", false));
+            redisCache.setCacheList(CacheConstants.COMMUNITY_TAG, communityTags);
+            redisCache.expire(CacheConstants.COMMUNITY_TAG, 24, TimeUnit.HOURS);
+        }
+
+        rspData.setTotal(communityArticleVos.size());
+        List<CommunityArticleVo> communityArticleVos_copy = new ArrayList<>(communityArticleVos);
+        List<CommunityArticleImages> videoList = new ArrayList<>();
+        for (CommunityArticleVo articleVo : communityArticleVos_copy) {
+            //判断当前文章是否被用户拉黑
+            communityUserBlocks
+                    .stream()
+                    .filter(item -> item.getUserId().equals(userId) && item.getPeerId().equals(articleVo.getUserId()))
+                    .findFirst()
+                    .ifPresent(communityUserBlock -> articleVo.setBlock(communityUserBlock.isBlock()));
+
+            //获取文章是否被关注
+            communityUserLikes
+                    .stream()
+                    .filter(item -> item.getUserId().equals(userId) && item.getLikeUserId().equals(articleVo.getUserId()))
+                    .findFirst()
+                    .ifPresent(communityUserLike -> articleVo.setCare(communityUserLike.getUserId() != null));
+
+            //设置文章的板块 提取 classId,并转换成 List<Long>
+            List<CommunityArticleClass> communityArticleClassList = communityArticleClasses
+                    .stream()
+                    .filter(item ->
+                            item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
+            classIds = communityArticleClassList
+                    .stream()
+                    .map(CommunityArticleClass::getClassId)
+                    .collect(Collectors.toList());
+            articleVo.setClassIds(classIds);
+
+            List<Map<String, Object>> imageList = articleVo.getImageList();
+            List<Map<String, Object>> imageList_copy = new ArrayList<>(imageList);
+            CommunityArticleImages videos = null;
+            for (Map<String, Object> image : imageList_copy) {
+                String imageUrl = image.get("imageUrl").toString();
+                //判断是否是视频
+                boolean isVideo = isVideoFile(imageUrl);
+                if (isVideo) {
+                    imageList.remove(image);
+                    videos = JSONObject.parseObject(JSONObject.toJSONString(image), CommunityArticleImages.class);
+                    //BeanUtils.copyProperties(image, videos);
+                    videoList.add(videos);
+                }
+            }
+            articleVo.setVideoList(videoList);
+
+            //设置评论回复数量
+            articleVo.setCommentCount(communityArticleCommentMapper.queryCommentCount(articleVo.getId()));
+            //设置文章的点赞数量
+            articleVo.setLikeCount((int) communityLikes.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
+            //设置文章的收藏数量
+            articleVo.setCollectCount((int) communityArticleCollects.stream().filter(item -> item.getArticleId().equals(articleVo.getId())).count());
+            //设置文章推荐数量
+            articleVo.setRecommendCount((int) communityArticleRecommends.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).count());
+            //设置文章所属合集
+            articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
+
+            //设置中奖信息
+            CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
+            communityCommentRaffles
+                    .stream()
+                    .filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.isDelete())
+                    .findFirst()
+                    .ifPresent(communityCommentRaffle -> {
+                        BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
+                        CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(), true);
+                        communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
+                        communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
+                        articleVo.setCommentRaffleVo(communityCommentRaffleVo);
+                    });
+
+            //判断是否已收藏
+            List<CommunityArticleCollect> collects = communityArticleCollects.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
+            articleVo.setCollect(!collects.isEmpty());
+
+            //判断是否已点赞
+            List<CommunityLike> likes = communityLikes.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId())).collect(Collectors.toList());
+            articleVo.setLike(!likes.isEmpty());
+
+            //判断是否已推荐
+            List<CommunityArticleRecommend> recommends = communityArticleRecommends.stream().filter(item -> item.getUserId().equals(userId) && item.getArticleId().equals(articleVo.getId()) && !item.isDelete()).collect(Collectors.toList());
+            articleVo.setRecommend(!recommends.isEmpty());
+
+            //获取文章标签
+            List<CommunityArticleTag> articleTags = communityArticleTags.stream().filter(item -> item.getArticleId().equals(articleVo.getId()) && !item.getIsDelete()).collect(Collectors.toList());
+            List<Long> tagList = articleTags.stream().map(CommunityArticleTag::getTagId).collect(Collectors.toList());
+            List<Long> tagIds = new ArrayList<>();
+
+            if (!tagList.isEmpty()) {
+                //判断当前标签是否被当前登录用户拉黑
+                List<CommunityTagBlock> communityTagBlockList = communityTagBlocks
+                        .stream()
+                        .filter(item -> tagList.contains(item.getTagId()) && item.getUserId().equals(userId))
+                        .collect(Collectors.toList());
+                for (CommunityTagBlock tagBlock : communityTagBlockList) {
+                    if (tagBlock.isBlock()) {
+                        communityArticleVos.remove(articleVo);
+                        break;
+                    }
+                    tagIds.add(tagBlock.getTagId());
+                }
+
+                if (communityTagBlockList.isEmpty()) {
+                    tagIds.addAll(tagList);
+                }
+
+                if (!tagIds.isEmpty()) {
+                    List<CommunityTag> communityTagList = communityTags
+                            .stream()
+                            .filter(item -> tagIds.contains(item.getId()))
+                            .collect(Collectors.toList());
+                    articleVo.setTags(communityTagList);
+                }
+            }
+        }
+        return communityArticleVos;
+    }
+
+    /**
+     * 发布文章
+     *
+     * @param communityArticle 文章信息
+     */
+    @Override
+    public void insertCommunityArticle(CommunityArticle communityArticle) {
+
+        //判断是否传ID 如果有ID贼删除原来的文章 重新插入一条新文章
+        if (communityArticle.getId() != null) {
+            //增加字段 文章编辑字段
+            communityArticle.setIsDelete(true);
+
+            UpdateWrapper<CommunityArticle> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.eq("id", communityArticle.getId());
+
+            // 创建一个新的 CommunityArticle 对象,只设置 isDelete 字段
+            CommunityArticle updateArticle = new CommunityArticle();
+            updateArticle.setIsDelete(communityArticle.getIsDelete());
+
+            communityArticleService.update(updateArticle, updateWrapper);
+
+            communityArticle.setParentId(communityArticle.getId());
+            communityArticle.setId(null);
+        }
+
+
+        Long userId = SecurityUtils.getLoginUser().getUserId();
+        //插入文章信息
+        communityArticle.setUserId(userId);
+        communityArticle.setCreateBy(userId);
+        communityArticle.setUpdateBy(userId);
+        communityArticle.setIsDelete(false);
+/*      communityArticle.setComment(false);
+        communityArticle.setDownload(false);
+        communityArticle.setRaffle(false);*/
+        communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+
+        String address = null;
+        try {
+            address = AddressUtils.getAddress(null);
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        communityArticle.setAddress(address);
+
+        communityArticleMapper.insert(communityArticle);
+        //插入标签日志
+        List<String> tags = communityArticle.getTags();
+        if (tags != null && !tags.isEmpty()) {
+            CommunityArticleTag tagLog = null;
+            for (String tag : tags) {
+                tagLog = new CommunityArticleTag();
+                tagLog.setArticleId(communityArticle.getId());
+                tagLog.setTagId(Long.parseLong(tag));
+                tagLog.setUpdateBy(userId);
+                tagLog.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                tagLog.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                tagLog.setCreateBy(userId);
+                articleTagMapper.insert(tagLog);
+
+                //标签热度自增
+                CommunityTag communityTag = communityTagMapper.selectById(Long.parseLong(tag));
+                communityTag.setTagHot(Objects.isNull(communityTag.getTagHot()) ? 1 : communityTag.getTagHot() + 1);
+                communityTag.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityTag.setUpdateBy(userId);
+                communityTagMapper.updateById(communityTag);
+            }
+        }
+
+        //插入图片日志
+        List<CommunityImagesVo> images = communityArticle.getImages();
+        if (images != null && !images.isEmpty()) {
+            CommunityArticleImages articleImages = null;
+            for (CommunityImagesVo image : images) {
+                articleImages = new CommunityArticleImages();
+                articleImages.setArticleId(communityArticle.getId());
+                articleImages.setImageUrl(image.getImages());
+                articleImages.setCompressUrl(image.getCompressedImages());
+                articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                articleImages.setCreateBy(userId);
+                communityArticleImagesMapper.insert(articleImages);
+            }
+        }
+
+        //插入板块
+        List<Long> classIds = communityArticle.getClassIds();
+        if (classIds != null && !classIds.isEmpty()) {
+            List<CommunityArticleClass> articleClasses = new ArrayList<>();
+            CommunityArticleClass articleClass = null;
+            for (Long classId : classIds) {
+                articleClass = new CommunityArticleClass();
+                articleClass.setClassId(classId);
+                articleClass.setArticleId(communityArticle.getId());
+                articleClass.setCreateBy(userId);
+                articleClass.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                articleClasses.add(articleClass);
+            }
+            communityArticleClassService.saveBatch(articleClasses);
+        }
+
+        //插入合集
+        List<String> collectionIds = communityArticle.getCollectionIds();
+        if (collectionIds != null && !collectionIds.isEmpty()) {
+            List<CommunityCollectionArticle> collectionArticles = new ArrayList<>();
+            CommunityCollectionArticle collectionArticle = null;
+            for (String collectionId : collectionIds) {
+                collectionArticle = new CommunityCollectionArticle();
+                collectionArticle.setCollectionId(Long.parseLong(collectionId));
+                collectionArticle.setArticleId(communityArticle.getId());
+                collectionArticle.setCreateBy(userId);
+                collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                collectionArticles.add(collectionArticle);
+            }
+            collectionArticleService.saveBatch(collectionArticles);
+        }
+
+
+        // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
+        if (communityArticle.getIsDraft() != null && !communityArticle.getIsDraft()) {
+            //拿到需要At人的ID
+            List<Long> atUserIds = communityArticle.getAtUserIds();
+            if (atUserIds != null && !atUserIds.isEmpty()) {
+                List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+                CommunityArticleAt communityArticleAt = null;
+                for (Long atUserId : atUserIds) {
+                    communityArticleAt = new CommunityArticleAt();
+                    communityArticleAt.setType(0L);
+                    communityArticleAt.setArticleId(communityArticle.getId());
+                    communityArticleAt.setUserId(userId);
+                    communityArticleAt.setPeerId(atUserId);
+                    communityArticleAt.setCreateBy(userId);
+                    communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityArticleAts.add(communityArticleAt);
+                }
+                communityArticleAtService.saveBatch(communityArticleAts);
+            }
+        }
+
+    }
+
+
+    /**
+     * 编辑文章
+     *
+     * @param communityArticle 文章信息
+     */
+    @Override
+    public void editCommunityArticle(CommunityArticle communityArticle) {
+
+        Long userId = SecurityUtils.getLoginUser().getUserId();
+        //编辑文章信息
+        communityArticle.setUpdateBy(userId);
+        communityArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+
+
+        CommunityArticle article = communityArticleMapper.selectOne((new QueryWrapper<CommunityArticle>()
+                .eq("id", communityArticle.getId())
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })));
+
+        if (article != null) {
+            Integer pageViews = Math.toIntExact(article.getPageViews());
+            if (pageViews != null) {
+                communityArticle.setPageViews(pageViews);
+            } else {
+                // 处理 pageViews 为 null 的情况,比如设置为 0 或记录日志
+                communityArticle.setPageViews(0);
+            }
+        }
+
+        String address = null;
+        try {
+            address = AddressUtils.getAddress(null);
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        communityArticle.setAddress(address);
+
+        communityArticleMapper.updateById(communityArticle);
+
+
+        //插入标签日志
+        List<String> tags = communityArticle.getTags();
+        if (tags != null && !tags.isEmpty()) {
+            //不在本次更新的标签都传失效
+            communityArticleTagMapper.update(
+                    null,
+                    new UpdateWrapper<CommunityArticleTag>()
+                            .eq("article_id", communityArticle.getId())
+                            .notIn("tag_id", tags)
+                            .set("is_delete", true)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                            })
+            );
+
+            CommunityArticleTag tagLog = null;
+            for (String tag : tags) {
+
+                //查询该标签是否在数据库中存在
+                CommunityArticleTag communityArticleTag = communityArticleTagMapper.selectOne((new QueryWrapper<CommunityArticleTag>()
+                        .eq("article_id", communityArticle.getId())
+                        .eq("tag_id", tag)
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        })));
+                //不为空就不操作
+                if (communityArticleTag == null) {
+                    tagLog = new CommunityArticleTag();
+                    tagLog.setArticleId(communityArticle.getId());
+                    tagLog.setTagId(Long.parseLong(tag));
+                    tagLog.setUpdateBy(userId);
+                    tagLog.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    tagLog.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    tagLog.setCreateBy(userId);
+                    articleTagMapper.insert(tagLog);
+
+                    //标签热度自增
+                    CommunityTag communityTag = communityTagMapper.selectById(Long.parseLong(tag));
+                    communityTag.setTagHot(Objects.isNull(communityTag.getTagHot()) ? 1 : communityTag.getTagHot() + 1);
+                    communityTag.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityTag.setUpdateBy(userId);
+                    communityTagMapper.updateById(communityTag);
+                }
+            }
+        }
+
+        //插入图片日志
+        List<CommunityImagesVo> images = communityArticle.getImages();
+
+        //插入图片日志 都失效
+        communityArticleImagesMapper.update(
+                null,
+                new UpdateWrapper<CommunityArticleImages>()
+                        .eq("article_id", communityArticle.getId())
+                        .set("is_delete", true)
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                        })
+        );
+
+        if (images != null && !images.isEmpty()) {
+            CommunityArticleImages articleImages = null;
+            for (CommunityImagesVo image : images) {
+                articleImages = new CommunityArticleImages();
+                articleImages.setArticleId(communityArticle.getId());
+                articleImages.setImageUrl(image.getImages());
+                articleImages.setCompressUrl(image.getCompressedImages());
+                articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                articleImages.setCreateBy(userId);
+                communityArticleImagesMapper.insert(articleImages);
+            }
+        }
+
+        //插入板块
+        List<Long> classIds = communityArticle.getClassIds();
+
+        //插入板块 都失效
+        communityArticleClassService.update(
+                null,
+                new UpdateWrapper<CommunityArticleClass>()
+                        .eq("article_id", communityArticle.getId())
+                        .set("is_delete", true)
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                        })
+        );
+
+        if (classIds != null && !classIds.isEmpty()) {
+            List<CommunityArticleClass> articleClasses = new ArrayList<>();
+            CommunityArticleClass articleClass = null;
+            for (Long classId : classIds) {
+                articleClass = new CommunityArticleClass();
+                articleClass.setClassId(classId);
+                articleClass.setArticleId(communityArticle.getId());
+                articleClass.setCreateBy(userId);
+                articleClass.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                articleClasses.add(articleClass);
+            }
+            communityArticleClassService.saveBatch(articleClasses);
+        }
+
+        //插入合集
+        List<String> collectionIds = communityArticle.getCollectionIds();
+
+        if (collectionIds != null && !collectionIds.isEmpty()) {
+            //插入合集 都失效
+            collectionArticleService.update(
+                    null,
+                    new UpdateWrapper<CommunityCollectionArticle>()
+                            .eq("article_id", communityArticle.getId())
+                            .eq("create_by", userId)
+                            .set("is_delete", true)
+                            .and((wrapper) -> {
+                                wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                            })
+            );
+
+            List<CommunityCollectionArticle> collectionArticles = new ArrayList<>();
+            CommunityCollectionArticle collectionArticle = null;
+            for (String collectionId : collectionIds) {
+                collectionArticle = new CommunityCollectionArticle();
+                collectionArticle.setCollectionId(Long.parseLong(collectionId));
+                collectionArticle.setArticleId(communityArticle.getId());
+                collectionArticle.setCreateBy(userId);
+                collectionArticle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                collectionArticles.add(collectionArticle);
+            }
+            collectionArticleService.saveBatch(collectionArticles);
+        }
+
+
+        // at 人插入at通知表 判断是不是草稿箱 草稿箱不需要通知
+        if (communityArticle.getIsDraft() != null && !communityArticle.getIsDraft()) {
+            //拿到需要At人的ID
+            List<Long> atUserIds = communityArticle.getAtUserIds();
+
+            if (atUserIds != null && !atUserIds.isEmpty()) {
+                List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+                CommunityArticleAt communityArticleAt = null;
+                for (Long atUserId : atUserIds) {
+                    communityArticleAt = new CommunityArticleAt();
+                    communityArticleAt.setType(0L);
+                    communityArticleAt.setArticleId(communityArticle.getId());
+                    communityArticleAt.setUserId(userId);
+                    communityArticleAt.setPeerId(atUserId);
+                    communityArticleAt.setCreateBy(userId);
+                    communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    communityArticleAts.add(communityArticleAt);
+                }
+                communityArticleAtService.saveBatch(communityArticleAts);
+            }
+        }
+
+    }
+
+    /**
+     * 发送评论
+     *
+     * @param communityArticleComment 评论信息
+     */
+    @Override
+    public void sendComment(CommunityArticleComment communityArticleComment) throws ParseException {
+        communityArticleComment.setId(null);
+        communityArticleComment.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+        communityArticleComment.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
+        communityArticleComment.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticleComment.setDelete(false);
+        String address = null;
+        try {
+            address = AddressUtils.getAddress(null);
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+
+        communityArticleComment.setAddress(address);
+        communityArticleCommentMapper.insert(communityArticleComment);
+
+        //拿到需要At人的ID
+        List<Long> atUserIds = communityArticleComment.getAtUserIds();
+        if (atUserIds != null && !atUserIds.isEmpty()) {
+            List<CommunityArticleAt> communityArticleAts = new ArrayList<>();
+            CommunityArticleAt communityArticleAt = null;
+            for (Long atUserId : atUserIds) {
+                communityArticleAt = new CommunityArticleAt();
+                communityArticleAt.setType(1L);
+                communityArticleAt.setArticleId(communityArticleComment.getArticleId());
+                communityArticleAt.setCommentId(communityArticleComment.getId());
+                communityArticleAt.setUserId(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setPeerId(atUserId);
+                communityArticleAt.setCreateBy(SecurityUtils.getLoginUser().getUserId());
+                communityArticleAt.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                communityArticleAts.add(communityArticleAt);
+            }
+            communityArticleAtService.saveBatch(communityArticleAts);
+        }
+    }
+
+    /**
+     * 删除评论
+     *
+     * @param communityArticleComment 评论信息
+     */
+    @Override
+    public void deleteComment(CommunityArticleComment communityArticleComment) {
+        communityArticleComment.setDelete(true);
+        communityArticleComment.setUpdateBy(SecurityUtils.getUserId());
+        communityArticleComment.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityArticleCommentMapper.updateById(communityArticleComment);
+    }
+
+
+    /**
+     * 查询该文章对应的用户是否已经点赞
+     *
+     * @param communityLike 点赞信息
+     * @return 点赞信息
+     */
+    @Override
+    public CommunityLike selectCommunityLikeById(CommunityLike communityLike) {
+        QueryWrapper<CommunityLike> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("article_id", communityLike.getArticleId()).eq("user_id", communityLike.getUserId());
+        return communityLikeMapper.selectOne(queryWrapper);
+    }
+
+
+    /**
+     * 新增点赞
+     *
+     * @param communityLike 点赞信息
+     * @return 点赞是否成功
+     */
+    @Override
+    public boolean insertCommunityLikeById(CommunityLike communityLike) {
+        return communityLikeMapper.insert(communityLike) > 0;
+    }
+
+
+    /**
+     * 删除点赞
+     *
+     * @param communityLike 点赞信息
+     * @return 删除是否成功
+     */
+    @Override
+    public boolean deleteCommunityLikeById(CommunityLike communityLike) {
+        return communityLikeMapper.deleteById(communityLike.getId()) > 0;
+    }
+
+
+    /**
+     * 查询该文章对应的用户是否已经收藏
+     *
+     * @param collect 收藏信息
+     * @return 收藏信息
+     */
+    @Override
+    public CommunityArticleCollect selectCommunityCollectById(CommunityArticleCollect collect) {
+        return communityCollectMapper.selectOne(new QueryWrapper<CommunityArticleCollect>().eq("article_id", collect.getArticleId()).eq("user_id", SecurityUtils.getUserId()));
+    }
+
+    /**
+     * 新增收藏
+     *
+     * @param collect 收藏信息
+     * @return 收藏是否成功
+     */
+    @Override
+    public boolean insertCommunityCollectById(CommunityArticleCollect collect) {
+        return communityCollectMapper.insert(collect) > 0;
+    }
+
+    /**
+     * 删除收藏
+     *
+     * @param collect 收藏信息
+     * @return 删除是否成功
+     */
+    @Override
+    public boolean deleteCommunityCollectById(CommunityArticleCollect collect) {
+        return communityCollectMapper.deleteById(collect) > 0;
+    }
+
+
+    /**
+     * 根据板块获取圈子列表
+     *
+     * @param classId 板块id
+     * @return 圈子列表信息
+     */
+    @Override
+    public List<CommunityCircleVo> selectCommunityCircleList(String classId) {
+        List<CommunityClassCircle> classes = communityClassCircleMapper.selectList(new QueryWrapper<CommunityClassCircle>().eq("class_id", classId));
+        List<Long> circleIds = new ArrayList<>();
+        for (CommunityClassCircle aClass : classes) {
+            circleIds.add(aClass.getCircleId());
+        }
+
+        List<CommunityCircleVo> communityCircleVos = null;
+        if (!circleIds.isEmpty()) {
+            List<CommunityCircle> communityCircles = communityCircleMapper.selectBatchIds(circleIds);
+            //复制到Vo对象中
+            communityCircleVos = new ArrayList<>();
+            CommunityCircleVo communityCircleVo = null;
+            for (CommunityCircle communityCircle : communityCircles) {
+                communityCircleVo = new CommunityCircleVo();
+                BeanUtils.copyProperties(communityCircle, communityCircleVo);
+
+                //获取当前用户是否有关注这些圈子
+                CommunityUserCircle communityUserCircles = communityUserCircleMapper.selectOne(new QueryWrapper<CommunityUserCircle>().eq("circle_id", communityCircle.getId()).eq("user_id", SecurityUtils.getLoginUser().getUserId()).eq("is_delete", 0));
+                if (Objects.isNull(communityUserCircles) || Objects.isNull(communityUserCircles.getId())) {
+                    //没找到关注数据,则设为false,反之则true
+                    communityCircleVo.setLike(false);
+                } else {
+                    communityCircleVo.setLike(true);
+                }
+                communityCircleVos.add(communityCircleVo);
+            }
+        }
+        return communityCircleVos;
+    }
+
+    /**
+     * 关注或取消关注用户粉丝/关注
+     *
+     * @param likeUserId 被关注人id
+     * @return 登录用户关注信息
+     */
+    @Override
+    public CommunityUserLike addOrDeleteUserLike(Long likeUserId) {
+        Long userId = SecurityUtils.getLoginUser().getUserId();  // 当前登录用户id
+        //1.检查是否已被当前用户关注
+        CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", userId).eq("like_user_id", likeUserId));
+        //2.1 没有则进行关注,返回关注列表信息
+        if (Objects.isNull(communityUserLike) || Objects.isNull(communityUserLike.getId())) {
+            communityUserLike = new CommunityUserLike();
+            communityUserLike.setUserId(userId);
+            communityUserLike.setLikeUserId(likeUserId);
+            communityUserLike.setRead(false);
+            communityUserLike.setCreateBy(userId);
+            communityUserLike.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityUserLikeMapper.insert(communityUserLike);
+
+            communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", userId).eq("like_user_id", likeUserId));
+            return communityUserLike;
+        }
+
+        //2.2 已关注则取消关注
+        communityUserLikeMapper.deleteById(communityUserLike);
+        return null;
+    }
+
+    /**
+     * 获取当前登录用户信息
+     *
+     * @param userId 用户id
+     * @return 用户信息
+     */
+    @Override
+    public CommunityUserInfoVo selectCommunityUserInfoById(Long userId, boolean isToken) {
+        SysUser sysUser = sysUserMapper.selectUserById(userId);
+
+        System.out.println(sysUser);
+        CommunityUserInfo communityUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", userId));
+        CommunityUserInfoVo communityUserInfoVo = new CommunityUserInfoVo();
+        BeanUtils.copyProperties(communityUserInfo, communityUserInfoVo);
+        communityUserInfoVo.setAvatar(sysUser.getAvatar());
+        communityUserInfoVo.setNickName(sysUser.getNickName());
+        communityUserInfoVo.setSex(sysUser.getSex());
+        communityUserInfoVo.setUserId(userId);
+        communityUserInfoVo.setUserState(sysUser.getUserState());
+        communityUserInfoVo.setReportTime(sysUser.getReportTime());
+
+        //设置关注,粉丝,陪伴天数 文章数量
+        communityUserInfoVo.setLikeCount(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("user_id", userId)).size());
+        communityUserInfoVo.setFansCount(communityUserLikeMapper.selectList(new QueryWrapper<CommunityUserLike>().eq("like_user_id", userId)).size());
+
+        Date createTime = sysUser.getCreateTime();
+        // 将 Date 对象转换为 LocalDate 对象
+        LocalDate localCreateTime = createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 计算两个日期之间的天数差
+        long daysDifference = ChronoUnit.DAYS.between(localCreateTime, today);
+        communityUserInfoVo.setCompanionCount((int) daysDifference);
+
+        communityUserInfoVo.setArticleCount(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                })).size());
+
+
+        String address = null;
+        try {
+            address = AddressUtils.getAddress(sysUser.getLoginIp());
+        } catch (ExecutionException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        communityUserInfoVo.setAddress(address);
+        //设置是否被当前登录的用户关注
+        communityUserInfoVo.setLike(false);
+        if (isToken) {
+            Long loginUserId = SecurityUtils.getLoginUser().getUserId();
+            if (!Objects.equals(userId, loginUserId)) {
+                CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>().eq("user_id", loginUserId).eq("like_user_id", userId));
+                if (!Objects.isNull(communityUserLike) && !Objects.isNull(communityUserLike.getId())) {
+                    communityUserInfoVo.setLike(true);
+                }
+            }
+        }
+        return communityUserInfoVo;
+    }
+
+    /**
+     * 根据条件搜索用户列表信息(无权限卡控)
+     *
+     * @param searchValue 搜索值
+     * @return 用户
+     */
+    @Override
+    public List<CommunityUserInfoVo> selectUserBySearchValue(@Param("searchValue") String searchValue,
+                                                             @Param("offset") int offset,
+                                                             @Param("limit") int limit) {
+        return communityUserInfoMapper.selectUserBySearchValue(searchValue, offset, limit);
+    }
+
+    @Override
+    public List<CommunityUserInfoVo> selectBlockUserBySearchValue(@Param("searchValue") String searchValue,
+                                                                  @Param("userId") Long userId,
+                                                                  @Param("offset") int offset,
+                                                                  @Param("limit") int limit) {
+        return communityUserInfoMapper.selectBlockUserBySearchValue(searchValue, userId, offset, limit);
+    }
+
+    /**
+     * 根据条件搜索用户列表信息(有权限卡控)
+     *
+     * @param searchValue 搜索值
+     * @return 用户
+     */
+    @Override
+    public List<CommunityUserInfoVo> selectUsersByAccountOrName(@Param("searchValue") String searchValue,
+                                                                @Param("offset") int offset,
+                                                                @Param("limit") int limit) {
+        List<CommunityUserInfoVo> communityUserInfoVos = communityUserInfoMapper.selectUsersByAccountOrName(searchValue, offset, limit);
+        communityUserInfoVos.forEach(item -> {
+            CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>()
+                    .eq("user_id", SecurityUtils.getUserId())
+                    .eq("like_user_id", item.getUserId()));
+
+            if (Objects.nonNull(communityUserLike)) {
+                item.setLike(true);
+            }
+        });
+        return communityUserInfoVos;
+    }
+
+
+    /**
+     * 获取关注列表
+     *
+     * @param userId 登录用户id
+     * @return 当前用户关注列表
+     */
+    @Override
+    public List<CommunityUserLikeVo> selectCommunityUserLikeList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
+        int offset = (pageNum - 1) * pageSize;
+//        Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
+//        QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
+//                .eq("user_id", userId);
+//        if (searchType == 1) {
+//            queryWrapper.orderByDesc("create_time");
+//        } else {
+//            queryWrapper.orderByAsc("create_time");
+//        }
+//
+//        List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
+
+        List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectUserLikeList(userId, offset, pageSize, userName, searchType);
+
+        List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
+        CommunityUserLikeVo communityUserLikeVo = null;
+        Boolean isCare = false;
+
+        for (CommunityUserLike communityUserLike : communityUserLikes) {
+            communityUserLikeVo = new CommunityUserLikeVo();
+            //用户信息
+            SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
+            SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
+            //用户自我介绍
+            CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
+            CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
+            BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
+
+            //关注的用户是否已经关注当前用户
+            CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
+                    new QueryWrapper<CommunityUserLike>()
+                            .eq("like_user_id", userId)
+                            .eq("user_id", communityUserLike.getLikeUserId()));
+
+            if (communityUserLikeFans != null) {
+                isCare = true;
+            }
+            communityUserLikeVo.setIsCare(isCare);
+
+            if (Objects.nonNull(userInfo)) {
+                communityUserLikeVo.setProfile(userInfo.getProfile());
+            }
+
+            if (Objects.nonNull(likeUserInfo)) {
+                communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
+            }
+
+            if (Objects.nonNull(sysUser)) {
+                communityUserLikeVo.setAvatar(sysUser.getAvatar());
+                communityUserLikeVo.setUsername(sysUser.getNickName());
+            }
+
+            if (Objects.nonNull(sysUserLike)) {
+                communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
+                communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
+            }
+
+            //如果不需要搜索名字直接添加
+//            if (userName != null && communityUserLikeVo.getLikeUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
+//                communityUserLikeVos.add(communityUserLikeVo);
+//            } else if (userName == null) {
+//                communityUserLikeVos.add(communityUserLikeVo);
+//            }
+            communityUserLikeVos.add(communityUserLikeVo);
+        }
+        return communityUserLikeVos;
+    }
+
+
+    /**
+     * 获取粉丝列表
+     *
+     * @param userId 登录用户id
+     * @return 当前用户粉丝列表
+     */
+    @Override
+    public List<CommunityUserLikeVo> selectUserFansList(Long userId, String userName, int pageNum, int pageSize, int searchType) {
+        //int offset = (pageNum - 1) * pageSize;
+        Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
+        QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
+                .eq("like_user_id", userId);
+        if (searchType == 1) {
+            queryWrapper.orderByDesc("create_time");
+        } else {
+            queryWrapper.orderByAsc("create_time");
+        }
+
+        List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
+
+        List<CommunityUserLikeVo> communityUserLikeVos = new ArrayList<>();
+        CommunityUserLikeVo communityUserLikeVo = null;
+
+        for (CommunityUserLike communityUserLike : communityUserLikes) {
+            Boolean isCare = false;
+            // System.out.println(communityUserLike.getUserId()  + "---" + userId);
+            //用户信息
+            SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
+            //用户自我介绍
+            CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
+            CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
+
+
+            //用户是否关注当前用户
+            CommunityUserLike communityUserLikeFans = communityUserLikeMapper.selectOne(
+                    new QueryWrapper<CommunityUserLike>()
+                            .eq("like_user_id", communityUserLike.getUserId())
+                            .eq("user_id", userId));
+
+            if (communityUserLikeFans != null) {
+                isCare = true;
+            }
+            communityUserLikeVo = new CommunityUserLikeVo();
+            BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
+            SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
+
+            communityUserLikeVo.setIsCare(isCare);
+
+
+            if (Objects.nonNull(sysUser)) {
+                communityUserLikeVo.setAvatar(sysUser.getAvatar());
+                communityUserLikeVo.setUsername(sysUser.getNickName());
+            }
+
+            if (Objects.nonNull(userInfo)) {
+                communityUserLikeVo.setProfile(userInfo.getProfile());
+            }
+
+            if (Objects.nonNull(sysUserLike)) {
+                communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
+                communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
+            }
+
+            if (Objects.nonNull(likeUserInfo)) {
+                communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
+            }
+            //如果不需要搜索名字直接添加
+            if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
+                communityUserLikeVos.add(communityUserLikeVo);
+            } else if (userName == null) {
+                communityUserLikeVos.add(communityUserLikeVo);
+            }
+
+        }
+        return communityUserLikeVos;
+    }
+
+    /**
+     * 获取互相关注列表
+     *
+     * @param userId 登录用户id
+     * @return 获取互相关注列表
+     */
+    @Override
+    public List<CommunityUserLikeVo> selectMutualAttention(Long userId, String userName, int pageNum, int pageSize, int searchType) {
+
+        //先查询自己关注的人
+        List<CommunityUserLikeVo> communityUserLikeVos = selectCommunityUserLikeList(userId, null, 1, 10000000, 0);
+        //再查询被关注的人是否关注自己
+        List<Long> likeUserIds = new ArrayList<>();
+        for (CommunityUserLikeVo communityUserLikeVo : communityUserLikeVos) {
+            likeUserIds.add(communityUserLikeVo.getLikeUserId());
+        }
+
+        if (!likeUserIds.isEmpty()) {
+            QueryWrapper<CommunityUserLike> queryWrapper = new QueryWrapper<CommunityUserLike>()
+                    .in("user_id", likeUserIds).eq("like_user_id", userId);
+            if (searchType == 1) {
+                queryWrapper.orderByDesc("create_time");
+            } else {
+                queryWrapper.orderByAsc("create_time");
+            }
+            //分页查询数据
+            //int offset = (pageNum - 1) * pageSize;
+            Page<CommunityUserLike> page = new Page<>(pageNum, pageSize);
+
+            List<CommunityUserLike> communityUserLikes = communityUserLikeMapper.selectPage(page, queryWrapper).getRecords();
+
+            System.out.println("communityUserLikes: " + communityUserLikes);
+            CommunityUserLikeVo communityUserLikeVo = null;
+            communityUserLikeVos = new ArrayList<>();
+            for (CommunityUserLike communityUserLike : communityUserLikes) {
+                //用户信息
+                SysUser sysUserLike = sysUserMapper.selectUserById(communityUserLike.getLikeUserId());
+                //用户自我介绍
+                CommunityUserInfo userInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getUserId()));
+                CommunityUserInfo likeUserInfo = communityUserInfoMapper.selectOne(new QueryWrapper<CommunityUserInfo>().eq("user_id", communityUserLike.getLikeUserId()));
+
+                communityUserLikeVo = new CommunityUserLikeVo();
+                BeanUtils.copyProperties(communityUserLike, communityUserLikeVo);
+                SysUser sysUser = sysUserMapper.selectUserById(communityUserLike.getUserId());
+                communityUserLikeVo.setProfile(userInfo.getProfile());
+                communityUserLikeVo.setAvatar(sysUser.getAvatar());
+                communityUserLikeVo.setUsername(sysUser.getNickName());
+                communityUserLikeVo.setLikeUsername(sysUserLike.getNickName());
+                communityUserLikeVo.setLikeAvatar(sysUserLike.getAvatar());
+                communityUserLikeVo.setLikeProfile(likeUserInfo.getProfile());
+                communityUserLikeVo.setIsCare(true);
+
+
+                //如果不需要搜索名字直接添加
+                if (userName != null && communityUserLikeVo.getUsername().matches("(?i).*" + Pattern.quote(userName) + ".*")) {
+                    communityUserLikeVos.add(communityUserLikeVo);
+                } else if (userName == null) {
+                    communityUserLikeVos.add(communityUserLikeVo);
+                }
+
+
+            }
+        }
+        return communityUserLikeVos;
+    }
+
+    /**
+     * 判断评论的人 是否在文章作者的关注列表中
+     *
+     * @param userId    必填
+     * @param commentId 可选  评论的评论接口
+     * @param articleId 可选  文章评论接口
+     * @return true or false
+     * @throws ParseException
+     */
+    @Override
+    public Boolean checkCommentPermission(Long userId, Long commentId, Long articleId) throws ParseException {
+        /**
+         * 1.传commentId 说明是 评论的评论接口
+         * 2.传articleId 说明是文章评论接口
+         * 3.询隐私设置表 communityPrivacyService.selectUserPrivacy 权限有没有开启
+         * 4.没有开启 直接结束
+         * 5.开启 查询作者关注列表
+         * 6。是否是关注的人评论我 有则评论成功,没有则返回失败
+         */
+        //假设传的评论ID 根据 评论ID要找到文章ID
+        if (articleId == null) {
+            List<CommunityArticleComment> communityArticleComments
+                    = communityArticleCommentMapper
+                    .selectList(new QueryWrapper<CommunityArticleComment>().eq("id", commentId));
+            CommunityArticleComment communityArticleComment = communityArticleComments.get(0);
+            articleId = communityArticleComment.getArticleId();
+        }
+        ;
+
+        //获取文章信息 找到文章创建人
+        List<CommunityArticle> communityArticles
+                = communityArticleMapper
+                .selectList(new QueryWrapper<CommunityArticle>().eq("id", articleId));
+
+        // 提取用户ID
+        Long articleUserId = null; // 初始化用户ID
+
+        if (!communityArticles.isEmpty()) { // 检查列表是否为空
+            CommunityArticle article = communityArticles.get(0); // 获取第一个文章
+            articleUserId = article.getUserId(); // 假设CommunityArticle有getUserId()方法
+        } else {
+            // 处理未找到文章的情况
+            // 例如,可以抛出异常或记录日志
+            return false;
+        }
+
+        // 直接允许作者评论
+        if (articleUserId.equals(userId)) {
+           /* // 如果评论者是文章作者,直接进行评论
+            communityArticleService.sendComment(communityArticleComment);*/
+            return true;
+        }
+
+        // 查询隐私设置
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = communityPrivacyService.selectUserPrivacy(articleUserId);
+        // 检查隐私设置 只允许我关注的人评论我
+        boolean IsComment = false;
+        for (CommunityUserPrivacyVo privacyVo : communityUserPrivacyVos) {
+            if (privacyVo.getIsComment() != null && privacyVo.getIsComment()) {
+                IsComment = true; // 只允许特定用户评论
+                break;
+            }
+        }
+        // 如果评论受限,则查询用户关注列表
+        if (IsComment) {
+            List<CommunityUserLikeVo> communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(articleUserId, null, 1, 100000, 0);
+            // 3. 检查评论者是否在关注列表中
+            boolean isFollower = communityUserLikeVos.stream()
+                    .anyMatch(like -> like.getLikeUserId().equals(userId));
+            System.out.println(userId);
+            // 如果不是关注者,返回失败
+            if (!isFollower) {
+                //return AjaxResult.error("您没有权限评论此文章,因为只允许关注的人评论您!");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public List<TrendingTop> selectTrendingTopByContent(String content) {
+        return communityArticleMapper.selectTrendingTopByContent(content);
+    }
+
+
+    /**
+     * 个人中心简介信息
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    public List<CommunityUserPromptVo> selectCommunityUserPrompt(Long userId) {
+        if (Objects.isNull(userId)) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
+        // 查询自己的通知列表
+        List<CommunityUserPrompt> communityUserPrompts
+                = communityUserPromptMapper
+                .selectList(new QueryWrapper<CommunityUserPrompt>().eq("user_id", userId));
+
+
+        // 创建一个用于存放VO的列表
+        List<CommunityUserPromptVo> communityUserPromptVos = new ArrayList<>();
+        // 遍历查询结果,复制属性到 VO 对象
+        for (CommunityUserPrompt communityUserPrompt : communityUserPrompts) {
+            CommunityUserPromptVo communityUserPromptVo = new CommunityUserPromptVo();
+            BeanUtils.copyProperties(communityUserPrompt, communityUserPromptVo);
+            communityUserPromptVos.add(communityUserPromptVo);
+        }
+        // 判断隐私权限是否为空
+        if (communityUserPromptVos.isEmpty()) {
+            // 如果没有隐私权限,插入一条关于 userId 的数据
+            CommunityUserPrompt newPrompt = new CommunityUserPrompt();
+            newPrompt.setUserId(userId);
+            newPrompt.setLikeUser(false);
+            newPrompt.setCommentCircle(false);
+            newPrompt.setLikeCollect(false);
+            // 设置其他必要的默认值,例如:
+            // 使用 MyBatis-Plus 执行插入操作
+            communityUserPromptMapper.insert(newPrompt);
+            // 将新插入的记录转换为 VO 并返回
+            CommunityUserPromptVo newPromptVo = new CommunityUserPromptVo();
+            BeanUtils.copyProperties(newPrompt, newPromptVo);
+            communityUserPromptVos.add(newPromptVo);
+        }
+        return communityUserPromptVos;
+    }
+
+    // 修改service实现
+    @Override
+    public List<CommunityArticleVo> selectUserNoCo(Long userId, int pageNum, int pageSize, int searchType) {
+        //PageHelper.startPage(pageNum, pageSize);
+        return communityArticleMapper.selectUserNoCoArticles(userId);
+    }
+
+    @Override
+    public List<CommunityArticleVo> selectUserLike(Long userId, int pageNum, int pageSize, int searchType) {
+        // 查询的喜欢列表
+        List<CommunityLike> communityUserLike
+                = communityLikeMapper
+                .selectList(new QueryWrapper<CommunityLike>().eq("user_id", userId));
+        List<Long> articleIds = communityUserLike.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
+        TableDataInfo rspData = null;
+        CommunityArticle communityArticle = null;
+        List<CommunityArticleVo> communityArticleVos = null;
+        if (!articleIds.isEmpty()) {
+            rspData = new TableDataInfo();
+            communityArticle = new CommunityArticle();
+            communityArticle.setArticleIds(articleIds);
+            communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
+        }
+        return communityArticleVos;
+    }
+
+    @Override
+    public List<CommunityArticleVo> selectUserCollect(Long userId, int pageNum, int pageSize, int searchType) {
+        // 查询收藏的列表
+        List<CommunityArticleCollect> communityArticleCollects
+                = communityArticleCollectMapper
+                .selectList(new QueryWrapper<CommunityArticleCollect>().eq("user_id", userId));
+
+
+        List<Long> articleIds = communityArticleCollects.stream().map(item -> item.getArticleId()).collect(Collectors.toList());
+        TableDataInfo rspData = null;
+        CommunityArticle communityArticle = null;
+        List<CommunityArticleVo> communityArticleVos = null;
+        if (!articleIds.isEmpty()) {
+            rspData = new TableDataInfo();
+            communityArticle = new CommunityArticle();
+            communityArticle.setArticleIds(articleIds);
+            communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
+        }
+        return communityArticleVos;
+    }
+
+    /**
+     * 开启抽奖
+     *
+     * @param articleId
+     * @return
+     */
+    @Override
+    public CommunityCommentRaffleVo selectCommentRaffle(Long articleId) {
+        CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
+                new QueryWrapper<CommunityCommentRaffle>()
+                        .eq("article_id", articleId)
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        }));
+
+        CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
+        CommunityUserInfoVo communityUserInfoVo = null;
+        //如果抽奖表为空则需要插入一条数据
+        if (communityCommentRaffle == null) {
+            List<CommunityArticleComment> communityArticleComments = communityArticleCommentMapper.selectList(new QueryWrapper<CommunityArticleComment>()
+                    .eq("article_id", articleId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    })
+            );
+            if (communityArticleComments.size() == 0) {
+                return communityCommentRaffleVo;
+            }
+            // 使用 Random 类生成一个随机索引
+            Random random = new Random();
+            int randomIndex = random.nextInt(communityArticleComments.size());
+            CommunityArticleComment communityArticleComment = communityArticleComments.get(randomIndex);
+            CommunityCommentRaffle commentRaffle = new CommunityCommentRaffle();
+            commentRaffle.setArticleId(communityArticleComment.getArticleId());
+            commentRaffle.setCommentId(communityArticleComment.getId());
+            commentRaffle.setUserId(communityArticleComment.getUserId());
+            commentRaffle.setCreateBy(SecurityUtils.getUserId());
+            commentRaffle.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCommentRaffleMapper.insert(commentRaffle);
+            BeanUtils.copyProperties(commentRaffle, communityCommentRaffleVo);
+            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(commentRaffle.getUserId(), true);
+            communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
+            communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
+            return communityCommentRaffleVo;
+        }
+
+        BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
+        communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(), true);
+        communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
+        communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
+        return communityCommentRaffleVo;
+    }
+
+
+    /**
+     * 判断是否是视频文件
+     *
+     * @param fileUrl 文件地址
+     * @return 结果
+     */
+    public static boolean isVideoFile(String fileUrl) {
+        try {
+            // 打开 HTTP 连接
+            URL url = new URL(fileUrl);
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setRequestMethod("GET");
+
+            // 获取文件类型
+            String mimeType = connection.getContentType();
+
+            // 判断是否为视频类型
+            return mimeType != null && mimeType.startsWith("video");
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+}

+ 11 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityArticleTagImpl.java

@@ -0,0 +1,11 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityArticleTag;
+import com.ruoyi.generator.mapper.community.CommunityArticleTagMapper;
+import com.ruoyi.generator.service.ICommunityArticleTagService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityArticleTagImpl extends ServiceImpl<CommunityArticleTagMapper, CommunityArticleTag> implements ICommunityArticleTagService {
+}

+ 13 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionArticleImpl.java

@@ -0,0 +1,13 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityCollectionArticle;
+import com.ruoyi.generator.mapper.community.CommunityCollectionArticleMapper;
+import com.ruoyi.generator.service.ICommunityCollectionArticleService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityCollectionArticleImpl extends ServiceImpl<CommunityCollectionArticleMapper, CommunityCollectionArticle> implements ICommunityCollectionArticleService {
+
+
+}

+ 309 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionServiceImpl.java

@@ -0,0 +1,309 @@
+package com.ruoyi.generator.service.impl;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.generator.domain.Community.*;
+import com.ruoyi.generator.mapper.community.*;
+import com.ruoyi.generator.service.ICommunityCollectionService;
+import com.ruoyi.generator.vo.CommunityCollectionArticleVo;
+import com.ruoyi.generator.vo.CommunityCollectionVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollectionMapper, CommunityCollection> implements ICommunityCollectionService {
+
+    @Autowired
+    private CommunityCollectionArticleMapper collectionArticleMapper;
+
+    @Autowired
+    private CommunityArticleMapper communityArticleMapper;
+
+    @Autowired
+    private CommunityLikeMapper communityLikeMapper;
+
+    @Autowired
+    private CommunityArticleCommentMapper communityArticleCommentMapper;
+
+    @Autowired
+    private CommunityArticleImagesMapper communityArticleImagesMapper;
+
+    @Autowired
+    private CommunityCollectionMapper communityCollectionMapper;
+
+    @Autowired
+    private CommunityCollectionArticleMapper communityCollectionArticleMapper;
+    @Autowired
+    private CommunityCollectionUserMapper communityCollectionUserMapper;
+
+    /**
+     * 添加文章到用户合集中
+     *
+     * @param collectionArticle 合集列表
+     */
+    @Override
+    public void addArticleToCollection(CommunityCollectionArticle collectionArticle) {
+        collectionArticleMapper.insert(collectionArticle);
+    }
+
+    /**
+     * 删除合集中的某个文章
+     *
+     * @param collectionId 合集id
+     * @param articleId    文章id
+     */
+    @Override
+    public void deleteArticleToCollection(Long collectionId, Long articleId) {
+        //删除合集中的文章
+        CommunityCollectionArticle collectionArticle = new CommunityCollectionArticle();
+        collectionArticle.setDelete(true);
+        collectionArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        collectionArticle.setUpdateBy(SecurityUtils.getUserId());
+        communityCollectionArticleMapper.update(collectionArticle, new UpdateWrapper<CommunityCollectionArticle>()
+                .eq("collection_id", collectionId)
+                .eq("article_id", articleId).and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
+    }
+
+    /**
+     * 根据合集id,查询合集下所有文章信息
+     *
+     * @param collectionId 合集id
+     * @return 文章信息
+     */
+    @Override
+    public JSONArray selectArticleInfoInCollection(Long userId,Long collectionId, Long searchType) {
+        if (searchType == null) {
+            searchType = 1L;
+        }
+        JSONArray jsonArray = new JSONArray();
+        List<CommunityCollectionArticleVo> collectionArticleVos = new ArrayList<>();
+        //查询合集表
+        CommunityCollection communityCollection = communityCollectionMapper.selectOne(new QueryWrapper<CommunityCollection>()
+                .eq("id", collectionId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
+
+        if (communityCollection == null) {
+            return null;
+        }
+        //没调用这一个接口 热度 + 1
+        UpdateWrapper<CommunityCollection> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("id", collectionId)
+                .and(w -> w.ne("is_delete", true).or().isNull("is_delete"));
+        updateWrapper.setSql("heat = IFNULL(heat, 0) + 1");
+        communityCollectionMapper.update(null, updateWrapper);
+
+        //一级层级
+        JSONObject collectionObject = new JSONObject();
+        collectionObject.put("CollectionName", communityCollection.getCollectionName());
+        Date updateTime = communityCollection.getUpdateTime();
+        if (updateTime == null) {
+            updateTime = communityCollection.getCreateTime();
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String formattedUpdateTime = sdf.format(updateTime);
+        collectionObject.put("collectioncreateby", communityCollection.getCreateBy());
+        collectionObject.put("collectionProfile", communityCollection.getCollectionProfile());
+        collectionObject.put("updateTime", formattedUpdateTime);
+        collectionObject.put("collectionImageUrl",communityCollection.getImages());
+        collectionObject.put("collectionTag",communityCollection.getCollectionTag());
+        collectionObject.put("followNumber", communityCollectionUserMapper.selectList(new QueryWrapper<CommunityCollectionUser>().eq("collection_id", collectionId).and((wrapper) -> {
+            wrapper.ne("is_delete", true)
+                    .or()
+                    .isNull("is_delete");
+        })).size());
+        collectionObject.put("heat", communityCollection.getHeat());
+        //浏览量设置默认值
+        collectionObject.put("articlePageViews",0);
+        collectionObject.put("articleNumber", 0);
+        collectionObject.put("articleNumber", 0);
+
+
+        //查询当前用户是否订阅
+        CommunityCollectionUser communityCollectionUser = communityCollectionUserMapper.selectOne(new QueryWrapper<CommunityCollectionUser>()
+                .eq("collection_id", collectionId)
+                .eq("user_id", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
+        boolean follow = false;
+        if (communityCollectionUser != null) {
+            follow = true;
+        }
+        collectionObject.put("follow", follow);
+        collectionObject.put("Article", collectionArticleVos);
+        //查询合集关联文章表
+        List<Object> articleIdsObj = collectionArticleMapper
+                .selectObjs(new QueryWrapper<CommunityCollectionArticle>()
+                        .select("article_id")
+                        .eq("collection_id", collectionId)
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true)
+                                    .or()
+                                    .isNull("is_delete");
+                        }));
+
+        if (articleIdsObj.isEmpty()) {
+            return JSONArray.of(collectionObject);
+        }
+
+        //转换object为long
+        List<Long> articleIds = articleIdsObj.stream()
+                .filter(item -> item instanceof Long)
+                .map(item -> (Long) item)
+                .collect(Collectors.toList());
+
+
+        List<CommunityArticle> communityArticles;
+
+        if (searchType == 1) {
+            // 查询最新的文章
+            communityArticles = communityArticleMapper.selectList(
+                    new QueryWrapper<CommunityArticle>().in("id", articleIds)
+                            .and((wrapper) -> {wrapper.ne("is_delete", true)
+                                .or()
+                                .isNull("is_delete");
+                    }).and((wrapper) -> {
+                                wrapper.ne("is_draft", true)
+                                        .or()
+                                        .isNull("is_draft");
+                            })
+                            .orderByDesc("create_time"));
+        } else {
+            // 查询最早的文章
+            communityArticles = communityArticleMapper.selectList(
+                    new QueryWrapper<CommunityArticle>().in("id", articleIds).and((wrapper) -> {
+                        wrapper.ne("is_delete", true)
+                                .or()
+                                .isNull("is_delete");
+                    }).and((wrapper) -> {
+                                wrapper.ne("is_draft", true)
+                                        .or()
+                                        .isNull("is_draft");
+                            })
+                            .orderByAsc("create_time"));
+        }
+        collectionObject.put("articleNumber", communityArticles.size());
+
+        //获取浏览量总数
+        collectionObject.put("articlePageViews",communityArticles.stream()
+                .mapToLong(CommunityArticle::getPageViews)
+                .sum());
+
+
+        CommunityCollectionArticleVo collectionArticleVo = null;
+        for (CommunityArticle communityArticle : communityArticles) {
+            collectionArticleVo = new CommunityCollectionArticleVo();
+            collectionArticleVo.setArticleId(communityArticle.getId());
+            collectionArticleVo.setCollectionId(collectionId);
+            collectionArticleVo.setTitle(communityArticle.getTitle());
+            collectionArticleVo.setArticleCreateTime(communityArticle.getCreateTime());
+            collectionArticleVo.setContent(communityArticle.getContent());
+
+            collectionArticleVo.setPageViews(communityArticle.getPageViews());
+            //设置用户点赞数
+            int likeCount = communityLikeMapper.selectCount(new QueryWrapper<CommunityLike>().eq("article_id", communityArticle.getId())).intValue();
+            collectionArticleVo.setLikeCount(likeCount);
+            //设置用户评论数
+            int commentCount = communityArticleCommentMapper.selectCount(new QueryWrapper<CommunityArticleComment>().eq("article_id", communityArticle.getId()).and((wrapper) -> {
+                wrapper.ne("is_delete", true)
+                        .or()
+                        .isNull("is_delete");
+            })).intValue();
+            collectionArticleVo.setCommentCount(commentCount);
+            //设置文章封面
+            List<CommunityArticleImages> articleImages = communityArticleImagesMapper.selectList(new QueryWrapper<CommunityArticleImages>()
+                    .select("image_url")
+                    .eq("article_id", communityArticle.getId()));
+            if (!articleImages.isEmpty()) {
+                if ( articleImages.get(0) != null ) {
+                    String imageUrl = articleImages.get(0).getImageUrl();
+                    collectionArticleVo.setImageUrl(imageUrl);
+                }
+            }
+
+            collectionArticleVos.add(collectionArticleVo);
+        }
+
+
+        collectionObject.put("Article", collectionArticleVos);
+        jsonArray.add(collectionObject);
+
+        return jsonArray;
+    }
+
+    /**
+     * 删除合集
+     *
+     * @param collectionId 合集id
+     */
+    @Override
+    public void deleteCollectionById(Long collectionId) {
+        //1.更新合集状态
+        CommunityCollection collection = communityCollectionMapper.selectOne(new QueryWrapper<CommunityCollection>()
+                .eq("id", collectionId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
+        collection.setDelete(true);
+        collection.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
+        collection.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityCollectionMapper.updateById(collection);
+        //2.更新合集关联的文章状态
+        List<Long> ids = communityCollectionArticleMapper.selectList(new QueryWrapper<CommunityCollectionArticle>()
+                .eq("collection_id", collectionId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                })).stream().map(item -> item.getId()).collect(Collectors.toList());
+        if (!ids.isEmpty()) {
+            CommunityCollectionArticle collectionArticle = new CommunityCollectionArticle();
+            collectionArticle.setDelete(true);
+            collectionArticle.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
+            collectionArticle.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCollectionArticleMapper.update(collectionArticle, new UpdateWrapper<CommunityCollectionArticle>().in("id", ids));
+        }
+    }
+
+    @Override
+    public List<CommunityCollectionVo> selectUserCollection(Long userId, Long articleId, int pageNum, int pageSize, int searchType) {
+        int offset = (pageNum - 1) * pageSize;
+        List<CommunityCollectionVo> communityCollectionVos = communityCollectionMapper.selectUserCollection(userId, articleId, offset, pageSize, searchType);
+        /*for (CommunityCollectionVo communityCollectionVo : communityCollectionVos) {
+            Long aLong = communityCollectionArticleMapper.selectCount(new QueryWrapper<CommunityCollectionArticle>()
+                    .eq("collection_id", communityCollectionVo.getId())
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true)
+                                .or()
+                                .isNull("is_delete");
+                    }));
+            communityCollectionVo.setArticleCount(aLong);
+        }*/
+        return communityCollectionVos;
+    }
+
+
+}

+ 68 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCollectionUserImpl.java

@@ -0,0 +1,68 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.generator.domain.Community.CommunityCollection;
+import com.ruoyi.generator.domain.Community.CommunityCollectionUser;
+import com.ruoyi.generator.mapper.community.CommunityCollectionMapper;
+import com.ruoyi.generator.mapper.community.CommunityCollectionUserMapper;
+import com.ruoyi.generator.service.ICommunityCollectionUserService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityCollectionUserImpl extends ServiceImpl<CommunityCollectionUserMapper, CommunityCollectionUser> implements ICommunityCollectionUserService {
+
+    @Autowired
+    private CommunityCollectionUserMapper communityCollectionUserMapper;
+
+    @Autowired
+    private CommunityCollectionMapper communityCollectionMapper;
+
+    @Override
+    public CommunityCollectionUser subscribeCollection(CommunityCollectionUser communityCollectionUser) {
+
+        //不能关注自己创建的合集
+        CommunityCollection communityCollection = communityCollectionMapper.selectOne(new QueryWrapper<CommunityCollection>()
+                .eq("id", communityCollectionUser.getCollectionId())
+                .eq("create_by", communityCollectionUser.getUserId())
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
+
+        if (communityCollection != null){
+            return  null;
+        }
+
+
+        CommunityCollectionUser collectionUser = communityCollectionUserMapper.selectOne(new QueryWrapper<CommunityCollectionUser>()
+                .eq("user_id", communityCollectionUser.getUserId())
+                .eq("collection_id", communityCollectionUser.getCollectionId()));
+
+        if (collectionUser != null) {
+            Boolean isdelete = false;
+            //是否取关
+            if (!collectionUser.isDelete()) {
+               isdelete = true;
+            }
+            collectionUser.setDelete(isdelete);
+            collectionUser.setUpdateBy(communityCollectionUser.getUserId());
+            collectionUser.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityCollectionUserMapper.updateById(collectionUser);
+            return collectionUser;
+        }
+
+        //新增记录
+        collectionUser = new CommunityCollectionUser();
+        BeanUtils.copyProperties(communityCollectionUser, collectionUser);
+        collectionUser.setCreateBy(communityCollectionUser.getUserId());
+        collectionUser.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityCollectionUserMapper.insert(collectionUser);
+        return collectionUser;
+
+    }
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCommentLikeServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityCommentLike;
+import com.ruoyi.generator.mapper.community.CommunityCommentLikeMapper;
+import com.ruoyi.generator.service.ICommunityCommentLikeService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityCommentLikeServiceImpl extends ServiceImpl<CommunityCommentLikeMapper, CommunityCommentLike> implements ICommunityCommentLikeService {
+
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityCommentReplyServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityCommentReply;
+import com.ruoyi.generator.mapper.community.CommunityCommentReplyMapper;
+import com.ruoyi.generator.service.ICommunityCommentReplyService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityCommentReplyServiceImpl extends ServiceImpl<CommunityCommentReplyMapper, CommunityCommentReply> implements ICommunityCommentReplyService {
+
+}

+ 115 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityFeedbackUserServiceImpl.java

@@ -0,0 +1,115 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.generator.domain.Community.CommunityFeedbackImages;
+import com.ruoyi.generator.domain.Community.CommunityFeedbackUser;
+import com.ruoyi.generator.mapper.community.CommunityFeedbackImagesMapper;
+import com.ruoyi.generator.mapper.community.CommunityFeedbackUserMapper;
+import com.ruoyi.generator.service.ICommunityFeedbackUserService;
+import com.ruoyi.generator.vo.CommunityImagesVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author fangqing
+ * @date 2025/6/13 10:49
+ */
+@Service
+public class CommunityFeedbackUserServiceImpl extends ServiceImpl<CommunityFeedbackUserMapper, CommunityFeedbackUser> implements ICommunityFeedbackUserService {
+
+    @Autowired
+    private CommunityFeedbackUserMapper communityFeedbackUserMapper;
+
+    @Autowired
+    private CommunityFeedbackImagesMapper communityFeedbackImagesMapper;
+
+
+    /**
+     * 用户反馈
+     * @param communityFeedbackUser
+     * @return
+     */
+    @Override
+    public CommunityFeedbackUser insertCommunityFeedbacktUser(CommunityFeedbackUser communityFeedbackUser) {
+        //创建一个新的对象匹配
+        CommunityFeedbackUser feedbackUser = new CommunityFeedbackUser();
+
+        Long userId = communityFeedbackUser.getUserId();
+        if (userId == null){
+            userId = SecurityUtils.getUserId();
+        }
+
+        feedbackUser.setType(communityFeedbackUser.getType());
+        feedbackUser.setIsChoice(communityFeedbackUser.getIsChoice());
+        feedbackUser.setUserId(userId);
+        feedbackUser.setUserFeedback(communityFeedbackUser.getUserFeedback());
+        feedbackUser.setCreateBy(userId);
+        feedbackUser.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+
+        communityFeedbackUserMapper.insert(feedbackUser);
+        System.out.println(communityFeedbackUser);
+        //插入图片日志
+        List<CommunityImagesVo> images = communityFeedbackUser.getUserImages();
+        if (images != null && !images.isEmpty()) {
+            CommunityFeedbackImages feedbackImages = null;
+            for (CommunityImagesVo image : images) {
+                feedbackImages = new CommunityFeedbackImages();
+                feedbackImages.setFeedbackId(feedbackUser.getId());
+                feedbackImages.setUserId(userId);
+                feedbackImages.setImageUrl(image.getImages());
+                feedbackImages.setCompressUrl(image.getCompressedImages());
+                feedbackImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                feedbackImages.setCreateBy(userId);
+                communityFeedbackImagesMapper.insert(feedbackImages);
+            }
+        }
+
+        return feedbackUser;
+    }
+
+    /**
+     * 管理员反馈
+     * @param communityFeedbackUser
+     * @return
+     */
+    @Override
+    public CommunityFeedbackUser updateCommunityFeedbacktUser(CommunityFeedbackUser communityFeedbackUser) {
+        //创建一个新的对象匹配
+        CommunityFeedbackUser feedbackUser = new CommunityFeedbackUser();
+
+        Long punishId = communityFeedbackUser.getPunishId();
+        if (punishId == null){
+            punishId = SecurityUtils.getUserId();
+        }
+
+        feedbackUser.setId(communityFeedbackUser.getId());
+        feedbackUser.setIsChoice(communityFeedbackUser.getIsChoice());
+        feedbackUser.setPunishId(punishId);
+        feedbackUser.setPunishFeedback(communityFeedbackUser.getPunishFeedback());
+        feedbackUser.setUpdateBy(punishId);
+        feedbackUser.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityFeedbackUserMapper.updateById(feedbackUser);
+
+        //插入管理员图片日志
+        List<CommunityImagesVo> images = communityFeedbackUser.getPunishImages();
+        if (images != null && !images.isEmpty()) {
+            CommunityFeedbackImages feedbackImages = null;
+            for (CommunityImagesVo image : images) {
+                feedbackImages = new CommunityFeedbackImages();
+                feedbackImages.setFeedbackId(feedbackUser.getId());
+                feedbackImages.setPunishId(punishId);
+                feedbackImages.setImageUrl(image.getImages());
+                feedbackImages.setCompressUrl(image.getCompressedImages());
+                feedbackImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                feedbackImages.setCreateBy(punishId);
+                communityFeedbackImagesMapper.insert(feedbackImages);
+            }
+        }
+
+        return feedbackUser;
+    }
+}

+ 142 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityImageProcessService.java

@@ -0,0 +1,142 @@
+package com.ruoyi.generator.service.impl;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.common.utils.file.ImageUtils;
+import com.ruoyi.common.utils.file.OssUtils;
+import com.ruoyi.generator.domain.Community.CommunityArticleImages;
+import com.ruoyi.generator.mapper.community.CommunityArticleImagesMapper;
+import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
+import com.ruoyi.generator.service.ICommunityArticleImagesService;
+import com.ruoyi.generator.vo.CommunityImagesVo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 社区图片处理服务
+ *
+ * @author fangzhen
+ */
+@Service
+public class CommunityImageProcessService {
+
+    private static final Logger log = LoggerFactory.getLogger(CommunityImageProcessService.class);
+
+    @Resource
+    private CommunityArticleMapper communityArticleMapper;
+    @Resource
+    private CommunityArticleImagesMapper communityArticleImagesMapper;
+    @Resource
+    private ICommunityArticleImagesService communityArticleImagesService;
+
+    /**
+     * 异步处理图片水印
+     *
+     * @param articleId   文章ID
+     * @param images      图片列表
+     * @param isFillWater 是否填充水印
+     * @param nickName    用户昵称
+     */
+    @Async("imageProcessExecutor")
+    public void processImagesWithWatermark(Long articleId, List<CommunityImagesVo> images, boolean isFillWater, String nickName, Long userId) {
+        log.info("开始异步处理文章[{}]的图片水印", articleId);
+        List<CommunityImagesVo> processedImages = new ArrayList<>();
+        try {
+            // 处理每张图片
+            for (CommunityImagesVo image : images) {
+                if (image == null) {
+                    continue;
+                }
+
+                String fileType = FileUtils.getFileTypeFromUrl(image.getImages());
+                log.info("处理文件类型:{}", fileType);
+
+                if ("image".equals(fileType)) {
+                    if (image.getImages().contains(".gif") || image.getImages().contains(".GIF")) {
+                        processedImages.add(image);
+                        continue;
+                    }
+
+                    // 本地临时水印文件路径
+                    String tempWatermarkFile = System.getProperty("java.io.tmpdir") + File.separator + "watermark_" + FileUtils.getName(image.getImages());
+                    String tempSourceFile = System.getProperty("java.io.tmpdir") + File.separator + "source_" + FileUtils.getName(image.getImages());
+
+                    try {
+                        OssUtils.downloadFile(image.getImages().replace("http://file.iciyuanshidai.com/", ""), tempSourceFile);
+                        ImageUtils.addWatermark(
+                                isFillWater,
+                                image.getImages().replace("http://file.iciyuanshidai.com/", ""),
+                                new File(tempSourceFile),
+                                new File(tempWatermarkFile),
+                                "@" + nickName,
+                                "次元时代-ACG爱好者社区"
+                        );
+
+                        // 上传加水印的文件到OSS
+                        String fileNameResult = OssUtils.uploadFile(tempWatermarkFile);
+                        image.setImages(fileNameResult.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", "http://file.iciyuanshidai.com/"));
+                        processedImages.add(image);
+
+                        // 清理临时文件
+                        new File(tempWatermarkFile).delete();
+                        new File(tempSourceFile).delete();
+                    } catch (Exception e) {
+                        log.error("处理图片水印失败: {}", e.getMessage());
+                    }
+                } else if ("video".equals(fileType)) {
+                    String tempThumbnailFile = System.getProperty("java.io.tmpdir") + File.separator + "thumbnail.jpg";
+
+                    try {
+                        boolean screenshotSuccess = FileUtils.screenShots(image.getImages(), tempThumbnailFile, "00:00:01");
+                        if (screenshotSuccess) {
+                            // 上传缩略图到OSS
+                            String thumbnailPath = OssUtils.uploadFile(tempThumbnailFile);
+                            image.setCompressedImages(thumbnailPath.replace("https://cysd.oss-cn-shanghai.aliyuncs.com", "http://file.iciyuanshidai.com/"));
+                            // 删除临时缩略图文件
+                            new File(tempThumbnailFile).delete();
+                        }
+                        processedImages.add(image);
+                    } catch (Exception e) {
+                        log.error("处理视频缩略图失败: {}", e.getMessage());
+                    }
+                } else {
+                    processedImages.add(image);
+                }
+            }
+
+            // 更新文章的图片信息
+            if (!processedImages.isEmpty()) {
+                List<CommunityArticleImages> imagesList = new ArrayList<>();
+                CommunityArticleImages articleImages = null;
+                for (CommunityImagesVo processedImage : processedImages) {
+                    if (processedImage == null) {
+                        continue;
+                    }
+                    articleImages = new CommunityArticleImages();
+                    articleImages.setImageUrl(processedImage.getImages());
+                    articleImages.setCompressUrl(processedImage.getCompressedImages());
+                    articleImages.setArticleId(articleId);
+                    articleImages.setCreateBy(userId);
+                    articleImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                    imagesList.add(articleImages);
+                }
+                //先删除再插入
+                communityArticleImagesService.remove(new QueryWrapper<CommunityArticleImages>().eq("article_id", articleId));
+                communityArticleImagesService.saveBatch(imagesList);
+
+                log.info("文章[{}]的图片水印处理完成并已更新", articleId);
+            }
+        } catch (Exception e) {
+            log.error("异步处理图片水印失败: {}", e.getMessage(), e);
+        }
+    }
+}

+ 14 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityLikeServiceImpl.java

@@ -0,0 +1,14 @@
+package com.ruoyi.generator.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityLike;
+
+import com.ruoyi.generator.mapper.community.CommunityLikeMapper;
+import com.ruoyi.generator.service.ICommunityLikeService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityLikeServiceImpl extends ServiceImpl<CommunityLikeMapper, CommunityLike> implements ICommunityLikeService {
+
+}

+ 119 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityNotificationServiceImpl.java

@@ -0,0 +1,119 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.generator.domain.Community.CommunityUserNotification;
+import com.ruoyi.generator.mapper.community.CommunityUserNotificationMapper;
+import com.ruoyi.generator.service.ICommunityNotificationService;
+import com.ruoyi.generator.vo.CommunityUserNotificationVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 业务 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class CommunityNotificationServiceImpl extends ServiceImpl<CommunityUserNotificationMapper, CommunityUserNotification> implements ICommunityNotificationService {
+
+    @Autowired
+    private CommunityUserNotificationMapper communityUserNotificationMapper;
+
+    /**
+     * 获取通知权限
+     * @param userId
+     * @return 获取通知权限
+     */
+    @Override
+    public List<CommunityUserNotificationVo> selectUserNotification(Long userId) {
+        if (Objects.isNull(userId)) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
+        // 查询自己的通知权限
+        List<CommunityUserNotification> communityUserNotifications
+                = communityUserNotificationMapper
+                .selectList(new QueryWrapper<CommunityUserNotification>().eq("user_id", userId));
+        // 创建一个用于存放VO的列表
+        List<CommunityUserNotificationVo> communityUserNotificationVos = new ArrayList<>();
+
+        // 遍历查询结果,复制属性到 VO 对象
+        for (CommunityUserNotification communityUserNotification : communityUserNotifications) {
+            CommunityUserNotificationVo communityUserNotificationVo = new CommunityUserNotificationVo();
+            BeanUtils.copyProperties(communityUserNotification, communityUserNotificationVo);
+            communityUserNotificationVos.add(communityUserNotificationVo);
+        }
+
+        // 判断通知权限是否为空
+        if (communityUserNotificationVos.isEmpty()) {
+            // 如果没有通知权限,插入一条关于 userId 的数据
+            CommunityUserNotification newNotification = new CommunityUserNotification();
+            newNotification.setUserId(userId);
+            newNotification.setIsCircle(false);
+            newNotification.setIsLetter(false);
+            newNotification.setIsComment(false);
+            newNotification.setIsAddAttention(false);
+            newNotification.setIsPraiseCollection(false);
+            // 设置其他必要的默认值,例如:
+            // 使用 MyBatis-Plus 执行插入操作
+            communityUserNotificationMapper.insert(newNotification);
+            // 将新插入的记录转换为 VO 并返回
+            CommunityUserNotificationVo newNotificationVo = new CommunityUserNotificationVo();
+            BeanUtils.copyProperties(newNotification, newNotificationVo);
+            communityUserNotificationVos.add(newNotificationVo);
+        }
+
+        return communityUserNotificationVos;
+    }
+
+
+    /**
+     * 更新通知权限
+     * @param communityUserNotification
+     * @return 返回修改成功的对象
+     */
+    public List<CommunityUserNotificationVo> modifyUserNotification(CommunityUserNotification communityUserNotification) {
+        //获取userId
+        Long userId = SecurityUtils.getUserId();
+        // 创建更新包装器
+        UpdateWrapper<CommunityUserNotification> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("user_id", userId);  // 根据 userId 条件
+        // 更新字段
+        if (communityUserNotification.getIsPraiseCollection() != null) {
+            updateWrapper.set("is_praise_collection", communityUserNotification.getIsPraiseCollection());
+        }
+        if (communityUserNotification.getIsAddAttention() != null) {
+            updateWrapper.set("is_add_attention", communityUserNotification.getIsAddAttention());
+        }
+        if (communityUserNotification.getIsComment() != null) {
+            updateWrapper.set("is_comment", communityUserNotification.getIsComment());
+        }
+        if (communityUserNotification.getIsCircle() != null) {
+            updateWrapper.set("is_circle", communityUserNotification.getIsCircle());
+        }
+        if (communityUserNotification.getIsLetter() != null) {
+            updateWrapper.set("is_letter", communityUserNotification.getIsLetter());
+        }
+        // 执行更新操作
+        boolean updated = this.update(updateWrapper);
+        if (!updated){
+            System.out.println("更新失败");
+        }
+        // 创建一个用于存放VO的列表
+        List<CommunityUserNotificationVo> communityUserNotificationVos = new ArrayList<>();
+        CommunityUserNotification updatedUserNotification = this.getOne(new UpdateWrapper<CommunityUserNotification>().eq("user_id", userId));
+        // 将新插入的记录转换为 VO 并返回
+        CommunityUserNotificationVo newNotificationVo = new CommunityUserNotificationVo();
+        BeanUtils.copyProperties(updatedUserNotification, newNotificationVo);
+        communityUserNotificationVos.add(newNotificationVo);
+
+        return communityUserNotificationVos;
+    }
+}

+ 151 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityPrivacyServiceImpl.java

@@ -0,0 +1,151 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.generator.domain.Community.CommunityUserPrivacy;
+import com.ruoyi.generator.mapper.community.CommunityUserPrivacyMapper;
+import com.ruoyi.generator.service.ICommunityPrivacyService;
+import com.ruoyi.generator.vo.CommunityUserPrivacyVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 业务 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class CommunityPrivacyServiceImpl extends ServiceImpl<CommunityUserPrivacyMapper, CommunityUserPrivacy> implements ICommunityPrivacyService {
+
+
+    @Autowired
+    private CommunityUserPrivacyMapper communityUserPrivacyMapper;
+
+    /**
+     * 获取隐私权限
+     * @param userId
+     * @return 获取隐私权限
+     */
+    @Override
+    public List<CommunityUserPrivacyVo> selectUserPrivacy(Long userId) {
+        if (Objects.isNull(userId)) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
+        // 查询自己的隐私权限
+        List<CommunityUserPrivacy> communityUserPrivacies
+                = communityUserPrivacyMapper
+                .selectList(new QueryWrapper<CommunityUserPrivacy>().eq("user_id", userId));
+        // 创建一个用于存放VO的列表
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = new ArrayList<>();
+
+        // 遍历查询结果,复制属性到 VO 对象
+        for (CommunityUserPrivacy communityUserPrivacy : communityUserPrivacies) {
+            CommunityUserPrivacyVo communityUserPrivacyVo = new CommunityUserPrivacyVo();
+            BeanUtils.copyProperties(communityUserPrivacy, communityUserPrivacyVo);
+            communityUserPrivacyVos.add(communityUserPrivacyVo);
+        }
+
+        // 判断隐私权限是否为空
+        if (communityUserPrivacyVos.isEmpty()) {
+            // 如果没有隐私权限,插入一条关于 userId 的数据
+            CommunityUserPrivacy newPrivacy = new CommunityUserPrivacy();
+            newPrivacy.setUserId(userId);
+            newPrivacy.setIsComment(false);
+            newPrivacy.setIsCircle(false);
+            newPrivacy.setIsWorks(false);
+            newPrivacy.setIsCollection(false);
+            newPrivacy.setIsLike(false);
+            newPrivacy.setIsCompilation(false);
+            newPrivacy.setIsAccounts(false);
+            newPrivacy.setIsNames(false);
+            newPrivacy.setIsFollow(false);
+            newPrivacy.setIsFans(false);
+            newPrivacy.setIsAccompany(false);
+            // 设置其他必要的默认值,例如:
+            // 使用 MyBatis-Plus 执行插入操作
+            communityUserPrivacyMapper.insert(newPrivacy);
+            // 将新插入的记录转换为 VO 并返回
+            CommunityUserPrivacyVo newPrivacyVo = new CommunityUserPrivacyVo();
+            BeanUtils.copyProperties(newPrivacy, newPrivacyVo);
+            communityUserPrivacyVos.add(newPrivacyVo);
+        }
+
+        return communityUserPrivacyVos;
+    }
+
+    /**
+     * 更新隐私权限
+     * @param communityUserPrivacy
+     * @return 返回修改成功的对象
+     */
+    @Override
+    public List<CommunityUserPrivacyVo> modifyUserPrivacy(CommunityUserPrivacy communityUserPrivacy) {
+        // 获取 userId
+        Long userId = SecurityUtils.getUserId();
+
+        // 创建更新包装器
+        UpdateWrapper<CommunityUserPrivacy> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("user_id", userId); // 根据 userId 条件
+
+        // 更新字段
+        if (communityUserPrivacy.getIsComment() != null) {
+            updateWrapper.set("is_comment", communityUserPrivacy.getIsComment());
+        }
+        if (communityUserPrivacy.getIsCircle() != null) {
+            updateWrapper.set("is_circle", communityUserPrivacy.getIsCircle());
+        }
+        if (communityUserPrivacy.getIsWorks() != null) {
+            updateWrapper.set("is_works", communityUserPrivacy.getIsWorks());
+        }
+        if (communityUserPrivacy.getIsCollection() != null) {
+            updateWrapper.set("is_collection", communityUserPrivacy.getIsCollection());
+        }
+        if (communityUserPrivacy.getIsLike() != null) {
+            updateWrapper.set("is_like", communityUserPrivacy.getIsLike());
+        }
+        if (communityUserPrivacy.getIsCompilation() != null) {
+            updateWrapper.set("is_compilation", communityUserPrivacy.getIsCompilation());
+        }
+        if (communityUserPrivacy.getIsAccounts() != null) {
+            updateWrapper.set("is_accounts", communityUserPrivacy.getIsAccounts());
+        }
+        if (communityUserPrivacy.getIsNames() != null) {
+            updateWrapper.set("is_names", communityUserPrivacy.getIsNames());
+        }
+        if (communityUserPrivacy.getIsFollow() != null) {
+            updateWrapper.set("is_follow", communityUserPrivacy.getIsFollow());
+        }
+
+        if (communityUserPrivacy.getIsFans() != null) {
+            updateWrapper.set("is_fans", communityUserPrivacy.getIsFans());
+        }
+
+        if (communityUserPrivacy.getIsAccompany() != null) {
+            updateWrapper.set("is_accompany", communityUserPrivacy.getIsAccompany());
+        }
+
+        // 执行更新操作
+        boolean updated = this.update(updateWrapper);
+        if (!updated) {
+            System.out.println("更新失败");
+        }
+
+        // 创建一个用于存放VO的列表
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = new ArrayList<>();
+        CommunityUserPrivacy updatedUserPrivacy = this.getOne(new UpdateWrapper<CommunityUserPrivacy>().eq("user_id", userId));
+
+        // 将新插入的记录转换为 VO 并返回
+        CommunityUserPrivacyVo newPrivacyVo = new CommunityUserPrivacyVo();
+        BeanUtils.copyProperties(updatedUserPrivacy, newPrivacyVo);
+        communityUserPrivacyVos.add(newPrivacyVo);
+
+        return communityUserPrivacyVos;
+    }
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportDataServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityReportData;
+import com.ruoyi.generator.mapper.community.CommunityReportDataMapper;
+import com.ruoyi.generator.service.ICommunityReportDataService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityReportDataServiceImpl extends ServiceImpl<CommunityReportDataMapper, CommunityReportData> implements ICommunityReportDataService {
+
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityReport;
+import com.ruoyi.generator.mapper.community.CommunityReportMapper;
+import com.ruoyi.generator.service.ICommunityReportService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityReportServiceImpl extends ServiceImpl<CommunityReportMapper, CommunityReport> implements ICommunityReportService {
+
+}

+ 81 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReportUserServiceImpl.java

@@ -0,0 +1,81 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.generator.domain.Community.CommunityReportImages;
+import com.ruoyi.generator.domain.Community.CommunityReportUser;
+import com.ruoyi.generator.mapper.community.CommunityReportImagesMapper;
+import com.ruoyi.generator.mapper.community.CommunityReportUserMapper;
+import com.ruoyi.generator.service.ICommunityReportUserService;
+import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class CommunityReportUserServiceImpl extends ServiceImpl<CommunityReportUserMapper, CommunityReportUser> implements ICommunityReportUserService {
+
+
+    @Autowired
+    private CommunityReportUserMapper communityReportUserMapper;
+
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private ISysUserService userService;
+
+    @Autowired
+    private CommunityReportImagesMapper communityReportImagesMapper;
+
+    @Override
+    public CommunityReportUser insertCommunityReportUser(CommunityReportUser communityReportUser) {
+        /*SysUser user = new SysUser();
+        user.setUserId(communityReportUser.getUserId());
+        user.setUserState(communityReportUser.getUserState());
+        userService.updateUserProfile(user);*/
+
+        //创建一个新的对象匹配
+        CommunityReportUser reportUser = new CommunityReportUser();
+
+        reportUser.setUserId(communityReportUser.getUserId());
+        reportUser.setType(communityReportUser.getType());
+        reportUser.setContent(communityReportUser.getContent());
+        reportUser.setTypeId(communityReportUser.getTypeId());
+        reportUser.setReportContent(communityReportUser.getReportContent());
+        reportUser.setArticleId(communityReportUser.getArticleId());
+        reportUser.setCommentId(communityReportUser.getCommentId());
+        reportUser.setReplyId(communityReportUser.getReplyId());
+
+        //根据用户信息查询用户头像名称
+        SysUser sysUser = sysUserMapper.selectUserById(reportUser.getUserId());
+        reportUser.setUserName(sysUser.getUserName());
+        reportUser.setAvatar(sysUser.getAvatar());
+        reportUser.setUserState(sysUser.getUserState());
+        reportUser.setCreateBy(SecurityUtils.getUserId());
+        reportUser.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityReportUserMapper.insert(reportUser);
+
+        Long id = reportUser.getId();
+        System.out.println(id);
+        //插入图片日志
+        List<String> images = communityReportUser.getImages();
+        if (images != null && !images.isEmpty()) {
+            CommunityReportImages reportImages = null;
+            for (String image : images) {
+                reportImages = new CommunityReportImages();
+                reportImages.setReportId(reportUser.getId());
+                reportImages.setImageUrl(image);
+                reportImages.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+                reportImages.setCreateBy(SecurityUtils.getUserId());
+                communityReportImagesMapper.insert(reportImages);
+            }
+        }
+
+        return reportUser;
+    }
+}

+ 49 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityReturnRecordServiceImpl.java

@@ -0,0 +1,49 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityReturnRecord;
+import com.ruoyi.generator.mapper.community.CommunityReturnRecordMapper;
+import com.ruoyi.generator.service.ICommunityReturnRecordService;
+import com.ruoyi.system.domain.vo.SysUserVo;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+public class CommunityReturnRecordServiceImpl extends ServiceImpl<CommunityReturnRecordMapper, CommunityReturnRecord> implements ICommunityReturnRecordService {
+
+    @Resource
+    private CommunityReturnRecordMapper returnRecordMapper;
+
+    @Override
+    public List<CommunityReturnRecord> getReturnRecord(Long userId, String status) {
+        List<CommunityReturnRecord> returnRecords = null;
+        List<SysUserVo> sysUserChatVos = null;
+        switch (status) {
+            case "0": //待完成
+                returnRecords = returnRecordMapper.selectList(new QueryWrapper<CommunityReturnRecord>()
+                        .eq("return_create_user_id", userId)
+                        .eq("status", false)
+                        .eq("is_delete", false));
+                break;
+            case "1": //待返图
+                returnRecords = returnRecordMapper.selectList(new QueryWrapper<CommunityReturnRecord>()
+                        .eq("return_receive_user_id", userId)
+                        .eq("status", false)
+                        .eq("is_delete", false));
+                break;
+            case "2": //已完成
+                returnRecords = returnRecordMapper.selectList(new QueryWrapper<CommunityReturnRecord>()
+                        .and(wrapper ->
+                                wrapper.eq("return_receive_user_id", userId)
+                                        .or()
+                                        .eq("return_create_user_id", userId))
+                        .eq("status", true)
+                        .eq("is_delete", false));
+                break;
+        }
+        return returnRecords;
+    }
+}

+ 52 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityTagServiceImpl.java

@@ -0,0 +1,52 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.generator.domain.Community.CommunityTag;
+import com.ruoyi.generator.domain.Community.CommunityTagBlock;
+import com.ruoyi.generator.mapper.community.CommunityTagBlockMapper;
+import com.ruoyi.generator.mapper.community.CommunityTagMapper;
+import com.ruoyi.generator.service.ICommunityTagService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityTagServiceImpl extends ServiceImpl<CommunityTagMapper, CommunityTag> implements ICommunityTagService {
+
+    @Autowired
+    private CommunityTagBlockMapper communityTagBlockMapper;
+
+    /**
+     * 拉黑标签
+     *
+     * @param communityTagBlock 拉黑标签记录
+     */
+    @Override
+    public CommunityTagBlock blockTag(CommunityTagBlock communityTagBlock) {
+        CommunityTagBlock tagBlock = communityTagBlockMapper.selectOne(new QueryWrapper<CommunityTagBlock>()
+                .eq("user_id", communityTagBlock.getUserId())
+                .eq("tag_id", communityTagBlock.getTagId()));
+
+        if (tagBlock != null) {
+            //是否拉黑
+            if (communityTagBlock.isBlock() == tagBlock.isBlock()) {
+                return tagBlock;
+            }
+            tagBlock.setBlock(communityTagBlock.isBlock());
+            tagBlock.setUpdateBy(communityTagBlock.getUserId());
+            tagBlock.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityTagBlockMapper.updateById(tagBlock);
+            return tagBlock;
+        }
+
+        //新增记录
+        tagBlock = new CommunityTagBlock();
+        BeanUtils.copyProperties(communityTagBlock, tagBlock);
+        tagBlock.setCreateBy(communityTagBlock.getUserId());
+        tagBlock.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityTagBlockMapper.insert(tagBlock);
+        return tagBlock;
+    }
+}

+ 52 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserBlockServiceImpl.java

@@ -0,0 +1,52 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.generator.domain.Community.CommunityUserBlock;
+import com.ruoyi.generator.mapper.community.CommunityUserBlockMapper;
+import com.ruoyi.generator.service.ICommunityUserBlockService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityUserBlockServiceImpl extends ServiceImpl<CommunityUserBlockMapper, CommunityUserBlock> implements ICommunityUserBlockService {
+
+    @Autowired
+    private CommunityUserBlockMapper communityUserBlockMapper;
+
+
+
+    /**
+     * 拉黑用户
+     *
+     * @param communityUserBlock 拉黑用户记录
+     */
+    @Override
+    public CommunityUserBlock blockUser(CommunityUserBlock communityUserBlock) {
+        CommunityUserBlock userBlock = communityUserBlockMapper.selectOne(new QueryWrapper<CommunityUserBlock>()
+                .eq("user_id", communityUserBlock.getUserId())
+                .eq("peer_id", communityUserBlock.getPeerId()));
+
+        if (userBlock != null) {
+            //是否拉黑
+            if (communityUserBlock.isBlock() == userBlock.isBlock()) {
+                return communityUserBlock;
+            }
+            userBlock.setBlock(communityUserBlock.isBlock());
+            userBlock.setUpdateBy(communityUserBlock.getUserId());
+            userBlock.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
+            communityUserBlockMapper.updateById(userBlock);
+            return userBlock;
+        }
+
+        //新增记录
+        userBlock = new CommunityUserBlock();
+        BeanUtils.copyProperties(communityUserBlock, userBlock);
+        userBlock.setCreateBy(communityUserBlock.getUserId());
+        userBlock.setCreateTime(DateUtils.parseDate(DateUtils.getTime()));
+        communityUserBlockMapper.insert(userBlock);
+        return userBlock;
+    }
+}

+ 12 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserLikeServiceImpl.java

@@ -0,0 +1,12 @@
+package com.ruoyi.generator.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityUserLike;
+import com.ruoyi.generator.mapper.community.CommunityUserLikeMapper;
+import com.ruoyi.generator.service.ICommunityUserLikeService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityUserLikeServiceImpl extends ServiceImpl<CommunityUserLikeMapper, CommunityUserLike> implements ICommunityUserLikeService {
+
+}

+ 13 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/CommunityUserProtocolServiceImpl.java

@@ -0,0 +1,13 @@
+package com.ruoyi.generator.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.CommunityUserProtocol;
+import com.ruoyi.generator.mapper.community.CommunityUserProtocolMapper;
+import com.ruoyi.generator.service.ICommunityUserProtocolService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommunityUserProtocolServiceImpl extends ServiceImpl<CommunityUserProtocolMapper, CommunityUserProtocol> implements ICommunityUserProtocolService {
+
+}

+ 70 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableColumnServiceImpl.java

@@ -0,0 +1,70 @@
+package com.ruoyi.generator.service.impl;
+
+import java.util.List;
+
+import com.ruoyi.generator.service.IGenTableColumnService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.generator.domain.GenTableColumn;
+import com.ruoyi.generator.mapper.GenTableColumnMapper;
+
+/**
+ * 业务字段 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class GenTableColumnServiceImpl implements IGenTableColumnService
+{
+	@Autowired
+	private GenTableColumnMapper genTableColumnMapper;
+
+	/**
+     * 查询业务字段列表
+     *
+     * @param tableId 业务字段编号
+     * @return 业务字段集合
+     */
+	@Override
+	public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
+	{
+	    return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
+	}
+
+    /**
+     * 新增业务字段
+     *
+     * @param genTableColumn 业务字段信息
+     * @return 结果
+     */
+	@Override
+	public int insertGenTableColumn(GenTableColumn genTableColumn)
+	{
+	    return genTableColumnMapper.insertGenTableColumn(genTableColumn);
+	}
+
+	/**
+     * 修改业务字段
+     *
+     * @param genTableColumn 业务字段信息
+     * @return 结果
+     */
+	@Override
+	public int updateGenTableColumn(GenTableColumn genTableColumn)
+	{
+	    return genTableColumnMapper.updateGenTableColumn(genTableColumn);
+	}
+
+	/**
+     * 删除业务字段对象
+     *
+     * @param ids 需要删除的数据ID
+     * @return 结果
+     */
+	@Override
+	public int deleteGenTableColumnByIds(String ids)
+	{
+		return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
+	}
+}

+ 533 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/impl/GenTableServiceImpl.java

@@ -0,0 +1,533 @@
+package com.ruoyi.generator.service.impl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import com.ruoyi.generator.service.IGenTableService;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.constant.GenConstants;
+import com.ruoyi.common.core.text.CharsetKit;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.generator.domain.GenTable;
+import com.ruoyi.generator.domain.GenTableColumn;
+import com.ruoyi.generator.mapper.GenTableColumnMapper;
+import com.ruoyi.generator.mapper.GenTableMapper;
+import com.ruoyi.generator.util.GenUtils;
+import com.ruoyi.generator.util.VelocityInitializer;
+import com.ruoyi.generator.util.VelocityUtils;
+
+/**
+ * 业务 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class GenTableServiceImpl implements IGenTableService
+{
+    private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class);
+
+    @Autowired
+    private GenTableMapper genTableMapper;
+
+    @Autowired
+    private GenTableColumnMapper genTableColumnMapper;
+
+    /**
+     * 查询业务信息
+     *
+     * @param id 业务ID
+     * @return 业务信息
+     */
+    @Override
+    public GenTable selectGenTableById(Long id)
+    {
+        GenTable genTable = genTableMapper.selectGenTableById(id);
+        setTableFromOptions(genTable);
+        return genTable;
+    }
+
+    /**
+     * 查询业务列表
+     *
+     * @param genTable 业务信息
+     * @return 业务集合
+     */
+    @Override
+    public List<GenTable> selectGenTableList(GenTable genTable)
+    {
+        return genTableMapper.selectGenTableList(genTable);
+    }
+
+    /**
+     * 查询据库列表
+     *
+     * @param genTable 业务信息
+     * @return 数据库表集合
+     */
+    @Override
+    public List<GenTable> selectDbTableList(GenTable genTable)
+    {
+        return genTableMapper.selectDbTableList(genTable);
+    }
+
+    /**
+     * 查询据库列表
+     *
+     * @param tableNames 表名称组
+     * @return 数据库表集合
+     */
+    @Override
+    public List<GenTable> selectDbTableListByNames(String[] tableNames)
+    {
+        return genTableMapper.selectDbTableListByNames(tableNames);
+    }
+
+    /**
+     * 查询所有表信息
+     *
+     * @return 表信息集合
+     */
+    @Override
+    public List<GenTable> selectGenTableAll()
+    {
+        return genTableMapper.selectGenTableAll();
+    }
+
+    /**
+     * 修改业务
+     *
+     * @param genTable 业务信息
+     * @return 结果
+     */
+    @Override
+    @Transactional
+    public void updateGenTable(GenTable genTable)
+    {
+        String options = JSON.toJSONString(genTable.getParams());
+        genTable.setOptions(options);
+        int row = genTableMapper.updateGenTable(genTable);
+        if (row > 0)
+        {
+            for (GenTableColumn cenTableColumn : genTable.getColumns())
+            {
+                genTableColumnMapper.updateGenTableColumn(cenTableColumn);
+            }
+        }
+    }
+
+    /**
+     * 删除业务对象
+     *
+     * @param tableIds 需要删除的数据ID
+     * @return 结果
+     */
+    @Override
+    @Transactional
+    public void deleteGenTableByIds(Long[] tableIds)
+    {
+        genTableMapper.deleteGenTableByIds(tableIds);
+        genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
+    }
+
+    /**
+     * 创建表
+     *
+     * @param sql 创建表语句
+     * @return 结果
+     */
+    @Override
+    public boolean createTable(String sql)
+    {
+        return genTableMapper.createTable(sql) == 0;
+    }
+
+    /**
+     * 导入表结构
+     *
+     * @param tableList 导入表列表
+     */
+    @Override
+    @Transactional
+    public void importGenTable(List<GenTable> tableList, String operName)
+    {
+        try
+        {
+            for (GenTable table : tableList)
+            {
+                String tableName = table.getTableName();
+                GenUtils.initTable(table, operName);
+                int row = genTableMapper.insertGenTable(table);
+                if (row > 0)
+                {
+                    // 保存列信息
+                    List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+                    for (GenTableColumn column : genTableColumns)
+                    {
+                        GenUtils.initColumnField(column, table);
+                        genTableColumnMapper.insertGenTableColumn(column);
+                    }
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            throw new ServiceException("导入失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * 预览代码
+     *
+     * @param tableId 表编号
+     * @return 预览数据列表
+     */
+    @Override
+    public Map<String, String> previewCode(Long tableId)
+    {
+        Map<String, String> dataMap = new LinkedHashMap<>();
+        // 查询表信息
+        GenTable table = genTableMapper.selectGenTableById(tableId);
+        // 设置主子表信息
+        setSubTable(table);
+        // 设置主键列信息
+        setPkColumn(table);
+        VelocityInitializer.initVelocity();
+
+        VelocityContext context = VelocityUtils.prepareContext(table);
+
+        // 获取模板列表
+        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        for (String template : templates)
+        {
+            // 渲染模板
+            StringWriter sw = new StringWriter();
+            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
+            tpl.merge(context, sw);
+            dataMap.put(template, sw.toString());
+        }
+        return dataMap;
+    }
+
+    /**
+     * 生成代码(下载方式)
+     *
+     * @param tableName 表名称
+     * @return 数据
+     */
+    @Override
+    public byte[] downloadCode(String tableName)
+    {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        generatorCode(tableName, zip);
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 生成代码(自定义路径)
+     *
+     * @param tableName 表名称
+     */
+    @Override
+    public void generatorCode(String tableName)
+    {
+        // 查询表信息
+        GenTable table = genTableMapper.selectGenTableByName(tableName);
+        // 设置主子表信息
+        setSubTable(table);
+        // 设置主键列信息
+        setPkColumn(table);
+
+        VelocityInitializer.initVelocity();
+
+        VelocityContext context = VelocityUtils.prepareContext(table);
+
+        // 获取模板列表
+        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        for (String template : templates)
+        {
+            if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
+            {
+                // 渲染模板
+                StringWriter sw = new StringWriter();
+                Template tpl = Velocity.getTemplate(template, Constants.UTF8);
+                tpl.merge(context, sw);
+                try
+                {
+                    String path = getGenPath(table, template);
+                    FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
+                }
+                catch (IOException e)
+                {
+                    throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
+                }
+            }
+        }
+    }
+
+    /**
+     * 同步数据库
+     *
+     * @param tableName 表名称
+     */
+    @Override
+    @Transactional
+    public void synchDb(String tableName)
+    {
+        GenTable table = genTableMapper.selectGenTableByName(tableName);
+        List<GenTableColumn> tableColumns = table.getColumns();
+        Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
+
+        List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+        if (StringUtils.isEmpty(dbTableColumns))
+        {
+            throw new ServiceException("同步数据失败,原表结构不存在");
+        }
+        List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
+
+        dbTableColumns.forEach(column -> {
+            GenUtils.initColumnField(column, table);
+            if (tableColumnMap.containsKey(column.getColumnName()))
+            {
+                GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
+                column.setColumnId(prevColumn.getColumnId());
+                if (column.isList())
+                {
+                    // 如果是列表,继续保留查询方式/字典类型选项
+                    column.setDictType(prevColumn.getDictType());
+                    column.setQueryType(prevColumn.getQueryType());
+                }
+                if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
+                        && (column.isInsert() || column.isEdit())
+                        && ((column.isUsableColumn()) || (!column.isSuperColumn())))
+                {
+                    // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
+                    column.setIsRequired(prevColumn.getIsRequired());
+                    column.setHtmlType(prevColumn.getHtmlType());
+                }
+                genTableColumnMapper.updateGenTableColumn(column);
+            }
+            else
+            {
+                genTableColumnMapper.insertGenTableColumn(column);
+            }
+        });
+
+        List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
+        if (StringUtils.isNotEmpty(delColumns))
+        {
+            genTableColumnMapper.deleteGenTableColumns(delColumns);
+        }
+    }
+
+    /**
+     * 批量生成代码(下载方式)
+     *
+     * @param tableNames 表数组
+     * @return 数据
+     */
+    @Override
+    public byte[] downloadCode(String[] tableNames)
+    {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ZipOutputStream zip = new ZipOutputStream(outputStream);
+        for (String tableName : tableNames)
+        {
+            generatorCode(tableName, zip);
+        }
+        IOUtils.closeQuietly(zip);
+        return outputStream.toByteArray();
+    }
+
+    /**
+     * 查询表信息并生成代码
+     */
+    private void generatorCode(String tableName, ZipOutputStream zip)
+    {
+        // 查询表信息
+        GenTable table = genTableMapper.selectGenTableByName(tableName);
+        // 设置主子表信息
+        setSubTable(table);
+        // 设置主键列信息
+        setPkColumn(table);
+
+        VelocityInitializer.initVelocity();
+
+        VelocityContext context = VelocityUtils.prepareContext(table);
+
+        // 获取模板列表
+        List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), table.getTplWebType());
+        for (String template : templates)
+        {
+            // 渲染模板
+            StringWriter sw = new StringWriter();
+            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
+            tpl.merge(context, sw);
+            try
+            {
+                // 添加到zip
+                zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
+                IOUtils.write(sw.toString(), zip, Constants.UTF8);
+                IOUtils.closeQuietly(sw);
+                zip.flush();
+                zip.closeEntry();
+            }
+            catch (IOException e)
+            {
+                log.error("渲染模板失败,表名:" + table.getTableName(), e);
+            }
+        }
+    }
+
+    /**
+     * 修改保存参数校验
+     *
+     * @param genTable 业务信息
+     */
+    @Override
+    public void validateEdit(GenTable genTable)
+    {
+        if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
+        {
+            String options = JSON.toJSONString(genTable.getParams());
+            JSONObject paramsObj = JSON.parseObject(options);
+            if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
+            {
+                throw new ServiceException("树编码字段不能为空");
+            }
+            else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
+            {
+                throw new ServiceException("树父编码字段不能为空");
+            }
+            else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
+            {
+                throw new ServiceException("树名称字段不能为空");
+            }
+            else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
+            {
+                if (StringUtils.isEmpty(genTable.getSubTableName()))
+                {
+                    throw new ServiceException("关联子表的表名不能为空");
+                }
+                else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
+                {
+                    throw new ServiceException("子表关联的外键名不能为空");
+                }
+            }
+        }
+    }
+
+    /**
+     * 设置主键列信息
+     *
+     * @param table 业务表信息
+     */
+    public void setPkColumn(GenTable table)
+    {
+        for (GenTableColumn column : table.getColumns())
+        {
+            if (column.isPk())
+            {
+                table.setPkColumn(column);
+                break;
+            }
+        }
+        if (StringUtils.isNull(table.getPkColumn()))
+        {
+            table.setPkColumn(table.getColumns().get(0));
+        }
+        if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
+        {
+            for (GenTableColumn column : table.getSubTable().getColumns())
+            {
+                if (column.isPk())
+                {
+                    table.getSubTable().setPkColumn(column);
+                    break;
+                }
+            }
+            if (StringUtils.isNull(table.getSubTable().getPkColumn()))
+            {
+                table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
+            }
+        }
+    }
+
+    /**
+     * 设置主子表信息
+     *
+     * @param table 业务表信息
+     */
+    public void setSubTable(GenTable table)
+    {
+        String subTableName = table.getSubTableName();
+        if (StringUtils.isNotEmpty(subTableName))
+        {
+            table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
+        }
+    }
+
+    /**
+     * 设置代码生成其他选项值
+     *
+     * @param genTable 设置后的生成对象
+     */
+    public void setTableFromOptions(GenTable genTable)
+    {
+        JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
+        if (StringUtils.isNotNull(paramsObj))
+        {
+            String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
+            String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
+            String treeName = paramsObj.getString(GenConstants.TREE_NAME);
+            String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
+            String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
+
+            genTable.setTreeCode(treeCode);
+            genTable.setTreeParentCode(treeParentCode);
+            genTable.setTreeName(treeName);
+            genTable.setParentMenuId(parentMenuId);
+            genTable.setParentMenuName(parentMenuName);
+        }
+    }
+
+    /**
+     * 获取代码生成地址
+     *
+     * @param table 业务表信息
+     * @param template 模板文件路径
+     * @return 生成地址
+     */
+    public static String getGenPath(GenTable table, String template)
+    {
+        String genPath = table.getGenPath();
+        if (StringUtils.equals(genPath, "/"))
+        {
+            return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
+        }
+        return genPath + File.separator + VelocityUtils.getFileName(template, table);
+    }
+}