|
@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
-import com.example.fms.common.model.dto.FileVersionCallbackHistoryDTO;
|
|
|
|
-import com.example.fms.common.model.dto.ForceSaveDTO;
|
|
|
|
-import com.example.fms.common.model.dto.QueryFileVersionDTO;
|
|
|
|
-import com.example.fms.common.model.dto.RestoreFileVersionDTO;
|
|
|
|
|
|
+import com.example.fms.common.model.dto.*;
|
|
import com.example.fms.common.model.vo.FileVersionInfoVO;
|
|
import com.example.fms.common.model.vo.FileVersionInfoVO;
|
|
import com.example.fms.common.model.vo.ForceSaveVO;
|
|
import com.example.fms.common.model.vo.ForceSaveVO;
|
|
import com.example.fms.common.model.vo.QueryFileVersionHistoryVO;
|
|
import com.example.fms.common.model.vo.QueryFileVersionHistoryVO;
|
|
@@ -25,6 +22,7 @@ import com.example.fms.service.permissions.MessageService;
|
|
import com.example.fms.service.permissions.PermissionService;
|
|
import com.example.fms.service.permissions.PermissionService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.compress.utils.IOUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -34,8 +32,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
@@ -70,16 +67,24 @@ public class FileVersionService {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
public Integer callback(Map<String, Object> params, String guid, String fileName,
|
|
public Integer callback(Map<String, Object> params, String guid, String fileName,
|
|
- String user, Integer previousVersion) throws IOException {
|
|
|
|
|
|
+ String user, String previousVersion) throws Exception {
|
|
boolean flag = true;
|
|
boolean flag = true;
|
|
if (!CollectionUtils.isEmpty(params)) {
|
|
if (!CollectionUtils.isEmpty(params)) {
|
|
int status = Integer.parseInt(params.get("status").toString());
|
|
int status = Integer.parseInt(params.get("status").toString());
|
|
- String url = params.get("url").toString();
|
|
|
|
- String changesUrl = params.get("changesurl").toString();
|
|
|
|
|
|
+ if (status != 2 && status != 6) {
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ String url = "";
|
|
|
|
+ if (ObjectUtils.isNotEmpty(params.get("url"))) {
|
|
|
|
+ url = params.get("url").toString();
|
|
|
|
+ }
|
|
|
|
+ String changesUrl = "";
|
|
|
|
+ if (ObjectUtils.isNotEmpty(params.get("changesurl"))) {
|
|
|
|
+ changesUrl = params.get("changesurl").toString();
|
|
|
|
+ }
|
|
if (status == 6 && StringUtils.isNotEmpty(url)) {
|
|
if (status == 6 && StringUtils.isNotEmpty(url)) {
|
|
- File file = FileUtils.urlToFile(url);
|
|
|
|
- MultipartFile multipartFile = FileUtils.fileToMultipartFile(file);
|
|
|
|
- String replaceFile = fileMangerService.replaceFile(multipartFile, guid, 1);
|
|
|
|
|
|
+ MultipartFile multipartFile = FileUtils.urlToMultipartFile(url, fileName);
|
|
|
|
+ String replaceFile = fileMangerService.replaceFile(multipartFile, guid, 6);
|
|
if (StringUtils.isEmpty(replaceFile)) {
|
|
if (StringUtils.isEmpty(replaceFile)) {
|
|
flag = false;
|
|
flag = false;
|
|
}
|
|
}
|
|
@@ -90,9 +95,8 @@ public class FileVersionService {
|
|
}
|
|
}
|
|
if (status == 2) {
|
|
if (status == 2) {
|
|
if (StringUtils.isNotEmpty(url)) {
|
|
if (StringUtils.isNotEmpty(url)) {
|
|
- File file = FileUtils.urlToFile(url);
|
|
|
|
- MultipartFile multipartFile = FileUtils.fileToMultipartFile(file);
|
|
|
|
- List<String> list = fileMangerService.uploadFile(Arrays.asList(multipartFile), 1);
|
|
|
|
|
|
+ MultipartFile multipartFile = FileUtils.urlToMultipartFile(url, fileName);
|
|
|
|
+ List<String> list = fileMangerService.uploadFile(Collections.singletonList(multipartFile), 6);
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
if (!CollectionUtils.isEmpty(list)) {
|
|
url = list.get(0);
|
|
url = list.get(0);
|
|
} else {
|
|
} else {
|
|
@@ -100,15 +104,23 @@ public class FileVersionService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (StringUtils.isNotEmpty(changesUrl)) {
|
|
if (StringUtils.isNotEmpty(changesUrl)) {
|
|
- File file1 = FileUtils.urlToFile(changesUrl);
|
|
|
|
- MultipartFile multipartFile1 = FileUtils.fileToMultipartFile(file1);
|
|
|
|
- List<String> list1 = fileMangerService.uploadFile(Arrays.asList(multipartFile1), 1);
|
|
|
|
|
|
+ MultipartFile multipartFile1 = FileUtils.urlToMultipartFile(changesUrl, fileName);
|
|
|
|
+ List<String> list1 = fileMangerService.uploadFile(Collections.singletonList(multipartFile1), 6);
|
|
if (!CollectionUtils.isEmpty(list1)) {
|
|
if (!CollectionUtils.isEmpty(list1)) {
|
|
changesUrl = list1.get(0);
|
|
changesUrl = list1.get(0);
|
|
} else {
|
|
} else {
|
|
changesUrl = "";
|
|
changesUrl = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (StringUtils.equals(fileName, "undefined")) {
|
|
|
|
+ fileName = "";
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.equals(user, "undefined")) {
|
|
|
|
+ user = "";
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.equals(previousVersion, "undefined")) {
|
|
|
|
+ previousVersion = "";
|
|
|
|
+ }
|
|
this.addFileVersion(params, guid, fileName, user, previousVersion, url, changesUrl);
|
|
this.addFileVersion(params, guid, fileName, user, previousVersion, url, changesUrl);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -120,17 +132,25 @@ public class FileVersionService {
|
|
}
|
|
}
|
|
|
|
|
|
public void addFileVersion(Map<String, Object> params, String guid, String fileName,
|
|
public void addFileVersion(Map<String, Object> params, String guid, String fileName,
|
|
- String user, Integer previousVersion, String url,
|
|
|
|
|
|
+ String user, String previousVersion, String url,
|
|
String changesUrl) throws IOException {
|
|
String changesUrl) throws IOException {
|
|
- String fileType = params.get("filetype").toString();
|
|
|
|
- String key = RandomUtil.generateInvitationCode();
|
|
|
|
|
|
+ String fileType = "";
|
|
|
|
+ if (ObjectUtils.isNotEmpty(params.get("filetype"))) {
|
|
|
|
+ fileType = params.get("filetype").toString();
|
|
|
|
+ }
|
|
String changes = "";
|
|
String changes = "";
|
|
String serverVersion = "";
|
|
String serverVersion = "";
|
|
- String history = params.get("history").toString();
|
|
|
|
|
|
+ String history = "";
|
|
|
|
+ if (ObjectUtils.isNotEmpty(params.get("history"))) {
|
|
|
|
+ history = params.get("history").toString();
|
|
|
|
+ }
|
|
if (StringUtils.isNotEmpty(history)) {
|
|
if (StringUtils.isNotEmpty(history)) {
|
|
- FileVersionCallbackHistoryDTO historyDTO = JSONObject.parseObject(history, FileVersionCallbackHistoryDTO.class);
|
|
|
|
- changes = historyDTO.getChanges();
|
|
|
|
- serverVersion = historyDTO.getServerVersion();
|
|
|
|
|
|
+ String strip = StringUtils.strip(history, "{}");
|
|
|
|
+ int i = strip.indexOf(",");
|
|
|
|
+ String s1 = strip.substring(0, i);
|
|
|
|
+ serverVersion = s1.trim().substring(s1.indexOf("=") + 1);
|
|
|
|
+ String s2 = strip.substring(i + 1);
|
|
|
|
+ changes = s2.trim().substring(s2.indexOf("=") + 1);
|
|
}
|
|
}
|
|
int version = 1;
|
|
int version = 1;
|
|
String originalFile = guid;
|
|
String originalFile = guid;
|
|
@@ -142,26 +162,29 @@ public class FileVersionService {
|
|
FileVersion fileVersion1 = new FileVersion();
|
|
FileVersion fileVersion1 = new FileVersion();
|
|
fileVersion1.setFileName(fileName);
|
|
fileVersion1.setFileName(fileName);
|
|
fileVersion1.setFileType(fileType);
|
|
fileVersion1.setFileType(fileType);
|
|
- fileVersion1.setFileKey(key);
|
|
|
|
- fileVersion1.setUrl(url);
|
|
|
|
|
|
+ fileVersion1.setFileKey(RandomUtil.generateInvitationCode());
|
|
|
|
+ fileVersion1.setUrl(guid);
|
|
fileVersion1.setVersion(version);
|
|
fileVersion1.setVersion(version);
|
|
fileVersion1.setOriginalFile(guid);
|
|
fileVersion1.setOriginalFile(guid);
|
|
fileVersion1.setUser(user);
|
|
fileVersion1.setUser(user);
|
|
fileVersion1.insert();
|
|
fileVersion1.insert();
|
|
|
|
+ previousVersion = "1";
|
|
}
|
|
}
|
|
version += 1;
|
|
version += 1;
|
|
//添加新版本数据
|
|
//添加新版本数据
|
|
FileVersion version1 = new FileVersion();
|
|
FileVersion version1 = new FileVersion();
|
|
version1.setFileName(fileName);
|
|
version1.setFileName(fileName);
|
|
version1.setFileType(fileType);
|
|
version1.setFileType(fileType);
|
|
- version1.setFileKey(key);
|
|
|
|
|
|
+ version1.setFileKey(RandomUtil.generateInvitationCode());
|
|
version1.setUrl(url);
|
|
version1.setUrl(url);
|
|
version1.setChangesUrl(changesUrl);
|
|
version1.setChangesUrl(changesUrl);
|
|
version1.setVersion(version);
|
|
version1.setVersion(version);
|
|
version1.setOriginalFile(originalFile);
|
|
version1.setOriginalFile(originalFile);
|
|
version1.setChanges(changes);
|
|
version1.setChanges(changes);
|
|
version1.setServerVersion(serverVersion);
|
|
version1.setServerVersion(serverVersion);
|
|
- version1.setPreviousVersion(previousVersion);
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(previousVersion)) {
|
|
|
|
+ version1.setPreviousVersion(Integer.valueOf(previousVersion));
|
|
|
|
+ }
|
|
version1.setUser(user);
|
|
version1.setUser(user);
|
|
version1.insert();
|
|
version1.insert();
|
|
|
|
|
|
@@ -180,7 +203,9 @@ public class FileVersionService {
|
|
operateRecord.setUserName(personnel.getPersonnelName());
|
|
operateRecord.setUserName(personnel.getPersonnelName());
|
|
}
|
|
}
|
|
operateRecord.setCurrentVersion(version);
|
|
operateRecord.setCurrentVersion(version);
|
|
- operateRecord.setPreviousVersion(previousVersion);
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(previousVersion)) {
|
|
|
|
+ operateRecord.setPreviousVersion(Integer.valueOf(previousVersion));
|
|
|
|
+ }
|
|
operateRecord.setOperate("2");
|
|
operateRecord.setOperate("2");
|
|
operateRecord.setOriginalFile(originalFile);
|
|
operateRecord.setOriginalFile(originalFile);
|
|
operateRecord.insert();
|
|
operateRecord.insert();
|
|
@@ -193,7 +218,7 @@ public class FileVersionService {
|
|
public void restoreFileVersion(RestoreFileVersionDTO vo) {
|
|
public void restoreFileVersion(RestoreFileVersionDTO vo) {
|
|
Integer currentVersion = vo.getRestoreVersion();
|
|
Integer currentVersion = vo.getRestoreVersion();
|
|
Integer previousVersion = vo.getPreviousVersion();
|
|
Integer previousVersion = vo.getPreviousVersion();
|
|
- String guid = vo.getOriginalFile();
|
|
|
|
|
|
+ String guid = vo.getGuid();
|
|
String userId = vo.getUserId();
|
|
String userId = vo.getUserId();
|
|
String userName = vo.getUserName();
|
|
String userName = vo.getUserName();
|
|
//新增操作记录
|
|
//新增操作记录
|
|
@@ -291,7 +316,7 @@ public class FileVersionService {
|
|
infoVO.setKey(i.getFileKey());
|
|
infoVO.setKey(i.getFileKey());
|
|
fileVersionInfoVOS.add(infoVO);
|
|
fileVersionInfoVOS.add(infoVO);
|
|
});
|
|
});
|
|
- historyVO.setFileVersionInfoVOS(fileVersionInfoVOS);
|
|
|
|
|
|
+ historyVO.setHistory(fileVersionInfoVOS);
|
|
}
|
|
}
|
|
FileOperateRecord operateRecord = fileVersionMapper.queryFileOperateRecord(vo.getGuid());
|
|
FileOperateRecord operateRecord = fileVersionMapper.queryFileOperateRecord(vo.getGuid());
|
|
if (ObjectUtils.isNotEmpty(operateRecord)) {
|
|
if (ObjectUtils.isNotEmpty(operateRecord)) {
|