|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.docus.server.common.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.img.ImgUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.docus.core.util.Func;
|
|
|
|
|
import com.docus.infrastructure.web.exception.ApiException;
|
|
|
|
@ -11,8 +13,11 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
@ -28,9 +33,12 @@ import java.util.UUID;
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
|
|
|
|
|
|
@Value("${file.uploadFolder:D://docus/}")
|
|
|
|
|
@Value("${file.uploadFolder:D://docus/source/}")
|
|
|
|
|
private String saveFilePath;
|
|
|
|
|
|
|
|
|
|
@Value("${file.uploadCutFolder:#{null}}")
|
|
|
|
|
private String saveCutFilePath;
|
|
|
|
|
|
|
|
|
|
private static final String UPLOAD_FOLDER = "upload";
|
|
|
|
|
|
|
|
|
|
private static DateTimeFormatter ymdDtf = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
@ -58,18 +66,16 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
|
|
|
|
|
|
String todayFormat = ymdDtf.format(LocalDateTime.now());
|
|
|
|
|
|
|
|
|
|
String path = pathKey + "/" + todayFormat + "/" + UUID.randomUUID().toString() + "/";
|
|
|
|
|
String path = pathKey + "/" + todayFormat + "/" + UUID.randomUUID().toString().replace("-", "") + "/";
|
|
|
|
|
File fileDir = new File(saveFilePath + path);
|
|
|
|
|
|
|
|
|
|
if (!fileDir.exists()) {
|
|
|
|
|
fileDir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
String fileName = path + multipartFile.getOriginalFilename();
|
|
|
|
|
|
|
|
|
|
String fileName = path + multipartFile.getOriginalFilename();
|
|
|
|
|
File dest = new File(saveFilePath + fileName);
|
|
|
|
|
|
|
|
|
|
multipartFile.transferTo(dest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UploadFileVO uploadFileVO = new UploadFileVO();
|
|
|
|
|
uploadFileVO.setFileName(multipartFile.getOriginalFilename());
|
|
|
|
|
uploadFileVO.setFileSize(multipartFile.getSize());
|
|
|
|
@ -77,6 +83,28 @@ public class FileUploadServiceImpl implements IFileUploadService {
|
|
|
|
|
uploadFileVO.setFileType(multipartFile.getContentType());
|
|
|
|
|
uploadFileVO.setFilePath(fileName);
|
|
|
|
|
|
|
|
|
|
if (Func.isNotBlank(saveCutFilePath)) {
|
|
|
|
|
File cutFileDir = new File(saveCutFilePath + path);
|
|
|
|
|
if (!cutFileDir.exists()) {
|
|
|
|
|
cutFileDir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
File cutDest = new File(saveCutFilePath + fileName);
|
|
|
|
|
|
|
|
|
|
BufferedImage image = ImageIO.read(multipartFile.getInputStream());
|
|
|
|
|
int height = image.getHeight();
|
|
|
|
|
int width = image.getWidth();
|
|
|
|
|
int minX = image.getMinX();
|
|
|
|
|
int minY = image.getMinY();
|
|
|
|
|
|
|
|
|
|
ImgUtil.cut(image, FileUtil.file(cutDest), new Rectangle(50, 50, width, (height / 2) / 2));
|
|
|
|
|
|
|
|
|
|
uploadFileVO.setWidth(width);
|
|
|
|
|
uploadFileVO.setHeight(height);
|
|
|
|
|
uploadFileVO.setX(minX);
|
|
|
|
|
uploadFileVO.setY(minY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
multipartFile.transferTo(dest);
|
|
|
|
|
return uploadFileVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|