|
@@ -191,10 +191,10 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
- public void addAllWaterMark() {
|
|
|
+ public String addAllWaterMark() {
|
|
|
List<CmProductArchiveFile> fileList = cmProductArchiveContentDao.findAllArchiveFile();
|
|
|
fileList.forEach(file->{
|
|
|
- if (file.getArchiveContentType() == 2 && StringUtils.isEmpty(file.getWaterOssName())) {
|
|
|
+ if (file.getArchiveContentType() != 2 && StringUtils.isEmpty(file.getWaterOssName())) {
|
|
|
String ossUrl = null;
|
|
|
if (file.getArchiveContentType() == 1) {
|
|
|
//图片添加水印
|
|
@@ -206,29 +206,55 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
if (StringUtils.isNotEmpty(ossUrl)) {
|
|
|
try {
|
|
|
String fileName = file.getFileName();
|
|
|
+ if (file.getArchiveContentType() == 1) {
|
|
|
+ fileName = file.getOssUrl().split("\\?")[0];
|
|
|
+ }
|
|
|
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
|
|
|
- String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
- String filePath = uuid + "." + fileType;
|
|
|
+ String uuid1 = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath1 = uuid1 + "." + fileType;
|
|
|
+ String uuid2 = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath2 = uuid2 + "." + 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);
|
|
|
+ if (!"doc".equals(contentType) && !"ppt".equals(contentType)) {
|
|
|
+ File archiveFile = new File(tempPath + filePath1);
|
|
|
+ archiveFile.createNewFile();
|
|
|
+ URL fileUrl = new URL(ossUrl);
|
|
|
+ InputStream inputStream = fileUrl.openStream();
|
|
|
+ OutputStream outputStream = new FileOutputStream(archiveFile);
|
|
|
+ int bytesRead = 0;
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
|
|
|
+ outputStream.write(buffer,0,bytesRead);
|
|
|
+ }
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+
|
|
|
+ //添加水印
|
|
|
+ Map<String, Object> map = WaterMarkUtils.addWaterMark(archiveFile, "采美365网", filePath2, file.getArchiveContentType() == 1 ? "img" : fileType, ossUrl);
|
|
|
+ String waterMarkUrl = null;
|
|
|
+ if (file.getArchiveContentType() == 1) {
|
|
|
+ filePath2 = (String) map.get("ossName");
|
|
|
+ waterMarkUrl = (String) map.get("imagePath");
|
|
|
+ } else {
|
|
|
+ File waterMarkFile = new File(tempPath + filePath2);
|
|
|
+ //水印文件上传oss
|
|
|
+ waterMarkUrl = OssArchiveUtil.ossUpload(filePath2, "archiveFile/", waterMarkFile, contentType, contentDispositon);
|
|
|
+ logger.info(">>>>>>>>>>>>>>>>>" + waterMarkUrl);
|
|
|
+ OssArchiveUtil.deleteFile(waterMarkFile);
|
|
|
+ }
|
|
|
+ //删除本地文件
|
|
|
+ OssArchiveUtil.deleteFile(archiveFile);
|
|
|
+ file.setWaterOssName(filePath2);
|
|
|
+ file.setWaterOssUrl(waterMarkUrl);
|
|
|
+ cmProductArchiveContentDao.updateFileWaterMark(file);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+ return "success";
|
|
|
}
|
|
|
}
|