Ver código fonte

文件名称优化

liuj 5 meses atrás
pai
commit
7769944bd2

+ 10 - 4
src/main/java/com/sunxung/factoring/service/financing/contract/impl/ContractMakingServiceImpl.java

@@ -824,15 +824,21 @@ public class ContractMakingServiceImpl implements ContractMakingService {
                 id = Long.parseLong(split[1]);
             }
             File newFile = newContractMakingService.createContractDocument(type, id, contractInfo);
+            File renameFile = null;
             for (File file : fileList) {
                 if (file.getName().equals(newFile.getName())) {
-                    String fileName = newFile.getName().substring(newFile.getName().lastIndexOf("."));
-                    String extension = newFile.getName().substring(newFile.getName().lastIndexOf(".") + 1);
-                    File renameFile = new File(newFile.getParentFile(), fileName + UUID.randomUUID() + extension);
+                    String fileName = newFile.getName().substring(0, newFile.getName().lastIndexOf("."));
+                    String extension = newFile.getName().substring(newFile.getName().lastIndexOf("."));
+                    renameFile = new File(newFile.getParentFile(), fileName + UUID.randomUUID() + extension);
                     newFile.renameTo(renameFile);
                 }
             }
-            fileList.add(newFile);
+            if (renameFile != null && renameFile.exists()) {
+                fileList.add(renameFile);
+            } else {
+                fileList.add(newFile);
+            }
+
         }
         if (CollectionUtil.isNotEmpty(fileList)) {
             // 打包成zip文件