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