|
@@ -22,6 +22,7 @@ import com.ruoyi.system.service.IFileService;
|
|
|
import com.ruoyi.system.service.IZbFileService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -91,10 +92,20 @@ public class FileServiceImpl implements IFileService {
|
|
|
String code = FileUtils.getRandomFileName(name);
|
|
|
String pathname = timeFormat + code;
|
|
|
ImgDetailInfo imgDetailInfo = new ImgDetailInfo();
|
|
|
+ //生成缩略图返回缩略图地址
|
|
|
+ String thumbnailPath = timeFormat + FileUtils.getRandomFileName(file.getOriginalFilename());
|
|
|
try {
|
|
|
+ //组合File.separator = \
|
|
|
File saveFile = new File(profile + File.separator + pathname);
|
|
|
+ File saveFileThumbnail = new File(profile + File.separator + thumbnailPath);
|
|
|
+ //检查目录是否存在
|
|
|
FileUtils.checkOrCreateParentDir(saveFile);
|
|
|
file.transferTo(saveFile);
|
|
|
+
|
|
|
+ //生成缩略图返回缩略图地址
|
|
|
+ Thumbnails.of(saveFile)
|
|
|
+ .size(36, 24)
|
|
|
+ .toFile(saveFileThumbnail);
|
|
|
// 如果图片需要立即解析属性信息,就同步操作去执行
|
|
|
if (parse) {
|
|
|
imgDetailInfo = printImageTags(saveFile);
|
|
@@ -114,6 +125,8 @@ public class FileServiceImpl implements IFileService {
|
|
|
xmFile.setSize(file.getSize());
|
|
|
xmFile.setUrl("?path=" + URLEncoder.createDefault().encode(pathname, Charset.defaultCharset()));
|
|
|
xmFile.setDetail(JSON.toJSONString(imgDetailInfo));
|
|
|
+ xmFile.setThumbnailPath(thumbnailPath);
|
|
|
+ xmFile.setThumbnailUrl("?path=" + URLEncoder.createDefault().encode(thumbnailPath, Charset.defaultCharset()));
|
|
|
zbFileService.save(xmFile);
|
|
|
// 如果图片需要立即解析属性信息
|
|
|
if (!parse && isImg(name)) {
|