分享接口联调
This commit is contained in:
parent
f3f157a1e0
commit
149a795abb
@ -0,0 +1,9 @@
|
|||||||
|
package com.qiwenshare.common.constant;
|
||||||
|
|
||||||
|
public class FileConstant {
|
||||||
|
/**
|
||||||
|
* 路径分隔符
|
||||||
|
*/
|
||||||
|
public static final String pathSeparator = "/";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.qiwenshare.common.exception;
|
||||||
|
|
||||||
|
public class NotLoginException extends RuntimeException{
|
||||||
|
public NotLoginException() {
|
||||||
|
super("未登录");
|
||||||
|
}
|
||||||
|
public NotLoginException(Throwable cause) {
|
||||||
|
super("未登录", cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotLoginException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotLoginException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.github.junrar.Archive;
|
|||||||
import com.github.junrar.rarfile.FileHeader;
|
import com.github.junrar.rarfile.FileHeader;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ import java.util.zip.ZipFile;
|
|||||||
/**
|
/**
|
||||||
* 文件操作
|
* 文件操作
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class FileOperation {
|
public class FileOperation {
|
||||||
private static Logger logger = LoggerFactory.getLogger(FileOperation.class);
|
private static Logger logger = LoggerFactory.getLogger(FileOperation.class);
|
||||||
|
|
||||||
@ -343,15 +345,15 @@ public class FileOperation {
|
|||||||
if (fos != null) {
|
if (fos != null) {
|
||||||
try {
|
try {
|
||||||
fos.close();
|
fos.close();
|
||||||
fos = null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("关闭流失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (archive != null) {
|
if (archive != null) {
|
||||||
try {
|
try {
|
||||||
archive.close();
|
archive.close();
|
||||||
archive = null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log.error("关闭流失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.common.operation.delete;
|
package com.qiwenshare.common.operation.delete;
|
||||||
|
|
||||||
import com.qiwenshare.common.domain.DeleteFile;
|
import com.qiwenshare.common.operation.delete.domain.DeleteFile;
|
||||||
|
|
||||||
public abstract class Deleter {
|
public abstract class Deleter {
|
||||||
public abstract void delete(DeleteFile deleteFile);
|
public abstract void delete(DeleteFile deleteFile);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.qiwenshare.common.domain;
|
package com.qiwenshare.common.operation.delete.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -4,7 +4,7 @@ import com.aliyun.oss.OSS;
|
|||||||
import com.aliyun.oss.OSSClientBuilder;
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||||
import com.qiwenshare.common.operation.delete.Deleter;
|
import com.qiwenshare.common.operation.delete.Deleter;
|
||||||
import com.qiwenshare.common.domain.DeleteFile;
|
import com.qiwenshare.common.operation.delete.domain.DeleteFile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -15,7 +15,6 @@ public class AliyunOSSDeleter extends Deleter {
|
|||||||
QiwenFileConfig qiwenFileConfig;
|
QiwenFileConfig qiwenFileConfig;
|
||||||
@Override
|
@Override
|
||||||
public void delete(DeleteFile deleteFile) {
|
public void delete(DeleteFile deleteFile) {
|
||||||
// AliyunOSSDelete.deleteObject(qiwenFileConfig.getAliyun().getOss(), deleteFile.getFileUrl().substring(1));
|
|
||||||
String endpoint = qiwenFileConfig.getAliyun().getOss().getEndpoint();
|
String endpoint = qiwenFileConfig.getAliyun().getOss().getEndpoint();
|
||||||
String accessKeyId = qiwenFileConfig.getAliyun().getOss().getAccessKeyId();
|
String accessKeyId = qiwenFileConfig.getAliyun().getOss().getAccessKeyId();
|
||||||
String accessKeySecret = qiwenFileConfig.getAliyun().getOss().getAccessKeySecret();
|
String accessKeySecret = qiwenFileConfig.getAliyun().getOss().getAccessKeySecret();
|
||||||
|
@ -2,7 +2,7 @@ package com.qiwenshare.common.operation.delete.product;
|
|||||||
|
|
||||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
import com.qiwenshare.common.operation.delete.Deleter;
|
import com.qiwenshare.common.operation.delete.Deleter;
|
||||||
import com.qiwenshare.common.domain.DeleteFile;
|
import com.qiwenshare.common.operation.delete.domain.DeleteFile;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.qiwenshare.common.operation.delete.product;
|
package com.qiwenshare.common.operation.delete.product;
|
||||||
|
|
||||||
import com.qiwenshare.common.operation.delete.Deleter;
|
import com.qiwenshare.common.operation.delete.Deleter;
|
||||||
import com.qiwenshare.common.domain.DeleteFile;
|
import com.qiwenshare.common.operation.delete.domain.DeleteFile;
|
||||||
import com.qiwenshare.common.operation.FileOperation;
|
import com.qiwenshare.common.operation.FileOperation;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.common.operation.download;
|
package com.qiwenshare.common.operation.download;
|
||||||
|
|
||||||
import com.qiwenshare.common.domain.DownloadFile;
|
import com.qiwenshare.common.operation.download.domain.DownloadFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.qiwenshare.common.domain;
|
package com.qiwenshare.common.operation.download.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -5,7 +5,7 @@ import com.aliyun.oss.OSSClientBuilder;
|
|||||||
import com.aliyun.oss.model.OSSObject;
|
import com.aliyun.oss.model.OSSObject;
|
||||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||||
import com.qiwenshare.common.domain.AliyunOSS;
|
import com.qiwenshare.common.domain.AliyunOSS;
|
||||||
import com.qiwenshare.common.domain.DownloadFile;
|
import com.qiwenshare.common.operation.download.domain.DownloadFile;
|
||||||
import com.qiwenshare.common.operation.download.Downloader;
|
import com.qiwenshare.common.operation.download.Downloader;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package com.qiwenshare.common.operation.download.product;
|
|||||||
|
|
||||||
import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
|
import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
|
||||||
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
||||||
import com.qiwenshare.common.domain.DownloadFile;
|
import com.qiwenshare.common.operation.download.domain.DownloadFile;
|
||||||
import com.qiwenshare.common.operation.download.Downloader;
|
import com.qiwenshare.common.operation.download.Downloader;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -33,8 +33,10 @@ public class FastDFSDownloader extends Downloader {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
outputStream.flush();
|
if (outputStream != null) {
|
||||||
outputStream.close();
|
outputStream.flush();
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.qiwenshare.common.operation.download.product;
|
package com.qiwenshare.common.operation.download.product;
|
||||||
|
|
||||||
import com.qiwenshare.common.domain.DownloadFile;
|
import com.qiwenshare.common.operation.download.domain.DownloadFile;
|
||||||
import com.qiwenshare.common.operation.FileOperation;
|
import com.qiwenshare.common.operation.FileOperation;
|
||||||
import com.qiwenshare.common.operation.download.Downloader;
|
import com.qiwenshare.common.operation.download.Downloader;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package com.qiwenshare.common.operation.upload;
|
package com.qiwenshare.common.operation.upload;
|
||||||
|
|
||||||
import com.qiwenshare.common.config.PropertiesUtil;
|
import com.qiwenshare.common.operation.upload.domain.UploadFile;
|
||||||
import com.qiwenshare.common.domain.UploadFile;
|
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -16,7 +14,6 @@ import java.security.SecureRandom;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class Uploader {
|
public abstract class Uploader {
|
||||||
@ -30,11 +27,11 @@ public abstract class Uploader {
|
|||||||
public abstract List<UploadFile> upload(HttpServletRequest request, UploadFile uploadFile);
|
public abstract List<UploadFile> upload(HttpServletRequest request, UploadFile uploadFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据字符串创建本地目录 并按照日期建立子目录返回
|
* 获取本地文件保存路径
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected String getSaveFilePath() {
|
protected String getLocalFileSavePath() {
|
||||||
|
|
||||||
String path = ROOT_PATH;
|
String path = ROOT_PATH;
|
||||||
SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
|
SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.qiwenshare.common.domain;
|
package com.qiwenshare.common.operation.upload.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -5,17 +5,14 @@ import com.aliyun.oss.OSS;
|
|||||||
import com.aliyun.oss.OSSClientBuilder;
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
import com.aliyun.oss.model.*;
|
import com.aliyun.oss.model.*;
|
||||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||||
import com.qiwenshare.common.domain.UploadFile;
|
import com.qiwenshare.common.operation.upload.domain.UploadFile;
|
||||||
import com.qiwenshare.common.exception.UploadGeneralException;
|
import com.qiwenshare.common.exception.UploadGeneralException;
|
||||||
import com.qiwenshare.common.operation.upload.Uploader;
|
import com.qiwenshare.common.operation.upload.Uploader;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||||
@ -23,11 +20,10 @@ import org.springframework.web.multipart.support.StandardMultipartHttpServletReq
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AliyunOSSUploader extends Uploader {
|
public class AliyunOSSUploader extends Uploader {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AliyunOSSUploader.class);
|
|
||||||
@Resource
|
@Resource
|
||||||
QiwenFileConfig qiwenFileConfig;
|
QiwenFileConfig qiwenFileConfig;
|
||||||
|
|
||||||
@ -40,7 +36,7 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UploadFile> upload(HttpServletRequest httpServletRequest, UploadFile uploadFile) {
|
public List<UploadFile> upload(HttpServletRequest httpServletRequest, UploadFile uploadFile) {
|
||||||
logger.info("开始上传upload");
|
log.info("开始上传upload");
|
||||||
|
|
||||||
List<UploadFile> saveUploadFileList = new ArrayList<>();
|
List<UploadFile> saveUploadFileList = new ArrayList<>();
|
||||||
StandardMultipartHttpServletRequest request = (StandardMultipartHttpServletRequest) httpServletRequest;
|
StandardMultipartHttpServletRequest request = (StandardMultipartHttpServletRequest) httpServletRequest;
|
||||||
@ -57,12 +53,12 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logger.info("结束上传");
|
log.info("结束上传");
|
||||||
return saveUploadFileList;
|
return saveUploadFileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UploadFile> doUpload(StandardMultipartHttpServletRequest standardMultipartHttpServletRequest, Iterator<String> iter, UploadFile uploadFile) {
|
private List<UploadFile> doUpload(StandardMultipartHttpServletRequest standardMultipartHttpServletRequest, Iterator<String> iter, UploadFile uploadFile) {
|
||||||
String savePath = getSaveFilePath();
|
String savePath = getLocalFileSavePath();
|
||||||
OSS ossClient = getClient(uploadFile);
|
OSS ossClient = getClient(uploadFile);
|
||||||
|
|
||||||
List<UploadFile> saveUploadFileList = new ArrayList<>();
|
List<UploadFile> saveUploadFileList = new ArrayList<>();
|
||||||
@ -105,11 +101,11 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
uploadPartRequest.setInputStream(multipartfile.getInputStream());
|
uploadPartRequest.setInputStream(multipartfile.getInputStream());
|
||||||
uploadPartRequest.setPartSize(uploadFile.getCurrentChunkSize());
|
uploadPartRequest.setPartSize(uploadFile.getCurrentChunkSize());
|
||||||
uploadPartRequest.setPartNumber(uploadFile.getChunkNumber());
|
uploadPartRequest.setPartNumber(uploadFile.getChunkNumber());
|
||||||
logger.info(JSON.toJSONString(uploadPartRequest));
|
log.info(JSON.toJSONString(uploadPartRequest));
|
||||||
|
|
||||||
UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
|
UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest);
|
||||||
synchronized (AliyunOSSUploader.class) {
|
synchronized (AliyunOSSUploader.class) {
|
||||||
logger.info("上传结果:" + JSON.toJSONString(uploadPartResult));
|
log.info("上传结果:" + JSON.toJSONString(uploadPartResult));
|
||||||
if (partETagsMap.get(uploadFile.getIdentifier()) == null) {
|
if (partETagsMap.get(uploadFile.getIdentifier()) == null) {
|
||||||
List<PartETag> partETags = new ArrayList<PartETag>();
|
List<PartETag> partETags = new ArrayList<PartETag>();
|
||||||
partETags.add(uploadPartResult.getPartETag());
|
partETags.add(uploadPartResult.getPartETag());
|
||||||
@ -121,7 +117,7 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
|
|
||||||
boolean isComplete = checkUploadStatus(uploadFile, confFile);
|
boolean isComplete = checkUploadStatus(uploadFile, confFile);
|
||||||
if (isComplete) {
|
if (isComplete) {
|
||||||
logger.info("分片上传完成");
|
log.info("分片上传完成");
|
||||||
completeMultipartUpload(uploadFile);
|
completeMultipartUpload(uploadFile);
|
||||||
|
|
||||||
uploadFile.setUrl("/" + uploadPartRequestMap.get(uploadFile.getIdentifier()).getKey());
|
uploadFile.setUrl("/" + uploadPartRequestMap.get(uploadFile.getIdentifier()).getKey());
|
||||||
@ -136,7 +132,7 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("上传出错:" + e);
|
log.error("上传出错:" + e);
|
||||||
throw new UploadGeneralException(e);
|
throw new UploadGeneralException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,10 +157,10 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
uploadFileInfo.getKey(),
|
uploadFileInfo.getKey(),
|
||||||
uploadFileInfo.getUploadId(),
|
uploadFileInfo.getUploadId(),
|
||||||
partETags);
|
partETags);
|
||||||
logger.info("----:" + JSON.toJSONString(partETags));
|
log.info("----:" + JSON.toJSONString(partETags));
|
||||||
// 完成上传。
|
// 完成上传。
|
||||||
CompleteMultipartUploadResult completeMultipartUploadResult = getClient(uploadFile).completeMultipartUpload(completeMultipartUploadRequest);
|
CompleteMultipartUploadResult completeMultipartUploadResult = getClient(uploadFile).completeMultipartUpload(completeMultipartUploadRequest);
|
||||||
logger.info("----:" + JSON.toJSONString(completeMultipartUploadRequest));
|
log.info("----:" + JSON.toJSONString(completeMultipartUploadRequest));
|
||||||
getClient(uploadFile).shutdown();
|
getClient(uploadFile).shutdown();
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -182,7 +178,7 @@ public class AliyunOSSUploader extends Uploader {
|
|||||||
PartListing partListing = getClient(uploadFile).listParts(listPartsRequest);
|
PartListing partListing = getClient(uploadFile).listParts(listPartsRequest);
|
||||||
|
|
||||||
for (PartSummary part : partListing.getParts()) {
|
for (PartSummary part : partListing.getParts()) {
|
||||||
logger.info("分片号:"+part.getPartNumber() + ", 分片数据大小: "+
|
log.info("分片号:"+part.getPartNumber() + ", 分片数据大小: "+
|
||||||
part.getSize() + ",分片的ETag:"+part.getETag()
|
part.getSize() + ",分片的ETag:"+part.getETag()
|
||||||
+ ", 分片最后修改时间:"+ part.getLastModified());
|
+ ", 分片最后修改时间:"+ part.getLastModified());
|
||||||
// 获取分片号。
|
// 获取分片号。
|
||||||
|
@ -2,7 +2,7 @@ package com.qiwenshare.common.operation.upload.product;
|
|||||||
|
|
||||||
import com.github.tobato.fastdfs.domain.StorePath;
|
import com.github.tobato.fastdfs.domain.StorePath;
|
||||||
import com.github.tobato.fastdfs.service.AppendFileStorageClient;
|
import com.github.tobato.fastdfs.service.AppendFileStorageClient;
|
||||||
import com.qiwenshare.common.domain.UploadFile;
|
import com.qiwenshare.common.operation.upload.domain.UploadFile;
|
||||||
import com.qiwenshare.common.exception.UploadGeneralException;
|
import com.qiwenshare.common.exception.UploadGeneralException;
|
||||||
import com.qiwenshare.common.operation.upload.Uploader;
|
import com.qiwenshare.common.operation.upload.Uploader;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
@ -42,7 +42,7 @@ public class FastDFSUploader extends Uploader {
|
|||||||
throw new UploadGeneralException("未包含文件上传域");
|
throw new UploadGeneralException("未包含文件上传域");
|
||||||
}
|
}
|
||||||
DiskFileItemFactory dff = new DiskFileItemFactory();//1、创建工厂
|
DiskFileItemFactory dff = new DiskFileItemFactory();//1、创建工厂
|
||||||
String savePath = getSaveFilePath();
|
String savePath = getLocalFileSavePath();
|
||||||
dff.setRepository(new File(savePath));
|
dff.setRepository(new File(savePath));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package com.qiwenshare.common.operation.upload.product;
|
package com.qiwenshare.common.operation.upload.product;
|
||||||
|
|
||||||
import com.qiwenshare.common.exception.NotSameFileExpection;
|
import com.qiwenshare.common.exception.NotSameFileExpection;
|
||||||
import com.qiwenshare.common.domain.UploadFile;
|
import com.qiwenshare.common.operation.upload.domain.UploadFile;
|
||||||
import com.qiwenshare.common.exception.UploadGeneralException;
|
import com.qiwenshare.common.exception.UploadGeneralException;
|
||||||
import com.qiwenshare.common.operation.ImageOperation;
|
import com.qiwenshare.common.operation.ImageOperation;
|
||||||
import com.qiwenshare.common.operation.upload.Uploader;
|
import com.qiwenshare.common.operation.upload.Uploader;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
||||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -27,16 +26,6 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@Component
|
@Component
|
||||||
public class LocalStorageUploader extends Uploader {
|
public class LocalStorageUploader extends Uploader {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LocalStorageUploader.class);
|
|
||||||
// private UploadFile uploadFile;
|
|
||||||
|
|
||||||
public LocalStorageUploader() {
|
|
||||||
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// public ChunkUploader(UploadFile uploadFile) {
|
|
||||||
// this.uploadFile = uploadFile;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UploadFile> upload(HttpServletRequest httpServletRequest,UploadFile uploadFile) {
|
public List<UploadFile> upload(HttpServletRequest httpServletRequest,UploadFile uploadFile) {
|
||||||
@ -46,17 +35,12 @@ public class LocalStorageUploader extends Uploader {
|
|||||||
if (!isMultipart) {
|
if (!isMultipart) {
|
||||||
throw new UploadGeneralException("未包含文件上传域");
|
throw new UploadGeneralException("未包含文件上传域");
|
||||||
}
|
}
|
||||||
//DiskFileItemFactory dff = new DiskFileItemFactory();//1、创建工厂
|
|
||||||
String savePath = getSaveFilePath();
|
|
||||||
//dff.setRepository(new File(savePath));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//ServletFileUpload sfu = new ServletFileUpload(dff);//2、创建文件上传解析器
|
|
||||||
//sfu.setSizeMax(this.maxSize * 1024L);
|
|
||||||
// sfu.setHeaderEncoding("utf-8");//3、解决文件名的中文乱码
|
|
||||||
Iterator<String> iter = standardMultipartHttpServletRequest.getFileNames();
|
Iterator<String> iter = standardMultipartHttpServletRequest.getFileNames();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
saveUploadFileList = doUpload(standardMultipartHttpServletRequest, savePath, iter, uploadFile);
|
saveUploadFileList = doUpload(standardMultipartHttpServletRequest, iter, uploadFile);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new UploadGeneralException("未包含文件上传域");
|
throw new UploadGeneralException("未包含文件上传域");
|
||||||
@ -66,7 +50,8 @@ public class LocalStorageUploader extends Uploader {
|
|||||||
return saveUploadFileList;
|
return saveUploadFileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UploadFile> doUpload(StandardMultipartHttpServletRequest standardMultipartHttpServletRequest, String savePath, Iterator<String> iter, UploadFile uploadFile) throws IOException, NotSameFileExpection {
|
private List<UploadFile> doUpload(StandardMultipartHttpServletRequest standardMultipartHttpServletRequest, Iterator<String> iter, UploadFile uploadFile) throws IOException, NotSameFileExpection {
|
||||||
|
String savePath = getLocalFileSavePath();
|
||||||
List<UploadFile> saveUploadFileList = new ArrayList<UploadFile>();
|
List<UploadFile> saveUploadFileList = new ArrayList<UploadFile>();
|
||||||
MultipartFile multipartfile = standardMultipartHttpServletRequest.getFile(iter.next());
|
MultipartFile multipartfile = standardMultipartHttpServletRequest.getFile(iter.next());
|
||||||
|
|
||||||
@ -92,7 +77,7 @@ public class LocalStorageUploader extends Uploader {
|
|||||||
uploadFile.setStorageType(0);
|
uploadFile.setStorageType(0);
|
||||||
uploadFile.setUrl(saveFilePath);
|
uploadFile.setUrl(saveFilePath);
|
||||||
|
|
||||||
if (StringUtils.isEmpty(uploadFile.getTaskId())) {// == null || "".equals(uploadFile.getTaskId())) {
|
if (StringUtils.isEmpty(uploadFile.getTaskId())) {
|
||||||
uploadFile.setTaskId(UUID.randomUUID().toString());
|
uploadFile.setTaskId(UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,136 +0,0 @@
|
|||||||
//package com.qiwenshare.common.upload.product;
|
|
||||||
//
|
|
||||||
//import com.qiwenshare.common.domain.UploadFile;
|
|
||||||
//import com.qiwenshare.common.operation.ImageOperation;
|
|
||||||
//import com.qiwenshare.common.upload.Uploader;
|
|
||||||
//import com.qiwenshare.common.util.FileUtil;
|
|
||||||
//import com.qiwenshare.common.util.PathUtil;
|
|
||||||
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
||||||
//import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
||||||
//import org.apache.commons.fileupload.util.Streams;
|
|
||||||
//import org.apache.commons.lang3.StringUtils;
|
|
||||||
//import org.slf4j.Logger;
|
|
||||||
//import org.slf4j.LoggerFactory;
|
|
||||||
//import org.springframework.web.multipart.MultipartFile;
|
|
||||||
//import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
|
||||||
//
|
|
||||||
//import javax.servlet.http.HttpServletRequest;
|
|
||||||
//import java.io.*;
|
|
||||||
//import java.util.ArrayList;
|
|
||||||
//import java.util.Iterator;
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
//public class NormalUploader extends Uploader {
|
|
||||||
// private static final Logger logger = LoggerFactory.getLogger(NormalUploader.class);
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public List<UploadFile> upload(HttpServletRequest httpServletRequest) {
|
|
||||||
// List<UploadFile> saveUploadFileList = new ArrayList<UploadFile>();
|
|
||||||
// this.request = (StandardMultipartHttpServletRequest) httpServletRequest;
|
|
||||||
// boolean isMultipart = ServletFileUpload.isMultipartContent(this.request);
|
|
||||||
// if (!isMultipart) {
|
|
||||||
// UploadFile uploadFile = new UploadFile();
|
|
||||||
// uploadFile.setSuccess(0);
|
|
||||||
// uploadFile.setMessage("未包含文件上传域");
|
|
||||||
// saveUploadFileList.add(uploadFile);
|
|
||||||
// return saveUploadFileList;
|
|
||||||
// }
|
|
||||||
// DiskFileItemFactory dff = new DiskFileItemFactory();//1、创建工厂
|
|
||||||
// String savePath = getSaveFilePath();
|
|
||||||
// dff.setRepository(new File(savePath));
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// ServletFileUpload sfu = new ServletFileUpload(dff);//2、创建文件上传解析器
|
|
||||||
// sfu.setSizeMax(this.maxSize * 1024L);
|
|
||||||
// sfu.setHeaderEncoding("utf-8");//3、解决文件名的中文乱码
|
|
||||||
// Iterator<String> iter = this.request.getFileNames();
|
|
||||||
// while (iter.hasNext()) {
|
|
||||||
// saveUploadFileList = doUpload(savePath, iter);
|
|
||||||
// }
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// UploadFile uploadFile = new UploadFile();
|
|
||||||
// uploadFile.setSuccess(1);
|
|
||||||
// uploadFile.setMessage("未知错误");
|
|
||||||
// saveUploadFileList.add(uploadFile);
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return saveUploadFileList;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private List<UploadFile> doUpload(String savePath, Iterator<String> iter) throws IOException {
|
|
||||||
// List<UploadFile> saveUploadFileList = new ArrayList<UploadFile>();
|
|
||||||
// UploadFile uploadFile = new UploadFile();
|
|
||||||
// MultipartFile multipartfile = this.request.getFile(iter.next());
|
|
||||||
//
|
|
||||||
// InputStream inputStream = multipartfile.getInputStream();
|
|
||||||
// String timeStampName = getTimeStampName();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// String originalName = multipartfile.getOriginalFilename();
|
|
||||||
//
|
|
||||||
// String fileName = getFileName(originalName);
|
|
||||||
//
|
|
||||||
// String fileType = FileUtil.getFileExtendName(originalName);
|
|
||||||
// uploadFile.setFileName(fileName);
|
|
||||||
// uploadFile.setFileType(fileType);
|
|
||||||
// uploadFile.setTimeStampName(timeStampName);
|
|
||||||
//
|
|
||||||
// String saveFilePath = savePath + FILE_SEPARATOR + timeStampName;
|
|
||||||
// String minFilePath = savePath + FILE_SEPARATOR + timeStampName;
|
|
||||||
// if (StringUtils.isNotEmpty(fileType)) {
|
|
||||||
// saveFilePath += "." + fileType;
|
|
||||||
// minFilePath += "_min" + "." + fileType;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// File file = new File(PathUtil.getStaticPath() + FILE_SEPARATOR + saveFilePath);
|
|
||||||
// File minFile = new File(PathUtil.getStaticPath() + FILE_SEPARATOR + minFilePath);
|
|
||||||
//
|
|
||||||
// uploadFile.setIsOSS(0);
|
|
||||||
// uploadFile.setStorageType(0);
|
|
||||||
// uploadFile.setUrl(saveFilePath);
|
|
||||||
// BufferedInputStream in = null;
|
|
||||||
// FileOutputStream out = null;
|
|
||||||
// BufferedOutputStream output = null;
|
|
||||||
//
|
|
||||||
// try {
|
|
||||||
// in = new BufferedInputStream(inputStream);
|
|
||||||
// out = new FileOutputStream(file);
|
|
||||||
// output = new BufferedOutputStream(out);
|
|
||||||
// Streams.copy(in, output, true);
|
|
||||||
// if (FileUtil.isImageFile(uploadFile.getFileType())){
|
|
||||||
// ImageOperation.thumbnailsImage(file, minFile, 300);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } catch (FileNotFoundException e) {
|
|
||||||
// logger.error("文件没有发现" + e);
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// logger.error("文件读取失败" + e);
|
|
||||||
// } finally {
|
|
||||||
//
|
|
||||||
// closeStream(in, out, output);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// uploadFile.setSuccess(1);
|
|
||||||
// uploadFile.setMessage("上传成功");
|
|
||||||
// uploadFile.setFileSize(request.getContentLengthLong());
|
|
||||||
// saveUploadFileList.add(uploadFile);
|
|
||||||
// return saveUploadFileList;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// private void closeStream(BufferedInputStream in, FileOutputStream out,
|
|
||||||
// BufferedOutputStream output) throws IOException {
|
|
||||||
// if (in != null) {
|
|
||||||
// in.close();
|
|
||||||
// }
|
|
||||||
// if (out != null) {
|
|
||||||
// out.close();
|
|
||||||
// }
|
|
||||||
// if (output != null) {
|
|
||||||
// output.close();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -13,6 +13,7 @@ public enum ResultCodeEnum {
|
|||||||
NULL_POINT(false, 20003, "空指针异常"),
|
NULL_POINT(false, 20003, "空指针异常"),
|
||||||
INDEX_OUT_OF_BOUNDS(false, 20004, "下标越界异常"),
|
INDEX_OUT_OF_BOUNDS(false, 20004, "下标越界异常"),
|
||||||
REQUEST_TIMEOUT(false, 20005, "请求超时"),
|
REQUEST_TIMEOUT(false, 20005, "请求超时"),
|
||||||
|
NOT_LOGIN_ERROR(false, 20006, "未登录异常"),
|
||||||
;
|
;
|
||||||
|
|
||||||
// 响应是否成功
|
// 响应是否成功
|
||||||
|
@ -76,7 +76,6 @@ public class FileUtil {
|
|||||||
public static String getFileExtendName(String fileName) {
|
public static String getFileExtendName(String fileName) {
|
||||||
if (fileName.lastIndexOf(".") == -1) {
|
if (fileName.lastIndexOf(".") == -1) {
|
||||||
return "";
|
return "";
|
||||||
//这里暂时用jpg,后续应该去获取真实的文件类型
|
|
||||||
}
|
}
|
||||||
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
return fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||||
}
|
}
|
||||||
|
@ -66,25 +66,6 @@ public class PathUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 依据原始文件名生成新文件名
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String getFileName(String fileName) {
|
|
||||||
String getfileName = "";
|
|
||||||
try {
|
|
||||||
SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
|
|
||||||
return getfileName = "" + number.nextInt(10000)
|
|
||||||
+ System.currentTimeMillis() + getFileExt(fileName);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
//LOG.error("生成安全随机数失败");
|
|
||||||
}
|
|
||||||
return getfileName = ""
|
|
||||||
+ System.currentTimeMillis() + getFileExt(fileName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件扩展名
|
* 获取文件扩展名
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.qiwenshare.file.advice;
|
package com.qiwenshare.file.advice;
|
||||||
|
|
||||||
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.result.ResultCodeEnum;
|
import com.qiwenshare.common.result.ResultCodeEnum;
|
||||||
import com.qiwenshare.common.exception.UploadGeneralException;
|
import com.qiwenshare.common.exception.UploadGeneralException;
|
||||||
@ -58,6 +59,16 @@ public class GlobalExceptionHandlerAdvice {
|
|||||||
return RestResult.setResult(ResultCodeEnum.REQUEST_TIMEOUT);
|
return RestResult.setResult(ResultCodeEnum.REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(NotLoginException.class)
|
||||||
|
@ResponseBody
|
||||||
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||||
|
public RestResult error(NotLoginException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("全局异常捕获:" + e);
|
||||||
|
return RestResult.setResult(ResultCodeEnum.NOT_LOGIN_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**-------- 自定义定异常处理方法 --------**/
|
/**-------- 自定义定异常处理方法 --------**/
|
||||||
@ExceptionHandler(CMSException.class)
|
@ExceptionHandler(CMSException.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ -7,6 +7,7 @@ import com.aliyun.oss.model.CopyObjectResult;
|
|||||||
import com.aliyun.oss.model.ObjectMetadata;
|
import com.aliyun.oss.model.ObjectMetadata;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.domain.AliyunOSS;
|
import com.qiwenshare.common.domain.AliyunOSS;
|
||||||
@ -82,7 +83,9 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId());
|
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||||
if (userFiles != null && !userFiles.isEmpty()) {
|
if (userFiles != null && !userFiles.isEmpty()) {
|
||||||
return RestResult.fail().message("同名文件已存在");
|
return RestResult.fail().message("同名文件已存在");
|
||||||
@ -146,13 +149,16 @@ public class FileController {
|
|||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
UserFile userFile = userFileService.getById(renameFileDto.getUserFileId());
|
UserFile userFile = userFileService.getById(renameFileDto.getUserFileId());
|
||||||
|
|
||||||
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), renameFileDto.getFilePath(), sessionUserBean.getUserId());
|
List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), renameFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||||
if (userFiles != null && !userFiles.isEmpty()) {
|
if (userFiles != null && !userFiles.isEmpty()) {
|
||||||
return RestResult.fail().message("同名文件已存在");
|
return RestResult.fail().message("同名文件已存在");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 == userFile.getIsDir()) {
|
if (1 == userFile.getIsDir()) {
|
||||||
LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName())
|
lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName())
|
||||||
@ -228,6 +234,9 @@ public class FileController {
|
|||||||
userFile.setUserId(2L);
|
userFile.setUserId(2L);
|
||||||
}else {
|
}else {
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
if (userFile == null) {
|
if (userFile == null) {
|
||||||
return RestResult.fail();
|
return RestResult.fail();
|
||||||
|
|
||||||
@ -271,6 +280,9 @@ public class FileController {
|
|||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
List<UserFile> userFiles = JSON.parseArray(batchDeleteFileDto.getFiles(), UserFile.class);
|
List<UserFile> userFiles = JSON.parseArray(batchDeleteFileDto.getFiles(), UserFile.class);
|
||||||
DigestUtils.md5Hex("data");
|
DigestUtils.md5Hex("data");
|
||||||
for (UserFile userFile : userFiles) {
|
for (UserFile userFile : userFiles) {
|
||||||
@ -293,7 +305,9 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
userFileService.deleteUserFile(deleteFileDto.getUserFileId(), sessionUserBean.getUserId());
|
userFileService.deleteUserFile(deleteFileDto.getUserFileId(), sessionUserBean.getUserId());
|
||||||
|
|
||||||
|
|
||||||
@ -310,7 +324,10 @@ public class FileController {
|
|||||||
if (!operationCheck(token).getSuccess()){
|
if (!operationCheck(token).getSuccess()){
|
||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
String zipFileUrl = PathUtil.getStaticPath() + unzipFileDto.getFileUrl();
|
String zipFileUrl = PathUtil.getStaticPath() + unzipFileDto.getFileUrl();
|
||||||
File file = FileOperation.newFile(zipFileUrl);
|
File file = FileOperation.newFile(zipFileUrl);
|
||||||
String unzipUrl = file.getParent();
|
String unzipUrl = file.getParent();
|
||||||
@ -336,7 +353,7 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<FileBean> fileBeanList = new ArrayList<>();
|
List<FileBean> fileBeanList = new ArrayList<>();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
|
||||||
log.info("解压缩文件数量:" + fileBeanList);
|
log.info("解压缩文件数量:" + fileBeanList);
|
||||||
|
|
||||||
for (int i = 0; i < fileEntryNameList.size(); i++){
|
for (int i = 0; i < fileEntryNameList.size(); i++){
|
||||||
@ -376,10 +393,7 @@ public class FileController {
|
|||||||
userFileService.save(userFile);
|
userFileService.save(userFile);
|
||||||
});
|
});
|
||||||
|
|
||||||
//fileBeanList.add(tempFileBean);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileService.batchInsertFile(fileBeanList, sessionUserBean.getUserId());
|
|
||||||
return RestResult.success();
|
return RestResult.success();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -396,6 +410,9 @@ public class FileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
String oldfilePath = moveFileDto.getOldFilePath();
|
String oldfilePath = moveFileDto.getOldFilePath();
|
||||||
String newfilePath = moveFileDto.getFilePath();
|
String newfilePath = moveFileDto.getFilePath();
|
||||||
String fileName = moveFileDto.getFileName();
|
String fileName = moveFileDto.getFileName();
|
||||||
@ -416,7 +433,9 @@ public class FileController {
|
|||||||
return operationCheck(token);
|
return operationCheck(token);
|
||||||
}
|
}
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
String files = batchMoveFileDto.getFiles();
|
String files = batchMoveFileDto.getFiles();
|
||||||
String newfilePath = batchMoveFileDto.getFilePath();
|
String newfilePath = batchMoveFileDto.getFilePath();
|
||||||
|
|
||||||
@ -455,6 +474,9 @@ public class FileController {
|
|||||||
public RestResult<List<Map<String, Object>>> selectFileByFileType(int fileType, Long currentPage, Long pageCount, @RequestHeader("token") String token) {
|
public RestResult<List<Map<String, Object>>> selectFileByFileType(int fileType, Long currentPage, Long pageCount, @RequestHeader("token") String token) {
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
long userId = sessionUserBean.getUserId();
|
long userId = sessionUserBean.getUserId();
|
||||||
if (qiwenFileConfig.isShareMode()){
|
if (qiwenFileConfig.isShareMode()){
|
||||||
userId = 2;
|
userId = 2;
|
||||||
@ -494,10 +516,13 @@ public class FileController {
|
|||||||
@Operation(summary = "获取文件树", description = "文件移动的时候需要用到该接口,用来展示目录树", tags = {"file"})
|
@Operation(summary = "获取文件树", description = "文件移动的时候需要用到该接口,用来展示目录树", tags = {"file"})
|
||||||
@RequestMapping(value = "/getfiletree", method = RequestMethod.GET)
|
@RequestMapping(value = "/getfiletree", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<TreeNode> getFileTree(@RequestHeader("token") String token){
|
public RestResult<TreeNode> getFileTree(@RequestHeader("token") String token) {
|
||||||
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
RestResult<TreeNode> result = new RestResult<TreeNode>();
|
||||||
UserFile userFile = new UserFile();
|
UserFile userFile = new UserFile();
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
if (qiwenFileConfig.isShareMode()){
|
if (qiwenFileConfig.isShareMode()){
|
||||||
userFile.setUserId(2L);
|
userFile.setUserId(2L);
|
||||||
}else{
|
}else{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.qiwenshare.file.controller;
|
package com.qiwenshare.file.controller;
|
||||||
|
|
||||||
import com.qiwenshare.common.config.QiwenFileConfig;
|
import com.qiwenshare.common.config.QiwenFileConfig;
|
||||||
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
import com.qiwenshare.common.util.FileUtil;
|
import com.qiwenshare.common.util.FileUtil;
|
||||||
@ -56,10 +57,10 @@ public class FiletransferController {
|
|||||||
public RestResult<UploadFileVo> uploadFileSpeed(UploadFileDTO uploadFileDto, @RequestHeader("token") String token) {
|
public RestResult<UploadFileVo> uploadFileSpeed(UploadFileDTO uploadFileDto, @RequestHeader("token") String token) {
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
if (sessionUserBean == null){
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
return RestResult.fail().message("未登录");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RestResult<String> operationCheckResult = fileController.operationCheck(token);
|
RestResult<String> operationCheckResult = fileController.operationCheck(token);
|
||||||
if (!operationCheckResult.getSuccess()){
|
if (!operationCheckResult.getSuccess()){
|
||||||
return RestResult.fail().message("没权限,请联系管理员!");
|
return RestResult.fail().message("没权限,请联系管理员!");
|
||||||
@ -108,8 +109,8 @@ public class FiletransferController {
|
|||||||
public RestResult<UploadFileVo> uploadFile(HttpServletRequest request, UploadFileDTO uploadFileDto, @RequestHeader("token") String token) {
|
public RestResult<UploadFileVo> uploadFile(HttpServletRequest request, UploadFileDTO uploadFileDto, @RequestHeader("token") String token) {
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
if (sessionUserBean == null){
|
if (sessionUserBean == null) {
|
||||||
return RestResult.fail().message("未登录");
|
throw new NotLoginException();
|
||||||
}
|
}
|
||||||
RestResult<String> operationCheckResult = fileController.operationCheck(token);
|
RestResult<String> operationCheckResult = fileController.operationCheck(token);
|
||||||
if (!operationCheckResult.getSuccess()){
|
if (!operationCheckResult.getSuccess()){
|
||||||
@ -141,6 +142,9 @@ public class FiletransferController {
|
|||||||
public RestResult<StorageBean> getStorage(@RequestHeader("token") String token) {
|
public RestResult<StorageBean> getStorage(@RequestHeader("token") String token) {
|
||||||
|
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
StorageBean storageBean = new StorageBean();
|
StorageBean storageBean = new StorageBean();
|
||||||
if (qiwenFileConfig.isShareMode()){
|
if (qiwenFileConfig.isShareMode()){
|
||||||
storageBean.setUserId(2L);
|
storageBean.setUserId(2L);
|
||||||
|
@ -3,6 +3,7 @@ package com.qiwenshare.file.controller;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.qiwenshare.common.exception.NotLoginException;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
import com.qiwenshare.common.result.RestResult;
|
import com.qiwenshare.common.result.RestResult;
|
||||||
import com.qiwenshare.common.util.PathUtil;
|
import com.qiwenshare.common.util.PathUtil;
|
||||||
@ -43,6 +44,10 @@ public class RecoveryFileController {
|
|||||||
@RequestMapping(value = "/deleterecoveryfile", method = RequestMethod.POST)
|
@RequestMapping(value = "/deleterecoveryfile", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> deleteRecoveryFile(@RequestBody DeleteRecoveryFileDTO deleteRecoveryFileDTO, @RequestHeader("token") String token) {
|
public RestResult<String> deleteRecoveryFile(@RequestBody DeleteRecoveryFileDTO deleteRecoveryFileDTO, @RequestHeader("token") String token) {
|
||||||
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
|
|
||||||
RecoveryFile recoveryFile = recoveryFileService.getById(deleteRecoveryFileDTO.getRecoveryFileId());
|
RecoveryFile recoveryFile = recoveryFileService.getById(deleteRecoveryFileDTO.getRecoveryFileId());
|
||||||
UserFile userFile =userFileService.getById(recoveryFile.getUserFileId());
|
UserFile userFile =userFileService.getById(recoveryFile.getUserFileId());
|
||||||
@ -58,7 +63,10 @@ public class RecoveryFileController {
|
|||||||
@MyLog(operation = "批量删除回收文件", module = CURRENT_MODULE)
|
@MyLog(operation = "批量删除回收文件", module = CURRENT_MODULE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> batchDeleteRecoveryFile(@RequestBody BatchDeleteRecoveryFileDTO batchDeleteRecoveryFileDTO, @RequestHeader("token") String token) {
|
public RestResult<String> batchDeleteRecoveryFile(@RequestBody BatchDeleteRecoveryFileDTO batchDeleteRecoveryFileDTO, @RequestHeader("token") String token) {
|
||||||
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
List<RecoveryFile> recoveryFileList = JSON.parseArray(batchDeleteRecoveryFileDTO.getRecoveryFileIds(), RecoveryFile.class);
|
List<RecoveryFile> recoveryFileList = JSON.parseArray(batchDeleteRecoveryFileDTO.getRecoveryFileIds(), RecoveryFile.class);
|
||||||
for (RecoveryFile recoveryFile : recoveryFileList) {
|
for (RecoveryFile recoveryFile : recoveryFileList) {
|
||||||
|
|
||||||
@ -75,6 +83,10 @@ public class RecoveryFileController {
|
|||||||
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<List<RecoveryFileListVo>> getRecoveryFileList(@RequestHeader("token") String token) {
|
public RestResult<List<RecoveryFileListVo>> getRecoveryFileList(@RequestHeader("token") String token) {
|
||||||
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
RestResult<List<RecoveryFileListVo>> restResult = new RestResult<List<RecoveryFileListVo>>();
|
RestResult<List<RecoveryFileListVo>> restResult = new RestResult<List<RecoveryFileListVo>>();
|
||||||
List<RecoveryFileListVo> recoveryFileList = recoveryFileService.selectRecoveryFileList();
|
List<RecoveryFileListVo> recoveryFileList = recoveryFileService.selectRecoveryFileList();
|
||||||
restResult.setData(recoveryFileList);
|
restResult.setData(recoveryFileList);
|
||||||
@ -89,6 +101,9 @@ public class RecoveryFileController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult restoreFile(@RequestBody RestoreFileDTO restoreFileDto, @RequestHeader("token") String token) {
|
public RestResult restoreFile(@RequestBody RestoreFileDTO restoreFileDto, @RequestHeader("token") String token) {
|
||||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||||
|
if (sessionUserBean == null) {
|
||||||
|
throw new NotLoginException();
|
||||||
|
}
|
||||||
recoveryFileService.restorefile(restoreFileDto.getDeleteBatchNum(), restoreFileDto.getFilePath(), sessionUserBean.getUserId());
|
recoveryFileService.restorefile(restoreFileDto.getDeleteBatchNum(), restoreFileDto.getFilePath(), sessionUserBean.getUserId());
|
||||||
return RestResult.success().message("还原成功!");
|
return RestResult.success().message("还原成功!");
|
||||||
}
|
}
|
||||||
|
@ -71,18 +71,23 @@ public class ShareController {
|
|||||||
List<ShareFile> saveFileList = new ArrayList<>();
|
List<ShareFile> saveFileList = new ArrayList<>();
|
||||||
for (ShareFile shareFile : fileList) {
|
for (ShareFile shareFile : fileList) {
|
||||||
UserFile userFile = userFileService.getById(shareFile.getUserFileId());
|
UserFile userFile = userFileService.getById(shareFile.getUserFileId());
|
||||||
|
if (userFile.getUserId() != sessionUserBean.getUserId()) {
|
||||||
|
return RestResult.fail().message("您只能分享自己的文件");
|
||||||
|
}
|
||||||
if (userFile.getIsDir() == 1) {
|
if (userFile.getIsDir() == 1) {
|
||||||
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath(), sessionUserBean.getUserId());
|
List<UserFile> userfileList = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
|
||||||
for (UserFile userFile1 : userfileList) {
|
for (UserFile userFile1 : userfileList) {
|
||||||
ShareFile shareFile1 = new ShareFile();
|
ShareFile shareFile1 = new ShareFile();
|
||||||
shareFile1.setUserFileId(userFile1.getUserFileId());
|
shareFile1.setUserFileId(userFile1.getUserFileId());
|
||||||
shareFile1.setShareBatchNum(uuid);
|
shareFile1.setShareBatchNum(uuid);
|
||||||
|
shareFile1.setShareFilePath(userFile1.getFilePath().replaceFirst(userFile.getFilePath(), "/"));
|
||||||
saveFileList.add(shareFile1);
|
saveFileList.add(shareFile1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
shareFile.setShareBatchNum(uuid);
|
|
||||||
saveFileList.add(shareFile);
|
|
||||||
}
|
}
|
||||||
|
shareFile.setShareFilePath("/");
|
||||||
|
shareFile.setShareBatchNum(uuid);
|
||||||
|
saveFileList.add(shareFile);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
shareService.batchInsertShareFile(saveFileList);
|
shareService.batchInsertShareFile(saveFileList);
|
||||||
@ -123,20 +128,13 @@ public class ShareController {
|
|||||||
return RestResult.success();
|
return RestResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String sss = "[{\"fileId\":null,\"timeStampName\":null,\"fileUrl\":null,\"fileSize\":null,\"isOSS\":null,\"storageType\":null,\"pointCount\":null,\"identifier\":null,\"userFileId\":619,\"userId\":2,\"fileName\":\"2222\",\"filePath\":\"/\",\"extendName\":null,\"isDir\":1,\"uploadTime\":\"2021-03-15 22:16:26\",\"deleteFlag\":0,\"deleteTime\":null,\"deleteBatchNum\":null}]";
|
|
||||||
List<ShareFile> fileList = JSON.parseArray(sss, ShareFile.class);
|
|
||||||
fileList.forEach(p->p.setShareBatchNum("123"));
|
|
||||||
System.out.println(fileList);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "分享列表", description = "分享列表", tags = {"share"})
|
@Operation(summary = "分享列表", description = "分享列表", tags = {"share"})
|
||||||
@GetMapping(value = "/sharefileList")
|
@GetMapping(value = "/sharefileList")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<List<ShareFileListVO>> shareFileListBySecret(ShareFileListBySecretDTO shareFileListBySecretDTO) {
|
public RestResult<List<ShareFileListVO>> shareFileListBySecret(ShareFileListBySecretDTO shareFileListBySecretDTO) {
|
||||||
log.info(JSON.toJSONString(shareFileListBySecretDTO));
|
String shareBatchNum = shareFileListBySecretDTO.getShareBatchNum();
|
||||||
List<ShareFileListVO> list = shareService.selectShareFileList(shareFileListBySecretDTO.getShareBatchNum(), shareFileListBySecretDTO.getFilePath());
|
String shareFilePath = shareFileListBySecretDTO.getShareFilePath();
|
||||||
|
List<ShareFileListVO> list = shareService.selectShareFileList(shareBatchNum, shareFilePath);
|
||||||
return RestResult.success().data(list);
|
return RestResult.success().data(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +155,6 @@ public class ShareController {
|
|||||||
@GetMapping(value = "/checkextractioncode")
|
@GetMapping(value = "/checkextractioncode")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public RestResult<String> checkExtractionCode(CheckExtractionCodeDTO checkExtractionCodeDTO) {
|
public RestResult<String> checkExtractionCode(CheckExtractionCodeDTO checkExtractionCodeDTO) {
|
||||||
// log.info(JSON.toJSONString(shareFileListBySecretDTO));
|
|
||||||
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
lambdaQueryWrapper.eq(Share::getShareBatchNum, checkExtractionCodeDTO.getShareBatchNum())
|
lambdaQueryWrapper.eq(Share::getShareBatchNum, checkExtractionCodeDTO.getShareBatchNum())
|
||||||
.eq(Share::getExtractionCode, checkExtractionCodeDTO.getExtractionCode());
|
.eq(Share::getExtractionCode, checkExtractionCodeDTO.getExtractionCode());
|
||||||
|
@ -18,5 +18,6 @@ public class ShareFile {
|
|||||||
private Long shareFileId;
|
private Long shareFileId;
|
||||||
private String shareBatchNum;
|
private String shareBatchNum;
|
||||||
private Long userFileId;
|
private Long userFileId;
|
||||||
|
private String shareFilePath;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
@Schema(name = "保存分享文件DTO",required = true)
|
@Schema(name = "保存分享文件DTO",required = true)
|
||||||
public class SaveShareFileDTO {
|
public class SaveShareFileDTO {
|
||||||
@Schema(description="文件集合")
|
@Schema(description="文件集合", example = "[{\"userFileId\":12},{\"userFileId\":13}]")
|
||||||
private String files;
|
private String files;
|
||||||
@Schema(description = "文件路径")
|
@Schema(description = "文件路径")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
@ -9,10 +9,8 @@ public class ShareFileListBySecretDTO {
|
|||||||
|
|
||||||
@Schema(description="批次号")
|
@Schema(description="批次号")
|
||||||
private String shareBatchNum;
|
private String shareBatchNum;
|
||||||
@Schema(description="提取码")
|
@Schema(description="分享文件路径")
|
||||||
private String extractionCode;
|
private String shareFilePath;
|
||||||
@Schema(description="文件路径")
|
|
||||||
private String filePath;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,57 +1,56 @@
|
|||||||
//package com.qiwenshare.file.interceptor;
|
package com.qiwenshare.file.interceptor;
|
||||||
//
|
|
||||||
//import com.qiwenshare.file.api.IUserService;
|
import com.qiwenshare.file.api.IUserService;
|
||||||
//import com.qiwenshare.file.domain.UserBean;
|
import com.qiwenshare.file.domain.UserBean;
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
//import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
//import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
//import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
//
|
|
||||||
//import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
//import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * token验证拦截
|
* token验证拦截
|
||||||
// */
|
*/
|
||||||
//@Slf4j
|
@Slf4j
|
||||||
//public class AuthenticationInterceptor implements HandlerInterceptor {
|
public class AuthenticationInterceptor implements HandlerInterceptor {
|
||||||
// @Autowired
|
@Autowired
|
||||||
// private IUserService userService;
|
private IUserService userService;
|
||||||
// @Override
|
@Override
|
||||||
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||||
// throws Exception {
|
throws Exception {
|
||||||
// log.info("---------------------------------------------------------");
|
log.info("---------------------------------------------------------");
|
||||||
// // 取得token
|
// 取得token
|
||||||
// String tokenHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
|
String tokenHeader = request.getHeader(HttpHeaders.AUTHORIZATION);
|
||||||
// if (tokenHeader == null || "".equals(tokenHeader)) {
|
if (tokenHeader == null || "".equals(tokenHeader)) {
|
||||||
// throw new Exception("token不存在");
|
throw new Exception("token不存在");
|
||||||
// }
|
}
|
||||||
// if (!tokenHeader.startsWith("Bearer")) {
|
if (!tokenHeader.startsWith("Bearer")) {
|
||||||
// throw new Exception("token格式错误");
|
throw new Exception("token格式错误");
|
||||||
// }
|
}
|
||||||
// String token = tokenHeader.replace("Bearer", "");
|
String token = tokenHeader.replace("Bearer", "");
|
||||||
// UserBean userBean = userService.getUserBeanByToken(token);
|
UserBean userBean = userService.getUserBeanByToken(token);
|
||||||
// if (userBean == null) {
|
if (userBean == null) {
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||||
// ModelAndView modelAndView) throws Exception {
|
ModelAndView modelAndView) throws Exception {
|
||||||
// // TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
||||||
// throws Exception {
|
throws Exception {
|
||||||
// // TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
|
@ -11,5 +11,5 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ShareMapper extends BaseMapper<Share> {
|
public interface ShareMapper extends BaseMapper<Share> {
|
||||||
void batchInsertShareFile(List<ShareFile> shareFiles);
|
void batchInsertShareFile(List<ShareFile> shareFiles);
|
||||||
List<ShareFileListVO> selectShareFileList(@Param("shareBatchNum") String shareBatchNum, @Param("filePath") String filePath);
|
List<ShareFileListVO> selectShareFileList(@Param("shareBatchNum") String shareBatchNum, @Param("shareFilePath") String filePath);
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.qiwenshare.common.exception.UploadGeneralException;
|
||||||
|
import com.qiwenshare.common.operation.upload.domain.UploadFile;
|
||||||
import com.qiwenshare.common.util.DateUtil;
|
import com.qiwenshare.common.util.DateUtil;
|
||||||
import com.qiwenshare.common.domain.DeleteFile;
|
import com.qiwenshare.common.operation.delete.domain.DeleteFile;
|
||||||
import com.qiwenshare.common.domain.DownloadFile;
|
import com.qiwenshare.common.operation.download.domain.DownloadFile;
|
||||||
import com.qiwenshare.common.domain.UploadFile;
|
|
||||||
//import com.qiwenshare.common.factory.FileOperationFactory;
|
|
||||||
import com.qiwenshare.common.operation.delete.Deleter;
|
import com.qiwenshare.common.operation.delete.Deleter;
|
||||||
import com.qiwenshare.common.operation.download.Downloader;
|
import com.qiwenshare.common.operation.download.Downloader;
|
||||||
import com.qiwenshare.common.factory.FileOperationFactory;
|
import com.qiwenshare.common.factory.FileOperationFactory;
|
||||||
@ -31,9 +31,10 @@ import com.qiwenshare.file.domain.FileBean;
|
|||||||
import com.qiwenshare.file.domain.StorageBean;
|
import com.qiwenshare.file.domain.StorageBean;
|
||||||
import com.qiwenshare.file.mapper.StorageMapper;
|
import com.qiwenshare.file.mapper.StorageMapper;
|
||||||
import com.qiwenshare.file.mapper.UserFileMapper;
|
import com.qiwenshare.file.mapper.UserFileMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class FiletransferService implements IFiletransferService {
|
public class FiletransferService implements IFiletransferService {
|
||||||
|
|
||||||
@ -65,8 +66,8 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
uploadFile.setIdentifier(UploadFileDto.getIdentifier());
|
uploadFile.setIdentifier(UploadFileDto.getIdentifier());
|
||||||
uploadFile.setTotalSize(UploadFileDto.getTotalSize());
|
uploadFile.setTotalSize(UploadFileDto.getTotalSize());
|
||||||
uploadFile.setCurrentChunkSize(UploadFileDto.getCurrentChunkSize());
|
uploadFile.setCurrentChunkSize(UploadFileDto.getCurrentChunkSize());
|
||||||
|
String storageType = qiwenFileConfig.getStorageType();
|
||||||
synchronized (FiletransferService.class) {
|
synchronized (FiletransferService.class) {
|
||||||
String storageType = qiwenFileConfig.getStorageType();
|
|
||||||
if ("0".equals(storageType)) {
|
if ("0".equals(storageType)) {
|
||||||
uploader = localStorageOperationFactory.getUploader();
|
uploader = localStorageOperationFactory.getUploader();
|
||||||
} else if ("1".equals(storageType)) {
|
} else if ("1".equals(storageType)) {
|
||||||
@ -75,6 +76,10 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
uploader = fastDFSOperationFactory.getUploader();
|
uploader = fastDFSOperationFactory.getUploader();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (uploader == null) {
|
||||||
|
log.error("上传失败,请检查storageType是否配置正确,当前storageType为:" + storageType);
|
||||||
|
throw new UploadGeneralException("上传失败");
|
||||||
|
}
|
||||||
|
|
||||||
List<UploadFile> uploadFileList = uploader.upload(request, uploadFile);
|
List<UploadFile> uploadFileList = uploader.upload(request, uploadFile);
|
||||||
for (int i = 0; i < uploadFileList.size(); i++){
|
for (int i = 0; i < uploadFileList.size(); i++){
|
||||||
@ -144,6 +149,10 @@ public class FiletransferService implements IFiletransferService {
|
|||||||
} else if (fileBean.getStorageType() == 2) {
|
} else if (fileBean.getStorageType() == 2) {
|
||||||
downloader = fastDFSOperationFactory.getDownloader();
|
downloader = fastDFSOperationFactory.getDownloader();
|
||||||
}
|
}
|
||||||
|
if (downloader == null) {
|
||||||
|
log.error("下载失败,文件存储类型不支持下载,storageType:{}, isOSS:{}", fileBean.getStorageType(), fileBean.getIsOSS());
|
||||||
|
throw new UploadGeneralException("下载失败");
|
||||||
|
}
|
||||||
DownloadFile uploadFile = new DownloadFile();
|
DownloadFile uploadFile = new DownloadFile();
|
||||||
uploadFile.setFileUrl(fileBean.getFileUrl());
|
uploadFile.setFileUrl(fileBean.getFileUrl());
|
||||||
// uploadFile.setTimeStampName(fileBean.getTimeStampName());
|
// uploadFile.setTimeStampName(fileBean.getTimeStampName());
|
||||||
|
@ -31,10 +31,6 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
FileMapper fileMapper;
|
FileMapper fileMapper;
|
||||||
@Resource
|
@Resource
|
||||||
RecoveryFileMapper recoveryFileMapper;
|
RecoveryFileMapper recoveryFileMapper;
|
||||||
@Resource
|
|
||||||
FiletransferService filetransferService;
|
|
||||||
@Resource
|
|
||||||
QiwenFileConfig qiwenFileConfig;
|
|
||||||
|
|
||||||
public static Executor executor = Executors.newFixedThreadPool(20);
|
public static Executor executor = Executors.newFixedThreadPool(20);
|
||||||
|
|
||||||
@ -153,14 +149,11 @@ public class UserFileService extends ServiceImpl<UserFileMapper, UserFile> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId) {
|
public List<UserFile> selectFileListLikeRightFilePath(String filePath, long userId) {
|
||||||
//UserFile userFile = new UserFile();
|
|
||||||
filePath = filePath.replace("\\", "\\\\\\\\");
|
filePath = filePath.replace("\\", "\\\\\\\\");
|
||||||
filePath = filePath.replace("'", "\\'");
|
filePath = filePath.replace("'", "\\'");
|
||||||
filePath = filePath.replace("%", "\\%");
|
filePath = filePath.replace("%", "\\%");
|
||||||
filePath = filePath.replace("_", "\\_");
|
filePath = filePath.replace("_", "\\_");
|
||||||
|
|
||||||
//userFile.setFilePath(filePath);
|
|
||||||
|
|
||||||
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserFile> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
log.info("查询文件路径:" + filePath);
|
log.info("查询文件路径:" + filePath);
|
||||||
|
@ -19,8 +19,8 @@ public class ShareFileListVO {
|
|||||||
private Integer isOSS;
|
private Integer isOSS;
|
||||||
@Schema(description="存储类型")
|
@Schema(description="存储类型")
|
||||||
private Integer storageType;
|
private Integer storageType;
|
||||||
//
|
@Schema(description="用户文件id")
|
||||||
// private Long userFileId;
|
private Long userFileId;
|
||||||
//
|
//
|
||||||
// private Long userId;
|
// private Long userId;
|
||||||
|
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
|
|
||||||
<insert id="batchInsertShareFile" parameterType="java.util.List">
|
<insert id="batchInsertShareFile" parameterType="java.util.List">
|
||||||
INSERT ignore INTO sharefile (shareBatchNum, userFileId)
|
INSERT ignore INTO sharefile (shareBatchNum, userFileId, shareFilePath)
|
||||||
VALUES
|
VALUES
|
||||||
<foreach collection="list" item="file" index="index" separator=",">
|
<foreach collection="list" item="file" index="index" separator=",">
|
||||||
(#{file.shareBatchNum}, #{file.userFileId})
|
(#{file.shareBatchNum}, #{file.userFileId}, #{file.shareFilePath})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
left join userfile b on b.userFileId = a.userFileId
|
left join userfile b on b.userFileId = a.userFileId
|
||||||
left join file c on c.fileId = b.fileId
|
left join file c on c.fileId = b.fileId
|
||||||
where a.shareBatchNum = #{shareBatchNum}
|
where a.shareBatchNum = #{shareBatchNum}
|
||||||
and b.filePath = #{filePath}
|
and a.shareFilePath = #{shareFilePath}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user