From f71fa463d8c14d852191b2e0b02e6b26f1340226 Mon Sep 17 00:00:00 2001 From: bai <1643359946@qq.com> Date: Wed, 29 May 2024 09:59:59 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B45=E6=9C=8829=E6=97=A5=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=99=BA=E6=85=A7=E6=95=99=E5=AE=A4=E4=BA=BA=E6=B5=81?= =?UTF-8?q?=E9=87=8F=E7=9B=91=E6=B5=8B=E6=9C=AA=E4=B8=8A=E4=BC=A0=E5=88=B0?= =?UTF-8?q?ftp=E7=9A=84=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/util/SFTPUtil.java | 6 +-- .../impl/KcDetectionDetailedServiceImpl.java | 51 +++++++++++++------ .../system/controller/CommonController.java | 8 ++- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SFTPUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SFTPUtil.java index 9b877b27..c643e7ab 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SFTPUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/SFTPUtil.java @@ -58,9 +58,7 @@ public class SFTPUtil { public static void getChannelSftp(SftpConfig sftpConfig){ try { if(sshSession == null){ - if(sshSession == null){ - getSession(sftpConfig); - } + getSession(sftpConfig); Channel channel = sshSession.openChannel("sftp"); channel.connect(); sftp = (ChannelSftp) channel; @@ -276,7 +274,7 @@ public class SFTPUtil { * @param saveFile 存在本地的路径 */ public static Map download(SftpConfig sftpConfig, String directory, String saveFile) { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put("code","0"); map.put("msg","下载成功"); String[] df = getDirectoryAndFileName(directory); diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/detection/service/impl/KcDetectionDetailedServiceImpl.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/detection/service/impl/KcDetectionDetailedServiceImpl.java index df028e72..6e2d5ce2 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/detection/service/impl/KcDetectionDetailedServiceImpl.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/detection/service/impl/KcDetectionDetailedServiceImpl.java @@ -1,47 +1,42 @@ package org.jeecg.modules.kc.detection.service.impl; -import java.util.*; import cn.hutool.core.date.DateTime; -import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.beust.jcommander.internal.Sets; import com.google.common.collect.Maps; -import io.swagger.annotations.ApiModelProperty; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.util.SFTPUtil; +import org.jeecg.common.util.SftpConfig; import org.jeecg.modules.kc.detection.entity.KcDetectionDetailed; import org.jeecg.modules.kc.detection.entity.KcDetectionMain; import org.jeecg.modules.kc.detection.mapper.KcDetectionDetailedMapper; import org.jeecg.modules.kc.detection.service.IKcDetectionDetailedService; import org.jeecg.modules.kc.detection.service.IKcDetectionMainService; -import org.jeecg.modules.kc.jiaoshi.controller.KcZhihuijiaoshiController; import org.jeecg.modules.kc.jiaoshi.entity.KcZhihuijiaoshi; import org.jeecg.modules.kc.jiaoshi.service.IKcZhihuijiaoshiService; import org.jeecg.modules.kc.kcJieci.entity.KcJieci; import org.jeecg.modules.kc.kcJieci.service.IKcJieciService; -import org.jeecg.modules.kc.ktgl.controller.KcKetangbiaoController; import org.jeecg.modules.kc.ktgl.entity.KcKetangbiao; import org.jeecg.modules.kc.ktgl.service.IKcKetangbiaoService; -import org.jeecg.modules.tools.AuthService; -import org.jeecg.modules.tools.CommonUtil; -import org.jeecg.modules.tools.DateUtils; -import org.jeecg.modules.tools.URLEncoder; +import org.jeecg.modules.tools.*; import org.jeecg.modules.tools.ffmpeg.FFmpegTools; -import org.jeecgframework.poi.excel.annotation.Excel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.util.FileCopyUtils; - import javax.annotation.Resource; import java.io.File; -import java.util.stream.Collectors; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * @Description: 教室人数检测-详细表 @@ -49,6 +44,7 @@ import java.util.stream.Collectors; * @Date: 2024-05-07 * @Version: V1.0 */ +@Slf4j @Service public class KcDetectionDetailedServiceImpl extends ServiceImpl implements IKcDetectionDetailedService { @@ -70,6 +66,14 @@ public class KcDetectionDetailedServiceImpl extends ServiceImpl res = SFTPUtil.upload(sftpConfig, false, outImagePathDir, outImagePath, outImagePathName ); + if(!StringUtils.equals(res.get("code"),"0")){ + log.error("上传文件出现错误:{}", res.get("msg")); + + } + } + + } //查找主表, QueryWrapper detectionMainQw = new QueryWrapper<>(); diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/CommonController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/CommonController.java index 811b001b..f6c302f9 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/CommonController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/CommonController.java @@ -472,7 +472,13 @@ public class CommonController { try{ logger.info("/sys/common/static/SFTP下载 ..."+new Date()); // SFTPUtil.writeFileToRes(sftpConfig,imgPath,response); - Map map = SFTPUtil.download(sftpConfig,imgPath,getDownloadPath("temp")); + int index = imgPath.lastIndexOf("/"); + String path = "temp"; + if(index != -1){ + path = imgPath.substring(0,index); + } + //TODO 不确定是否有问题, + Map map = SFTPUtil.download(sftpConfig,imgPath,getDownloadPath(path)); if(!map.get("code").equals("0")){ response.setStatus(404); throw new RuntimeException(map.get("msg"));