浏览代码

添加查询条件

zhaojinyu 2 周之前
父节点
当前提交
418968a14e

+ 18 - 1
base-modules/service-file/src/main/java/com/ruoyi/file/controller/FilesController.java

@@ -1,7 +1,9 @@
 package com.ruoyi.file.controller;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.file.service.FileUploadResponse;
+import com.ruoyi.file.service.Files;
 import com.ruoyi.file.service.FilesService;
 import com.usky.common.core.bean.ApiResult;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
 
 @RestController
 //@RequestMapping("/files")
@@ -41,4 +44,18 @@ public class FilesController {
         }
     }
 
-}
+    @GetMapping("/query")
+    public R<Page<Files>> queryFiles(
+            @RequestParam(required = false) String filesName,
+            @RequestParam(required = false) LocalDateTime startTime,
+            @RequestParam(required = false) LocalDateTime endTime,
+            @RequestParam(required = false) Boolean isDeleted,
+            @RequestParam(required = false) String fileType,
+            @RequestParam int current,
+            @RequestParam int size) {
+
+        Page<Files> page = new Page<>(current, size);
+        Page<Files> resultPage = filesService.queryFiles(filesName, startTime, endTime, isDeleted, fileType, page);
+        return R.ok(resultPage);
+    }
+}

+ 5 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesService.java

@@ -1,9 +1,11 @@
 package com.ruoyi.file.service;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
 
 public interface FilesService extends IService<Files> {
     // 修改返回类型为 FileUploadResponse
@@ -15,4 +17,7 @@ public interface FilesService extends IService<Files> {
     // 删除文件
     void deleteFile(String filesUUID);
 
+    // 新增查询方法
+    Page<Files> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, Page<Files> page);
+
 }

+ 32 - 0
base-modules/service-file/src/main/java/com/ruoyi/file/service/FilesServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.file.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.file.mapper.FileSequenceMapper;
 import com.ruoyi.file.mapper.FilesMapper;
@@ -198,4 +199,35 @@ public class FilesServiceImpl extends ServiceImpl<FilesMapper, Files> implements
             throw new RuntimeException("删除文件失败:" + e.getMessage());
         }
     }
+
+    @Override
+    public Page<Files> queryFiles(String filesName, LocalDateTime startTime, LocalDateTime endTime, Boolean isDeleted, String fileType, Page<Files> page) {
+        QueryWrapper<Files> queryWrapper = new QueryWrapper<>();
+
+        // 默认查询未删除的文件
+        if (isDeleted == null) {
+            queryWrapper.eq("is_delete", 0);
+        } else {
+            queryWrapper.eq("is_delete", isDeleted ? 1 : 0);
+        }
+
+        if (filesName != null && !filesName.isEmpty()) {
+            queryWrapper.like("files_name", filesName);
+        }
+
+        if (startTime != null && endTime != null) {
+            queryWrapper.ge("create_time", startTime); // 大于等于起始时间
+            queryWrapper.le("create_time", endTime);   // 小于等于结束时间
+        } else if (startTime != null) {
+            queryWrapper.ge("create_time", startTime); // 只有起始时间
+        } else if (endTime != null) {
+            queryWrapper.le("create_time", endTime);   // 只有结束时间
+        }
+
+        if (fileType != null && !fileType.isEmpty()) {
+            queryWrapper.eq("type", fileType);
+        }
+
+        return page(page, queryWrapper);
+    }
 }