From a4380c43097950a96c1b0db9e4d54d556bff3add Mon Sep 17 00:00:00 2001 From: zhangtq <2452618307@qq.com> Date: Mon, 20 Jan 2025 09:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=91=98=E4=B8=8A=E4=BC=A0=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ImportServiceImpl.java | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ImportServiceImpl.java b/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ImportServiceImpl.java index b569e7a..c6147eb 100644 --- a/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ImportServiceImpl.java +++ b/bonus-modules/bonus-project/src/main/java/com/bonus/project/service/impl/ImportServiceImpl.java @@ -18,6 +18,7 @@ import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; @@ -214,7 +215,7 @@ public class ImportServiceImpl implements ImportService { } catch (Exception e) { ajaxResult.isError(); // throw new Exception("文件上传失败"+e); - e.printStackTrace(); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } return ajaxResult; @@ -268,6 +269,7 @@ public class ImportServiceImpl implements ImportService { deleteAllFile(uploadUrl + folderName); } file.transferTo(new File(uploadUrl + packageName)); + String filesName = file.getOriginalFilename(); if (file.getOriginalFilename().indexOf(".zip") > 0) { unPackZip(packageName, uploadUrl); } @@ -313,6 +315,13 @@ public class ImportServiceImpl implements ImportService { @NotNull private static List getSysFileInfos(List inLibraryList, int i, SubPerson bean) { List fileList = new ArrayList<>(); + int _index = 0; + String[] parts = nameList.get(0).split("/"); + for (int m = 0; m < parts.length; m++) { + if (parts[m].contains("_")) { + _index = m; + } + } //当前人员的所有文件 for (String path : nameList) { if (path.contains(inLibraryList.get(i).getPhone())) { @@ -322,11 +331,11 @@ public class ImportServiceImpl implements ImportService { sysFileInfo.setId(inLibraryList.get(i).getId()); sysFileInfo.setUuid(inLibraryList.get(i).getUuid()); sysFileInfo.setProId(bean.getProId()); - sysFileInfo.setFileName(path.split("/")[3]); + sysFileInfo.setFileName(path.split("/")[_index + 2]); sysFileInfo.setCreatePerson(SecurityUtils.getLoginUser().getUsername()); sysFileInfo.setUserId(String.valueOf(SecurityUtils.getLoginUser().getUserid())); sysFileInfo.setUserType(bean.getUserType()); - switch (path.split("/")[2]) { + switch (path.split("/")[_index + 1]) { case "人脸照片": sysFileInfo.setInformationType("5"); break; @@ -405,7 +414,7 @@ public class ImportServiceImpl implements ImportService { nameList = new ArrayList<>(); namePhoneList = new ArrayList<>(); map = new HashMap<>(); - String encoding = "GBK"; + String encoding = "UTF-8"; ZipFile zipFile = new ZipFile(path); zipFile.setFileNameCharset(encoding); List list = zipFile.getFileHeaders(); @@ -413,15 +422,23 @@ public class ImportServiceImpl implements ImportService { String beforeName = ""; StringBuilder folderName = new StringBuilder(); int i = 0; + int _index = 0; while (i < list.size()) { FileHeader fileHeader = list.get(i); String fileName = fileHeader.getFileName(); - - if (fileName.contains(".")) { + if (fileName.contains(".") && fileName.contains("_")) { if (StringUtils.isEmpty(folderName)) { + //判断_在第几个位置 + String[] parts = fileName.split("/"); + for (int m = 0; m < parts.length; m++) { + if (parts[m].contains("_")) { + _index = m; + } + } // 初次进入赋值第一个人的名称_手机号 和对应的 value - beforeName = fileName.split("/")[1].split("_")[1]; - map.put(beforeName, "其他文件".equals(fileName.split("/")[2]) ? "" : fileName.split("/")[2]); + beforeName = fileName.split("/")[_index].split("_")[1]; + String name = fileName.split("/")[_index + 1]; + map.put(beforeName, "其他文件".equals(fileName.split("/")[_index + 1]) ? "" : fileName.split("/")[_index + 1]); } // 设置编码 @@ -436,7 +453,7 @@ public class ImportServiceImpl implements ImportService { if (i == (list.size() - 1)) { map.put(beforeName, folderName.toString()); } - String currentName = fileName.split("/")[1].split("_")[1]; + String currentName = fileName.split("/")[_index].split("_")[1]; if (!beforeName.equals(currentName)) { // 不相同名称时,对map进行赋值 map.put(beforeName, folderName.toString()); @@ -444,8 +461,11 @@ public class ImportServiceImpl implements ImportService { folderName = new StringBuilder(); } - if (!"其他文件".equals(fileName.split("/")[2])) { - folderName.append(fileName.split("/")[2]).append(","); + if (!"其他文件".equals(fileName.split("/")[_index + 1])) { + folderName.append(fileName.split("/")[_index + 1]).append(","); + } + if (!"人脸照片".equals(fileName.split("/")[_index + 1])) { + folderName.append(fileName.split("/")[_index + 1]).append(","); } if (i == list.size() - 1) {