修改本地文件删除时调用的方法

master
Guo XIn 1 year ago
parent 1a6ca60bd6
commit de0d51b7ea
  1. 8
      shandan-basedata/src/main/java/com/keyware/shandan/dynacmicform/controller/DynamicDataController.java
  2. 4
      shandan-browser/src/main/java/com/keyware/shandan/browser/service/ExportComponent.java
  3. 4
      shandan-common/src/main/java/com/keyware/shandan/common/util/FileDownload.java
  4. 1
      shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java
  5. 4
      shandan-system/src/main/java/com/keyware/shandan/system/service/impl/SysFileServiceImpl.java
  6. 20
      shandan-system/src/main/java/com/keyware/shandan/system/utils/FileChunkUploadUtil.java

@ -292,7 +292,9 @@ public class DynamicDataController {
String filePath = System.getProperty("user.home") + File.separator + formInfo.getFormId() + ".xlsx";
File file = new File(filePath);
file.deleteOnExit();
if(file.exists()){
file.delete();
}
ExcelWriter excelWriter = ExcelUtil.getWriter(file);
excelWriter.merge(colIds.size() - 1, formInfo.getFormName());
excelWriter.write(rows, true);
@ -317,7 +319,9 @@ public class DynamicDataController {
String filePath = System.getProperty("user.home") + File.separator + formInfo.getFormId() + "_template.xlsx";
File file = new File(filePath);
file.deleteOnExit();
if(file.exists()){
file.delete();
}
ExcelWriter excelWriter = ExcelUtil.getWriter(file);
excelWriter.merge(colIds.size() - 1, formInfo.getFormName());
excelWriter.write(rows, true);

@ -189,7 +189,9 @@ public class ExportComponent {
private void delete(String path) {
File file = new File(path);
file.deleteOnExit();
if(file.exists()){
file.delete();
}
}
@AllArgsConstructor

@ -81,7 +81,9 @@ public class FileDownload {
return "下载过程出现错误,文件流读取异常!";
} finally {
if (delete) {
file.deleteOnExit();
if(file.exists()){
file.delete();
}
}
}
return "下载完成";

@ -176,7 +176,6 @@ public class SysFileController extends BaseController<SysFileService, SysFile, S
*/
@PostMapping("/upload/chunk")
public Result<Object> uploadChunk(MultipartFile file, SysFile fileInfo, SysFileChunk fileChunk) throws Exception {
//;
return Result.of(FileChunkUploadUtil.uploadChunk(file, fileInfo, fileChunk));
}

@ -234,7 +234,9 @@ public class SysFileServiceImpl extends BaseServiceImpl<SysFileMapper, SysFile,
@Override
public void clearFiles() {
File file = new File(customProperties.getFileStorage().getPath());
file.deleteOnExit();
if(file.exists()){
file.delete();
}
}
@Override

@ -141,7 +141,9 @@ public class FileChunkUploadUtil {
public void uploadChunk(MultipartFile uploadFile, SysFileChunk chunk) throws IOException {
if (!chunksCache.containsKey(chunk.getChunkMd5())) {
File chunkFile = new File(chunkFIleStorePath + File.separator + chunk.getChunkMd5() + ".chunk");
chunkFile.deleteOnExit();
if(chunkFile.exists()){
chunkFile.delete();
}
uploadFile.transferTo(chunkFile);
chunk.setChunkPath(chunkFile.getAbsolutePath());
chunksCache.put(chunk.getChunkMd5(), chunk);
@ -161,18 +163,20 @@ public class FileChunkUploadUtil {
if (!parent.exists()) {
parent.mkdirs();
}
targetFile.deleteOnExit();
targetFile.createNewFile();
if(targetFile.exists()){
targetFile.delete();
targetFile.createNewFile();
}
List<SysFileChunk> chunks = new ArrayList<>(chunksCache.values());
chunks.sort((o1, o2) -> (int) (o1.getChunkIndex() - o2.getChunkIndex()));
FileOutputStream outputStream = new FileOutputStream(targetFile, true);
for (SysFileChunk chunk : chunks) {
File chunkFile = new File(chunk.getChunkPath());
FileUtils.copyFile(chunkFile, outputStream);
try (FileOutputStream outputStream = new FileOutputStream(targetFile, true)) {
for (SysFileChunk chunk : chunks) {
File chunkFile = new File(chunk.getChunkPath());
FileUtils.copyFile(chunkFile, outputStream);
}
}
outputStream.close();
// 删除分片缓存文件,该方法为递归删除
FileUtil.del(chunkFIleStorePath);