Compare commits
3 Commits
ca270a56e2
...
f7b644ecae
Author | SHA1 | Date |
---|---|---|
|
f7b644ecae | |
|
61a8fc5198 | |
|
ef0dc2ca85 |
|
@ -252,6 +252,11 @@
|
|||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.55</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -214,6 +214,7 @@ public interface CommonConstant {
|
|||
String UPLOAD_TYPE_LOCAL = "local";
|
||||
String UPLOAD_TYPE_MINIO = "minio";
|
||||
String UPLOAD_TYPE_OSS = "alioss";
|
||||
String UPLOAD_TYPE_SFTP = "sftp";
|
||||
|
||||
/**
|
||||
* 文档上传自定义桶名称
|
||||
|
|
|
@ -1,31 +1,27 @@
|
|||
package org.jeecg.modules.zyk.utils.sftp;
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.jeecg.common.util.CommonUtils;
|
||||
import org.jeecg.modules.zyk.utils.text.StringUtils;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.util.text.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@Service
|
||||
public class SFTPUtil {
|
||||
private long count = 3;
|
||||
private long count1 = 0;
|
||||
private long sleepTime = 300000;//5分钟
|
||||
private static long count = 3;
|
||||
private static long count1 = 0;
|
||||
private static long sleepTime = 300000;//5分钟
|
||||
private static final Logger logger = LoggerFactory.getLogger(SFTPUtil.class);
|
||||
|
||||
@Autowired
|
||||
private SftpConfig sftpConfig;
|
||||
|
||||
public ChannelSftp connect(){
|
||||
public static ChannelSftp connect(SftpConfig sftpConfig){
|
||||
ChannelSftp sftp = null;
|
||||
try {
|
||||
JSch jsch = new JSch();
|
||||
|
@ -52,7 +48,7 @@ public class SFTPUtil {
|
|||
}
|
||||
Thread.sleep(sleepTime);
|
||||
logger.info("重新连接....");
|
||||
connect();
|
||||
connect(sftpConfig);
|
||||
} catch (InterruptedException e1){
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
@ -60,7 +56,38 @@ public class SFTPUtil {
|
|||
return sftp;
|
||||
}
|
||||
|
||||
private void mkdirs(String directory,ChannelSftp sftp) throws SftpException{
|
||||
public static Session getSession(SftpConfig sftpConfig){
|
||||
Session sshSession = null;
|
||||
try {
|
||||
JSch jsch = new JSch();
|
||||
sshSession = jsch.getSession(sftpConfig.getUsername(), sftpConfig.getHostname(), sftpConfig.getPort());
|
||||
logger.info("Session created ... host=" + sftpConfig.getHostname() + ";port=" + sftpConfig.getPort()+";UserName=" + sftpConfig.getUsername() + ";Password="+sftpConfig.getPassword());
|
||||
// jsch.addIdentity("e:/sftp_keys.ppk","");
|
||||
sshSession.setPassword(sftpConfig.getPassword());
|
||||
Properties sshConfig = new Properties();
|
||||
sshConfig.put("StrictHostKeyChecking", "no");
|
||||
sshSession.setConfig(sshConfig);
|
||||
sshSession.setTimeout(sftpConfig.getTimeout());
|
||||
sshSession.connect();
|
||||
logger.info("Session connected ...");
|
||||
logger.info("Opening Channel ...");
|
||||
} catch (Exception e){
|
||||
try{
|
||||
count1 += 1;
|
||||
if(count == count1){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Thread.sleep(sleepTime);
|
||||
logger.info("重新连接....");
|
||||
getSession(sftpConfig);
|
||||
} catch (InterruptedException e1){
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
return sshSession;
|
||||
}
|
||||
|
||||
private static void mkdirs(String directory,ChannelSftp sftp) throws SftpException {
|
||||
String[] dics = directory.split("/");
|
||||
for(int i=0;i< dics.length;i++){
|
||||
try {
|
||||
|
@ -86,15 +113,15 @@ public class SFTPUtil {
|
|||
* @param uploadFileName 要上传的文件名称(重新定义的文件名称)
|
||||
* @param
|
||||
*/
|
||||
public Map<String,String> upload(String directory, String uploadFilePath, String uploadFileName) {
|
||||
public static Map<String,String> upload(SftpConfig sftpConfig, String directory, String uploadFilePath, String uploadFileName) {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
map.put("msg","上传成功");
|
||||
ChannelSftp sftp = null;
|
||||
try{
|
||||
sftp = connect();
|
||||
sftp = connect(sftpConfig);
|
||||
try {
|
||||
directory = getDirectory(directory);
|
||||
directory = getDirectory(sftpConfig.getUploadpath(),directory);
|
||||
sftp.cd(directory);
|
||||
} catch (SftpException e1) {
|
||||
try {
|
||||
|
@ -131,6 +158,58 @@ public class SFTPUtil {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static Map<String,String> upload(SftpConfig sftpConfig, MultipartFile file, String directory) {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
map.put("msg","上传成功");
|
||||
ChannelSftp sftp = null;
|
||||
try{
|
||||
sftp = connect(sftpConfig);
|
||||
try {
|
||||
// directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
||||
sftp.cd(directory);
|
||||
} catch (SftpException e1) {
|
||||
try {
|
||||
mkdirs(directory,sftp);
|
||||
// sftp.mkdir(directory);
|
||||
// sftp.cd(directory);
|
||||
} catch (SftpException e2) {
|
||||
map.put("code","1");
|
||||
map.put("msg","ftp创建"+directory+"文件路径失败");
|
||||
// throw new RuntimeException("ftp创建文件路径失败" + directory);
|
||||
}
|
||||
}
|
||||
String fileName = null;
|
||||
// 获取文件名
|
||||
String orgName = file.getOriginalFilename();
|
||||
orgName = CommonUtils.getFileName(orgName);
|
||||
if(orgName.indexOf(SymbolConstant.SPOT)!=-1){
|
||||
fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf("."));
|
||||
}else{
|
||||
fileName = orgName+ "_" + System.currentTimeMillis();
|
||||
}
|
||||
InputStream inputStream=null;
|
||||
try {
|
||||
sftp.put(file.getInputStream(), fileName);
|
||||
map.put("data",directory.concat("/").concat(fileName));
|
||||
} catch (Exception e3) {
|
||||
map.put("code","1");
|
||||
map.put("msg","上传文件异常:" + e3.getMessage());
|
||||
// throw new RuntimeException("sftp异常" + e3);
|
||||
} finally {
|
||||
closeStream(inputStream,null);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
map.put("code","1");
|
||||
map.put("msg","sftp异常:" + e.getMessage());
|
||||
}finally {
|
||||
if(sftp!=null){
|
||||
disConnect(sftp);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
|
@ -138,13 +217,13 @@ public class SFTPUtil {
|
|||
* @param downloadFile 下载的文件
|
||||
* @param saveFile 存在本地的路径
|
||||
*/
|
||||
public Map<String,String> download(String directory, String downloadFile, String saveFile) {
|
||||
public static Map<String,String> download(SftpConfig sftpConfig, String directory, String downloadFile, String saveFile) {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
map.put("msg","删除成功");
|
||||
ChannelSftp sftp = null;
|
||||
try{
|
||||
sftp = connect();
|
||||
sftp = connect(sftpConfig);
|
||||
OutputStream output = null;
|
||||
try {
|
||||
File localDirFile = new File(saveFile);
|
||||
|
@ -189,14 +268,16 @@ public class SFTPUtil {
|
|||
/**
|
||||
* 网页下载文件
|
||||
* @param response
|
||||
* @param directory
|
||||
* @param downloadFile
|
||||
* @param downloadFilePath
|
||||
* @throws Exception
|
||||
*/
|
||||
public void writeFileToRes(String directory, String downloadFile,HttpServletResponse response) throws Exception {
|
||||
public static void writeFileToRes(SftpConfig sftpConfig, String downloadFilePath, HttpServletResponse response) throws Exception {
|
||||
String[] df = getDirectoryAndFileName(downloadFilePath);
|
||||
String directory = df[0];
|
||||
String downloadFile = df[1];
|
||||
ChannelSftp sftp = null;
|
||||
try{
|
||||
sftp = connect();
|
||||
sftp = connect(sftpConfig);
|
||||
InputStream inputStream = null;
|
||||
ServletOutputStream outputStream=null;
|
||||
try {
|
||||
|
@ -236,18 +317,139 @@ public class SFTPUtil {
|
|||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 上传文件
|
||||
// * @param oldpath 原文件路径(文件路径+名称)
|
||||
// * @param directory 目的文件路径
|
||||
// * @param newname 目的文件名称
|
||||
// * @param
|
||||
// */
|
||||
// public static Map<String,String> rename(SftpConfig sftpConfig, String oldpath, String directory, String newname) {
|
||||
// Map<String,String> map = new HashMap<String,String>();
|
||||
// map.put("code","0");
|
||||
// map.put("msg","上传成功");
|
||||
// ChannelSftp sftp = null;
|
||||
// try{
|
||||
// sftp = connect(sftpConfig);
|
||||
// try {
|
||||
// directory = getDirectory(sftpConfig.getUploadpath(),directory);
|
||||
// sftp.cd(directory);
|
||||
// } catch (SftpException e1) {
|
||||
// try {
|
||||
// mkdirs(directory,sftp);
|
||||
// } catch (SftpException e2) {
|
||||
// map.put("code","1");
|
||||
// map.put("msg","ftp创建"+directory+"文件路径失败");
|
||||
// }
|
||||
// }
|
||||
// try {
|
||||
// String newpath = directory.concat(newname);
|
||||
// sftp.rename(oldpath,newpath);
|
||||
// } catch (SftpException e1) {
|
||||
// map.put("code","1");
|
||||
// map.put("msg",e1.getMessage());
|
||||
//// throw new RuntimeException("ftp创建文件路径失败" + directory);
|
||||
// }
|
||||
// }catch (Exception e) {
|
||||
// map.put("code","1");
|
||||
// map.put("msg","sftp异常:" + e.getMessage());
|
||||
// }finally {
|
||||
// if(sftp!=null){
|
||||
// disConnect(sftp);
|
||||
// }
|
||||
// }
|
||||
// return map;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 移动文件
|
||||
* @param oldpath 原文件路径(文件路径+名称)
|
||||
* @param directory 目的文件路径
|
||||
* @param newname 目的文件名称
|
||||
* @param
|
||||
*/
|
||||
public static Map<String,String> move(SftpConfig sftpConfig, String oldpath, String directory, String newname) {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
map.put("msg","上传成功");
|
||||
ChannelSftp sftp = null;
|
||||
try {
|
||||
sftp = connect(sftpConfig);
|
||||
try {
|
||||
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
||||
sftp.cd(directory);
|
||||
} catch (SftpException e1) {
|
||||
try {
|
||||
mkdirs(directory, sftp);
|
||||
} catch (SftpException e2) {
|
||||
map.put("code", "1");
|
||||
map.put("msg", "ftp创建" + directory + "文件路径失败");
|
||||
}
|
||||
}
|
||||
Channel channel = null;
|
||||
try {
|
||||
String oldfullpath = sftpConfig.getFullpath().concat(oldpath);
|
||||
String newpath = directory.concat(newname);
|
||||
String newfullpath = sftpConfig.getFullpath().concat(newpath);
|
||||
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
||||
Session session = sftp.getSession();
|
||||
channel = session.openChannel("exec");
|
||||
((ChannelExec) channel).setCommand(moveCommand);
|
||||
channel.setInputStream(null);
|
||||
((ChannelExec) channel).setErrStream(System.err);
|
||||
InputStream in = channel.getInputStream();
|
||||
channel.connect();
|
||||
byte[] tmp = new byte[1024];
|
||||
while (true) {
|
||||
while (in.available() > 0) {
|
||||
int i = in.read(tmp, 0, 1024);
|
||||
if (i < 0) break;
|
||||
}
|
||||
if (channel.isClosed()) {
|
||||
System.out.println("exit-status: " + channel.getExitStatus());
|
||||
break;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
channel.disconnect();
|
||||
session.disconnect();
|
||||
map.put("data",newpath);
|
||||
} catch (Exception e1) {
|
||||
map.put("code","1");
|
||||
map.put("msg",e1.getMessage());
|
||||
// throw new RuntimeException("ftp创建文件路径失败" + directory);
|
||||
}finally {
|
||||
if(channel!=null){
|
||||
channel.disconnect();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
map.put("code","1");
|
||||
map.put("msg","sftp异常:" + e.getMessage());
|
||||
}finally {
|
||||
if(sftp!=null){
|
||||
disConnect(sftp);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @param directory 要删除文件所在目录
|
||||
* @param deleteFile 要删除的文件
|
||||
*/
|
||||
public Map<String,String> delete(String directory, String deleteFile) {
|
||||
public static Map<String,String> delete(SftpConfig sftpConfig, String directory, String deleteFile) {
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
map.put("msg","删除成功");
|
||||
ChannelSftp sftp = null;
|
||||
try{
|
||||
sftp = connect();
|
||||
sftp = connect(sftpConfig);
|
||||
directory = delDiagonalLines(directory);
|
||||
sftp.cd(directory);
|
||||
sftp.rm(deleteFile);
|
||||
|
@ -262,16 +464,15 @@ public class SFTPUtil {
|
|||
return map;
|
||||
}
|
||||
|
||||
private String getDirectory(String directory){
|
||||
String rootPath = sftpConfig.getUploadpath();
|
||||
if(rootPath.endsWith("/")){
|
||||
return sftpConfig.getUploadpath() + directory;
|
||||
private static String getDirectory(String uploadpath, String directory){
|
||||
if(uploadpath.endsWith("/")){
|
||||
return uploadpath + directory;
|
||||
}else{
|
||||
return sftpConfig.getUploadpath() +"/"+ directory;
|
||||
return uploadpath +"/"+ directory;
|
||||
}
|
||||
}
|
||||
|
||||
private String delDiagonalLines(String directory){
|
||||
private static String delDiagonalLines(String directory){
|
||||
if(directory.startsWith("/")){
|
||||
directory = directory.substring(directory.indexOf("/")+1);
|
||||
delDiagonalLines(directory);
|
||||
|
@ -282,7 +483,7 @@ public class SFTPUtil {
|
|||
/**
|
||||
* 断掉连接
|
||||
*/
|
||||
public void disConnect(ChannelSftp sftp) {
|
||||
public static void disConnect(ChannelSftp sftp) {
|
||||
try {
|
||||
sftp.disconnect();
|
||||
sftp.getSession().disconnect();
|
||||
|
@ -291,20 +492,11 @@ public class SFTPUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public SFTPUtil(long count, long sleepTime) {
|
||||
this.count = count;
|
||||
this.sleepTime = sleepTime;
|
||||
}
|
||||
|
||||
public SFTPUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭流
|
||||
* @param outputStream
|
||||
*/
|
||||
private void closeStream(InputStream inputStream,OutputStream outputStream) {
|
||||
private static void closeStream(InputStream inputStream,OutputStream outputStream) {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
|
@ -321,6 +513,15 @@ public class SFTPUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String[] getDirectoryAndFileName(String fileName) {
|
||||
String[] ss = new String[2];
|
||||
String path = fileName.substring(0,fileName.lastIndexOf("/"));
|
||||
String name = fileName.substring(fileName.lastIndexOf("/")+1);
|
||||
ss[0] = path;
|
||||
ss[1] = name;
|
||||
return ss;
|
||||
}
|
||||
|
||||
/*****************以下为预留方法*******************/
|
||||
// /**
|
||||
// * 下载远程文件夹下的所有文件
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.sftp;
|
||||
package org.jeecg.common.util;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
@ -14,14 +14,16 @@ public class SftpConfig {
|
|||
private String password;
|
||||
private Integer timeout;
|
||||
private String uploadpath;
|
||||
private String fullpath;
|
||||
|
||||
public SftpConfig(String hostname,Integer port,String username,String password,Integer timeout,String uploadpath){
|
||||
public SftpConfig(String hostname,Integer port,String username,String password,Integer timeout,String uploadpath,String fullpath){
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.timeout = timeout;
|
||||
this.uploadpath = uploadpath;
|
||||
this.fullpath = fullpath;
|
||||
}
|
||||
|
||||
public SftpConfig(){}
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.text;
|
||||
package org.jeecg.common.util.text;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.text;
|
||||
package org.jeecg.common.util.text;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.text;
|
||||
package org.jeecg.common.util.text;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.text;
|
||||
package org.jeecg.common.util.text;
|
||||
|
||||
/**
|
||||
* 字符串格式化
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.text;
|
||||
package org.jeecg.common.util.text;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
|
@ -621,4 +621,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
|
|||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String nullToEmpty(Object obj){
|
||||
if(obj == null){
|
||||
return "";
|
||||
}
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
|
@ -80,11 +80,6 @@
|
|||
<artifactId>hutool-http</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.55</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -7,19 +7,12 @@ import io.swagger.annotations.ApiOperation;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.zyk.entity.ZykInfo;
|
||||
import org.jeecg.modules.zyk.service.IZykService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -48,7 +41,6 @@ public class ZykController extends JeecgController<ZykInfo, IZykService> {
|
|||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
|
||||
@AutoLog(value = "资源库信息-添加")
|
||||
@ApiOperation(value="资源库信息-添加", notes="资源库信息-添加")
|
||||
@PostMapping(value = "/add")
|
||||
|
@ -67,6 +59,7 @@ public class ZykController extends JeecgController<ZykInfo, IZykService> {
|
|||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody ZykInfo zykInfo) {
|
||||
String res = zykService.modifyInfo(zykInfo);
|
||||
// Map<String,String> res = zykService.saveToZyk(zykInfo);
|
||||
return Result.OK(res);
|
||||
}
|
||||
|
||||
|
@ -96,12 +89,12 @@ public class ZykController extends JeecgController<ZykInfo, IZykService> {
|
|||
return Result.OK(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览图片&下载文件
|
||||
* 请求地址:http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
// /**
|
||||
// * 预览图片&下载文件
|
||||
// * 请求地址:http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg}
|
||||
// * @param request
|
||||
// * @param response
|
||||
// */
|
||||
// @GetMapping(value = "/static/**")
|
||||
// public void view(HttpServletRequest request, HttpServletResponse response) {
|
||||
// // ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
|
@ -159,35 +152,35 @@ public class ZykController extends JeecgController<ZykInfo, IZykService> {
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
@GetMapping(value = "/static/**")
|
||||
public void view(HttpServletRequest request, HttpServletResponse response) {
|
||||
// ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
String filePath = extractPathFromPattern(request);
|
||||
if(oConvertUtils.isEmpty(filePath) || CommonConstant.STRING_NULL.equals(filePath)){
|
||||
return;
|
||||
}
|
||||
try {
|
||||
filePath = filePath.replace("..", "").replace("../","");
|
||||
if (filePath.endsWith(SymbolConstant.COMMA)) {
|
||||
filePath = filePath.substring(0, filePath.length() - 1);
|
||||
}
|
||||
zykService.downloadRes(filePath,response);
|
||||
} catch (Exception e) {
|
||||
log.error("预览文件失败" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @GetMapping(value = "/static/**")
|
||||
// public void view(HttpServletRequest request, HttpServletResponse response) {
|
||||
// // ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
// String filePath = extractPathFromPattern(request);
|
||||
// if(oConvertUtils.isEmpty(filePath) || CommonConstant.STRING_NULL.equals(filePath)){
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// filePath = filePath.replace("..", "").replace("../","");
|
||||
// if (filePath.endsWith(SymbolConstant.COMMA)) {
|
||||
// filePath = filePath.substring(0, filePath.length() - 1);
|
||||
// }
|
||||
// zykService.downloadRes(filePath,response);
|
||||
// } catch (Exception e) {
|
||||
// log.error("预览文件失败" + e.getMessage());
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 把指定URL后的字符串全部截断当成参数
|
||||
* 这么做是为了防止URL中包含中文或者特殊字符(/等)时,匹配不了的问题
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private static String extractPathFromPattern(final HttpServletRequest request) {
|
||||
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
|
||||
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
|
||||
}
|
||||
// /**
|
||||
// * 把指定URL后的字符串全部截断当成参数
|
||||
// * 这么做是为了防止URL中包含中文或者特殊字符(/等)时,匹配不了的问题
|
||||
// * @param request
|
||||
// * @return
|
||||
// */
|
||||
// private static String extractPathFromPattern(final HttpServletRequest request) {
|
||||
// String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
|
||||
// String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||
// return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmxx;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel(value="zyk_info对象", description="资源库信息")
|
||||
|
@ -55,6 +57,9 @@ public class ZykInfo implements Serializable {
|
|||
/**文件名称*/
|
||||
@ApiModelProperty(value = "文件名称")
|
||||
private String fileName;
|
||||
/**PDF文件名称*/
|
||||
@ApiModelProperty(value = "PDF文件名称")
|
||||
private String pdfName;
|
||||
/**学号*/
|
||||
@TableField(exist = false)
|
||||
private String xh;
|
||||
|
@ -68,4 +73,19 @@ public class ZykInfo implements Serializable {
|
|||
@TableField(exist = false)
|
||||
private String section;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ZykInfo> xqxnList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ZykInfo> kkdwList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ZykInfo> kcmcList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ZykInfo> skjsList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<ZykInfo> wjlxList;
|
||||
|
||||
}
|
||||
|
|
|
@ -17,47 +17,30 @@
|
|||
skjs,
|
||||
wjlx,
|
||||
file_name,
|
||||
xh,
|
||||
seq,
|
||||
pdf_name,
|
||||
chapter,
|
||||
section
|
||||
from zyk_info a
|
||||
<where>
|
||||
where xh is null
|
||||
<if test="params.createBy != null and params.createBy != ''">
|
||||
AND create_by = #{params.createBy}
|
||||
</if>
|
||||
<if test="params.bizId != null and params.bizId != ''">
|
||||
AND biz_id = #{params.bizId}
|
||||
</if>
|
||||
<if test="params.bizTable != null and params.bizTable != ''">
|
||||
AND biz_table = #{params.bizTable}
|
||||
</if>
|
||||
<if test="params.xqxn != null and params.xqxn != ''">
|
||||
AND xqxn = #{params.xqxn}
|
||||
</if>
|
||||
<if test="params.kkdw != null and params.kkdw != ''">
|
||||
AND kkdw = #{params.kkdw}
|
||||
</if>
|
||||
<if test="params.kcmc != null and params.kcmc != ''">
|
||||
AND kcmc = #{params.kcmc}
|
||||
</if>
|
||||
<if test="params.skjs != null and params.skjs != ''">
|
||||
AND skjs = #{params.skjs}
|
||||
</if>
|
||||
<if test="params.wjlx != null and params.wjlx != ''">
|
||||
AND wjlx = #{params.wjlx}
|
||||
</if>
|
||||
<if test="params.xh != null and params.xh != ''">
|
||||
AND xh = #{params.xh}
|
||||
</if>
|
||||
<if test="params.seq != null and params.seq != ''">
|
||||
AND seq = #{params.seq}
|
||||
</if>
|
||||
<if test="params.chapter != null and params.chapter != ''">
|
||||
AND chapter = #{params.chapter}
|
||||
</if>
|
||||
<if test="params.section != null and params.section != ''">
|
||||
AND section = #{params.section}
|
||||
</if>
|
||||
</where>
|
||||
order by create_time
|
||||
order by xqxn asc,kkdw asc,kcmc asc,skjs asc,wjlx asc,create_time desc
|
||||
</select>
|
||||
|
||||
<select id="getById" parameterType="String" resultType="org.jeecg.modules.zyk.entity.ZykInfo">
|
||||
|
@ -75,6 +58,7 @@
|
|||
skjs,
|
||||
wjlx,
|
||||
file_name,
|
||||
pdf_name,
|
||||
xh,
|
||||
seq,
|
||||
chapter,
|
||||
|
@ -96,12 +80,13 @@
|
|||
skjs,
|
||||
wjlx,
|
||||
file_name,
|
||||
pdf_name,
|
||||
xh,
|
||||
seq,
|
||||
chapter,
|
||||
section
|
||||
)
|
||||
value(
|
||||
values(
|
||||
#{id},
|
||||
#{createBy},
|
||||
#{createTime},
|
||||
|
@ -113,6 +98,7 @@
|
|||
#{skjs},
|
||||
#{wjlx},
|
||||
#{fileName},
|
||||
#{pdfName},
|
||||
#{xh},
|
||||
#{seq},
|
||||
#{chapter},
|
||||
|
@ -125,7 +111,8 @@
|
|||
set
|
||||
update_by = #{updateBy},
|
||||
update_time = #{updateTime},
|
||||
file_name = #{fileName}
|
||||
file_name = #{fileName},
|
||||
pdf_name = #{pdfName}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
|
@ -148,6 +135,7 @@
|
|||
skjs,
|
||||
wjlx,
|
||||
file_name,
|
||||
pdf_name,
|
||||
xh,
|
||||
seq,
|
||||
chapter,
|
||||
|
|
|
@ -5,10 +5,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.text.StringUtils;
|
||||
import org.jeecg.modules.zyk.entity.ZykInfo;
|
||||
import org.jeecg.modules.zyk.mapper.ZykMapper;
|
||||
import org.jeecg.modules.zyk.service.IZykService;
|
||||
import org.jeecg.modules.zyk.utils.util.FileHandleUtil;
|
||||
|
||||
import org.jeecg.modules.zyk.utils.FileHandleUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -42,11 +44,19 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
|
||||
@Override
|
||||
public String saveInfo(ZykInfo zykInfo){
|
||||
Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
Map<String,String> map = fileHandleUtil.move(zykInfo);
|
||||
if(!map.get("code").equals("0")){
|
||||
return map.get("msg");
|
||||
}
|
||||
zykInfo.setFileName(map.get("data"));
|
||||
if(!StringUtils.isEmpty(map.get("data"))){
|
||||
String fileName = map.get("data");
|
||||
zykInfo.setFileName(fileName);
|
||||
}
|
||||
if(!StringUtils.isEmpty(map.get("pdfData"))){
|
||||
String pdfName = map.get("pdfData");
|
||||
zykInfo.setPdfName(pdfName);
|
||||
}
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
zykInfo.setCreateBy(user.getUsername());
|
||||
zykInfo.setCreateTime(new Date());
|
||||
|
@ -58,11 +68,19 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
|
||||
@Override
|
||||
public String modifyInfo(ZykInfo zykInfo){
|
||||
Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
Map<String,String> map = fileHandleUtil.move(zykInfo);
|
||||
if(!map.get("code").equals("0")){
|
||||
return map.get("msg");
|
||||
}
|
||||
zykInfo.setFileName(map.get("data"));
|
||||
if(!StringUtils.isEmpty(map.get("data"))){
|
||||
String fileName = map.get("data");
|
||||
zykInfo.setFileName(fileName);
|
||||
}
|
||||
if(!StringUtils.isEmpty(map.get("pdfData"))){
|
||||
String pdfName = map.get("pdfData");
|
||||
zykInfo.setPdfName(pdfName);
|
||||
}
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
zykInfo.setUpdateBy(user.getUsername());
|
||||
zykInfo.setUpdateTime(new Date());
|
||||
|
@ -73,9 +91,15 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
@Override
|
||||
public String removeById(String id){
|
||||
ZykInfo zykInfo = zykMapper.getById(id);
|
||||
if(zykInfo.getFileName() != null && !zykInfo.getFileName().equals("")){
|
||||
if(!StringUtils.isEmpty(zykInfo.getFileName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(zykInfo.getFileName());
|
||||
if(!df[0].equals("")&&!df[1].equals("")){
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(zykInfo.getPdfName());
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +112,15 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
for(int i=0;i<list.size();i++){
|
||||
String id = list.get(i);
|
||||
ZykInfo zykInfo = zykMapper.getById(id);
|
||||
if(zykInfo.getFileName() != null && !zykInfo.getFileName().equals("")){
|
||||
if(!StringUtils.isEmpty(zykInfo.getFileName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(zykInfo.getFileName());
|
||||
if(!df[0].equals("")&&!df[1].equals("")){
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(zykInfo.getPdfName());
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
|
@ -139,19 +169,16 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
*/
|
||||
@Override
|
||||
public void downloadRes(String filePath, HttpServletResponse response) throws Exception {
|
||||
if(filePath == null || filePath.equals("")){
|
||||
if(StringUtils.isEmpty(filePath)){
|
||||
throw new RuntimeException("文件["+filePath+"]不存在!");
|
||||
}
|
||||
if(filePath.lastIndexOf("/")==-1){
|
||||
throw new RuntimeException("文件路径不存在!");
|
||||
}
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(filePath);
|
||||
if(df[0].equals("")){
|
||||
if(StringUtils.isEmpty(df[0])||StringUtils.isEmpty(df[1])){
|
||||
throw new RuntimeException("文件路径不存在!");
|
||||
}
|
||||
if(df[1].equals("")){
|
||||
throw new RuntimeException("文件不存在!");
|
||||
}
|
||||
fileHandleUtil.downloadRes(df[0],df[1],response);
|
||||
}
|
||||
|
||||
|
@ -162,25 +189,25 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
*/
|
||||
@Override
|
||||
public Map<String,String> saveToZyk(ZykInfo zykInfo){
|
||||
Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||
Map<String,String> map = fileHandleUtil.move(zykInfo);
|
||||
if(!map.get("code").equals("0")){
|
||||
return map;
|
||||
}
|
||||
zykInfo.setFileName(map.get("data"));
|
||||
ZykInfo entity = zykMapper.getByBiz(zykInfo);
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
if(entity!=null){
|
||||
zykInfo.setUpdateBy(user.getUsername());
|
||||
zykInfo.setUpdateTime(new Date());
|
||||
zykInfo.setId(entity.getId());
|
||||
zykMapper.modifyInfo(zykInfo);
|
||||
}else{
|
||||
zykInfo.setCreateBy(user.getUsername());
|
||||
zykInfo.setCreateTime(new Date());
|
||||
Long id = new DefaultIdentifierGenerator().nextId(new ZykInfo());
|
||||
zykInfo.setId(id.toString());
|
||||
zykMapper.addInfo(zykInfo);
|
||||
if(!StringUtils.isEmpty(map.get("data"))){
|
||||
String fileName = map.get("data");
|
||||
zykInfo.setFileName(fileName);
|
||||
}
|
||||
if(!StringUtils.isEmpty(map.get("pdfData"))){
|
||||
String pdfName = map.get("pdfData");
|
||||
zykInfo.setPdfName(pdfName);
|
||||
}
|
||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
zykInfo.setCreateBy(user.getUsername());
|
||||
zykInfo.setCreateTime(new Date());
|
||||
Long id = new DefaultIdentifierGenerator().nextId(new ZykInfo());
|
||||
zykInfo.setId(id.toString());
|
||||
zykMapper.addInfo(zykInfo);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -194,9 +221,15 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
|||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
ZykInfo entity = zykMapper.getByBiz(zykInfo);
|
||||
if(entity.getFileName() != null && !entity.getFileName().equals("")){
|
||||
if(!StringUtils.isEmpty(entity.getFileName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(entity.getFileName());
|
||||
if(!df[0].equals("")&&!df[1].equals("")){
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
if(!StringUtils.isEmpty(entity.getPdfName())){
|
||||
String[] df = fileHandleUtil.getDirectoryAndFileName(entity.getPdfName());
|
||||
if(!StringUtils.isEmpty(df[0])&&!StringUtils.isEmpty(df[1])){
|
||||
fileHandleUtil.delete(df[0],df[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,342 @@
|
|||
package org.jeecg.modules.zyk.utils;
|
||||
|
||||
import org.jeecg.common.util.SFTPUtil;
|
||||
import org.jeecg.common.util.text.StringUtils;
|
||||
import org.jeecg.modules.zyk.entity.ZykInfo;
|
||||
|
||||
import org.jeecg.common.util.SftpConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FileHandleUtil {
|
||||
|
||||
@Autowired
|
||||
SftpConfig sftpConfig;
|
||||
|
||||
@Value(value = "${jeecg.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
// @Value(value = "${jeecg.path.webapp}")
|
||||
// private String downloadpath;
|
||||
|
||||
// public Map<String,String> uploadFile(ZykInfo zykInfo){
|
||||
// Map<String,String> map = new HashMap<String,String>();
|
||||
// map.put("code","0");
|
||||
// Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||
// if(!directoryMap.get("code").equals("0")){
|
||||
// return directoryMap;
|
||||
// }
|
||||
// //资源库文件路径
|
||||
// String directory = directoryMap.get("directory");
|
||||
//
|
||||
// if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
||||
// //源文件路径
|
||||
// Map<String,String> fileNameMap = getFileName(zykInfo);
|
||||
// if(!fileNameMap.get("code").equals("0")){
|
||||
// return fileNameMap;
|
||||
// }
|
||||
// //上传文件
|
||||
// Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,directory,fileNameMap.get("filePath"),fileNameMap.get("fileName"));
|
||||
// if(!uploadMap.get("code").equals("0")){
|
||||
// return uploadMap;
|
||||
// }
|
||||
// map.put("data",uploadMap.get("data"));
|
||||
// }
|
||||
//
|
||||
// if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
||||
// //源文件路径
|
||||
// Map<String,String> fileNameMap = getPdfName(zykInfo);
|
||||
// if(!fileNameMap.get("code").equals("0")){
|
||||
// return fileNameMap;
|
||||
// }
|
||||
// //上传文件
|
||||
// Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,directory,fileNameMap.get("filePath"),fileNameMap.get("pdfName"));
|
||||
// if(!uploadMap.get("code").equals("0")){
|
||||
// return uploadMap;
|
||||
// }
|
||||
// map.put("pdfData",uploadMap.get("data"));
|
||||
// }
|
||||
// return map;
|
||||
// }
|
||||
|
||||
public String[] getDirectoryAndFileName(String fileName) {
|
||||
String[] ss = new String[2];
|
||||
String path = fileName.substring(0,fileName.lastIndexOf("/"));
|
||||
String name = fileName.substring(fileName.lastIndexOf("/")+1);
|
||||
ss[0] = path;
|
||||
ss[1] = name;
|
||||
return ss;
|
||||
}
|
||||
|
||||
// public Map<String,String> download(String directory, String downloadFile){
|
||||
// return SFTPUtil.download(sftpConfig,directory,downloadFile,getDownloadPath("temp"));
|
||||
// }
|
||||
|
||||
public void downloadRes(String directory, String downloadFile,HttpServletResponse response) throws Exception{
|
||||
SFTPUtil.writeFileToRes(sftpConfig,downloadFile,response);
|
||||
}
|
||||
|
||||
public Map<String,String> move(ZykInfo zykInfo){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||
if(!directoryMap.get("code").equals("0")){
|
||||
return directoryMap;
|
||||
}
|
||||
//资源库文件路径
|
||||
String directory = directoryMap.get("directory");
|
||||
|
||||
String newname = "";
|
||||
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
||||
//源文件路径
|
||||
newname = getName(zykInfo,false);
|
||||
}
|
||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
||||
newname = getName(zykInfo,false);
|
||||
}
|
||||
return SFTPUtil.move(sftpConfig,zykInfo.getFileName(),directory,newname);
|
||||
}
|
||||
|
||||
public void delete(String directory, String downloadFile){
|
||||
SFTPUtil.delete(sftpConfig,directory,downloadFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源库文件路径
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
private Map<String,String> getDirectory(ZykInfo zykInfo){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if(StringUtils.isEmpty(zykInfo.getXqxn())){
|
||||
map.put("code","1");
|
||||
map.put("msg","学期学年不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getXqxn());
|
||||
sb.append("/");
|
||||
if(StringUtils.isEmpty(zykInfo.getKkdw())){
|
||||
map.put("code","1");
|
||||
map.put("msg","开课单位不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getKkdw());
|
||||
sb.append("/");
|
||||
if(StringUtils.isEmpty(zykInfo.getKcmc())){
|
||||
map.put("code","1");
|
||||
map.put("msg","课程名称不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getKcmc());
|
||||
sb.append("/");
|
||||
if(StringUtils.isEmpty(zykInfo.getSkjs())){
|
||||
map.put("code","1");
|
||||
map.put("msg","授课教师不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getSkjs());
|
||||
sb.append("/");
|
||||
if(StringUtils.isEmpty(zykInfo.getWjlx())){
|
||||
map.put("code","1");
|
||||
map.put("msg","文件类型不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getWjlx());
|
||||
sb.append("/");
|
||||
map.put("directory",sb.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径和新文件名称
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
// private Map<String,String> getFileName(ZykInfo zykInfo){
|
||||
// Map<String,String> map = new HashMap<String,String>();
|
||||
// map.put("code","0");
|
||||
// String uploadFileName = getRealFileFullPath(zykInfo.getFileName());
|
||||
// if(StringUtils.isEmpty(uploadFileName)){
|
||||
// map.put("code","1");
|
||||
// map.put("msg","文件路径不能为空!");
|
||||
// return map;
|
||||
// }
|
||||
// File file = new File(uploadFileName);
|
||||
// if(!file.exists()){
|
||||
// map.put("code","1");
|
||||
// map.put("msg","文件["+uploadFileName+"]不存在..");
|
||||
// return map;
|
||||
// }
|
||||
// map.put("filePath",uploadFileName);
|
||||
// String fileName = uploadFileName.substring(uploadFileName.lastIndexOf('/')+1, uploadFileName.indexOf("_"));
|
||||
// String suffix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
|
||||
// fileName = fileName + suffix;
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXDG.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_"+WjlxEnum.JXDG.getType()+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXRL.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_"+WjlxEnum.JXRL.getType()+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.KCLW.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_要求"+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.XSLW.getType())){
|
||||
//// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
//// String xh = StringUtils.nullToEmpty(zykInfo.getXh());
|
||||
//// String seq = StringUtils.nullToEmpty(zykInfo.getSeq());
|
||||
//// fileName = kcmc+"_"+xh+"_"+seq+"_"+fileName;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXDY.getType())){
|
||||
//// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
//// String chapter = StringUtils.nullToEmpty(zykInfo.getChapter());
|
||||
//// String section = StringUtils.nullToEmpty(zykInfo.getSection());
|
||||
//// fileName = kcmc+"_第"+chapter+"章_第"+section+"节"+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.QT.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_其他_"+fileName;
|
||||
//// }
|
||||
// map.put("fileName",fileName);
|
||||
// return map;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取文件名称
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
private String getName(ZykInfo zykInfo,boolean isPdf){
|
||||
String fileName = "";
|
||||
String uploadFileName = "";
|
||||
if(isPdf){
|
||||
uploadFileName = zykInfo.getPdfName();
|
||||
}else{
|
||||
uploadFileName = zykInfo.getFileName();
|
||||
}
|
||||
fileName = uploadFileName.substring(uploadFileName.lastIndexOf('/')+1, uploadFileName.indexOf("_"));
|
||||
String suffix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
|
||||
fileName = fileName + suffix;
|
||||
// if(zykInfo.getWjlx().equals(WjlxEnum.XSLW.getType())){
|
||||
// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
// String xh = StringUtils.nullToEmpty(zykInfo.getXh());
|
||||
// String seq = StringUtils.nullToEmpty(zykInfo.getSeq());
|
||||
// fileName = kcmc+"_"+xh+"_"+seq+"_"+fileName;
|
||||
// }
|
||||
// if(zykInfo.getWjlx().equals(WjlxEnum.JXDY.getType())){
|
||||
// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
// String chapter = StringUtils.nullToEmpty(zykInfo.getChapter());
|
||||
// String section = StringUtils.nullToEmpty(zykInfo.getSection());
|
||||
// fileName = kcmc+"_第"+chapter+"章_第"+section+"节"+suffix;
|
||||
// }
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径和新文件名称
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
// private Map<String,String> getPdfName(ZykInfo zykInfo){
|
||||
// Map<String,String> map = new HashMap<String,String>();
|
||||
// map.put("code","0");
|
||||
// String uploadFileName = getRealFileFullPath(zykInfo.getPdfName());
|
||||
// if(StringUtils.isEmpty(uploadFileName)){
|
||||
// map.put("code","1");
|
||||
// map.put("msg","文件路径不能为空!");
|
||||
// return map;
|
||||
// }
|
||||
// File file = new File(uploadFileName);
|
||||
// if(!file.exists()){
|
||||
// map.put("code","1");
|
||||
// map.put("msg","文件["+uploadFileName+"]不存在..");
|
||||
// return map;
|
||||
// }
|
||||
// map.put("filePath",uploadFileName);
|
||||
// String fileName = uploadFileName.substring(uploadFileName.lastIndexOf('/')+1, uploadFileName.indexOf("_"));
|
||||
// String suffix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
|
||||
// fileName = fileName + suffix;
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXDG.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_"+WjlxEnum.JXDG.getType()+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXRL.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_"+WjlxEnum.JXRL.getType()+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.KCLW.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_要求"+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.XSLW.getType())){
|
||||
//// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
//// String xh = StringUtils.nullToEmpty(zykInfo.getXh());
|
||||
//// String seq = StringUtils.nullToEmpty(zykInfo.getSeq());
|
||||
//// fileName = kcmc+"_"+xh+"_"+seq+"_"+fileName;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.JXDY.getType())){
|
||||
//// String kcmc = StringUtils.nullToEmpty(zykInfo.getKcmc());
|
||||
//// String chapter = StringUtils.nullToEmpty(zykInfo.getChapter());
|
||||
//// String section = StringUtils.nullToEmpty(zykInfo.getSection());
|
||||
//// fileName = kcmc+"_第"+chapter+"章_第"+section+"节"+suffix;
|
||||
//// }
|
||||
//// if(zykInfo.getWjlx().equals(WjlxEnum.QT.getType())){
|
||||
//// String kcmc = zykInfo.getKcmc();
|
||||
//// fileName = kcmc+"_其他_"+fileName;
|
||||
//// }
|
||||
// map.put("pdfName",fileName);
|
||||
// return map;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取文件真实路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private String getRealFileFullPath(String path){
|
||||
String filePath = "";
|
||||
if(StringUtils.isEmpty(path)){
|
||||
return "";
|
||||
}
|
||||
path = path.replace("\\", "/");
|
||||
int idx = path.indexOf(uploadpath);
|
||||
if(idx==-1){
|
||||
filePath = uploadpath + File.separator + path;
|
||||
}else{
|
||||
filePath = path;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件真实路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
// private String getDownloadPath(String path){
|
||||
// String filePath = "";
|
||||
// if(StringUtils.isEmpty(path)){
|
||||
// return "";
|
||||
// }
|
||||
// int idx = path.indexOf(downloadpath);
|
||||
// if(idx==-1){
|
||||
// filePath = downloadpath + File.separator + path;
|
||||
// }else{
|
||||
// filePath = path;
|
||||
// }
|
||||
// return filePath;
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.jeecg.modules.zyk.utils.util;
|
||||
package org.jeecg.modules.zyk.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
package org.jeecg.modules.zyk.utils.util;
|
||||
|
||||
import org.jeecg.modules.zyk.entity.ZykInfo;
|
||||
import org.jeecg.modules.zyk.utils.sftp.SFTPUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FileHandleUtil {
|
||||
|
||||
@Autowired
|
||||
private SFTPUtil sftpUtil;
|
||||
|
||||
@Value(value = "${jeecg.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
@Value(value = "${jeecg.path.webapp}")
|
||||
private String downloadpath;
|
||||
|
||||
public Map<String,String> uploadFile(ZykInfo zykInfo){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||
if(!directoryMap.get("code").equals("0")){
|
||||
return directoryMap;
|
||||
}
|
||||
//资源库文件路径
|
||||
String directory = directoryMap.get("directory");
|
||||
//源文件路径
|
||||
Map<String,String> fileNameMap = getFileName(zykInfo);
|
||||
if(!fileNameMap.get("code").equals("0")){
|
||||
return fileNameMap;
|
||||
}
|
||||
//上传文件
|
||||
Map<String,String> uploadMap = sftpUtil.upload(directory,fileNameMap.get("filePath"),fileNameMap.get("fileName"));
|
||||
if(!uploadMap.get("code").equals("0")){
|
||||
return uploadMap;
|
||||
}
|
||||
map.put("data",uploadMap.get("data"));
|
||||
return map;
|
||||
}
|
||||
|
||||
public String[] getDirectoryAndFileName(String fileName) {
|
||||
String[] ss = new String[2];
|
||||
String path = fileName.substring(0,fileName.lastIndexOf("/"));
|
||||
String name = fileName.substring(fileName.lastIndexOf("/")+1);
|
||||
ss[0] = path;
|
||||
ss[1] = name;
|
||||
return ss;
|
||||
}
|
||||
|
||||
public Map<String,String> download(String directory, String downloadFile){
|
||||
return sftpUtil.download(directory,downloadFile,getDownloadPath("temp"));
|
||||
}
|
||||
|
||||
public void downloadRes(String directory, String downloadFile,HttpServletResponse response) throws Exception{
|
||||
sftpUtil.writeFileToRes(directory,downloadFile,response);
|
||||
}
|
||||
|
||||
public void delete(String directory, String downloadFile){
|
||||
sftpUtil.delete(directory,downloadFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源库文件路径
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
private Map<String,String> getDirectory(ZykInfo zykInfo){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if(zykInfo.getXqxn()==null || zykInfo.getXqxn().equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","学期学年不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getXqxn());
|
||||
sb.append("/");
|
||||
if(zykInfo.getKkdw()==null || zykInfo.getKkdw().equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","开课单位不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getKkdw());
|
||||
sb.append("/");
|
||||
if(zykInfo.getKcmc()==null || zykInfo.getKcmc().equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","课程名称不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getKcmc());
|
||||
sb.append("/");
|
||||
if(zykInfo.getSkjs()==null || zykInfo.getSkjs().equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","授课教师不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getSkjs());
|
||||
sb.append("/");
|
||||
if(zykInfo.getWjlx()==null || zykInfo.getWjlx().equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","文件类型不能为空!");
|
||||
return map;
|
||||
}
|
||||
sb.append(zykInfo.getWjlx());
|
||||
sb.append("/");
|
||||
map.put("directory",sb.toString());
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件路径和新文件名称
|
||||
* @param zykInfo
|
||||
* @return
|
||||
*/
|
||||
private Map<String,String> getFileName(ZykInfo zykInfo){
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("code","0");
|
||||
String uploadFileName = getRealFileFullPath(zykInfo.getFileName());
|
||||
if(uploadFileName.equals("")){
|
||||
map.put("code","1");
|
||||
map.put("msg","文件路径不能为空!");
|
||||
return map;
|
||||
}
|
||||
File file = new File(uploadFileName);
|
||||
if(!file.exists()){
|
||||
map.put("code","1");
|
||||
map.put("msg","文件["+zykInfo.getFileName()+"]不存在..");
|
||||
return map;
|
||||
}
|
||||
map.put("filePath",uploadFileName);
|
||||
String fileName = uploadFileName.substring(uploadFileName.lastIndexOf('/')+1, uploadFileName.indexOf("_"));
|
||||
String suffix = uploadFileName.substring(uploadFileName.lastIndexOf("."));
|
||||
fileName = fileName + suffix;
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.JXDG.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
fileName = kcmc+"_"+WjlxEnum.JXDG.getType()+suffix;
|
||||
}
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.JXRL.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
fileName = kcmc+"_"+WjlxEnum.JXRL.getType()+suffix;
|
||||
}
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.KCLW.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
fileName = kcmc+"_要求"+suffix;
|
||||
}
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.XSLW.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
String xh = zykInfo.getXh();
|
||||
String seq = zykInfo.getSeq();
|
||||
fileName = kcmc+"_"+xh+"_"+seq+suffix;
|
||||
}
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.JXDY.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
String chapter = zykInfo.getChapter();
|
||||
String section = zykInfo.getSection();
|
||||
fileName = kcmc+"_第"+chapter+"章_第"+section+"节"+suffix;
|
||||
}
|
||||
if(zykInfo.getWjlx().equals(WjlxEnum.QT.getType())){
|
||||
String kcmc = zykInfo.getKcmc();
|
||||
fileName = kcmc+"_其他_"+fileName;
|
||||
}
|
||||
map.put("fileName",fileName);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件真实路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private String getRealFileFullPath(String path){
|
||||
String filePath = "";
|
||||
if(path==null || path.equals("")){
|
||||
return "";
|
||||
}
|
||||
path = path.replace("\\", "/");
|
||||
int idx = path.indexOf(uploadpath);
|
||||
if(idx==-1){
|
||||
filePath = uploadpath + File.separator + path;
|
||||
}else{
|
||||
filePath = path;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件真实路径
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
private String getDownloadPath(String path){
|
||||
String filePath = "";
|
||||
if(path==null || path.equals("")){
|
||||
return "";
|
||||
}
|
||||
int idx = path.indexOf(downloadpath);
|
||||
if(idx==-1){
|
||||
filePath = downloadpath + File.separator + path;
|
||||
}else{
|
||||
filePath = path;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
}
|
|
@ -7,11 +7,9 @@ import org.jeecg.common.api.vo.Result;
|
|||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.SymbolConstant;
|
||||
import org.jeecg.common.exception.JeecgBootException;
|
||||
import org.jeecg.common.util.CommonUtils;
|
||||
import org.jeecg.common.util.RestUtil;
|
||||
import org.jeecg.common.util.TokenUtils;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.common.util.filter.FileTypeFilter;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
@ -29,6 +27,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 前端控制器
|
||||
|
@ -51,6 +51,9 @@ public class CommonController {
|
|||
@Value(value="${jeecg.uploadType}")
|
||||
private String uploadType;
|
||||
|
||||
@Autowired
|
||||
SftpConfig sftpConfig;
|
||||
|
||||
/**
|
||||
* @Author 政辉
|
||||
* @return
|
||||
|
@ -111,6 +114,9 @@ public class CommonController {
|
|||
savePath = this.uploadLocal(file,bizPath);
|
||||
}
|
||||
*/
|
||||
}if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
|
||||
FileTypeFilter.fileTypeFilter(file);
|
||||
savePath = this.uploadSftp(file,bizPath);
|
||||
}else{
|
||||
//update-begin-author:taoyan date:20200814 for:文件上传改造
|
||||
savePath = CommonUtils.upload(file, bizPath, uploadType);
|
||||
|
@ -168,6 +174,18 @@ public class CommonController {
|
|||
return "";
|
||||
}
|
||||
|
||||
private String uploadSftp(MultipartFile mf,String bizPath){
|
||||
try {
|
||||
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,mf,bizPath);
|
||||
if(uploadMap.get("code").equals("0")){
|
||||
return uploadMap.get("data");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// @PostMapping(value = "/upload2")
|
||||
// public Result<?> upload2(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Result<?> result = new Result<>();
|
||||
|
@ -227,24 +245,28 @@ public class CommonController {
|
|||
if (imgPath.endsWith(SymbolConstant.COMMA)) {
|
||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||
}
|
||||
String filePath = uploadpath + File.separator + imgPath;
|
||||
File file = new File(filePath);
|
||||
if(!file.exists()){
|
||||
response.setStatus(404);
|
||||
throw new RuntimeException("文件["+imgPath+"]不存在..");
|
||||
if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
|
||||
SFTPUtil.writeFileToRes(sftpConfig,imgPath,response);
|
||||
}else {
|
||||
String filePath = uploadpath + File.separator + imgPath;
|
||||
File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
response.setStatus(404);
|
||||
throw new RuntimeException("文件[" + imgPath + "]不存在..");
|
||||
}
|
||||
// 设置强制下载不打开
|
||||
response.setContentType("application/force-download");
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"), "iso-8859-1"));
|
||||
inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
}
|
||||
// 设置强制下载不打开
|
||||
response.setContentType("application/force-download");
|
||||
response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1"));
|
||||
inputStream = new BufferedInputStream(new FileInputStream(filePath));
|
||||
outputStream = response.getOutputStream();
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
response.flushBuffer();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("预览文件失败" + e.getMessage());
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -177,6 +177,7 @@ jeecg:
|
|||
signUrls: /sys/dict/getDictItems/*,/sys/dict/loadDict/*,/sys/dict/loadDictOrderByValue/*,/sys/dict/loadDictItem/*,/sys/dict/loadTreeData,/sys/api/queryTableDictItemsByCode,/sys/api/queryFilterTableDictInfo,/sys/api/queryTableDictByKeys,/sys/api/translateDictFromTable,/sys/api/translateDictFromTableByKeys
|
||||
#local、minio、alioss
|
||||
uploadType: local
|
||||
# uploadType: sftp
|
||||
# 前端访问地址
|
||||
domainUrl:
|
||||
pc: http://localhost:3100
|
||||
|
@ -344,4 +345,5 @@ sftp:
|
|||
username: sftp
|
||||
password: sftp
|
||||
timeout: 1000
|
||||
uploadpath: /kczx
|
||||
uploadpath: /kczx
|
||||
fullpath: /home/sftp
|
|
@ -176,6 +176,7 @@ jeecg:
|
|||
signUrls: /sys/dict/getDictItems/*,/sys/dict/loadDict/*,/sys/dict/loadDictOrderByValue/*,/sys/dict/loadDictItem/*,/sys/dict/loadTreeData,/sys/api/queryTableDictItemsByCode,/sys/api/queryFilterTableDictInfo,/sys/api/queryTableDictByKeys,/sys/api/translateDictFromTable,/sys/api/translateDictFromTableByKeys
|
||||
#local\minio\alioss
|
||||
uploadType: local
|
||||
# uploadType: sftp
|
||||
# 前端访问地址
|
||||
domainUrl:
|
||||
pc: http://210.47.17.166
|
||||
|
@ -351,4 +352,5 @@ sftp:
|
|||
username: sftp
|
||||
password: sftp
|
||||
timeout: 1000
|
||||
uploadpath: /kczx
|
||||
uploadpath: /kczx
|
||||
fullpath: /home/sftp
|
Loading…
Reference in New Issue