|
@@ -2,6 +2,7 @@ package com.caimei.modules.archive.service;
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
+import java.net.URI;
|
|
|
import java.net.URL;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
@@ -58,7 +59,7 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
List<CmProductArchiveContent> archiveList = archivePage.getList();
|
|
|
archiveList.forEach(archive->{
|
|
|
if (cmProductArchiveContent.getType() != 1) {
|
|
|
- archive.setFileUrl(OSSUtils.generateProductArchiveUrl(archive));
|
|
|
+ archive.setFileUrl(OSSUtils.generateProductArchiveUrl(archive.getOssName(),archive.getUploadTime()));
|
|
|
}
|
|
|
});
|
|
|
return archivePage;
|
|
@@ -84,7 +85,7 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
image.setOssUrl(imageUrl);
|
|
|
- Map<String, Object> map = WaterMarkUtils.addWaterMark(null, null, imageUrl, "img", null);
|
|
|
+ Map<String, Object> map = WaterMarkUtils.addWaterMark(null, null, null, "img", imageUrl);
|
|
|
if (null != map) {
|
|
|
String ossName = (String)map.get("ossName");
|
|
|
String waterUrl = (String) map.get("imagePath");
|
|
@@ -190,47 +191,44 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
- public Map<String, Object> addWaterMark(MultipartFile multipartFile, String fileName) {
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- String fileAllName = multipartFile.getOriginalFilename();
|
|
|
- String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
|
|
|
- String uuid_1 = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- String filePath_1 = uuid_1 + "." + fileType;
|
|
|
- String uuid_2 = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- String filePath_2 = uuid_2 + "." + fileType;
|
|
|
- String contentType = OssArchiveUtil.getContentType(fileAllName);
|
|
|
- try {
|
|
|
- //保存本地
|
|
|
- File file = OssArchiveUtil.ossUpload(multipartFile);
|
|
|
- logger.info("默认路径>>>" + file.getAbsolutePath());
|
|
|
- WaterMarkUtils.addWaterMark(file, "采美365网", filePath_2, fileType, null);
|
|
|
- File waterMarkFile = new File(tempPath + filePath_2);
|
|
|
- String contentDispositon = "pdf".equals(fileType) ? "inline" : "attachment";
|
|
|
- //上传oss
|
|
|
-// String url = OssArchiveUtil.ossUpload(filePath_1, "archiveFile/", file, contentType, contentDispositon);
|
|
|
- String waterMarkUrl = OssArchiveUtil.ossUpload(filePath_2, "archiveFile/", waterMarkFile, contentType, contentDispositon);
|
|
|
- logger.info(">>>>>>>>>>>>>>>>>" + waterMarkUrl);
|
|
|
- //删除本地文件
|
|
|
- OssArchiveUtil.deleteFile(file);
|
|
|
- OssArchiveUtil.deleteFile(waterMarkFile);
|
|
|
- //保存关联关系
|
|
|
- /*CmProductArchiveFile archiveFile = new CmProductArchiveFile();
|
|
|
- archiveFile.setFileName(fileName);
|
|
|
- archiveFile.setOssName(filePath_1);
|
|
|
- archiveFile.setWaterOssName(filePath_2);
|
|
|
- archiveFile.setOssUrl(url);
|
|
|
- archiveFile.setWaterOssUrl(waterMarkUrl);
|
|
|
- archiveFile.setUploadTime(new Date());
|
|
|
- cmProductArchiveContentDao.insertFile(archiveFile);*/
|
|
|
- map.put("success", true);
|
|
|
- map.put("msg", "操作成功");
|
|
|
-// map.put("archiveFile", archiveFile);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- map.put("success", false);
|
|
|
- map.put("msg", "操作失败");
|
|
|
- logger.info("上传异常!!!");
|
|
|
- }
|
|
|
- return map;
|
|
|
+ public void addAllWaterMark() {
|
|
|
+ List<CmProductArchiveFile> fileList = cmProductArchiveContentDao.findAllArchiveFile();
|
|
|
+ fileList.forEach(file->{
|
|
|
+ if (file.getArchiveContentType() == 2 && StringUtils.isEmpty(file.getWaterOssName())) {
|
|
|
+ String ossUrl = null;
|
|
|
+ if (file.getArchiveContentType() == 1) {
|
|
|
+ //图片添加水印
|
|
|
+ ossUrl = file.getOssUrl();
|
|
|
+ } else if (file.getArchiveContentType() == 3) {
|
|
|
+ //文件添加水印
|
|
|
+ ossUrl = OSSUtils.generateProductArchiveUrl(file.getOssName(), file.getUploadTime());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(ossUrl)) {
|
|
|
+ try {
|
|
|
+ String fileName = file.getFileName();
|
|
|
+ String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath = uuid + "." + fileType;
|
|
|
+ String contentType = OssArchiveUtil.getContentType(fileName);
|
|
|
+ String contentDispositon = "pdf".equals(fileType) ? "inline" : "attachment";
|
|
|
+ File archiveFile = new File(new URI(ossUrl));
|
|
|
+ //添加水印
|
|
|
+ WaterMarkUtils.addWaterMark(archiveFile, "采美365网", filePath, file.getArchiveContentType() == 1 ? "img" : fileType, ossUrl);
|
|
|
+ File waterMarkFile = new File(tempPath + filePath);
|
|
|
+ //水印文件上传oss
|
|
|
+ String waterMarkUrl = OssArchiveUtil.ossUpload(filePath, "archiveFile/", waterMarkFile, contentType, contentDispositon);
|
|
|
+ logger.info(">>>>>>>>>>>>>>>>>" + waterMarkUrl);
|
|
|
+ //删除本地文件
|
|
|
+ OssArchiveUtil.deleteFile(waterMarkFile);
|
|
|
+ file.setWaterOssName(filePath);
|
|
|
+ file.setWaterOssUrl(waterMarkUrl);
|
|
|
+ cmProductArchiveContentDao.updateFileWaterMark(file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
}
|