From 54d1e9547443cfc660f3f9ca25695d95c750fbb8 Mon Sep 17 00:00:00 2001 From: nieziyan Date: Fri, 13 Oct 2023 11:13:47 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A1.=E5=90=AF=E7=94=A8=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=202.FTP=E7=9B=AE=E5=BD=95=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jeecg/common/constant/Prompt.java | 2 ++ .../main/java/org/jeecg/common/util/FTPUtil.java | 15 +++++++++++++++ .../service/impl/SpectrumFileServiceImpl.java | 6 +++--- .../system/controller/LoginController.java | 5 +++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java index 69310723..3c159176 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/Prompt.java @@ -44,4 +44,6 @@ public interface Prompt { String FILE_IS_EMPTY = "The List Of Files You Uploaded Is Empty!"; String NEED_TIME = "The Start Time Or End Time Cannot Be Empty!"; + + String DIR_CREATE_FAIL = "Directory Creation Failure: "; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java index f26a7763..82f0bc36 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/FTPUtil.java @@ -7,6 +7,7 @@ import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply; +import org.jeecg.common.constant.SymbolConstant; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -279,4 +280,18 @@ public class FTPUtil { } } + public static boolean createDirs(FTPClient ftp , String path) throws IOException { + /* 该部分为逐级创建 */ + String[] split = path.split(SymbolConstant.SINGLE_SLASH); + for (String str : split) { + if(StringUtils.isBlank(str)) + continue; + if (!ftp.changeWorkingDirectory(str)) { + boolean makeDir = ftp.makeDirectory(str); + if (!makeDir) return false; + ftp.changeWorkingDirectory(str); + } + } + return true; + } } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java index e5a45a54..90cc2ef8 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumFileServiceImpl.java @@ -80,9 +80,9 @@ public class SpectrumFileServiceImpl implements ISpectrumFileService { ftpClient = ftpUtil.LoginFTP(); if (ObjectUtil.isNull(ftpClient)) return Result.error(Prompt.FTP_ERR); - // 如果指定目录不存在,创建目录 - boolean exist = ftpClient.changeWorkingDirectory(filePath); - if (!exist) ftpClient.makeDirectory(filePath); + // 如果指定目录不存在,逐级创建目录 + boolean created = FTPUtil.createDirs(ftpClient, filePath); + if (!created) return Result.error(Prompt.DIR_CREATE_FAIL + filePath); // 上传所有文件 for (File oneFile : fileList) { String fullFilePath = filePath + slash + oneFile.getName(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java index 9c38ead9..445b362b 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/LoginController.java @@ -29,6 +29,7 @@ import org.jeecg.modules.system.service.impl.SysBaseApiImpl; import org.jeecg.modules.system.util.RandImageUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -87,7 +88,7 @@ public class LoginController { //update-begin-author:taoyan date:20190828 for:校验验证码 - /* String captcha = sysLoginModel.getCaptcha(); + String captcha = sysLoginModel.getCaptcha(); if(captcha==null){ result.error500("验证码无效"); return result; @@ -106,7 +107,7 @@ public class LoginController { // 改成特殊的code 便于前端判断 result.setCode(HttpStatus.PRECONDITION_FAILED.value()); return result; - }*/ + } //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效