|
@@ -1,6 +1,7 @@
|
|
|
package com.gz.service.archive.impl;
|
|
package com.gz.service.archive.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
@@ -15,26 +16,30 @@ import com.gz.dto.system.MenuRoleDTO;
|
|
|
import com.gz.mapper.archive.ArchiveFileMapper;
|
|
import com.gz.mapper.archive.ArchiveFileMapper;
|
|
|
import com.gz.mapper.archive.ArchiveMapper;
|
|
import com.gz.mapper.archive.ArchiveMapper;
|
|
|
import com.gz.mapper.system.MenuRoleMapper;
|
|
import com.gz.mapper.system.MenuRoleMapper;
|
|
|
|
|
+import com.gz.mapper.system.RoleMapper;
|
|
|
import com.gz.rvo.archive.ArchiveFileRVO;
|
|
import com.gz.rvo.archive.ArchiveFileRVO;
|
|
|
import com.gz.rvo.archive.ArchiveRVO;
|
|
import com.gz.rvo.archive.ArchiveRVO;
|
|
|
import com.gz.service.archive.ArchiveFileService;
|
|
import com.gz.service.archive.ArchiveFileService;
|
|
|
|
|
+import com.gz.service.system.RoleService;
|
|
|
import com.gz.utils.JwtUtils;
|
|
import com.gz.utils.JwtUtils;
|
|
|
|
|
+import com.gz.utils.WatermarkUtils;
|
|
|
import com.gz.vo.archive.SearchArchiveFileVO;
|
|
import com.gz.vo.archive.SearchArchiveFileVO;
|
|
|
import com.gz.vo.rabbitmq.OcrEtlVO;
|
|
import com.gz.vo.rabbitmq.OcrEtlVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import sun.text.resources.cldr.yav.FormatData_yav;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.lang.reflect.Executable;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author LiuchangLan
|
|
* @author LiuchangLan
|
|
@@ -55,6 +60,9 @@ public class ArchiveFileServiceImpl implements ArchiveFileService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private MenuRoleMapper menuRoleMapper;
|
|
private MenuRoleMapper menuRoleMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RoleService roleService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Value("${rabbitmq.data-exchange}")
|
|
@Value("${rabbitmq.data-exchange}")
|
|
|
private String dataExchangeName;
|
|
private String dataExchangeName;
|
|
@@ -66,9 +74,11 @@ public class ArchiveFileServiceImpl implements ArchiveFileService {
|
|
|
private String serverFileUrlPrefix;
|
|
private String serverFileUrlPrefix;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ ExecutorService archiveWatermarkHandleThreadPool = Executors.newCachedThreadPool();
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
- public ArchiveFileDTO upload(MultipartFile file, Integer archiveId, Integer fileType,Integer secondaryArchiveId) throws BusinessException, IOException {
|
|
|
|
|
|
|
+ public ArchiveFileDTO upload(MultipartFile file, Integer archiveId, Integer fileType, Integer secondaryArchiveId) throws BusinessException, IOException {
|
|
|
if (file.isEmpty()) {
|
|
if (file.isEmpty()) {
|
|
|
throw new BusinessException(CustomExceptionEnum.File_NOT_EXISTS);
|
|
throw new BusinessException(CustomExceptionEnum.File_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
@@ -87,18 +97,18 @@ public class ArchiveFileServiceImpl implements ArchiveFileService {
|
|
|
switch (fileFormat) {
|
|
switch (fileFormat) {
|
|
|
case "PDF":
|
|
case "PDF":
|
|
|
// serverFileUploadPath = String.format(FileUploadConfig.ARCHIVE_UPLOAD_PATH_PDF_FOMAT, archiveDTO.getGdnd(), archiveDTO.getQzh(), archiveDTO.getBgqx(), archiveDTO.getGdnd(), fileFormat);
|
|
// serverFileUploadPath = String.format(FileUploadConfig.ARCHIVE_UPLOAD_PATH_PDF_FOMAT, archiveDTO.getGdnd(), archiveDTO.getQzh(), archiveDTO.getBgqx(), archiveDTO.getGdnd(), fileFormat);
|
|
|
- serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/pdf";
|
|
|
|
|
|
|
+ serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/pdf/";
|
|
|
// pdf文件名为档号
|
|
// pdf文件名为档号
|
|
|
- if (secondaryArchiveId != null){
|
|
|
|
|
- fn = String.format("%s_%s.%s", archiveDTO.getDh(),secondaryArchiveId, fileFormat.toLowerCase());
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ if (secondaryArchiveId != null) {
|
|
|
|
|
+ fn = String.format("%s_%s.%s", archiveDTO.getDh(), secondaryArchiveId, fileFormat.toLowerCase());
|
|
|
|
|
+ } else {
|
|
|
fn = String.format("%s.%s", archiveDTO.getDh(), fileFormat.toLowerCase());
|
|
fn = String.format("%s.%s", archiveDTO.getDh(), fileFormat.toLowerCase());
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case "TIF":
|
|
case "TIF":
|
|
|
// tif文件名为页码 无法通过后台生成 读取上传文件的名称
|
|
// tif文件名为页码 无法通过后台生成 读取上传文件的名称
|
|
|
fn = fileName;
|
|
fn = fileName;
|
|
|
- serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/tif";
|
|
|
|
|
|
|
+ serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/tif/";
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
// 其他文件直接抛错
|
|
// 其他文件直接抛错
|
|
@@ -106,7 +116,7 @@ public class ArchiveFileServiceImpl implements ArchiveFileService {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 附件
|
|
// 附件
|
|
|
- serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/other";
|
|
|
|
|
|
|
+ serverFileUploadPath = "/" + archiveDTO.getQzh() + "/" + archiveDTO.getGdnd() + "/" + archiveDTO.getMl() + "/" + archiveDTO.getBgqx() + "/" + archiveDTO.getDh() + "/other/";
|
|
|
fn = String.format("%s.%s", IdUtil.simpleUUID(), fileFormat.toLowerCase());
|
|
fn = String.format("%s.%s", IdUtil.simpleUUID(), fileFormat.toLowerCase());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -174,6 +184,34 @@ public class ArchiveFileServiceImpl implements ArchiveFileService {
|
|
|
if (menuRoleMapper.select(param).stream().filter(i -> i.getMenuId() == 2).count() <= 0) {
|
|
if (menuRoleMapper.select(param).stream().filter(i -> i.getMenuId() == 2).count() <= 0) {
|
|
|
throw new BusinessException(CustomExceptionEnum.NO_ROLE);
|
|
throw new BusinessException(CustomExceptionEnum.NO_ROLE);
|
|
|
}
|
|
}
|
|
|
- return archiveFileMapper.selectFileAndJnml(vo);
|
|
|
|
|
|
|
+ List<ArchiveFileRVO> archiveFileRVOS = archiveFileMapper.selectFileAndJnml(vo);
|
|
|
|
|
+ // 是否需要水印
|
|
|
|
|
+ if (roleService.selectArchiveRole(JwtUtils.getCurrentUserJwtPayload().getRoleId(), 3)) {
|
|
|
|
|
+ archiveFileRVOS.forEach(this::converHasWatermarkPdf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return archiveFileRVOS;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void converHasWatermarkPdf(ArchiveFileDTO sourceFile) {
|
|
|
|
|
+ // 需要生成水印的pdf文件
|
|
|
|
|
+ String sourcePdfFile = FileUploadConfig.ARCHIVE_FILE_ROOT_DIRECTORY + sourceFile.getFilePath() + sourceFile.getFileName();
|
|
|
|
|
+ // 水印生成位置文件
|
|
|
|
|
+ String watermarkFilePathStr = FileUploadConfig.WATERMARK_ARCHIVE_FILE_ROOT_DIRECTORY + "/"
|
|
|
|
|
+ + JwtUtils.getCurrentUserJwtPayload().getId()
|
|
|
|
|
+ + sourceFile.getFilePath();
|
|
|
|
|
+ File watermarkFilePath = FileUtil.file(watermarkFilePathStr);
|
|
|
|
|
+ if (!watermarkFilePath.exists()) {
|
|
|
|
|
+ // 目录不存在,创建目录
|
|
|
|
|
+ watermarkFilePath.mkdirs();
|
|
|
|
|
+ }
|
|
|
|
|
+ // 水印文件夹不存在生成水印后的文件
|
|
|
|
|
+ if (!FileUtil.file(watermarkFilePath + sourceFile.getFileName()).exists()) {
|
|
|
|
|
+ String adminName = JwtUtils.getCurrentUserJwtPayload().getAdminName();
|
|
|
|
|
+ // 使用线程池后台进行生成 不影响正常响应速度
|
|
|
|
|
+// archiveWatermarkHandleThreadPool.execute(() -> WatermarkUtils.generateWatermarkPdf(sourcePdfFile, watermarkFilePathStr + sourceFile.getFileName(), adminName));
|
|
|
|
|
+ WatermarkUtils.generateWatermarkPdf(sourcePdfFile, watermarkFilePathStr + sourceFile.getFileName(), adminName);
|
|
|
|
|
+ }
|
|
|
|
|
+ sourceFile.setFilePath(JwtUtils.getCurrentUserJwtPayload().getId() + sourceFile.getFilePath());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|