|
|
@@ -1,10 +1,10 @@
|
|
|
package com.yingpaipay.business.controller;
|
|
|
|
|
|
import com.yingpaipay.business.domain.Document;
|
|
|
-import com.yingpaipay.business.domain.dto.WpsGetVersionsDto;
|
|
|
+import com.yingpaipay.business.domain.dto.WpsGetVersionsDTO;
|
|
|
import com.yingpaipay.business.domain.dto.WpsR;
|
|
|
-import com.yingpaipay.business.domain.dto.WpsVersionControlDto;
|
|
|
-import com.yingpaipay.business.domain.dto.WpsVersionDto;
|
|
|
+import com.yingpaipay.business.domain.dto.WpsVersionControlDTO;
|
|
|
+import com.yingpaipay.business.domain.dto.WpsVersionDTO;
|
|
|
import com.yingpaipay.business.service.common.CommonDocumentService;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -47,7 +47,7 @@ public class WpsController extends BaseController {
|
|
|
/**
|
|
|
* 这里为版本控制缓存
|
|
|
*/
|
|
|
- private static final Map<Long, WpsVersionControlDto> DOCUMENT_MAP = new ConcurrentHashMap<>();
|
|
|
+ private static final Map<Long, WpsVersionControlDTO> DOCUMENT_MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
private final ISysOssService ossService;
|
|
|
private final CommonDocumentService documentService;
|
|
|
@@ -56,7 +56,7 @@ public class WpsController extends BaseController {
|
|
|
@PutMapping(value = "/upload/file/{documentId}", consumes = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
|
|
public void upload(@PathVariable String documentId, HttpServletRequest request) {
|
|
|
String[] ids = documentId.split("_");
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(Long.valueOf(ids[0]));
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(Long.valueOf(ids[0]));
|
|
|
File tempFile = null;
|
|
|
try {
|
|
|
|
|
|
@@ -77,8 +77,8 @@ public class WpsController extends BaseController {
|
|
|
OssClient storage = OssFactory.instance();
|
|
|
UploadResult uploadResult = storage.uploadSuffix(tempFile, suffix, originalfileName);
|
|
|
dto.setCurrentVersion(Long.parseLong(ids[1]));
|
|
|
- List<WpsVersionDto> versions = dto.getVersions();
|
|
|
- for (WpsVersionDto version : versions) {
|
|
|
+ List<WpsVersionDTO> versions = dto.getVersions();
|
|
|
+ for (WpsVersionDTO version : versions) {
|
|
|
if (Objects.equals(version.getVersion(), Long.valueOf(ids[1]))) {
|
|
|
|
|
|
// FIXME 由于原始版本不能被删除,暂时先不实现: 每新增一个版本,就将原始版本上传一个全新的版本
|
|
|
@@ -150,12 +150,12 @@ public class WpsController extends BaseController {
|
|
|
long version = Long.parseLong(ids[1]);
|
|
|
|
|
|
if (DOCUMENT_MAP.containsKey(id)) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(id);
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(id);
|
|
|
return WpsR.ok(new WpsGetFileInfoDto(
|
|
|
documentId, dto.getFileName(), 1, dto.getSize(), Math.toIntExact(new Date().getTime() / 1000L), Math.toIntExact(new Date().getTime() / 1000L), dto.getCreator(), dto.getUpdator()
|
|
|
));
|
|
|
}
|
|
|
- WpsVersionControlDto dto = initDocument(id);
|
|
|
+ WpsVersionControlDTO dto = initDocument(id);
|
|
|
return WpsR.ok(new WpsGetFileInfoDto(
|
|
|
documentId, dto.getFileName(), 1, dto.getSize(), Math.toIntExact(new Date().getTime() / 1000L), Math.toIntExact(new Date().getTime() / 1000L), dto.getCreator(), dto.getUpdator()
|
|
|
));
|
|
|
@@ -186,9 +186,9 @@ public class WpsController extends BaseController {
|
|
|
long version = Long.parseLong(ids[1]);
|
|
|
|
|
|
if (DOCUMENT_MAP.containsKey(id)) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(id);
|
|
|
- List<WpsVersionDto> versions = dto.getVersions();
|
|
|
- for (WpsVersionDto versionDto : versions) {
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(id);
|
|
|
+ List<WpsVersionDTO> versions = dto.getVersions();
|
|
|
+ for (WpsVersionDTO versionDto : versions) {
|
|
|
if (versionDto.getVersion() == version) {
|
|
|
return WpsR.ok(new WpsGetUrlDto(versionDto.getUrl()));
|
|
|
}
|
|
|
@@ -196,9 +196,9 @@ public class WpsController extends BaseController {
|
|
|
return WpsR.ok(new WpsGetUrlDto(dto.getVersions().get(0).getUrl()));
|
|
|
}
|
|
|
|
|
|
- WpsVersionControlDto dto = initDocument(id);
|
|
|
- List<WpsVersionDto> versions = dto.getVersions();
|
|
|
- for (WpsVersionDto versionDto : versions) {
|
|
|
+ WpsVersionControlDTO dto = initDocument(id);
|
|
|
+ List<WpsVersionDTO> versions = dto.getVersions();
|
|
|
+ for (WpsVersionDTO versionDto : versions) {
|
|
|
if (Objects.equals(versionDto.getVersion(), dto.getCurrentVersion())) {
|
|
|
return WpsR.ok(new WpsGetUrlDto(versionDto.getUrl()));
|
|
|
}
|
|
|
@@ -209,10 +209,10 @@ public class WpsController extends BaseController {
|
|
|
@GetMapping("/files/{documentId}/versions/{version}/download")
|
|
|
public WpsR getUrlByVersion(@PathVariable String documentId, @PathVariable Integer version) {
|
|
|
if (DOCUMENT_MAP.containsKey(Long.valueOf(documentId.split("_")[0]))) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(Long.valueOf(documentId.split("_")[0]));
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(Long.valueOf(documentId.split("_")[0]));
|
|
|
return WpsR.ok(new WpsGetUrlDto(dto.getVersions().get(Integer.parseInt(documentId.split("_")[1])).getUrl()));
|
|
|
}
|
|
|
- WpsVersionControlDto dto = initDocument(Long.valueOf(documentId.split("_")[0]));
|
|
|
+ WpsVersionControlDTO dto = initDocument(Long.valueOf(documentId.split("_")[0]));
|
|
|
return WpsR.ok(new WpsGetUrlDto(dto.getVersions().get(0).getUrl()));
|
|
|
}
|
|
|
|
|
|
@@ -249,17 +249,17 @@ public class WpsController extends BaseController {
|
|
|
return R.ok(DOCUMENT_MAP.get(documentId).getCurrentVersion());
|
|
|
}
|
|
|
|
|
|
- private WpsVersionControlDto initDocument(Long ossId) {
|
|
|
+ private WpsVersionControlDTO initDocument(Long ossId) {
|
|
|
SysOssVo ossVo = ossService.getById(ossId);
|
|
|
Document document = documentService.getByOssId(ossId);
|
|
|
if (DOCUMENT_MAP.containsKey(document.getId())) {
|
|
|
throw new BusinessException("已有其他人正在审核该文件");
|
|
|
}
|
|
|
long currentVersion = System.currentTimeMillis();
|
|
|
- List<WpsVersionDto> list = new ArrayList<>();
|
|
|
- list.add(new WpsVersionDto(ossVo.getFileName(), 0L, ossVo.getUrl(), new Date(), new Date(), Math.toIntExact(document.getCreateTime().getTime() / 1000L), Math.toIntExact(document.getUpdateTime().getTime() / 1000L)));
|
|
|
- list.add(new WpsVersionDto(ossVo.getFileName(), currentVersion, ossVo.getUrl(), new Date(), new Date(), Math.toIntExact(document.getCreateTime().getTime() / 1000L), Math.toIntExact(document.getUpdateTime().getTime() / 1000L)));
|
|
|
- WpsVersionControlDto dto = new WpsVersionControlDto();
|
|
|
+ List<WpsVersionDTO> list = new ArrayList<>();
|
|
|
+ list.add(new WpsVersionDTO(ossVo.getFileName(), 0L, ossVo.getUrl(), new Date(), new Date(), Math.toIntExact(document.getCreateTime().getTime() / 1000L), Math.toIntExact(document.getUpdateTime().getTime() / 1000L)));
|
|
|
+ list.add(new WpsVersionDTO(ossVo.getFileName(), currentVersion, ossVo.getUrl(), new Date(), new Date(), Math.toIntExact(document.getCreateTime().getTime() / 1000L), Math.toIntExact(document.getUpdateTime().getTime() / 1000L)));
|
|
|
+ WpsVersionControlDTO dto = new WpsVersionControlDTO();
|
|
|
dto.setCurrentVersion(currentVersion);
|
|
|
dto.setVersions(list);
|
|
|
dto.setSuffix(ossVo.getFileSuffix());
|
|
|
@@ -275,9 +275,9 @@ public class WpsController extends BaseController {
|
|
|
|
|
|
@PutMapping("/clean/{documentId}")
|
|
|
public R clean(@PathVariable Long documentId) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(documentId);
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(documentId);
|
|
|
long currentVersion = System.currentTimeMillis();
|
|
|
- dto.getVersions().add(new WpsVersionDto(
|
|
|
+ dto.getVersions().add(new WpsVersionDTO(
|
|
|
dto.getVersions().get(0).getFileName(), currentVersion, dto.getVersions().get(0).getUrl(), new Date(), new Date(), Math.toIntExact(new Date().getTime() / 1000L), Math.toIntExact(new Date().getTime() / 1000L)
|
|
|
));
|
|
|
dto.setCurrentVersion(currentVersion);
|
|
|
@@ -291,10 +291,10 @@ public class WpsController extends BaseController {
|
|
|
*/
|
|
|
@GetMapping("/files/{documentId}/versions")
|
|
|
public WpsR getVersions(@PathVariable Long documentId, @RequestParam(value = "offset", required = false) Integer offset, @RequestParam(value = "limit", required = false) Integer size) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(documentId);
|
|
|
- List<WpsVersionDto> versions = dto.getVersions();
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(documentId);
|
|
|
+ List<WpsVersionDTO> versions = dto.getVersions();
|
|
|
|
|
|
- List<WpsVersionDto> reversed = new ArrayList<>(versions);
|
|
|
+ List<WpsVersionDTO> reversed = new ArrayList<>(versions);
|
|
|
Collections.reverse(reversed);
|
|
|
|
|
|
if (offset == null || size == null) {
|
|
|
@@ -304,14 +304,14 @@ public class WpsController extends BaseController {
|
|
|
int fromIndex = Math.min(offset, reversed.size());
|
|
|
int toIndex = Math.min(offset + size, reversed.size());
|
|
|
|
|
|
- List<WpsVersionDto> paginated = reversed.subList(fromIndex, toIndex);
|
|
|
+ List<WpsVersionDTO> paginated = reversed.subList(fromIndex, toIndex);
|
|
|
|
|
|
- List<WpsGetVersionsDto> list = new ArrayList<>();
|
|
|
- paginated.forEach(e -> list.add(new WpsGetVersionsDto(
|
|
|
+ List<WpsGetVersionsDTO> list = new ArrayList<>();
|
|
|
+ paginated.forEach(e -> list.add(new WpsGetVersionsDTO(
|
|
|
String.valueOf(documentId), dto.getFileName(), Math.toIntExact(e.getVersion() / 1000L), dto.getSize(), e.getCreate_time(), e.getUpdate_time(), dto.getCreator(), dto.getUpdator()
|
|
|
)));
|
|
|
|
|
|
- WpsR<List<WpsGetVersionsDto>> r = WpsR.ok(list);
|
|
|
+ WpsR<List<WpsGetVersionsDTO>> r = WpsR.ok(list);
|
|
|
String str = JsonUtils.toJsonString(r);
|
|
|
log.warn(str);
|
|
|
return r;
|
|
|
@@ -322,16 +322,16 @@ public class WpsController extends BaseController {
|
|
|
*/
|
|
|
@GetMapping("/files/{documentId}/versions/{version}")
|
|
|
public WpsR getFileByVersion(@PathVariable Long documentId, @PathVariable Integer version) {
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(documentId);
|
|
|
- WpsVersionDto current = dto.getVersions().get(version - 1);
|
|
|
- return WpsR.ok(new WpsGetVersionsDto(
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(documentId);
|
|
|
+ WpsVersionDTO current = dto.getVersions().get(version - 1);
|
|
|
+ return WpsR.ok(new WpsGetVersionsDTO(
|
|
|
String.valueOf(documentId), dto.getFileName(), Math.toIntExact(current.getVersion() / 1000L), dto.getSize(), current.getCreate_time(), current.getUpdate_time(), dto.getCreator(), dto.getUpdator()
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@GetMapping("/files/list")
|
|
|
- public R<List<WpsVersionDto>> getVersionList(@RequestParam("ossId") Long ossId) {
|
|
|
- List<WpsVersionDto> list = DOCUMENT_MAP.get(ossId).getVersions();
|
|
|
+ public R<List<WpsVersionDTO>> getVersionList(@RequestParam("ossId") Long ossId) {
|
|
|
+ List<WpsVersionDTO> list = DOCUMENT_MAP.get(ossId).getVersions();
|
|
|
list.forEach(e -> log.info("{}", JsonUtils.toJsonString(e)));
|
|
|
return R.ok(list.stream().filter(e -> e.getVersion() != 0L).sorted((e1, e2) -> Math.toIntExact(e2.getVersion() - e1.getVersion())).toList());
|
|
|
}
|
|
|
@@ -344,9 +344,9 @@ public class WpsController extends BaseController {
|
|
|
|
|
|
log.info("文档编号为 {}, 版本号为 : {}", documentId, version);
|
|
|
|
|
|
- WpsVersionControlDto dto = DOCUMENT_MAP.get(documentId);
|
|
|
- List<WpsVersionDto> versions = dto.getVersions();
|
|
|
- for (WpsVersionDto versionDto : versions) {
|
|
|
+ WpsVersionControlDTO dto = DOCUMENT_MAP.get(documentId);
|
|
|
+ List<WpsVersionDTO> versions = dto.getVersions();
|
|
|
+ for (WpsVersionDTO versionDto : versions) {
|
|
|
log.info("当前轮询的版本号为 {}", versionDto.getVersion());
|
|
|
if (versionDto.getVersion() == version) {
|
|
|
String url = versionDto.getUrl();
|