|
|
@@ -1,21 +1,17 @@
|
|
|
package com.yingpaipay.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.yingpaipay.business.constant.DictTypeConst;
|
|
|
-import com.yingpaipay.business.constant.DocumentAuditorTypeConst;
|
|
|
-import com.yingpaipay.business.constant.DocumentStatusConst;
|
|
|
-import com.yingpaipay.business.constant.DocumentTypeConst;
|
|
|
+import com.yingpaipay.business.constant.*;
|
|
|
import com.yingpaipay.business.domain.DocumentAuditLog;
|
|
|
import com.yingpaipay.business.domain.Folder;
|
|
|
-import com.yingpaipay.business.domain.Project;
|
|
|
import com.yingpaipay.business.domain.bo.*;
|
|
|
import com.yingpaipay.business.domain.vo.*;
|
|
|
import com.yingpaipay.business.mapper.DocumentAuditLogMapper;
|
|
|
import com.yingpaipay.common.file.util.PdfUtils;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
+import org.dromara.common.core.constant.GlobalConstants;
|
|
|
import org.dromara.common.core.exception.BusinessException;
|
|
|
-import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.MessageUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
@@ -29,6 +25,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.dromara.common.oss.core.OssClient;
|
|
|
import org.dromara.common.oss.factory.OssFactory;
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
import org.dromara.system.domain.vo.SysOssVo;
|
|
|
@@ -45,8 +42,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.io.*;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
-import java.nio.file.Paths;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 文档Service业务层处理
|
|
|
@@ -68,6 +66,11 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
private final CommonFolderService folderService;
|
|
|
private final CommonProjectService projectService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 水印的锁
|
|
|
+ */
|
|
|
+ private static final Map<Long, Object> WATERMARK_LOCK = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
/**
|
|
|
* 查询文档
|
|
|
*
|
|
|
@@ -100,16 +103,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
List<Long> folderIds = new ArrayList<>();
|
|
|
Map<Long, String> folderMap = new HashMap<>();
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
|
- Map<String, String> planDocumentTypeMap = new HashMap<>();
|
|
|
- Map<String, String> centerFileSpecificationMap = new HashMap<>();
|
|
|
- Map<String, String> projectFileSpecificationMap = new HashMap<>();
|
|
|
Map<Long, String> userMap = new HashMap<>();
|
|
|
- dictTypeService.selectDictDataByType(DictTypeConst.PLAN_DOCUMENT_TYPE)
|
|
|
- .forEach(e -> planDocumentTypeMap.put(e.getDictValue(), e.getDictLabel()));
|
|
|
- dictTypeService.selectDictDataByType(DictTypeConst.CENTER_FILE_SPECIFICATION)
|
|
|
- .forEach(e -> centerFileSpecificationMap.put(e.getDictValue(), e.getDictLabel()));
|
|
|
- dictTypeService.selectDictDataByType(DictTypeConst.PROJECT_FILE_SPECIFICATION)
|
|
|
- .forEach(e -> projectFileSpecificationMap.put(e.getDictValue(), e.getDictLabel()));
|
|
|
documents.forEach(e -> {
|
|
|
ossIds.add(e.getOssId());
|
|
|
folderIds.add(e.getFolderId());
|
|
|
@@ -126,7 +120,8 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
}
|
|
|
e.setSubmitterName(userMap.get(e.getSubmitter()));
|
|
|
e.setPlanSubmitterName(userMap.get(e.getPlanSubmitter()));
|
|
|
- e.setFolderName(folderMap.get(e.getFolderId()));
|
|
|
+ String folderName = folderMap.get(e.getFolderId());
|
|
|
+ e.setFolderName(StringUtils.isNotBlank(folderName) ? folderName : MessageUtils.message("search.temp"));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -377,7 +372,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
public void download(Long ossId, HttpServletResponse response) throws IOException {
|
|
|
SysOssVo sysOss = ossService.getById(ossId);
|
|
|
if (sysOss == null) {
|
|
|
- throw new ServiceException("文件数据不存在!");
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.download.notfound"));
|
|
|
}
|
|
|
|
|
|
String originalExt = FilenameUtils.getExtension(sysOss.getOriginalName());
|
|
|
@@ -417,6 +412,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
|
|
|
private String buildRemark(Long ossId) {
|
|
|
Document document = baseMapper.selectOne(Wrappers.lambdaQuery(Document.class).eq(Document::getOssId, ossId));
|
|
|
+ // 也有可能直接下载审核版本
|
|
|
if (document == null) {
|
|
|
DocumentAuditLog log = auditLogMapper.selectOne(
|
|
|
Wrappers.lambdaQuery(DocumentAuditLog.class)
|
|
|
@@ -427,8 +423,20 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
}
|
|
|
document = baseMapper.selectById(log.getDocumentId());
|
|
|
}
|
|
|
- Project project = projectService.queryById(document.getProjectId());
|
|
|
- return project.getCode() + ":" + document.getId();
|
|
|
+
|
|
|
+ Object lock = WATERMARK_LOCK.computeIfAbsent(document.getId(), id -> new Object());
|
|
|
+ String key = GlobalConstants.DOCUMENT_WATERMARK_KEY + document.getId();
|
|
|
+ synchronized (lock) {
|
|
|
+ int count;
|
|
|
+ if (RedisUtils.hasKey(key)) {
|
|
|
+ count = RedisUtils.getCacheObject(key);
|
|
|
+ count++;
|
|
|
+ } else {
|
|
|
+ count = 1;
|
|
|
+ }
|
|
|
+ RedisUtils.setCacheObject(key, count);
|
|
|
+ return document.getId() + ":" + String.format("%06d", count);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -494,7 +502,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
AppletMineCountVo vo = new AppletMineCountVo();
|
|
|
List<Document> documentList = baseMapper.selectList(
|
|
|
Wrappers.lambdaQuery(Document.class)
|
|
|
- .eq(Document::getSubmitter, LoginHelper.getUserId())
|
|
|
+ .eq(Document::getPlanSubmitter, LoginHelper.getUserId())
|
|
|
.in(Document::getStatus, List.of(DocumentStatusConst.UN_UPLOAD, DocumentStatusConst.UN_AUDIT, DocumentStatusConst.AUDIT_REJECT))
|
|
|
);
|
|
|
vo.setToSubmit(
|
|
|
@@ -539,7 +547,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
IPage<Document> page = baseMapper.selectPage(
|
|
|
pageQuery.build(),
|
|
|
Wrappers.lambdaQuery(Document.class)
|
|
|
- .eq(Document::getSubmitter, LoginHelper.getUserId())
|
|
|
+ .eq(Document::getPlanSubmitter, LoginHelper.getUserId())
|
|
|
.eq(bo.getStatus() != null, Document::getStatus, bo.getStatus())
|
|
|
.like(StringUtils.isNotBlank(bo.getName()), Document::getName, bo.getName())
|
|
|
.orderByDesc(Document::getId)
|
|
|
@@ -562,7 +570,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
IPage<Document> page = baseMapper.selectPage(
|
|
|
pageQuery.build(),
|
|
|
Wrappers.lambdaQuery(Document.class)
|
|
|
- .eq(Document::getSubmitter, LoginHelper.getUserId())
|
|
|
+ .eq(Document::getPlanSubmitter, LoginHelper.getUserId())
|
|
|
.in(Document::getStatus, List.of(DocumentStatusConst.UN_UPLOAD, DocumentStatusConst.AUDIT_REJECT))
|
|
|
.like(StringUtils.isNotBlank(bo.getName()), Document::getName, bo.getName())
|
|
|
.orderByDesc(Document::getId)
|
|
|
@@ -571,10 +579,17 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
Map<Long, Folder> folderMap = new HashMap<>();
|
|
|
Map<Long, String> projectMap = new HashMap<>();
|
|
|
|
|
|
- page.getRecords().forEach(e -> projectIds.add(e.getProjectId()));
|
|
|
+ page.getRecords().forEach(e -> {
|
|
|
+ if (!projectIds.contains(e.getProjectId())) {
|
|
|
+ projectIds.add(e.getProjectId());
|
|
|
+ }
|
|
|
+ });
|
|
|
projectService.queryByIds(projectIds).forEach(e -> projectMap.put(e.getId(), e.getName()));
|
|
|
List<Folder> folderList = folderService.queryByProjectIds(projectIds);
|
|
|
- folderList.forEach(e -> folderMap.put(e.getId(), e));
|
|
|
+// folderList.forEach(e -> folderMap.put(e.getId(), e));
|
|
|
+ for (Folder folder : folderList) {
|
|
|
+ folderMap.put(folder.getId(), folder);
|
|
|
+ }
|
|
|
|
|
|
return TableDataInfo.build(page.convert(e -> {
|
|
|
AppletDocumentScanSubmitVo vo = new AppletDocumentScanSubmitVo();
|
|
|
@@ -607,7 +622,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
List<String> fileBase64List = bo.getFileBase64List();
|
|
|
|
|
|
if (fileBase64List == null || fileBase64List.isEmpty()) {
|
|
|
- throw new BusinessException("提交的文件列表为空");
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.uploadempty"));
|
|
|
}
|
|
|
|
|
|
File file;
|
|
|
@@ -623,6 +638,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
.eq(Document::getId, bo.getDocumentId())
|
|
|
.set(Document::getOssId, ossVo.getOssId())
|
|
|
.set(Document::getStatus, DocumentStatusConst.UN_AUDIT)
|
|
|
+ .set(Document::getSubmitter, LoginHelper.getUserId())
|
|
|
.set(Document::getSubmitTime, new Date())
|
|
|
) > 0;
|
|
|
}
|
|
|
@@ -652,7 +668,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
}
|
|
|
|
|
|
if (files.isEmpty()) {
|
|
|
- throw new BusinessException("未解析到有效的 PDF 文件数据");
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.cannotparseusablepdf"));
|
|
|
}
|
|
|
|
|
|
finalFile = PdfUtils.merge(files, fileName);
|
|
|
@@ -667,7 +683,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
List<String> fileBase64List = bo.getFiles();
|
|
|
|
|
|
if (fileBase64List == null || fileBase64List.isEmpty()) {
|
|
|
- throw new BusinessException("提交的文件列表为空");
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.uploadempty"));
|
|
|
}
|
|
|
|
|
|
File file;
|
|
|
@@ -691,11 +707,6 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
document.setSendFlag(false);
|
|
|
document.setSendStatus(false);
|
|
|
document.setTenantId(TenantHelper.getTenantId());
|
|
|
- document.setCreateDept(LoginHelper.getDeptId());
|
|
|
- document.setCreateBy(LoginHelper.getUserId());
|
|
|
- document.setCreateTime(new Date());
|
|
|
- document.setUpdateBy(LoginHelper.getUserId());
|
|
|
- document.setUpdateTime(new Date());
|
|
|
|
|
|
return baseMapper.insert(document) > 0;
|
|
|
}
|
|
|
@@ -712,6 +723,87 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 文件上传和插入数据库并非原子操作,因此无需使用事务控制
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean upload(AppletUploadBo bo) {
|
|
|
+
|
|
|
+ List<String> fileBase64List = bo.getFiles();
|
|
|
+
|
|
|
+ if (fileBase64List == null || fileBase64List.isEmpty()) {
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.uploadempty"));
|
|
|
+ }
|
|
|
+
|
|
|
+ File file;
|
|
|
+ try {
|
|
|
+ file = convertToFile(fileBase64List, bo.getName());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ SysOssVo ossVo = ossService.upload(file);
|
|
|
+
|
|
|
+ List<Folder> folders = folderService.queryByProjectIds(List.of(bo.getProjectId()));
|
|
|
+ Map<Long, Folder> folderMap = new HashMap<>();
|
|
|
+ folders.forEach(e -> folderMap.put(e.getId(), e));
|
|
|
+ Map<Long, List<Folder>> childrenMap = folders.stream().filter(e -> e.getParentId() != null).collect(Collectors.groupingBy(Folder::getParentId));
|
|
|
+ List<Long> selected = new ArrayList<>();
|
|
|
+ if (bo.getCenter() != 0L) {
|
|
|
+ buildFolders(selected, folderMap.get(bo.getCenter()), childrenMap);
|
|
|
+ } else {
|
|
|
+ if (bo.getCountry() != 0L) {
|
|
|
+ buildFolders(selected, folderMap.get(bo.getCountry()), childrenMap);
|
|
|
+ } else {
|
|
|
+ selected = folders.stream().map(Folder::getId).toList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Document> documents = baseMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(Document.class)
|
|
|
+ .in(Document::getFolderId, selected)
|
|
|
+ );
|
|
|
+ for (Document document : documents) {
|
|
|
+ if (document.getName().equals(bo.getName())) {
|
|
|
+ document.setOssId(ossVo.getOssId());
|
|
|
+ document.setSubmitter(LoginHelper.getUserId());
|
|
|
+ document.setSubmitTime(new Date());
|
|
|
+ document.setStatus(DocumentStatusConst.UN_AUDIT);
|
|
|
+ return baseMapper.updateById(document) > 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Document document = new Document();
|
|
|
+ document.setFolderId(bo.getCenter() != 0L ? bo.getCenter() : bo.getCountry());
|
|
|
+ document.setName(bo.getName());
|
|
|
+ document.setStatus(DocumentStatusConst.UN_AUDIT);
|
|
|
+ document.setOssId(ossVo.getOssId());
|
|
|
+ document.setType(DocumentTypeConst.NOT_PLAN);
|
|
|
+ document.setSubmitter(LoginHelper.getUserId());
|
|
|
+ document.setSubmitTime(new Date());
|
|
|
+ document.setProjectId(bo.getProjectId());
|
|
|
+ document.setSpecificationType(bo.getCenter() != 0L ? SpecificationTypeConst.CENTER : SpecificationTypeConst.PROJECT);
|
|
|
+ document.setTenantId(TenantHelper.getTenantId());
|
|
|
+
|
|
|
+ return baseMapper.insert(document) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long countTemp(Long projectId) {
|
|
|
+ return baseMapper.selectCount(
|
|
|
+ Wrappers.lambdaQuery(Document.class)
|
|
|
+ .eq(Document::getProjectId, projectId)
|
|
|
+ .eq(Document::getFolderId, 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildFolders(List<Long> selected, Folder folder, Map<Long, List<Folder>> childrenMap) {
|
|
|
+ selected.add(folder.getId());
|
|
|
+ List<Folder> childrens = childrenMap.get(folder.getId());
|
|
|
+ if (childrens == null || childrens.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ childrens.forEach(e -> buildFolders(selected, e, childrenMap));
|
|
|
+ }
|
|
|
+
|
|
|
private LambdaQueryWrapper<Document> buildFilingListWrapper(TaskCenterFilingListBo bo, List<Long> folderIds) {
|
|
|
return Wrappers.lambdaQuery(Document.class)
|
|
|
.like(StringUtils.isNotBlank(bo.getName()), Document::getName, bo.getName())
|
|
|
@@ -768,6 +860,7 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
log.setCreateTime(new Date());
|
|
|
log.setUpdateBy(LoginHelper.getUserId());
|
|
|
log.setUpdateTime(new Date());
|
|
|
+ log.setSubmitter(document.getSubmitter());
|
|
|
return log;
|
|
|
}
|
|
|
}
|