Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
b95b4b78dc
|
@ -36,4 +36,15 @@ public interface BusinessDataFileMapper {
|
||||||
@Param("newFileName") String newFileName,
|
@Param("newFileName") String newFileName,
|
||||||
@Param("newFilePath") String newFilePath);
|
@Param("newFilePath") String newFilePath);
|
||||||
|
|
||||||
|
// // 批量更新文件路径
|
||||||
|
// void updateFilePathByFolderId(
|
||||||
|
// @Param("folderId") Long folderId,
|
||||||
|
// @Param("newFolderPath") String newFolderPath,
|
||||||
|
// @Param("separator") String separator);
|
||||||
|
|
||||||
|
// 批量更新子文件夹下文件的路径
|
||||||
|
void updateSubFilePaths(@Param("oldParentPath1") String oldParentPath1,
|
||||||
|
@Param("newParentPath1") String newParentPath1,
|
||||||
|
@Param("oldParentPath2") String oldParentPath2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,12 @@ public interface BusinessDataMapper {
|
||||||
void reName(BusinessDataEntity businessDataEntity);
|
void reName(BusinessDataEntity businessDataEntity);
|
||||||
|
|
||||||
public List<BusinessDataEntity> ListWithCondition(@Param("folderName") String folderName);
|
public List<BusinessDataEntity> ListWithCondition(@Param("folderName") String folderName);
|
||||||
|
|
||||||
|
// 批量更新子文件夹路径
|
||||||
|
void updateSubFolderPaths(@Param("oldParentPath1") String oldParentPath,
|
||||||
|
@Param("newParentPath1") String newParentPath,
|
||||||
|
@Param("processedOldParentPath") String processedOldParentPath,
|
||||||
|
@Param("processedNewParentPath") String processedNewParentPath,
|
||||||
|
@Param("folderId") Long folderId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@ApiOperation("商务资料文件service")
|
@ApiOperation("商务资料文件service")
|
||||||
@Service
|
@Service
|
||||||
|
@ -40,4 +41,11 @@ public interface BusinessDataFileService {
|
||||||
|
|
||||||
@ApiOperation("预览文件")
|
@ApiOperation("预览文件")
|
||||||
void preview(Long fileId, HttpServletResponse response);
|
void preview(Long fileId, HttpServletResponse response);
|
||||||
|
|
||||||
|
// @ApiOperation("批量更新文件路径")
|
||||||
|
// public void updateFilePathByFolderId(Long folderId, String newFolderPath);
|
||||||
|
|
||||||
|
@ApiOperation("批量更新子文件夹下文件的路径")
|
||||||
|
void updateSubFilePaths(String oldParentPath, String newParentPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,6 @@ public interface BusinessDataService {
|
||||||
Result delete(Long folderId);
|
Result delete(Long folderId);
|
||||||
Result reName(Long folderId, String newName);
|
Result reName(Long folderId, String newName);
|
||||||
|
|
||||||
|
void updateSubFolderPaths(String oldParentPath1, String newParentPath1, Long folderId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
}
|
}
|
||||||
@ApiOperation("删除文件")
|
@ApiOperation("删除文件")
|
||||||
public Result delete(Long fileId, Long folderId) {
|
public Result delete(Long fileId, Long folderId) {
|
||||||
//删除数据库数据
|
//删除文件夹时候,调用这个方法,才会删除所有文件的数据库数据,
|
||||||
|
// 至于具体文件,不用在这个方法删除
|
||||||
if (folderId != null){
|
if (folderId != null){
|
||||||
businessDataFileMapper.delete(null,folderId);
|
businessDataFileMapper.delete(null,folderId);
|
||||||
return Result.okM("删除成功");
|
return Result.okM("删除成功");
|
||||||
|
@ -155,8 +156,11 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建新文件路径
|
// 构建新文件路径
|
||||||
|
// 获取父目录
|
||||||
String parentPath = oldFile.getParent();
|
String parentPath = oldFile.getParent();
|
||||||
|
// 获取文件扩展名
|
||||||
String fileExtension = "";
|
String fileExtension = "";
|
||||||
|
// 获取文件名(不包含扩展名)
|
||||||
String fileNameWithoutExt = newFileName;
|
String fileNameWithoutExt = newFileName;
|
||||||
|
|
||||||
// 获取原文件扩展名
|
// 获取原文件扩展名
|
||||||
|
@ -246,7 +250,7 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
byte[] bytes = file.getBytes();
|
byte[] bytes = file.getBytes();
|
||||||
String uploadDir = businessDataService.getPath(folderId);
|
String uploadDir = businessDataService.getPath(folderId);
|
||||||
|
|
||||||
File uploadedFile = new File(uploadDir + "/" + file.getOriginalFilename());
|
File uploadedFile = new File(uploadDir + File.separator + file.getOriginalFilename());
|
||||||
if (uploadedFile.exists()) {
|
if (uploadedFile.exists()) {
|
||||||
return Result.error("文件已存在");
|
return Result.error("文件已存在");
|
||||||
}
|
}
|
||||||
|
@ -256,7 +260,7 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
BusinessDataFileEntity fileEntity = new BusinessDataFileEntity();
|
BusinessDataFileEntity fileEntity = new BusinessDataFileEntity();
|
||||||
fileEntity.setFolderId(folderId);
|
fileEntity.setFolderId(folderId);
|
||||||
fileEntity.setFileName(file.getOriginalFilename());
|
fileEntity.setFileName(file.getOriginalFilename());
|
||||||
fileEntity.setFilePath(uploadDir + "/" + file.getOriginalFilename());
|
fileEntity.setFilePath(uploadDir + File.separator + file.getOriginalFilename());
|
||||||
fileEntity.setFileType(file.getContentType());
|
fileEntity.setFileType(file.getContentType());
|
||||||
fileEntity.setFileSize(file.getSize()/1024);
|
fileEntity.setFileSize(file.getSize()/1024);
|
||||||
fileEntity.setUploadTime(new Date());
|
fileEntity.setUploadTime(new Date());
|
||||||
|
@ -544,4 +548,21 @@ public class BusinessDataFileServiceImpl implements BusinessDataFileService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ApiOperation("批量更新文件路径")
|
||||||
|
// @Override
|
||||||
|
// public void updateFilePathByFolderId(Long folderId, String newFolderPath) {
|
||||||
|
// businessDataFileMapper.updateFilePathByFolderId(folderId, newFolderPath, File.separator);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@ApiOperation("批量更新子文件夹下文件的路径")
|
||||||
|
@Override
|
||||||
|
public void updateSubFilePaths(String oldParentPath1, String newParentPath1) {
|
||||||
|
// 处理路径中的分隔符,如果是反斜杠则替换为双反斜杠
|
||||||
|
String oldParentPath2 = oldParentPath1;
|
||||||
|
if ("\\".equals(File.separator)) {
|
||||||
|
oldParentPath2 = oldParentPath1.replace("\\", "\\\\");
|
||||||
|
}
|
||||||
|
businessDataFileMapper.updateSubFilePaths(oldParentPath1, newParentPath1, oldParentPath2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文件夹名称前置一个/
|
// 文件夹名称前置一个/
|
||||||
String folderName1 = "/" + folderName;
|
String folderName1 = File.separator + folderName;
|
||||||
// 目标文件夹
|
// 目标文件夹
|
||||||
File targetDir = Paths.get(businessDataPath, folderName1).toFile();
|
File targetDir = Paths.get(businessDataPath, folderName1).toFile();
|
||||||
if (parentId != 0L) {
|
if (parentId != 0L) {
|
||||||
|
@ -147,23 +147,37 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("批量更新子文件夹路径")
|
||||||
|
@Override
|
||||||
|
public void updateSubFolderPaths(String oldParentPath1, String newParentPath1,Long folderId) {
|
||||||
|
// 处理路径中的分隔符,如果是反斜杠则替换为双反斜杠
|
||||||
|
String processedOldParentPath = oldParentPath1;
|
||||||
|
String processedNewParentPath = newParentPath1;
|
||||||
|
if ("\\".equals(File.separator)) {
|
||||||
|
processedOldParentPath = oldParentPath1.replace("\\", "\\\\");
|
||||||
|
processedNewParentPath = newParentPath1.replace("\\", "\\\\");
|
||||||
|
}
|
||||||
|
|
||||||
|
businessDataMapper.updateSubFolderPaths(oldParentPath1,newParentPath1,processedOldParentPath, processedNewParentPath, folderId);
|
||||||
|
}
|
||||||
@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(File.separator)) + File.separator + 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);
|
File file1 = new File(folderPath);
|
||||||
// 将原文件夹更改为A,其中路径是必要的。注意
|
boolean renameSuccess = file1.renameTo(new File(newPath));
|
||||||
file1.renameTo(new File(newPath));
|
|
||||||
|
if (!renameSuccess) {
|
||||||
|
return Result.error("文件夹重命名失败");
|
||||||
|
}
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
// 更新文件夹信息
|
||||||
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
BusinessDataEntity businessDataEntity = new BusinessDataEntity(
|
||||||
folderId,
|
folderId,
|
||||||
newName,
|
newName,
|
||||||
|
@ -174,6 +188,21 @@ public class BusinessDataServiceImpl implements BusinessDataService {
|
||||||
null,
|
null,
|
||||||
newPath);
|
newPath);
|
||||||
businessDataMapper.reName(businessDataEntity);
|
businessDataMapper.reName(businessDataEntity);
|
||||||
|
|
||||||
|
// // 批量更新该文件夹下所有文件的路径
|
||||||
|
// businessDataFileService.updateFilePathByFolderId(folderId, newPath);
|
||||||
|
|
||||||
|
|
||||||
|
String folderPath1 = folderPath+File.separator;
|
||||||
|
String newPath1 = newPath+File.separator;
|
||||||
|
|
||||||
|
// 批量更新子文件夹下所有文件的路径
|
||||||
|
businessDataFileService.updateSubFilePaths(folderPath1, newPath1);
|
||||||
|
// 批量更新子文件夹的路径
|
||||||
|
updateSubFolderPaths(folderPath1, newPath1,folderId);
|
||||||
|
|
||||||
return Result.okM("重命名成功");
|
return Result.okM("重命名成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,5 +94,20 @@
|
||||||
</set>
|
</set>
|
||||||
where file_id = #{fileId}
|
where file_id = #{fileId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- <!– 批量更新文件路径 –>-->
|
||||||
|
<!-- <update id="updateFilePathByFolderId">-->
|
||||||
|
<!-- update business_data_part_file-->
|
||||||
|
<!-- set file_path = concat(#{newFolderPath}, #{separator}, file_name)-->
|
||||||
|
<!-- where folder_id = #{folderId}-->
|
||||||
|
<!-- </update>-->
|
||||||
|
|
||||||
|
<!-- 批量更新子文件夹下文件的路径 -->
|
||||||
|
<update id="updateSubFilePaths">
|
||||||
|
update business_data_part_file
|
||||||
|
set file_path = replace(file_path, #{oldParentPath1}, #{newParentPath1})
|
||||||
|
where file_path like concat(#{oldParentPath2}, '%')
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|
|
@ -51,5 +51,14 @@
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 批量更新子文件夹路径 -->
|
||||||
|
<update id="updateSubFolderPaths">
|
||||||
|
update business_data_part
|
||||||
|
set folder_path = replace(folder_path, #{oldParentPath1}, #{newParentPath1}),
|
||||||
|
update_time = now()
|
||||||
|
where folder_path like concat(#{processedOldParentPath}, '%')
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue