|
@@ -1,8 +1,12 @@
|
|
|
package com.ruoyi.file.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.file.domain.FileUpdateInfo;
|
|
|
import com.ruoyi.file.mapper.FileUpdateInfoMapper;
|
|
|
import com.ruoyi.file.service.FileUpdateInfoService;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -17,6 +21,7 @@ import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -41,7 +46,15 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
|
|
|
|
|
|
@Override
|
|
|
public void addFileToDatabase(FileUpdateInfo fileUpdateInfo) throws Exception {
|
|
|
- String filePath = fileUpdateInfo.getFilePath(); // 使用新的 getFilePath 方法
|
|
|
+ // 假设前端只传入文件名
|
|
|
+ String fileName = fileUpdateInfo.getFileName();
|
|
|
+ if (fileName == null || fileName.trim().isEmpty()) {
|
|
|
+ throw new IllegalArgumentException("文件名不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置文件路径
|
|
|
+ String filePath = FileUpdateInfo.getServiceDir() + File.separator + fileUpdateInfo.getFileName();
|
|
|
+
|
|
|
File file = new File(filePath);
|
|
|
|
|
|
if (file.exists()) {
|
|
@@ -177,15 +190,34 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<FileUpdateInfo> getAllFiles() {
|
|
|
- return fileUpdateInfoMapper.selectList(null);
|
|
|
+ public CommonPage<FileUpdateInfo> getAllFiles(int current, int size) throws Exception {
|
|
|
+ // 使用 MyBatis-Plus 的分页功能
|
|
|
+ Page<FileUpdateInfo> page = new Page<>(current, size);
|
|
|
+ IPage<FileUpdateInfo> result = fileUpdateInfoMapper.selectPage(page, null);
|
|
|
+
|
|
|
+ // 将 MyBatis-Plus 的分页结果转换为 CommonPage
|
|
|
+ return new CommonPage<>(
|
|
|
+ result.getRecords(),
|
|
|
+ (int) result.getTotal(),
|
|
|
+ size,
|
|
|
+ current
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<FileUpdateInfo> getFilesByFileNameContaining(String fileName) {
|
|
|
- return fileUpdateInfoMapper.selectList(
|
|
|
- new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<FileUpdateInfo>()
|
|
|
- .like("file_name", fileName)
|
|
|
+ public CommonPage<FileUpdateInfo> getFilesByFileNameContaining(String fileName, int current, int size) throws Exception {
|
|
|
+ // 使用 MyBatis-Plus 的分页功能
|
|
|
+ Page<FileUpdateInfo> page = new Page<>(current, size);
|
|
|
+ QueryWrapper<FileUpdateInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.like("file_name", fileName);
|
|
|
+ IPage<FileUpdateInfo> result = fileUpdateInfoMapper.selectPage(page, queryWrapper);
|
|
|
+
|
|
|
+ // 将 MyBatis-Plus 的分页结果转换为 CommonPage
|
|
|
+ return new CommonPage<>(
|
|
|
+ result.getRecords(),
|
|
|
+ (int) result.getTotal(),
|
|
|
+ size,
|
|
|
+ current
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -231,4 +263,40 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
|
|
|
throw new Exception("不支持的操作系统: " + osName);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //扫描服务所在目录下的文件
|
|
|
+ @Override
|
|
|
+ public CommonPage<String> scanFilesInServiceDir(int current, int size) throws Exception {
|
|
|
+ // 获取 JAR 文件所在的目录
|
|
|
+ String serviceDir = FileUpdateInfo.getServiceDir();
|
|
|
+ File dir = new File(serviceDir);
|
|
|
+
|
|
|
+ if (!dir.exists() || !dir.isDirectory()) {
|
|
|
+ throw new Exception("无法找到服务目录: " + serviceDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取目录中的所有文件名
|
|
|
+ File[] files = dir.listFiles();
|
|
|
+ if (files == null) {
|
|
|
+ throw new Exception("无法读取目录内容: " + serviceDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取文件名
|
|
|
+ List<String> fileNames = new ArrayList<>();
|
|
|
+ for (File file : files) {
|
|
|
+ if (file.isFile()) {
|
|
|
+ fileNames.add(file.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对文件名列表进行分页处理
|
|
|
+ int total = fileNames.size();
|
|
|
+ int start = (current - 1) * size;
|
|
|
+ int end = Math.min(start + size, total);
|
|
|
+
|
|
|
+ List<String> pageFileNames = fileNames.subList(start, end);
|
|
|
+
|
|
|
+ // 返回分页结果
|
|
|
+ return new CommonPage<>(pageFileNames, total, size, current);
|
|
|
+ }
|
|
|
}
|