|
|
|
|
@ -3,7 +3,6 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
@ -24,7 +23,6 @@ import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
|
|
|
|
import com.electromagnetic.industry.software.common.util.*;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.other.FileInfoVO;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.other.UploadRecordDTO;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.pojo.req.*;
|
|
|
|
|
@ -36,8 +34,8 @@ import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
|
|
|
|
import com.electromagnetic.industry.software.manage.service.PermissionService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.core.io.FileSystemResource;
|
|
|
|
|
import org.springframework.core.io.InputStreamResource;
|
|
|
|
|
@ -72,6 +70,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
private Environment environment;
|
|
|
|
|
@Resource
|
|
|
|
|
private PermissionService permissionService;
|
|
|
|
|
@Resource
|
|
|
|
|
@Lazy
|
|
|
|
|
private EdFileRelationService edFileRelationService;
|
|
|
|
|
|
|
|
|
|
private String downloadDataDir = "";
|
|
|
|
|
private String uploadDataDir = "";
|
|
|
|
|
@ -175,7 +176,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
res.add(fileProjectVO);
|
|
|
|
|
});
|
|
|
|
|
res.sort(Comparator.comparing(FileProjectVO::getSort));
|
|
|
|
|
return ElectromagneticResultUtil.success(commonService.queryAllPrjInfo(false));
|
|
|
|
|
return ElectromagneticResultUtil.success(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -215,11 +216,12 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath());
|
|
|
|
|
Assert.isTrue(FileUtil.exist(fileSysPath), "下载文件不存在。");
|
|
|
|
|
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
|
|
|
|
|
String fileName = fileSystemResource.getFilename();
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
|
|
|
headers.add("Pragma", "no-cache");
|
|
|
|
|
headers.add("Expires", "0");
|
|
|
|
|
String fileName = Base64.encode(fileSystemResource.getFilename());
|
|
|
|
|
fileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
|
|
|
|
|
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
|
|
|
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
|
|
|
|
return ResponseEntity
|
|
|
|
|
@ -261,13 +263,21 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
} else {
|
|
|
|
|
queryWrapper.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code);
|
|
|
|
|
}
|
|
|
|
|
long count = this.baseMapper.selectCount(Wrappers.<EdFileInfo>lambdaQuery()
|
|
|
|
|
.select(EdFileInfo::getFileName)
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.<EdFileInfo>lambdaQuery()
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFileName)
|
|
|
|
|
.eq(EdFileInfo::getParentId, parentId)
|
|
|
|
|
.eq(EdFileInfo::getFileName, updateFileInfoDTO.getFileName())
|
|
|
|
|
.eq(EdFileInfo::getFileType, fileInfo.getFileType())
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
|
|
|
|
Assert.isTrue(count == 0, "文件名已存在");
|
|
|
|
|
Map<String, EdFileInfo> map = edFileInfos.stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
|
|
|
|
if (map.size() == 1) {
|
|
|
|
|
if (!map.values().iterator().next().getId().equals(updateFileInfoDTO.getId())) {
|
|
|
|
|
throw new BizException(-1, "文件名已经存在");
|
|
|
|
|
}
|
|
|
|
|
} else if (map.size() > 1) {
|
|
|
|
|
log.warn("数据库中存在了两份同名同后缀的文件");
|
|
|
|
|
throw new BizException(-1, "文件名已经存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath());
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
@ -563,13 +573,14 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
@Override
|
|
|
|
|
public ResponseEntity<InputStreamResource> batchExport(String dataIdArr, HttpServletResponse response) throws IOException {
|
|
|
|
|
String[] ids = dataIdArr.split(",");
|
|
|
|
|
List<EdFileInfo> resFiles = new ArrayList<>();
|
|
|
|
|
Map<String, EdFileInfo> maps = new HashMap<>();
|
|
|
|
|
for (String id : ids) {
|
|
|
|
|
List<EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
Map<String, EdFileInfo> edFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT)
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, true));
|
|
|
|
|
resFiles.addAll(edFileInfos);
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)).stream().collect(Collectors.toMap(EdFileInfo::getId, e -> e));
|
|
|
|
|
maps.putAll(edFileInfos);
|
|
|
|
|
}
|
|
|
|
|
List<EdFileInfo> resFiles = new ArrayList<>(maps.values());
|
|
|
|
|
String prjId = resFiles.get(0).getFilePath().split(MYSQL_FILE_PATH_SPLIT)[0];
|
|
|
|
|
List<EdFileInfo> prjFolders = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.likeRight(EdFileInfo::getFilePath, prjId + MYSQL_FILE_PATH_SPLIT)
|
|
|
|
|
@ -734,8 +745,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
|
|
|
|
|
// 获取原文件mysql模型
|
|
|
|
|
EdFileInfo srcFileInfo = this.baseMapper.selectById(id);
|
|
|
|
|
String srcFileDbPath = srcFileInfo.getFilePath();
|
|
|
|
|
String fileCode = srcFileInfo.getFileCode();
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
// 判断目标路径下是否有同名文件,如果所有的同名文件:1)如果所有文件都已经被作废,则该文件为新文件,版本号从100开始。2)如果有没有被作废的文件,则冲突处理方式按---1-跳过冲突文件 2-做版本更新 3-重命名,文件名加"_1"
|
|
|
|
|
long count = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
@ -757,8 +767,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
.setFileCode(newFileCode);
|
|
|
|
|
this.baseMapper.updateById(srcFileInfo);
|
|
|
|
|
// 文件系统移动文件
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileDbPath);
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destFolderInfo.getFilePath());
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
fileSystemService.moveFile(srcFilePath, destFilePath);
|
|
|
|
|
} else {
|
|
|
|
|
return handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo);
|
|
|
|
|
@ -880,9 +889,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> lambdaQuery = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.select(EdFileInfo::getId, EdFileInfo::getFileName, EdFileInfo::getSaveStatus, EdFileInfo::getCreatedTime, EdFileInfo::getFileType)
|
|
|
|
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FILE.code)
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
|
|
|
|
.likeRight(EdFileInfo::getFilePath, prjIds.get(0));
|
|
|
|
|
for (int i = 1; i < pageSize; i++) {
|
|
|
|
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
|
|
|
|
for (int i = 0; i < prjIds.size(); i++) {
|
|
|
|
|
lambdaQuery.or().likeRight(EdFileInfo::getFilePath, prjIds.get(i));
|
|
|
|
|
}
|
|
|
|
|
Page<EdFileInfo> edFileInfoPage = this.baseMapper.selectPage(new Page<>(pageNum, pageSize), lambdaQuery);
|
|
|
|
|
@ -914,10 +922,11 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
|
|
|
|
|
if (strategy == 2) {
|
|
|
|
|
// 做版本更新
|
|
|
|
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
|
|
|
|
|
.eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()));
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType());
|
|
|
|
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(queryWrapper);
|
|
|
|
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
|
|
|
|
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
|
|
|
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
|
|
|
|
@ -931,6 +940,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|
|
|
|
.setPreVersion(maxFileVersion)
|
|
|
|
|
.setEffectFlag(EffectFlagEnum.EFFECT.code)
|
|
|
|
|
.setFileCode(fileCode);
|
|
|
|
|
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class).eq(EdFileInfo::getParentId, targetFolderId)
|
|
|
|
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
|
|
|
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()).set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
|
|
|
|
|
this.baseMapper.insert(destSaveFileInfo);
|
|
|
|
|
String srcFilePath = commonService.getFileSysPath(srcFileInfo.getFilePath());
|
|
|
|
|
String destFilePath = commonService.getFileSysPath(destSaveFileInfo.getFilePath());
|
|
|
|
|
|