From e49b8e05d4919e05a8e99984a452ca8932485204 Mon Sep 17 00:00:00 2001 From: jishenghua <752718920@qq.com> Date: Thu, 5 Dec 2024 21:27:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=A0=E9=99=A4=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=81=87=E5=88=B0=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accountHead/AccountHeadService.java | 4 +- .../service/depotHead/DepotHeadService.java | 4 +- .../erp/service/material/MaterialService.java | 4 +- .../systemConfig/SystemConfigService.java | 92 ++++++++++--------- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java index 7d2fcd671..2bd338bae 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java @@ -228,7 +228,9 @@ public class AccountHeadService { List pathList = new ArrayList<>(); for(AccountHead accountHead: list){ sb.append("[").append(accountHead.getBillNo()).append("]"); - pathList.add(accountHead.getFileName()); + if(StringUtil.isNotEmpty(accountHead.getFileName())) { + pathList.add(accountHead.getFileName()); + } if("1".equals(accountHead.getStatus())) { throw new BusinessRunTimeException(ExceptionConstants.ACCOUNT_HEAD_UN_AUDIT_DELETE_FAILED_CODE, String.format(ExceptionConstants.ACCOUNT_HEAD_UN_AUDIT_DELETE_FAILED_MSG)); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java index 710961171..d8a2cab3a 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java @@ -450,7 +450,9 @@ public class DepotHeadService { List dhList = getDepotHeadListByIds(ids); for(DepotHead depotHead: dhList){ sb.append("[").append(depotHead.getNumber()).append("]"); - pathList.add(depotHead.getFileName()); + if(StringUtil.isNotEmpty(depotHead.getFileName())) { + pathList.add(depotHead.getFileName()); + } //只有未审核的单据才能被删除 if("0".equals(depotHead.getStatus())) { User userInfo = userService.getCurrentUser(); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java index 6cb25bfe1..5afda108f 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java @@ -299,7 +299,9 @@ public class MaterialService { List list = getMaterialListByIds(ids); for(Material material: list){ sb.append("[").append(material.getName()).append("]"); - pathList.add(material.getImgName()); + if(StringUtil.isNotEmpty(material.getImgName())) { + pathList.add(material.getImgName()); + } } logService.insertLog("商品", sb.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java index d88d03cf8..7ec3edbee 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java @@ -364,32 +364,33 @@ public class SystemConfigService { if(fileUploadType == 1) { //本地 for(String pathStr: pathList) { - String[] pathArr = pathStr.split(","); - for (int i = 0; i < pathArr.length; i++) { - String path = pathArr[i]; - // 提取文件的路径 - String pathDir = getDirByPath(path); - if(StringUtil.isNotEmpty(pathDir)) { - // 源文件路径 - Path sourcePath = Paths.get(filePath + File.separator + path); - // 目标文件路径(注意这里是新文件的完整路径,包括文件名) - Path targetPath = Paths.get(filePath + File.separator + DELETED + File.separator + path); - try { - File file = new File(filePath + File.separator + DELETED + File.separator + pathDir); - if (!file.exists()) { - file.mkdirs();// 创建文件根目录 + if(StringUtil.isNotEmpty(pathStr)) { + String[] pathArr = pathStr.split(","); + for (String path : pathArr) { + // 提取文件的路径 + String pathDir = getDirByPath(path); + if (StringUtil.isNotEmpty(pathDir)) { + // 源文件路径 + Path sourcePath = Paths.get(filePath + File.separator + path); + // 目标文件路径(注意这里是新文件的完整路径,包括文件名) + Path targetPath = Paths.get(filePath + File.separator + DELETED + File.separator + path); + try { + File file = new File(filePath + File.separator + DELETED + File.separator + pathDir); + if (!file.exists()) { + file.mkdirs();// 创建文件根目录 + } + // 复制文件,如果目标文件已存在则替换它 + Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); + // 删除源文件 + Files.delete(sourcePath); + logger.info("File copied successfully."); + } catch (NoSuchFileException e) { + logger.error("Source file not found: " + e.getMessage()); + } catch (IOException e) { + logger.error("An I/O error occurred: " + e.getMessage()); + } catch (SecurityException e) { + logger.error("No permission to copy file: " + e.getMessage()); } - // 复制文件,如果目标文件已存在则替换它 - Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); - // 删除源文件 - Files.delete(sourcePath); - logger.info("File copied successfully."); - } catch (NoSuchFileException e) { - logger.error("Source file not found: " + e.getMessage()); - } catch (IOException e) { - logger.error("An I/O error occurred: " + e.getMessage()); - } catch (SecurityException e) { - logger.error("No permission to copy file: " + e.getMessage()); } } } @@ -401,25 +402,28 @@ public class SystemConfigService { String accessKeySecret = platformConfigService.getPlatformConfigByKey("aliOss_accessKeySecret").getPlatformValue(); String bucketName = platformConfigService.getPlatformConfigByKey("aliOss_bucketName").getPlatformValue(); for(String pathStr: pathList) { - String[] pathArr = pathStr.split(","); - for (int i = 0; i < pathArr.length; i++) { - String path = pathArr[i]; - // 创建OSSClient实例。 - OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); - try { - String filePathStr = StringUtil.isNotEmpty(filePath)? filePath.substring(1):""; - String sourceObjectKey = filePathStr + "/" + path; - String sourceSmallObjectKey = filePathStr + "-small/" + path; - String destinationObjectKey = DELETED + "/list/" + sourceObjectKey; - String destinationSmallObjectKey = DELETED + "/list/" + sourceSmallObjectKey; - this.copySourceToDest(ossClient, bucketName, sourceObjectKey, destinationObjectKey); - this.copySourceToDest(ossClient, bucketName, sourceSmallObjectKey, destinationSmallObjectKey); - } catch (Exception e) { - logger.error(e.getMessage()); - } finally { - // 关闭OSSClient。 - if (ossClient != null) { - ossClient.shutdown(); + if(StringUtil.isNotEmpty(pathStr)) { + String[] pathArr = pathStr.split(","); + for (String path : pathArr) { + if(StringUtil.isNotEmpty(path)) { + // 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + try { + String filePathStr = StringUtil.isNotEmpty(filePath) ? filePath.substring(1) : ""; + String sourceObjectKey = filePathStr + "/" + path; + String sourceSmallObjectKey = filePathStr + "-small/" + path; + String destinationObjectKey = DELETED + "/list/" + sourceObjectKey; + String destinationSmallObjectKey = DELETED + "/list/" + sourceSmallObjectKey; + this.copySourceToDest(ossClient, bucketName, sourceObjectKey, destinationObjectKey); + this.copySourceToDest(ossClient, bucketName, sourceSmallObjectKey, destinationSmallObjectKey); + } catch (Exception e) { + logger.error(e.getMessage()); + } finally { + // 关闭OSSClient。 + if (ossClient != null) { + ossClient.shutdown(); + } + } } } }