合并development代码到master #1
|
@ -25,7 +25,7 @@ public class BusinessDataEntity {
|
||||||
// 父级文件夹
|
// 父级文件夹
|
||||||
private Long parentId = null;
|
private Long parentId = null;
|
||||||
// 创建人
|
// 创建人
|
||||||
private Long creatorId = null;
|
private String creatorId = null;
|
||||||
// 创建时间
|
// 创建时间
|
||||||
private LocalDateTime createTime = null;
|
private LocalDateTime createTime = null;
|
||||||
// 更新时间
|
// 更新时间
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class BusinessDataFileEntity {
|
||||||
//上传时间
|
//上传时间
|
||||||
private Date uploadTime = null;
|
private Date uploadTime = null;
|
||||||
//上传人id
|
//上传人id
|
||||||
private Long uploaderId = null;
|
private String uploaderId = null;
|
||||||
//是否删除
|
//是否删除
|
||||||
private Boolean isDeleted = false;
|
private Boolean isDeleted = false;
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,7 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
//删除数据库数据
|
//删除数据库数据
|
||||||
if (folderId != null){
|
if (folderId != null){
|
||||||
businessDataFileMapper.delete(null,folderId);
|
businessDataFileMapper.delete(null,folderId);
|
||||||
System.out.println("888888888走对了");
|
return Result.okM("删除成功");
|
||||||
|
|
||||||
return Result.okM("删除,走对了,成功");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文件
|
//删除文件
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dite.znpt.service.impl;
|
package com.dite.znpt.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
import com.dite.znpt.domain.entity.BusinessDataEntity;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
|
@ -54,12 +55,13 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
@ApiOperation(value = "创建文件夹")
|
@ApiOperation(value = "创建文件夹")
|
||||||
@Override
|
@Override
|
||||||
public Result createFolder(String folderName, Long parentId) {
|
public Result createFolder(String folderName, Long parentId) {
|
||||||
//获取ID
|
// 获取ID
|
||||||
Long loginIdAsLong = 888L;
|
String loginIdAsLong = "未登录用户";
|
||||||
// loginIdAsLong = StpUtil.getLoginIdAsLong();
|
if(StpUtil.isLogin()){
|
||||||
//
|
loginIdAsLong = StpUtil.getLoginIdAsString();
|
||||||
|
}
|
||||||
// 文件夹名称不能为空
|
// 文件夹名称不能为空
|
||||||
//TODO: 添加文件夹名称校验,后续最好更规范些,写个工具类专门校验,用正则表达式
|
// TODO: 添加文件夹名称校验,后续最好更规范些,写个工具类专门校验,用正则表达式
|
||||||
if (folderName == null || folderName.trim().isEmpty()) {
|
if (folderName == null || folderName.trim().isEmpty()) {
|
||||||
return Result.error("文件夹名称不能为空");
|
return Result.error("文件夹名称不能为空");
|
||||||
}
|
}
|
||||||
|
@ -70,10 +72,19 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
// 文件夹名称前置一个/
|
// 文件夹名称前置一个/
|
||||||
String folderName1 = "/" + folderName;
|
String folderName1 = "/" + folderName;
|
||||||
// 目标文件夹
|
// 目标文件夹
|
||||||
File targetDir=Paths.get(businessDataPath, folderName1).toFile();
|
File targetDir = Paths.get(businessDataPath, folderName1).toFile();
|
||||||
if(parentId != 0L){
|
if (parentId != 0L) {
|
||||||
// 获取父文件夹路径
|
// 获取父文件夹路径
|
||||||
targetDir = Paths.get(businessDataMapper.getPath(parentId), folderName1).toFile();
|
targetDir = Paths.get(businessDataMapper.getPath(parentId), folderName1).toFile();
|
||||||
|
} else {
|
||||||
|
// 如果是根目录,检查默认路径是否存在,不存在则创建
|
||||||
|
File defaultPathDir = new File(businessDataPath);
|
||||||
|
if (!defaultPathDir.exists()) {
|
||||||
|
boolean created = defaultPathDir.mkdirs();
|
||||||
|
if (!created) {
|
||||||
|
return Result.error("默认路径创建失败: " + businessDataPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 创建文件夹和新增文件夹路径
|
// 创建文件夹和新增文件夹路径
|
||||||
if (!targetDir.exists()) {
|
if (!targetDir.exists()) {
|
||||||
|
@ -82,7 +93,7 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
if (!created) {
|
if (!created) {
|
||||||
throw new RuntimeException("文件夹创建失败: " + targetDir.getAbsolutePath());
|
throw new RuntimeException("文件夹创建失败: " + targetDir.getAbsolutePath());
|
||||||
}
|
}
|
||||||
//上面是新增文件夹功能,但没有往数据库插入文件夹相关数据,所以下面新增
|
// 上面是新增文件夹功能,但没有往数据库插入文件夹相关数据,所以下面新增
|
||||||
// 创建BusinessDataEntity对象并设置属性
|
// 创建BusinessDataEntity对象并设置属性
|
||||||
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
||||||
null,
|
null,
|
||||||
|
@ -92,11 +103,10 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
LocalDateTime.now(),
|
LocalDateTime.now(),
|
||||||
LocalDateTime.now(),
|
LocalDateTime.now(),
|
||||||
false,
|
false,
|
||||||
targetDir.getAbsolutePath()
|
targetDir.getAbsolutePath());
|
||||||
);
|
|
||||||
// 插入到数据库
|
// 插入到数据库
|
||||||
businessDataMapper.insert(businessDataEntity);
|
businessDataMapper.insert(businessDataEntity);
|
||||||
return Result.okM( "文件夹创建成功");
|
return Result.okM("文件夹创建成功");
|
||||||
} else {
|
} else {
|
||||||
return Result.error("文件夹已存在: ");
|
return Result.error("文件夹已存在: ");
|
||||||
}
|
}
|
||||||
|
@ -107,75 +117,50 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
return businessDataMapper.getPath(parentId);
|
return businessDataMapper.getPath(parentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ApiOperation("删除文件夹")
|
@ApiOperation("删除文件夹")
|
||||||
// @Override
|
@Override
|
||||||
// public Result delete(Long folderId) {
|
public Result delete(Long folderId) {
|
||||||
// // 获取文件夹路径
|
// 获取文件夹路径
|
||||||
// String folderPath = businessDataMapper.getPath(folderId);
|
String folderPath = businessDataMapper.getPath(folderId);
|
||||||
//
|
|
||||||
// // 创建File对象并删除文件夹
|
|
||||||
// File folder = new File(folderPath);
|
|
||||||
// if (folder.exists()) {
|
|
||||||
// boolean deleted = folder.delete();
|
|
||||||
// if (!deleted) {
|
|
||||||
// // throw new RuntimeException("文件夹删除失败: " + folderPath);
|
|
||||||
// // TODO: 以后可以用全局异常处理器捕获,或者用try catch捕获
|
|
||||||
// return Result.error("文件夹删除失败: " + folderPath);
|
|
||||||
// }
|
|
||||||
// //删除数据库中文件夹的数据
|
|
||||||
// businessDataMapper.delete(folderId);
|
|
||||||
// //删除文件夹下文件的数据
|
|
||||||
// businessDataFileService.delete(folderId);
|
|
||||||
// return Result.okM("删除成功");
|
|
||||||
// } else {
|
|
||||||
// // throw new RuntimeException("文件夹不存在: " + folderPath);
|
|
||||||
// return Result.error("文件夹不存在: " + folderPath);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
@ApiOperation("删除文件夹")
|
|
||||||
@Override
|
|
||||||
public Result delete(Long folderId) {
|
|
||||||
// 获取文件夹路径
|
|
||||||
String folderPath = businessDataMapper.getPath(folderId);
|
|
||||||
|
|
||||||
// 创建Path对象并删除文件夹
|
// 创建Path对象并删除文件夹
|
||||||
Path folder = Paths.get(folderPath);
|
Path folder = Paths.get(folderPath);
|
||||||
if (Files.exists(folder)) {
|
if (Files.exists(folder)) {
|
||||||
try {
|
try {
|
||||||
// 使用Files.walk获取所有文件和目录,按深度排序后删除
|
// 使用Files.walk获取所有文件和目录,按深度排序后删除
|
||||||
java.util.stream.Stream<Path> filePaths = Files.walk(folder);
|
java.util.stream.Stream<Path> filePaths = Files.walk(folder);
|
||||||
filePaths.sorted(Comparator.reverseOrder())
|
filePaths.sorted(Comparator.reverseOrder())
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.forEach(File::delete);
|
.forEach(File::delete);
|
||||||
filePaths.close();
|
filePaths.close();
|
||||||
|
|
||||||
//删除数据库中文件夹的数据
|
// 删除数据库中文件夹的数据
|
||||||
businessDataMapper.delete(folderId);
|
businessDataMapper.delete(folderId);
|
||||||
//删除文件夹下文件的数据
|
// 删除文件夹下文件的数据
|
||||||
businessDataFileService.delete(null , folderId);
|
businessDataFileService.delete(null, folderId);
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Result.error("文件夹不存在: " + folderPath);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return Result.error("文件夹不存在: " + folderPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation("重命名文件夹")
|
@ApiOperation("重命名文件夹")
|
||||||
@Override
|
@Override
|
||||||
public Result reName(Long folderId, String newName) {
|
public Result reName(Long folderId, String newName) {
|
||||||
// 获取文件夹路径
|
// 获取文件夹路径
|
||||||
String folderPath = businessDataMapper.getPath(folderId);
|
String folderPath = businessDataMapper.getPath(folderId);
|
||||||
String newPath = folderPath.substring(0, folderPath.lastIndexOf('\\'))+"\\" + newName;
|
String newPath = folderPath.substring(0, folderPath.lastIndexOf('\\')) + "\\" + newName;
|
||||||
System.out.printf("7777777"+newPath);
|
//
|
||||||
//
|
// //想命名的原文件的路径
|
||||||
// //想命名的原文件的路径
|
// File file = new File("f:/a/a.xlsx");
|
||||||
// File file = new File("f:/a/a.xlsx");
|
// //将原文件更改为f:\a\b.xlsx,其中路径是必要的。注意
|
||||||
// //将原文件更改为f:\a\b.xlsx,其中路径是必要的。注意
|
// file.renameTo(new File("f:/a/b.xlsx"));
|
||||||
// file.renameTo(new File("f:/a/b.xlsx"));
|
// 想命名的原文件夹的路径
|
||||||
//想命名的原文件夹的路径
|
|
||||||
File file1 = new File(folderPath);
|
File file1 = new File(folderPath);
|
||||||
//将原文件夹更改为A,其中路径是必要的。注意
|
// 将原文件夹更改为A,其中路径是必要的。注意
|
||||||
file1.renameTo(new File(newPath));
|
file1.renameTo(new File(newPath));
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
@ -187,11 +172,8 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
null,
|
null,
|
||||||
now,
|
now,
|
||||||
null,
|
null,
|
||||||
newPath
|
newPath);
|
||||||
);
|
|
||||||
System.out.println(businessDataEntity);
|
|
||||||
businessDataMapper.reName(businessDataEntity);
|
businessDataMapper.reName(businessDataEntity);
|
||||||
return Result.okM("重命名成功");
|
return Result.okM("重命名成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.dite.znpt.web.controller;
|
package com.dite.znpt.web.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.dite.znpt.domain.Result;
|
import com.dite.znpt.domain.Result;
|
||||||
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
import com.dite.znpt.domain.entity.BusinessDataFileEntity;
|
||||||
import com.dite.znpt.domain.page.PageBean;
|
import com.dite.znpt.domain.page.PageBean;
|
||||||
|
@ -53,6 +54,10 @@ public class BusinessDataFileController {
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public Result add(@RequestParam("file") MultipartFile file,
|
public Result add(@RequestParam("file") MultipartFile file,
|
||||||
@RequestParam Long folderId) {
|
@RequestParam Long folderId) {
|
||||||
|
String loginIdAsLong = "未登录用户";
|
||||||
|
if(StpUtil.isLogin()){
|
||||||
|
loginIdAsLong = StpUtil.getLoginIdAsString();
|
||||||
|
}
|
||||||
|
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
return Result.error("上传文件为空");
|
return Result.error("上传文件为空");
|
||||||
|
@ -75,9 +80,9 @@ public class BusinessDataFileController {
|
||||||
fileEntity.setFileName(file.getOriginalFilename());
|
fileEntity.setFileName(file.getOriginalFilename());
|
||||||
fileEntity.setFilePath(uploadDir + "\\" + file.getOriginalFilename());
|
fileEntity.setFilePath(uploadDir + "\\" + file.getOriginalFilename());
|
||||||
fileEntity.setFileType(file.getContentType());
|
fileEntity.setFileType(file.getContentType());
|
||||||
fileEntity.setFileSize(file.getSize());
|
fileEntity.setFileSize(file.getSize()/1024);
|
||||||
fileEntity.setUploadTime(new Date());
|
fileEntity.setUploadTime(new Date());
|
||||||
fileEntity.setUploaderId(0L);
|
fileEntity.setUploaderId(loginIdAsLong);
|
||||||
System.out.println(uploadDir + "\\" + file.getOriginalFilename());
|
System.out.println(uploadDir + "\\" + file.getOriginalFilename());
|
||||||
businessDataFileService.add(fileEntity);
|
businessDataFileService.add(fileEntity);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
server:
|
server:
|
||||||
# 服务器的HTTP端口,默认为8080
|
# 服务器的HTTP端口,默认为8080
|
||||||
|
|
||||||
port: 8888
|
port: 8888
|
||||||
|
|
||||||
# 数据源配置
|
# 数据源配置
|
||||||
|
|
Loading…
Reference in New Issue